blob: 22c6a0d4597c23ca6928e2dab3603dc360e16fcf [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
Klement Sekera73884482017-02-23 09:26:30 +010039class UnexpectedApiReturnValueError(Exception):
40 """ exception raised when the API return value is unexpected """
41 pass
42
43
Klement Sekeraf62ae122016-10-11 11:47:09 +020044class VppPapiProvider(object):
45 """VPP-api provider using vpp-papi
46
47 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020048 """
49
Klement Sekerae0545ef2017-01-25 08:00:40 +010050 _zero, _negative = range(2)
51
Klement Sekera7bb873a2016-11-18 07:38:42 +010052 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020053 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020054 self.name = name
55 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010056 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010057 self._expect_api_retval = self._zero
58 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010059 jsonfiles = []
60
Klement Sekera0e3c0de2016-09-29 14:43:44 +020061 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010062 for root, dirnames, filenames in os.walk(install_dir):
63 for filename in fnmatch.filter(filenames, '*.api.json'):
64 jsonfiles.append(os.path.join(root, filename))
65
Ole Troan3cc49712017-03-08 12:02:24 +010066 self.vpp = VPP(jsonfiles, logger=test_class.logger)
Klement Sekerae4504c62016-12-08 10:16:41 +010067 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020068
Klement Sekerae0545ef2017-01-25 08:00:40 +010069 def __enter__(self):
70 return self
71
72 def expect_negative_api_retval(self):
73 """ Expect API failure """
74 self._expect_stack.append(self._expect_api_retval)
75 self._expect_api_retval = self._negative
76 return self
77
78 def expect_zero_api_retval(self):
79 """ Expect API success """
80 self._expect_stack.append(self._expect_api_retval)
81 self._expect_api_retval = self._zero
82 return self
83
84 def __exit__(self, exc_type, exc_value, traceback):
85 self._expect_api_retval = self._expect_stack.pop()
86
Klement Sekeraf62ae122016-10-11 11:47:09 +020087 def register_hook(self, hook):
88 """Replace hook registration with new hook
89
90 :param hook:
91
92 """
93 self.hook = hook
94
Klement Sekera0e3c0de2016-09-29 14:43:44 +020095 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +010096 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +020097 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +010098 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +020099 return e
100
101 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100102 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100103 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100104 self.test_class.logger.debug("Expecting event '%s' within %ss",
105 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300106 else:
107 self.test_class.logger.debug("Expecting event within %ss",
108 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100109 if self._events:
110 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200111 limit = time.time() + timeout
112 while time.time() < limit:
113 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100114 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200115 if name and type(e).__name__ != name:
116 raise Exception(
117 "Unexpected event received: %s, expected: %s" %
118 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100119 self.test_class.logger.debug("Returning event %s:%s" %
120 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200121 return e
122 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200123 raise Exception("Event did not occur within timeout")
124
125 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200127 # FIXME use the name instead of relying on type(e).__name__ ?
128 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100129 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200130 self._events.append(event)
131
Klement Sekeraf62ae122016-10-11 11:47:09 +0200132 def connect(self):
133 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100134 self.vpp.connect(self.name, self.shm_prefix)
135 self.papi = self.vpp.api
136 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200137
138 def disconnect(self):
139 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100140 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200141
142 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200144 Call the appropriate hooks before and after the API call
145
146 :param api_fn: API function to call
147 :param api_args: tuple of API function arguments
148 :param expected_retval: Expected return value (Default value = 0)
149 :returns: reply from the API
150
151 """
152 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100153 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100154 if self._expect_api_retval == self._negative:
155 if hasattr(reply, 'retval') and reply.retval >= 0:
156 msg = "API call passed unexpectedly: expected negative "\
157 "return value instead of %d in %s" % \
158 (reply.retval, repr(reply))
159 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100160 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100161 elif self._expect_api_retval == self._zero:
162 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700163 msg = "API call failed, expected %d return value instead "\
164 "of %d in %s" % (expected_retval, reply.retval,
165 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100166 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 else:
169 raise Exception("Internal error, unexpected value for "
170 "self._expect_api_retval %s" %
171 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200172 self.hook.after_api(api_fn.__name__, api_args)
173 return reply
174
175 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100176 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200177
178 :param cli: CLI to execute
179 :returns: CLI output
180
181 """
182 self.hook.before_cli(cli)
183 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100184 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200185 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200186 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100187 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188
Jan49c0fca2016-10-26 15:44:27 +0200189 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100190 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200191
192 :param cli: CLI to execute
193 :returns: CLI output
194 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600195 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200196
Jan4af521d2016-11-15 17:05:00 +0100197 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200198 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100199
Klement Sekeraf62ae122016-10-11 11:47:09 +0200200 def show_version(self):
201 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100202 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203
204 def pg_create_interface(self, pg_index):
205 """
206
207 :param pg_index:
208
209 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100210 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200211 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212
213 def sw_interface_dump(self, filter=None):
214 """
215
216 :param filter: (Default value = None)
217
218 """
219 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100222 args = {}
223 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200224
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000225 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100226 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000227
228 :param sw_if_index:
229 :param is_ipv6:
230 :param table_id:
231
232 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100233 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
235 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000236
Klement Sekeraf62ae122016-10-11 11:47:09 +0200237 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
238 is_ipv6=0, is_add=1, del_all=0):
239 """
240
241 :param addr: param is_ipv6: (Default value = 0)
242 :param sw_if_index:
243 :param addr_len:
244 :param is_ipv6: (Default value = 0)
245 :param is_add: (Default value = 1)
246 :param del_all: (Default value = 0)
247
248 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100249 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200250 {'sw_if_index': sw_if_index,
251 'is_add': is_add,
252 'is_ipv6': is_ipv6,
253 'del_all': del_all,
254 'address_length': addr_len,
255 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200256
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800257 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
258 is_add=1):
259 """ Set the Interface to be unnumbered
260
261 :param is_add: (Default value = 1)
262 :param sw_if_index - interface That will be unnumbered
263 :param ip_sw_if_index - interface with an IP addres
264
265 """
266 return self.api(self.papi.sw_interface_set_unnumbered,
267 {'sw_if_index': ip_sw_if_index,
268 'unnumbered_sw_if_index': sw_if_index,
269 'is_add': is_add})
270
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000271 def sw_interface_enable_disable_mpls(self, sw_if_index,
272 is_enable=1):
273 """
274 Enable/Disable MPLS on the interface
275 :param sw_if_index:
276 :param is_enable: (Default value = 1)
277
278 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100279 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200280 {'sw_if_index': sw_if_index,
281 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000282
Jan Gelety057bb8c2016-12-20 17:32:45 +0100283 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100284 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100285 {'sw_if_index': sw_if_index,
286 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200287
Neale Ranns227038a2017-04-21 01:07:59 -0700288 def set_ip_flow_hash(self,
289 table_id,
290 src=1,
291 dst=1,
292 sport=1,
293 dport=1,
294 proto=1,
295 reverse=0,
296 is_ip6=0):
297 return self.api(self.papi.set_ip_flow_hash,
298 {'vrf_id': table_id,
299 'src': src,
300 'dst': dst,
301 'dport': dport,
302 'sport': sport,
303 'proto': proto,
304 'reverse': reverse,
305 'is_ipv6': is_ip6})
306
Neale Ranns3f844d02017-02-18 00:03:54 -0800307 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
308 return self.api(self.papi.ip6nd_proxy_add_del,
309 {'address': address,
310 'sw_if_index': sw_if_index,
311 'is_del': is_del})
312
Neale Ranns75152282017-01-09 01:00:45 -0800313 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000314 no,
Neale Ranns75152282017-01-09 01:00:45 -0800315 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000316 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800317 return self.api(self.papi.sw_interface_ip6nd_ra_config,
318 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000319 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100320 'suppress': suppress,
321 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800322
Neale Ranns87df12d2017-02-18 08:16:41 -0800323 def ip6_sw_interface_ra_prefix(self,
324 sw_if_index,
325 address,
326 address_length,
327 use_default=0,
328 no_advertise=0,
329 off_link=0,
330 no_autoconfig=0,
331 no_onlink=0,
332 is_no=0,
333 val_lifetime=0xffffffff,
334 pref_lifetime=0xffffffff):
335 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
336 {'sw_if_index': sw_if_index,
337 'address': address,
338 'address_length': address_length,
339 'use_default': use_default,
340 'no_advertise': no_advertise,
341 'off_link': off_link,
342 'no_autoconfig': no_autoconfig,
343 'no_onlink': no_onlink,
344 'is_no': is_no,
345 'val_lifetime': val_lifetime,
346 'pref_lifetime': pref_lifetime})
347
Neale Ranns75152282017-01-09 01:00:45 -0800348 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
349 """
350 Enable/Disable An interface for IPv6
351 """
352 return self.api(self.papi.sw_interface_ip6_enable_disable,
353 {'sw_if_index': sw_if_index,
354 'enable': enable})
355
Klement Sekeraf62ae122016-10-11 11:47:09 +0200356 def vxlan_add_del_tunnel(
357 self,
358 src_addr,
359 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200360 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200361 is_add=1,
362 is_ipv6=0,
363 encap_vrf_id=0,
364 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600365 vni=0,
366 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200367 """
368
369 :param dst_addr:
370 :param src_addr:
371 :param is_add: (Default value = 1)
372 :param is_ipv6: (Default value = 0)
373 :param encap_vrf_id: (Default value = 0)
374 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200375 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200376 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600377 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200378
379 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100380 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200381 {'is_add': is_add,
382 'is_ipv6': is_ipv6,
383 'src_address': src_addr,
384 'dst_address': dst_addr,
385 'mcast_sw_if_index': mcast_sw_if_index,
386 'encap_vrf_id': encap_vrf_id,
387 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600388 'vni': vni,
389 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200390
Marco Varleseb598f1d2017-09-19 14:25:28 +0200391 def geneve_add_del_tunnel(
392 self,
393 local_addr,
394 remote_addr,
395 mcast_sw_if_index=0xFFFFFFFF,
396 is_add=1,
397 is_ipv6=0,
398 encap_vrf_id=0,
399 decap_next_index=0xFFFFFFFF,
400 vni=0):
401 """
402
403 :param remote_addr:
404 :param local_addr:
405 :param is_add: (Default value = 1)
406 :param is_ipv6: (Default value = 0)
407 :param encap_vrf_id: (Default value = 0)
408 :param decap_next_index: (Default value = 0xFFFFFFFF)
409 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
410 :param vni: (Default value = 0)
411
412 """
413 return self.api(self.papi.geneve_add_del_tunnel,
414 {'is_add': is_add,
415 'is_ipv6': is_ipv6,
416 'local_address': local_addr,
417 'remote_address': remote_addr,
418 'mcast_sw_if_index': mcast_sw_if_index,
419 'encap_vrf_id': encap_vrf_id,
420 'decap_next_index': decap_next_index,
421 'vni': vni})
422
Jan4af521d2016-11-15 17:05:00 +0100423 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
424 learn=1, arp_term=0, is_add=1):
425 """Create/delete bridge domain.
426
427 :param int bd_id: Bridge domain index.
428 :param int flood: Enable/disable bcast/mcast flooding in the BD.
429 (Default value = 1)
430 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
431 (Default value = 1)
432 :param int forward: Enable/disable forwarding on all interfaces in
433 the BD. (Default value = 1)
434 :param int learn: Enable/disable learning on all interfaces in the BD.
435 (Default value = 1)
436 :param int arp_term: Enable/disable arp termination in the BD.
437 (Default value = 1)
438 :param int is_add: Add or delete flag. (Default value = 1)
439 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100440 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200441 {'bd_id': bd_id,
442 'flood': flood,
443 'uu_flood': uu_flood,
444 'forward': forward,
445 'learn': learn,
446 'arp_term': arp_term,
447 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100448
Eyal Baric86e5922017-07-02 18:33:16 +0300449 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
450 return self.api(self.papi.bd_ip_mac_add_del,
451 {'bd_id': bd_id,
452 'is_add': is_add,
453 'is_ipv6': is_ipv6,
454 'ip_address': ip,
455 'mac_address': mac})
456
Eyal Bari20197482017-09-13 12:29:08 +0300457 def want_ip4_arp_events(self, enable_disable=1, address=0):
458 return self.api(self.papi.want_ip4_arp_events,
459 {'enable_disable': enable_disable,
460 'address': address,
461 'pid': os.getpid(), })
462
Eyal Baric125ecc2017-09-20 11:29:17 +0300463 def want_ip6_nd_events(self, enable_disable=1, address=0):
464 return self.api(self.papi.want_ip6_nd_events,
465 {'enable_disable': enable_disable,
466 'address': address,
467 'pid': os.getpid(), })
468
Eyal Bari24db0ec2017-09-27 21:43:51 +0300469 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
470 max_macs_in_event=0, learn_limit=0):
471 return self.api(self.papi.want_l2_macs_events,
472 {'enable_disable': enable_disable,
473 'scan_delay': scan_delay,
474 'max_macs_in_event': max_macs_in_event,
475 'learn_limit': learn_limit,
476 'pid': os.getpid(), })
477
Jan4af521d2016-11-15 17:05:00 +0100478 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
479 filter_mac=0, bvi_mac=0):
480 """Create/delete L2 FIB entry.
481
482 :param str mac: MAC address to create FIB entry for.
483 :param int bd_id: Bridge domain index.
484 :param int sw_if_index: Software interface index of the interface.
485 :param int is_add: Add or delete flag. (Default value = 1)
486 :param int static_mac: Set to 1 to create static MAC entry.
487 (Default value = 0)
488 :param int filter_mac: Set to 1 to drop packet that's source or
489 destination MAC address contains defined MAC address.
490 (Default value = 0)
491 :param int bvi_mac: Set to 1 to create entry that points to BVI
492 interface. (Default value = 0)
493 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100494 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200495 {'mac': self._convert_mac(mac),
496 'bd_id': bd_id,
497 'sw_if_index': sw_if_index,
498 'is_add': is_add,
499 'static_mac': static_mac,
500 'filter_mac': filter_mac,
501 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100502
Eyal Bari93b503e2017-05-15 10:13:15 +0300503 def l2fib_flush_int(self, sw_if_index):
504 """Flush L2 FIB entries for sw_if_index.
505
506 :param int sw_if_index: Software interface index of the interface.
507 """
508 return self.api(self.papi.l2fib_flush_int,
509 {'sw_if_index': sw_if_index})
510
511 def l2fib_flush_bd(self, bd_id):
512 """Flush L2 FIB entries for bd_id.
513
514 :param int sw_if_index: Bridge Domain id.
515 """
516 return self.api(self.papi.l2fib_flush_bd,
517 {'bd_id': bd_id})
518
519 def l2fib_flush_all(self):
520 """Flush all L2 FIB.
521 """
522 return self.api(self.papi.l2fib_flush_all, {})
523
Klement Sekeraf62ae122016-10-11 11:47:09 +0200524 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
525 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100526 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200527
Jan4af521d2016-11-15 17:05:00 +0100528 :param int sw_if_index: Software interface index of the interface.
529 :param int bd_id: Bridge domain index.
530 :param int shg: Split-horizon group index. (Default value = 0)
531 :param int bvi: Set interface as a bridge group virtual interface.
532 (Default value = 0)
533 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200534 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100535 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200536 {'rx_sw_if_index': sw_if_index,
537 'bd_id': bd_id,
538 'shg': shg,
539 'bvi': bvi,
540 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200541
Jan00dad122016-11-29 10:04:53 +0100542 def bridge_flags(self, bd_id, is_set, feature_bitmap):
543 """Enable/disable required feature of the bridge domain with defined ID.
544
545 :param int bd_id: Bridge domain ID.
546 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
547 :param int feature_bitmap: Bitmap value of the feature to be set:
548 - learn (1 << 0),
549 - forward (1 << 1),
550 - flood (1 << 2),
551 - uu-flood (1 << 3) or
552 - arp-term (1 << 4).
553 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100554 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200555 {'bd_id': bd_id,
556 'is_set': is_set,
557 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100558
559 def bridge_domain_dump(self, bd_id=0):
560 """
561
562 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
563 existing bridge domains returned)
564 :return: Dictionary of bridge domain(s) data.
565 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100566 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200567 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100568
Klement Sekeraf62ae122016-10-11 11:47:09 +0200569 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
570 enable):
571 """Create or delete unidirectional cross-connect from Tx interface to
572 Rx interface.
573
Jan4af521d2016-11-15 17:05:00 +0100574 :param int rx_sw_if_index: Software interface index of Rx interface.
575 :param int tx_sw_if_index: Software interface index of Tx interface.
576 :param int enable: Create cross-connect if equal to 1, delete
577 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200578
579 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100580 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200581 {'rx_sw_if_index': rx_sw_if_index,
582 'tx_sw_if_index': tx_sw_if_index,
583 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200584
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200585 def sw_interface_set_l2_tag_rewrite(
586 self,
587 sw_if_index,
588 vtr_oper,
589 push=0,
590 tag1=0,
591 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000592 """L2 interface vlan tag rewrite configure request
593 :param client_index - opaque cookie to identify the sender
594 :param context - sender context, to match reply w/ request
595 :param sw_if_index - interface the operation is applied to
596 :param vtr_op - Choose from l2_vtr_op_t enum values
597 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
598 :param tag1 - Needed for any push or translate vtr op
599 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
600
601 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100602 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200603 {'sw_if_index': sw_if_index,
604 'vtr_op': vtr_oper,
605 'push_dot1q': push,
606 'tag1': tag1,
607 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000608
Neale Ranns55d03782017-10-21 06:34:22 -0700609 def sw_interface_set_l2_emulation(
610 self,
611 sw_if_index,
612 enable=1):
613 """L2 Emulation
614 :param sw_if_index - interface the operation is applied to
615
616 """
617 return self.api(self.papi.l2_emulation,
618 {'sw_if_index': sw_if_index,
619 'enable': enable})
620
Neale Rannsa07bd702017-08-07 07:53:49 -0700621 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200622 """
623
624 :param admin_up_down:
625 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200626
627 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100628 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200629 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700630 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200631
Neale Rannsffd78d12018-02-09 06:05:16 -0800632 def sw_interface_set_mtu(self, sw_if_index, mtu):
633 """
634 :param sw_if_index:
635 :param mtu:
636
637 """
638 return self.api(self.papi.sw_interface_set_mtu,
639 {'sw_if_index': sw_if_index,
640 'mtu': mtu})
641
Neale Rannsc819fc62018-02-16 02:44:05 -0800642 def sw_interface_set_mac_address(self, sw_if_index, mac):
643 return self.api(self.papi.sw_interface_set_mac_address,
644 {'sw_if_index': sw_if_index,
645 'mac_address': mac})
646
Klement Sekeraf62ae122016-10-11 11:47:09 +0200647 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
648 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
649 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
650 """Create subinterface
651 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
652
653 :param sub_id: param inner_vlan:
654 :param sw_if_index:
655 :param outer_vlan:
656 :param inner_vlan:
657 :param no_tags: (Default value = 0)
658 :param one_tag: (Default value = 0)
659 :param two_tags: (Default value = 0)
660 :param dot1ad: (Default value = 0)
661 :param exact_match: (Default value = 0)
662 :param default_sub: (Default value = 0)
663 :param outer_vlan_id_any: (Default value = 0)
664 :param inner_vlan_id_any: (Default value = 0)
665
666 """
667 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100668 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200669 {'sw_if_index': sw_if_index,
670 'sub_id': sub_id,
671 'no_tags': no_tags,
672 'one_tag': one_tag,
673 'two_tags': two_tags,
674 'dot1ad': dot1ad,
675 'exact_match': exact_match,
676 'default_sub': default_sub,
677 'outer_vlan_id_any': outer_vlan_id_any,
678 'inner_vlan_id_any': inner_vlan_id_any,
679 'outer_vlan_id': outer_vlan,
680 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200681
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200682 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
683 """Create p2p ethernet subinterface
684
685 :param sw_if_index: main (parent) interface
686 :param remote_mac: client (remote) mac address
687
688 """
689 return self.api(
690 self.papi.p2p_ethernet_add,
691 {'parent_if_index': sw_if_index,
692 'remote_mac': remote_mac,
693 'subif_id': subif_id})
694
Neale Ranns177bbdc2016-11-15 09:46:51 +0000695 def delete_subif(self, sw_if_index):
696 """Delete subinterface
697
698 :param sw_if_index:
699 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100700 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200701 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000702
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200703 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
704 """Delete p2p ethernet subinterface
705
706 :param sw_if_index: main (parent) interface
707 :param remote_mac: client (remote) mac address
708
709 """
710 return self.api(
711 self.papi.p2p_ethernet_del,
712 {'parent_if_index': sw_if_index,
713 'remote_mac': remote_mac})
714
Klement Sekeraf62ae122016-10-11 11:47:09 +0200715 def create_vlan_subif(self, sw_if_index, vlan):
716 """
717
718 :param vlan:
719 :param sw_if_index:
720
721 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100722 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200723 {'sw_if_index': sw_if_index,
724 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200725
Matej Klotton0178d522016-11-04 11:11:44 +0100726 def create_loopback(self, mac=''):
727 """
728
729 :param mac: (Optional)
730 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100731 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200732 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100733
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100734 def delete_loopback(self, sw_if_index):
735 return self.api(self.papi.delete_loopback,
736 {'sw_if_index': sw_if_index, })
737
Neale Ranns15002542017-09-10 04:39:11 -0700738 def ip_table_add_del(self,
739 table_id,
740 is_add=1,
741 is_ipv6=0):
742 """
743
744 :param table_id
745 :param is_add: (Default value = 1)
746 :param is_ipv6: (Default value = 0)
747
748 """
749
750 return self.api(
751 self.papi.ip_table_add_del,
752 {'table_id': table_id,
753 'is_add': is_add,
754 'is_ipv6': is_ipv6})
755
Klement Sekeraf62ae122016-10-11 11:47:09 +0200756 def ip_add_del_route(
757 self,
758 dst_address,
759 dst_address_length,
760 next_hop_address,
761 next_hop_sw_if_index=0xFFFFFFFF,
762 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200763 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000764 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200765 next_hop_n_out_labels=0,
766 next_hop_out_label_stack=[],
767 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800768 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000769 is_resolve_host=0,
770 is_resolve_attached=0,
771 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200772 is_add=1,
773 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200774 is_unreach=0,
775 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200776 is_ipv6=0,
777 is_local=0,
778 is_classify=0,
779 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800780 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800781 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200782 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200783 """
784
785 :param dst_address_length:
786 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
787 :param dst_address:
788 :param next_hop_address:
789 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
790 :param vrf_id: (Default value = 0)
791 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200792 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200793 :param is_add: (Default value = 1)
794 :param is_drop: (Default value = 0)
795 :param is_ipv6: (Default value = 0)
796 :param is_local: (Default value = 0)
797 :param is_classify: (Default value = 0)
798 :param is_multipath: (Default value = 0)
799 :param is_resolve_host: (Default value = 0)
800 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800801 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700802 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200803 :param next_hop_weight: (Default value = 1)
804
805 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000806
Klement Sekeraf62ae122016-10-11 11:47:09 +0200807 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100808 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200809 {'next_hop_sw_if_index': next_hop_sw_if_index,
810 'table_id': table_id,
811 'classify_table_index': classify_table_index,
812 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200813 'is_add': is_add,
814 'is_drop': is_drop,
815 'is_unreach': is_unreach,
816 'is_prohibit': is_prohibit,
817 'is_ipv6': is_ipv6,
818 'is_local': is_local,
819 'is_classify': is_classify,
820 'is_multipath': is_multipath,
821 'is_resolve_host': is_resolve_host,
822 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800823 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700824 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800825 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200826 'next_hop_weight': next_hop_weight,
827 'dst_address_length': dst_address_length,
828 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800829 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200830 'next_hop_address': next_hop_address,
831 'next_hop_n_out_labels': next_hop_n_out_labels,
832 'next_hop_via_label': next_hop_via_label,
833 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100834
Matej Klotton16a14cd2016-12-07 15:09:13 +0100835 def ip_fib_dump(self):
836 return self.api(self.papi.ip_fib_dump, {})
837
Jan Gelety057bb8c2016-12-20 17:32:45 +0100838 def ip6_fib_dump(self):
839 return self.api(self.papi.ip6_fib_dump, {})
840
Matej Klotton0178d522016-11-04 11:11:44 +0100841 def ip_neighbor_add_del(self,
842 sw_if_index,
843 mac_address,
844 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100845 is_add=1,
846 is_ipv6=0,
847 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800848 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100849 ):
850 """ Add neighbor MAC to IPv4 or IPv6 address.
851
852 :param sw_if_index:
853 :param mac_address:
854 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100855 :param is_add: (Default value = 1)
856 :param is_ipv6: (Default value = 0)
857 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800858 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100859 """
860
861 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100862 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800863 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200864 'is_add': is_add,
865 'is_ipv6': is_ipv6,
866 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800867 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200868 'mac_address': mac_address,
869 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100870 }
Matej Klotton0178d522016-11-04 11:11:44 +0100871 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100872
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800873 def ip_neighbor_dump(self,
874 sw_if_index,
875 is_ipv6=0):
876 """ Return IP neighbor dump.
877
878 :param sw_if_index:
879 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
880 """
881
882 return self.api(
883 self.papi.ip_neighbor_dump,
884 {'is_ipv6': is_ipv6,
885 'sw_if_index': sw_if_index
886 }
887 )
888
889 def proxy_arp_add_del(self,
890 low_address,
891 hi_address,
892 vrf_id=0,
893 is_add=1):
894 """ Config Proxy Arp Range.
895
896 :param low_address: Start address in the rnage to Proxy for
897 :param hi_address: End address in the rnage to Proxy for
898 :param vrf_id: The VRF/table in which to proxy
899 """
900
901 return self.api(
902 self.papi.proxy_arp_add_del,
903 {'vrf_id': vrf_id,
904 'is_add': is_add,
905 'low_address': low_address,
906 'hi_address': hi_address,
907 }
908 )
909
910 def proxy_arp_intfc_enable_disable(self,
911 sw_if_index,
912 is_enable=1):
913 """ Enable/Disable an interface for proxy ARP requests
914
915 :param sw_if_index: Interface
916 :param enable_disable: Enable/Disable
917 """
918
919 return self.api(
920 self.papi.proxy_arp_intfc_enable_disable,
921 {'sw_if_index': sw_if_index,
922 'enable_disable': is_enable
923 }
924 )
925
Jane546d3b2016-12-08 13:10:03 +0100926 def reset_vrf(self,
927 vrf_id,
928 is_ipv6=0,
929 ):
930 """ Reset VRF (remove all routes etc.) request.
931
932 :param int vrf_id: ID of the FIB table / VRF to reset.
933 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
934 """
935
936 return self.api(
937 self.papi.reset_vrf,
938 {'vrf_id': vrf_id,
939 'is_ipv6': is_ipv6,
940 }
941 )
942
943 def reset_fib(self,
944 vrf_id,
945 is_ipv6=0,
946 ):
947 """ Reset VRF (remove all routes etc.) request.
948
949 :param int vrf_id: ID of the FIB table / VRF to reset.
950 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
951 """
952
953 return self.api(
954 self.papi.reset_fib,
955 {'vrf_id': vrf_id,
956 'is_ipv6': is_ipv6,
957 }
958 )
959
960 def ip_dump(self,
961 is_ipv6=0,
962 ):
963 """ Return IP dump.
964
965 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
966 """
967
968 return self.api(
969 self.papi.ip_dump,
970 {'is_ipv6': is_ipv6,
971 }
972 )
973
Klement Sekera7bb873a2016-11-18 07:38:42 +0100974 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300975 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100976 """
977
978 :param sw_if_index_from:
979 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100980 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300981 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100982 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100983 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200984 {'sw_if_index_from': sw_if_index_from,
985 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300986 'state': state,
987 'is_l2': is_l2,
988 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000989
990 def gre_tunnel_add_del(self,
991 src_address,
992 dst_address,
993 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500994 tunnel_type=0,
995 instance=0xFFFFFFFF,
996 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000997 is_add=1,
998 is_ip6=0):
999 """ Add a GRE tunnel
1000
1001 :param src_address:
1002 :param dst_address:
1003 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001004 :param tunnel_type: (Default value = 0)
1005 :param instance: (Default value = 0xFFFFFFFF)
1006 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001007 :param is_add: (Default value = 1)
1008 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001009 """
1010
1011 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001012 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001013 {'is_add': is_add,
1014 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001015 'tunnel_type': tunnel_type,
1016 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001017 'src_address': src_address,
1018 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001019 'outer_fib_id': outer_fib_id,
1020 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001021 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001022
Neale Ranns810086d2017-11-05 16:26:46 -08001023 def udp_encap_add_del(self,
1024 id,
1025 src_ip,
1026 dst_ip,
1027 src_port,
1028 dst_port,
1029 table_id=0,
1030 is_add=1,
1031 is_ip6=0):
1032 """ Add a GRE tunnel
1033 :param id: user provided ID
1034 :param src_ip:
1035 :param dst_ip:
1036 :param src_port:
1037 :param dst_port:
1038 :param outer_fib_id: (Default value = 0)
1039 :param is_add: (Default value = 1)
1040 :param is_ipv6: (Default value = 0)
1041 """
1042
1043 return self.api(
1044 self.papi.udp_encap_add_del,
1045 {'id': id,
1046 'is_add': is_add,
1047 'is_ip6': is_ip6,
1048 'src_ip': src_ip,
1049 'dst_ip': dst_ip,
1050 'src_port': src_port,
1051 'dst_port': dst_port,
1052 'table_id': table_id}
1053 )
1054
1055 def udp_encap_dump(self):
1056 return self.api(self.papi.udp_encap_dump, {})
1057
Neale Ranns5a8123b2017-01-26 01:18:23 -08001058 def mpls_fib_dump(self):
1059 return self.api(self.papi.mpls_fib_dump, {})
1060
Neale Ranns15002542017-09-10 04:39:11 -07001061 def mpls_table_add_del(
1062 self,
1063 table_id,
1064 is_add=1):
1065 """
1066
1067 :param table_id
1068 :param is_add: (Default value = 1)
1069
1070 """
1071
1072 return self.api(
1073 self.papi.mpls_table_add_del,
1074 {'mt_table_id': table_id,
1075 'mt_is_add': is_add})
1076
Neale Rannsad422ed2016-11-02 14:20:04 +00001077 def mpls_route_add_del(
1078 self,
1079 label,
1080 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001081 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001082 next_hop_address,
1083 next_hop_sw_if_index=0xFFFFFFFF,
1084 table_id=0,
1085 next_hop_table_id=0,
1086 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001087 next_hop_n_out_labels=0,
1088 next_hop_out_label_stack=[],
1089 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001090 is_resolve_host=0,
1091 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001092 is_interface_rx=0,
1093 is_rpf_id=0,
1094 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001095 is_add=1,
1096 is_drop=0,
1097 is_multipath=0,
1098 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001099 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001100 """
1101
1102 :param dst_address_length:
1103 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1104 :param dst_address:
1105 :param next_hop_address:
1106 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1107 :param vrf_id: (Default value = 0)
1108 :param lookup_in_vrf: (Default value = 0)
1109 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001110 :param is_add: (Default value = 1)
1111 :param is_drop: (Default value = 0)
1112 :param is_ipv6: (Default value = 0)
1113 :param is_local: (Default value = 0)
1114 :param is_classify: (Default value = 0)
1115 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001116 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001117 :param is_resolve_host: (Default value = 0)
1118 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001119 :param next_hop_weight: (Default value = 1)
1120
1121 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001122 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001123 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001124 {'mr_label': label,
1125 'mr_eos': eos,
1126 'mr_table_id': table_id,
1127 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001128 'mr_is_add': is_add,
1129 'mr_is_classify': is_classify,
1130 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001131 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001132 'mr_is_resolve_host': is_resolve_host,
1133 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001134 'mr_is_interface_rx': is_interface_rx,
1135 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001136 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001137 'mr_next_hop_weight': next_hop_weight,
1138 'mr_next_hop': next_hop_address,
1139 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1140 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1141 'mr_next_hop_table_id': next_hop_table_id,
1142 'mr_next_hop_via_label': next_hop_via_label,
1143 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001144
1145 def mpls_ip_bind_unbind(
1146 self,
1147 label,
1148 dst_address,
1149 dst_address_length,
1150 table_id=0,
1151 ip_table_id=0,
1152 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001153 is_bind=1):
1154 """
1155 """
1156 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001157 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001158 {'mb_mpls_table_id': table_id,
1159 'mb_label': label,
1160 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001161 'mb_is_bind': is_bind,
1162 'mb_is_ip4': is_ip4,
1163 'mb_address_length': dst_address_length,
1164 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001165
1166 def mpls_tunnel_add_del(
1167 self,
1168 tun_sw_if_index,
1169 next_hop_proto_is_ip4,
1170 next_hop_address,
1171 next_hop_sw_if_index=0xFFFFFFFF,
1172 next_hop_table_id=0,
1173 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001174 next_hop_n_out_labels=0,
1175 next_hop_out_label_stack=[],
1176 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001177 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001178 l2_only=0,
1179 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001180 """
1181
1182 :param dst_address_length:
1183 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1184 :param dst_address:
1185 :param next_hop_address:
1186 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1187 :param vrf_id: (Default value = 0)
1188 :param lookup_in_vrf: (Default value = 0)
1189 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001190 :param is_add: (Default value = 1)
1191 :param is_drop: (Default value = 0)
1192 :param is_ipv6: (Default value = 0)
1193 :param is_local: (Default value = 0)
1194 :param is_classify: (Default value = 0)
1195 :param is_multipath: (Default value = 0)
1196 :param is_resolve_host: (Default value = 0)
1197 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001198 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001199 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001200
1201 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001202 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001203 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001204 {'mt_sw_if_index': tun_sw_if_index,
1205 'mt_is_add': is_add,
1206 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001207 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001208 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1209 'mt_next_hop_weight': next_hop_weight,
1210 'mt_next_hop': next_hop_address,
1211 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1212 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1213 'mt_next_hop_table_id': next_hop_table_id,
1214 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001215
Matus Fabian2ba92e32017-08-21 07:05:03 -07001216 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001217 self,
1218 sw_if_index,
1219 is_inside=1,
1220 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001221 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001222
1223 :param sw_if_index: Software index of the interface
1224 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1225 :param is_add: 1 if add, 0 if delete (Default value = 1)
1226 """
1227 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001228 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001229 {'is_add': is_add,
1230 'is_inside': is_inside,
1231 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001232
Matus Fabian2ba92e32017-08-21 07:05:03 -07001233 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001234 self,
1235 sw_if_index,
1236 is_inside=1,
1237 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001238 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001239
1240 :param sw_if_index: Software index of the interface
1241 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1242 :param is_add: 1 if add, 0 if delete (Default value = 1)
1243 """
1244 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001245 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001246 {'is_add': is_add,
1247 'is_inside': is_inside,
1248 'sw_if_index': sw_if_index})
1249
Matus Fabian2ba92e32017-08-21 07:05:03 -07001250 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001251 self,
1252 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001253 external_ip=0,
1254 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001255 local_port=0,
1256 external_port=0,
1257 addr_only=1,
1258 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001259 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001260 twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001261 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001262 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001263 is_add=1):
1264 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001265
1266 :param local_ip: Local IP address
1267 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001268 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001269 :param local_port: Local port number (Default value = 0)
1270 :param external_port: External port number (Default value = 0)
1271 :param addr_only: 1 if address only mapping, 0 if address and port
1272 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001273 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001274 :param twice_nat: 1 if translate external host address and port
Matus Fabiane82488f2018-01-18 03:38:45 -08001275 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001276 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001277 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001278 """
1279 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001280 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001281 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001282 'addr_only': addr_only,
1283 'local_ip_address': local_ip,
1284 'external_ip_address': external_ip,
1285 'local_port': local_port,
1286 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001287 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001288 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001289 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001290 'twice_nat': twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001291 'out2in_only': out2in_only,
1292 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001293
Matus Fabianab7a8052017-11-28 04:29:41 -08001294 def nat44_add_del_identity_mapping(
1295 self,
1296 ip='0',
1297 sw_if_index=0xFFFFFFFF,
1298 port=0,
1299 addr_only=1,
1300 vrf_id=0,
1301 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001302 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001303 is_add=1):
1304 """Add/delete NAT44 identity mapping
1305
1306 :param ip: IP address (Default value = 0)
1307 :param sw_if_index: Interface instead of IP address
1308 :param port: Port number (Default value = 0)
1309 :param addr_only: 1 if address only mapping, 0 if address and port
1310 :param vrf_id: VRF ID
1311 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001312 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001313 :param is_add: 1 if add, 0 if delete (Default value = 1)
1314 """
1315 return self.api(
1316 self.papi.nat44_add_del_identity_mapping,
1317 {'is_add': is_add,
1318 'addr_only': addr_only,
1319 'ip_address': ip,
1320 'port': port,
1321 'sw_if_index': sw_if_index,
1322 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001323 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001324 'protocol': protocol})
1325
Matus Fabian2ba92e32017-08-21 07:05:03 -07001326 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001327 self,
1328 first_ip_address,
1329 last_ip_address,
1330 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001331 vrf_id=0xFFFFFFFF,
1332 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001333 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001334
1335 :param first_ip_address: First IP address
1336 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001337 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001338 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001339 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001340 """
1341 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001342 self.papi.nat44_add_del_address_range,
1343 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001344 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001345 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001346 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001347 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001348
Matus Fabian2ba92e32017-08-21 07:05:03 -07001349 def nat44_address_dump(self):
1350 """Dump NAT44 addresses
1351 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001352 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001353 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001354
Matus Fabian2ba92e32017-08-21 07:05:03 -07001355 def nat44_interface_dump(self):
1356 """Dump interfaces with NAT44 feature
1357 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001358 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001359 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001360
Matus Fabian2ba92e32017-08-21 07:05:03 -07001361 def nat44_interface_output_feature_dump(self):
1362 """Dump interfaces with NAT44 output feature
1363 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001364 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001365 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001366
Matus Fabian2ba92e32017-08-21 07:05:03 -07001367 def nat44_static_mapping_dump(self):
1368 """Dump NAT44 static mappings
1369 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001370 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001371 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001372
Matus Fabianab7a8052017-11-28 04:29:41 -08001373 def nat44_identity_mapping_dump(self):
1374 """Dump NAT44 identity mappings
1375 :return: Dictionary of NAT44 identity mappings
1376 """
1377 return self.api(self.papi.nat44_identity_mapping_dump, {})
1378
Matus Fabian2ba92e32017-08-21 07:05:03 -07001379 def nat_show_config(self):
1380 """Show NAT plugin config
1381 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001382 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001383 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001384
Matus Fabian2ba92e32017-08-21 07:05:03 -07001385 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001386 self,
1387 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001388 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001389 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001390 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001391
1392 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001393 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001394 :param is_add: 1 if add, 0 if delete (Default value = 1)
1395 """
Matus Fabianb932d262017-12-18 05:38:24 -08001396 return self.api(
1397 self.papi.nat44_add_del_interface_addr,
1398 {'is_add': is_add,
1399 'sw_if_index': sw_if_index,
1400 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001401
Matus Fabian2ba92e32017-08-21 07:05:03 -07001402 def nat44_interface_addr_dump(self):
1403 """Dump NAT44 addresses interfaces
1404 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001405 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001406 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001407
Matus Fabian2ba92e32017-08-21 07:05:03 -07001408 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001409 self,
1410 domain_id=1,
1411 src_port=4739,
1412 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001413 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001414
1415 :param domain_id: Observation domain ID (Default value = 1)
1416 :param src_port: Source port number (Default value = 4739)
1417 :param enable: 1 if enable, 0 if disable (Default value = 1)
1418 """
1419 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001420 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001421 {'domain_id': domain_id,
1422 'src_port': src_port,
1423 'enable': enable})
1424
Matus Fabian2ba92e32017-08-21 07:05:03 -07001425 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001426 self,
1427 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001428 vrf_id):
1429 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001430
1431 :param ip_address: ip adress of the user to be dumped
1432 :param cpu_index: cpu_index on which the user is
1433 :param vrf_id: VRF ID
1434 :return: Dictionary of S-NAT sessions
1435 """
1436 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001437 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001438 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001439 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001440
Matus Fabian2ba92e32017-08-21 07:05:03 -07001441 def nat44_user_dump(self):
1442 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001443
Matus Fabian2ba92e32017-08-21 07:05:03 -07001444 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001445 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001446 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001447
Matus Fabian704018c2017-09-04 02:17:18 -07001448 def nat44_add_del_lb_static_mapping(
1449 self,
1450 external_addr,
1451 external_port,
1452 protocol,
1453 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001454 twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001455 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001456 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001457 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001458 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001459 is_add=1):
1460 """Add/delete NAT44 load balancing static mapping
1461
Matus Fabianb932d262017-12-18 05:38:24 -08001462 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001463 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001464 :param is_add - 1 if add, 0 if delete
1465 """
1466 return self.api(
1467 self.papi.nat44_add_del_lb_static_mapping,
1468 {'is_add': is_add,
1469 'external_addr': external_addr,
1470 'external_port': external_port,
1471 'protocol': protocol,
1472 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001473 'twice_nat': twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001474 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001475 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001476 'local_num': local_num,
1477 'locals': locals})
1478
1479 def nat44_lb_static_mapping_dump(self):
1480 """Dump NAT44 load balancing static mappings
1481
1482 :return: Dictionary of NAT44 load balancing static mapping
1483 """
1484 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1485
Matus Fabian5ba86f72017-10-26 03:37:38 -07001486 def nat44_del_session(
1487 self,
1488 addr,
1489 port,
1490 protocol,
1491 vrf_id=0,
1492 is_in=1):
1493 """Delete NAT44 session
1494
1495 :param addr: IPv4 address
1496 :param por: port number
1497 :param protocol: IP protocol number
1498 :param vrf_id: VRF ID
1499 :param is_in: 1 if inside network addres and port pari, 0 if outside
1500 """
1501 return self.api(
1502 self.papi.nat44_del_session,
1503 {'address': addr,
1504 'port': port,
1505 'protocol': protocol,
1506 'vrf_id': vrf_id,
1507 'is_in': is_in})
1508
Juraj Sloboda7b929792017-11-23 13:20:48 +01001509 def nat44_forwarding_enable_disable(
1510 self,
1511 enable):
1512 """Enable/disable forwarding for NAT44
1513
1514 :param enable: 1 for enable, 0 for disable
1515 """
1516 return self.api(
1517 self.papi.nat44_forwarding_enable_disable,
1518 {'enable': enable})
1519
Matus Fabianefcd1e92017-08-15 06:59:19 -07001520 def nat_set_reass(
1521 self,
1522 timeout=2,
1523 max_reass=1024,
1524 max_frag=5,
1525 drop_frag=0,
1526 is_ip6=0):
1527 """Set NAT virtual fragmentation reassembly
1528
1529 :param timeout: reassembly timeout (Default 2sec)
1530 :param max_reass: maximum concurrent reassemblies (Default 1024)
1531 :param max_frag: maximum fragmets per reassembly (Default 5)
1532 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1533 :param is_ip6: 1 if IPv6, 0 if IPv4
1534 """
1535 return self.api(
1536 self.papi.nat_set_reass,
1537 {'timeout': timeout,
1538 'max_reass': max_reass,
1539 'max_frag': max_frag,
1540 'drop_frag': drop_frag,
1541 'is_ip6': is_ip6})
1542
1543 def nat_get_reass(self):
1544 """Get NAT virtual fragmentation reassembly configuration
1545
1546 :return: NAT virtual fragmentation reassembly configuration
1547 """
1548 return self.api(self.papi.nat_get_reass, {})
1549
1550 def nat_reass_dump(self):
1551 """Dump NAT virtual fragmentation reassemblies
1552
1553 :return: Dictionary of NAT virtual fragmentation reassemblies
1554 """
1555 return self.api(self.papi.nat_reass_dump, {})
1556
Matus Fabian2ba92e32017-08-21 07:05:03 -07001557 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001558 self,
1559 in_addr,
1560 in_plen,
1561 out_addr,
1562 out_plen,
1563 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001564 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001565
1566 :param is_add - 1 if add, 0 if delete
1567 :param in_addr - inside IP address
1568 :param in_plen - inside IP address prefix length
1569 :param out_addr - outside IP address
1570 :param out_plen - outside IP address prefix length
1571 """
1572 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001573 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001574 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001575 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001576 'in_addr': in_addr,
1577 'in_plen': in_plen,
1578 'out_addr': out_addr,
1579 'out_plen': out_plen})
1580
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001582 self,
1583 in_addr):
1584 """Get outside address and port range from inside address
1585
1586 :param in_addr - inside IP address
1587 """
1588 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001589 self.papi.nat_det_forward,
1590 {'in_addr': in_addr,
1591 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001592
Matus Fabian2ba92e32017-08-21 07:05:03 -07001593 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001594 self,
1595 out_addr,
1596 out_port):
1597 """Get inside address from outside address and port
1598
1599 :param out_addr - outside IP address
1600 :param out_port - outside port
1601 """
1602 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001603 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001604 {'out_addr': out_addr,
1605 'out_port': out_port})
1606
Matus Fabian2ba92e32017-08-21 07:05:03 -07001607 def nat_det_map_dump(self):
1608 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001609
Matus Fabian2ba92e32017-08-21 07:05:03 -07001610 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001611 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001612 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001613
Matus Fabian2ba92e32017-08-21 07:05:03 -07001614 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001615 self,
1616 udp=300,
1617 tcp_established=7440,
1618 tcp_transitory=240,
1619 icmp=60):
1620 """Set values of timeouts for deterministic NAT (in seconds)
1621
1622 :param udp - UDP timeout (Default value = 300)
1623 :param tcp_established - TCP established timeout (Default value = 7440)
1624 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1625 :param icmp - ICMP timeout (Default value = 60)
1626 """
1627 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001628 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001629 {'udp': udp,
1630 'tcp_established': tcp_established,
1631 'tcp_transitory': tcp_transitory,
1632 'icmp': icmp})
1633
Matus Fabian2ba92e32017-08-21 07:05:03 -07001634 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001635 """Get values of timeouts for deterministic NAT
1636
1637 :return: Timeouts for deterministic NAT (in seconds)
1638 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001639 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001640
Matus Fabian2ba92e32017-08-21 07:05:03 -07001641 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001642 self,
1643 out_addr,
1644 out_port,
1645 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001646 ext_port):
1647 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001648
1649 :param out_addr - outside IP address
1650 :param out_port - outside port
1651 :param ext_addr - external host IP address
1652 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001653 """
1654 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001655 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001656 {'out_addr': out_addr,
1657 'out_port': out_port,
1658 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001659 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001660
Matus Fabian2ba92e32017-08-21 07:05:03 -07001661 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001662 self,
1663 in_addr,
1664 in_port,
1665 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001666 ext_port):
1667 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001668
1669 :param in_addr - inside IP address
1670 :param in_port - inside port
1671 :param ext_addr - external host IP address
1672 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001673 """
1674 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001675 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001676 {'in_addr': in_addr,
1677 'in_port': in_port,
1678 'ext_addr': ext_addr,
1679 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001680 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001681
Matus Fabian2ba92e32017-08-21 07:05:03 -07001682 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001683 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001684 user_addr):
1685 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001686
1687 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001688 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001689 """
1690 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001691 self.papi.nat_det_session_dump,
1692 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001693 'user_addr': user_addr})
1694
Matus Fabian06596c52017-06-06 04:53:28 -07001695 def nat64_add_del_pool_addr_range(
1696 self,
1697 start_addr,
1698 end_addr,
1699 vrf_id=0xFFFFFFFF,
1700 is_add=1):
1701 """Add/del address range to NAT64 pool
1702
1703 :param start_addr: First IP address
1704 :param end_addr: Last IP address
1705 :param vrf_id: VRF id for the address range
1706 :param is_add: 1 if add, 0 if delete (Default value = 1)
1707 """
1708 return self.api(
1709 self.papi.nat64_add_del_pool_addr_range,
1710 {'start_addr': start_addr,
1711 'end_addr': end_addr,
1712 'vrf_id': vrf_id,
1713 'is_add': is_add})
1714
1715 def nat64_pool_addr_dump(self):
1716 """Dump NAT64 pool addresses
1717 :return: Dictionary of NAT64 pool addresses
1718 """
1719 return self.api(self.papi.nat64_pool_addr_dump, {})
1720
1721 def nat64_add_del_interface(
1722 self,
1723 sw_if_index,
1724 is_inside=1,
1725 is_add=1):
1726 """Enable/disable NAT64 feature on the interface
1727 :param sw_if_index: Index of the interface
1728 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1729 :param is_add: 1 if add, 0 if delete (Default value = 1)
1730 """
1731 return self.api(
1732 self.papi.nat64_add_del_interface,
1733 {'sw_if_index': sw_if_index,
1734 'is_inside': is_inside,
1735 'is_add': is_add})
1736
1737 def nat64_interface_dump(self):
1738 """Dump interfaces with NAT64 feature
1739 :return: Dictionary of interfaces with NAT64 feature
1740 """
1741 return self.api(self.papi.nat64_interface_dump, {})
1742
1743 def nat64_add_del_static_bib(
1744 self,
1745 in_ip,
1746 out_ip,
1747 in_port,
1748 out_port,
1749 protocol,
1750 vrf_id=0,
1751 is_add=1):
1752 """Add/delete S-NAT static BIB entry
1753
1754 :param in_ip: Inside IPv6 address
1755 :param out_ip: Outside IPv4 address
1756 :param in_port: Inside port number
1757 :param out_port: Outside port number
1758 :param protocol: IP protocol
1759 :param vrf_id: VRF ID (Default value = 0)
1760 :param is_add: 1 if add, 0 if delete (Default value = 1)
1761 """
1762 return self.api(
1763 self.papi.nat64_add_del_static_bib,
1764 {'i_addr': in_ip,
1765 'o_addr': out_ip,
1766 'i_port': in_port,
1767 'o_port': out_port,
1768 'vrf_id': vrf_id,
1769 'proto': protocol,
1770 'is_add': is_add})
1771
Matus Fabianab9a59c2017-08-16 05:37:36 -07001772 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001773 """Dump NAT64 BIB
1774
Matus Fabianab9a59c2017-08-16 05:37:36 -07001775 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001776 :returns: Dictionary of NAT64 BIB entries
1777 """
1778 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1779
1780 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1781 tcp_incoming_syn=6):
1782 """Set values of timeouts for NAT64 (in seconds)
1783
Matus Fabian428dc912017-06-21 06:15:18 -07001784 :param udpi: UDP timeout (Default value = 300)
1785 :param icmp: ICMP timeout (Default value = 60)
1786 :param tcp_trans: TCP transitory timeout (Default value = 240)
1787 :param tcp_est: TCP established timeout (Default value = 7440)
1788 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001789 """
1790 return self.api(
1791 self.papi.nat64_set_timeouts,
1792 {'udp': udp,
1793 'icmp': icmp,
1794 'tcp_trans': tcp_trans,
1795 'tcp_est': tcp_est,
1796 'tcp_incoming_syn': tcp_incoming_syn})
1797
1798 def nat64_get_timeouts(self):
1799 """Get values of timeouts for NAT64
1800
1801 :return: Timeouts for NAT64 (in seconds)
1802 """
1803 return self.api(self.papi.nat64_get_timeouts, {})
1804
Matus Fabianab9a59c2017-08-16 05:37:36 -07001805 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001806 """Dump NAT64 session table
1807
Matus Fabianab9a59c2017-08-16 05:37:36 -07001808 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001809 :returns: Dictionary of NAT64 sesstion table entries
1810 """
1811 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1812
Matus Fabian428dc912017-06-21 06:15:18 -07001813 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1814 """Add/del NAT64 prefix
1815
1816 :param prefix: NAT64 prefix
1817 :param plen: NAT64 prefix length
1818 :param vrf_id: VRF id of tenant (Default 0)
1819 :param is_add: 1 if add, 0 if delete (Default value = 1)
1820 """
1821 return self.api(
1822 self.papi.nat64_add_del_prefix,
1823 {'prefix': prefix,
1824 'prefix_len': plen,
1825 'vrf_id': vrf_id,
1826 'is_add': is_add})
1827
1828 def nat64_prefix_dump(self):
1829 """Dump NAT64 prefix
1830
1831 :returns: Dictionary of NAT64 prefixes
1832 """
1833 return self.api(self.papi.nat64_prefix_dump, {})
1834
Matus Fabian0938dcf2017-11-08 01:59:38 -08001835 def nat64_add_interface_addr(
1836 self,
1837 sw_if_index,
1838 is_add=1):
1839 """Add/del NAT64 address from interface
1840
1841 :param sw_if_index: Software index of the interface
1842 :param is_add: 1 if add, 0 if delete (Default value = 1)
1843 """
1844 return self.api(self.papi.nat64_add_del_interface_addr,
1845 {'is_add': is_add, 'sw_if_index': sw_if_index})
1846
Matus Fabian8ebe6252017-11-06 05:04:53 -08001847 def dslite_set_aftr_addr(self, ip6, ip4):
1848 """Set DS-Lite AFTR addresses
1849
1850 :param ip4: IPv4 address
1851 :param ip6: IPv6 address
1852 """
1853 return self.api(
1854 self.papi.dslite_set_aftr_addr,
1855 {'ip4_addr': ip4,
1856 'ip6_addr': ip6})
1857
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001858 def dslite_set_b4_addr(self, ip6, ip4):
1859 """Set DS-Lite B4 IPv6 address
1860
1861 :param ip4: IPv4 address
1862 :param ip6: IPv6 address
1863 """
1864 return self.api(
1865 self.papi.dslite_set_b4_addr,
1866 {'ip4_addr': ip4,
1867 'ip6_addr': ip6})
1868
Matus Fabian8ebe6252017-11-06 05:04:53 -08001869 def dslite_add_del_pool_addr_range(
1870 self,
1871 start_addr,
1872 end_addr,
1873 is_add=1):
1874 """Add/del address range to DS-Lite pool
1875
1876 :param start_addr: First IP address
1877 :param end_addr: Last IP address
1878 :param is_add: 1 if add, 0 if delete (Default value = 1)
1879 """
1880 return self.api(
1881 self.papi.dslite_add_del_pool_addr_range,
1882 {'start_addr': start_addr,
1883 'end_addr': end_addr,
1884 'is_add': is_add})
1885
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001886 def nat66_add_del_interface(
1887 self,
1888 sw_if_index,
1889 is_inside=1,
1890 is_add=1):
1891 """Enable/disable NAT66 feature on the interface
1892 :param sw_if_index: Index of the interface
1893 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1894 :param is_add: 1 if add, 0 if delete (Default value = 1)
1895 """
1896 return self.api(
1897 self.papi.nat66_add_del_interface,
1898 {'sw_if_index': sw_if_index,
1899 'is_inside': is_inside,
1900 'is_add': is_add})
1901
1902 def nat66_add_del_static_mapping(
1903 self,
1904 in_ip,
1905 out_ip,
1906 vrf_id=0,
1907 is_add=1):
1908 """Add/delete NAT66 static mapping
1909
1910 :param in_ip: Inside IPv6 address
1911 :param out_ip: Outside IPv6 address
1912 :param vrf_id: VRF ID (Default value = 0)
1913 :param is_add: 1 if add, 0 if delete (Default value = 1)
1914 """
1915 return self.api(
1916 self.papi.nat66_add_del_static_mapping,
1917 {'local_ip_address': in_ip,
1918 'external_ip_address': out_ip,
1919 'vrf_id': vrf_id,
1920 'is_add': is_add})
1921
1922 def nat66_interface_dump(self):
1923 """Dump interfaces with NAT66 feature
1924 :return: Dictionary of interfaces with NAT66 feature
1925 """
1926 return self.api(self.papi.nat66_interface_dump, {})
1927
1928 def nat66_static_mapping_dump(self):
1929 """Dump NAT66 static mappings
1930 :return: Dictionary of NAT66 static mappings
1931 """
1932 return self.api(self.papi.nat66_static_mapping_dump, {})
1933
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001934 def control_ping(self):
1935 self.api(self.papi.control_ping)
1936
1937 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001938 detect_mult, local_addr, peer_addr, is_ipv6=0,
1939 bfd_key_id=None, conf_key_id=None):
1940 if bfd_key_id is None:
1941 return self.api(self.papi.bfd_udp_add,
1942 {
1943 'sw_if_index': sw_if_index,
1944 'desired_min_tx': desired_min_tx,
1945 'required_min_rx': required_min_rx,
1946 'local_addr': local_addr,
1947 'peer_addr': peer_addr,
1948 'is_ipv6': is_ipv6,
1949 'detect_mult': detect_mult,
1950 })
1951 else:
1952 return self.api(self.papi.bfd_udp_add,
1953 {
1954 'sw_if_index': sw_if_index,
1955 'desired_min_tx': desired_min_tx,
1956 'required_min_rx': required_min_rx,
1957 'local_addr': local_addr,
1958 'peer_addr': peer_addr,
1959 'is_ipv6': is_ipv6,
1960 'detect_mult': detect_mult,
1961 'is_authenticated': 1,
1962 'bfd_key_id': bfd_key_id,
1963 'conf_key_id': conf_key_id,
1964 })
1965
Klement Sekeraa57a9702017-02-02 06:58:07 +01001966 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1967 detect_mult, local_addr, peer_addr, is_ipv6=0):
1968 return self.api(self.papi.bfd_udp_mod,
1969 {
1970 'sw_if_index': sw_if_index,
1971 'desired_min_tx': desired_min_tx,
1972 'required_min_rx': required_min_rx,
1973 'local_addr': local_addr,
1974 'peer_addr': peer_addr,
1975 'is_ipv6': is_ipv6,
1976 'detect_mult': detect_mult,
1977 })
1978
Klement Sekerab17dd962017-01-09 07:43:48 +01001979 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1980 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1981 is_delayed=False):
1982 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001983 {
1984 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001985 'local_addr': local_addr,
1986 'peer_addr': peer_addr,
1987 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001988 'is_delayed': 1 if is_delayed else 0,
1989 'bfd_key_id': bfd_key_id,
1990 'conf_key_id': conf_key_id,
1991 })
1992
1993 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1994 is_ipv6=0, is_delayed=False):
1995 return self.api(self.papi.bfd_udp_auth_deactivate,
1996 {
1997 'sw_if_index': sw_if_index,
1998 'local_addr': local_addr,
1999 'peer_addr': peer_addr,
2000 'is_ipv6': is_ipv6,
2001 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002002 })
2003
2004 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2005 return self.api(self.papi.bfd_udp_del,
2006 {
2007 'sw_if_index': sw_if_index,
2008 'local_addr': local_addr,
2009 'peer_addr': peer_addr,
2010 'is_ipv6': is_ipv6,
2011 })
2012
2013 def bfd_udp_session_dump(self):
2014 return self.api(self.papi.bfd_udp_session_dump, {})
2015
Klement Sekerab17dd962017-01-09 07:43:48 +01002016 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2017 peer_addr, is_ipv6=0):
2018 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002019 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002020 'sw_if_index': sw_if_index,
2021 'local_addr': local_addr,
2022 'peer_addr': peer_addr,
2023 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002024 })
2025
2026 def want_bfd_events(self, enable_disable=1):
2027 return self.api(self.papi.want_bfd_events, {
2028 'enable_disable': enable_disable,
2029 'pid': os.getpid(),
2030 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002031
Klement Sekerab17dd962017-01-09 07:43:48 +01002032 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2033 return self.api(self.papi.bfd_auth_set_key, {
2034 'conf_key_id': conf_key_id,
2035 'auth_type': auth_type,
2036 'key': key,
2037 'key_len': len(key),
2038 })
2039
2040 def bfd_auth_del_key(self, conf_key_id):
2041 return self.api(self.papi.bfd_auth_del_key, {
2042 'conf_key_id': conf_key_id,
2043 })
2044
2045 def bfd_auth_keys_dump(self):
2046 return self.api(self.papi.bfd_auth_keys_dump, {})
2047
Klement Sekera239790f2017-02-16 10:53:53 +01002048 def bfd_udp_set_echo_source(self, sw_if_index):
2049 return self.api(self.papi.bfd_udp_set_echo_source,
2050 {'sw_if_index': sw_if_index})
2051
Klement Sekera73884482017-02-23 09:26:30 +01002052 def bfd_udp_del_echo_source(self):
2053 return self.api(self.papi.bfd_udp_del_echo_source, {})
2054
Steve Shin7957d6e2016-12-19 09:24:50 -08002055 def classify_add_del_table(
2056 self,
2057 is_add,
2058 mask,
2059 match_n_vectors=1,
2060 table_index=0xFFFFFFFF,
2061 nbuckets=2,
2062 memory_size=2097152,
2063 skip_n_vectors=0,
2064 next_table_index=0xFFFFFFFF,
2065 miss_next_index=0xFFFFFFFF,
2066 current_data_flag=0,
2067 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002068 """
2069 :param is_add:
2070 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002071 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002072 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002073 :param nbuckets: (Default value = 2)
2074 :param memory_size: (Default value = 2097152)
2075 :param skip_n_vectors: (Default value = 0)
2076 :param next_table_index: (Default value = 0xFFFFFFFF)
2077 :param miss_next_index: (Default value = 0xFFFFFFFF)
2078 :param current_data_flag: (Default value = 0)
2079 :param current_data_offset: (Default value = 0)
2080 """
2081
2082 return self.api(
2083 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002084 {'is_add': is_add,
2085 'table_index': table_index,
2086 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002087 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002088 'skip_n_vectors': skip_n_vectors,
2089 'match_n_vectors': match_n_vectors,
2090 'next_table_index': next_table_index,
2091 'miss_next_index': miss_next_index,
2092 'current_data_flag': current_data_flag,
2093 'current_data_offset': current_data_offset,
2094 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002095
2096 def classify_add_del_session(
2097 self,
2098 is_add,
2099 table_index,
2100 match,
2101 opaque_index=0xFFFFFFFF,
2102 hit_next_index=0xFFFFFFFF,
2103 advance=0,
2104 action=0,
2105 metadata=0):
2106 """
2107 :param is_add:
2108 :param table_index:
2109 :param match:
2110 :param opaque_index: (Default value = 0xFFFFFFFF)
2111 :param hit_next_index: (Default value = 0xFFFFFFFF)
2112 :param advance: (Default value = 0)
2113 :param action: (Default value = 0)
2114 :param metadata: (Default value = 0)
2115 """
2116
2117 return self.api(
2118 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002119 {'is_add': is_add,
2120 'table_index': table_index,
2121 'hit_next_index': hit_next_index,
2122 'opaque_index': opaque_index,
2123 'advance': advance,
2124 'action': action,
2125 'metadata': metadata,
2126 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002127
2128 def input_acl_set_interface(
2129 self,
2130 is_add,
2131 sw_if_index,
2132 ip4_table_index=0xFFFFFFFF,
2133 ip6_table_index=0xFFFFFFFF,
2134 l2_table_index=0xFFFFFFFF):
2135 """
2136 :param is_add:
2137 :param sw_if_index:
2138 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2139 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2140 :param l2_table_index: (Default value = 0xFFFFFFFF)
2141 """
2142
2143 return self.api(
2144 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002145 {'sw_if_index': sw_if_index,
2146 'ip4_table_index': ip4_table_index,
2147 'ip6_table_index': ip6_table_index,
2148 'l2_table_index': l2_table_index,
2149 'is_add': is_add})
2150
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002151 def output_acl_set_interface(
2152 self,
2153 is_add,
2154 sw_if_index,
2155 ip4_table_index=0xFFFFFFFF,
2156 ip6_table_index=0xFFFFFFFF,
2157 l2_table_index=0xFFFFFFFF):
2158 """
2159 :param is_add:
2160 :param sw_if_index:
2161 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2162 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2163 :param l2_table_index: (Default value = 0xFFFFFFFF)
2164 """
2165
2166 return self.api(
2167 self.papi.output_acl_set_interface,
2168 {'sw_if_index': sw_if_index,
2169 'ip4_table_index': ip4_table_index,
2170 'ip6_table_index': ip6_table_index,
2171 'l2_table_index': l2_table_index,
2172 'is_add': is_add})
2173
Klement Sekera77fabdb2017-01-02 07:46:14 +01002174 def set_ipfix_exporter(
2175 self,
2176 collector_address,
2177 src_address,
2178 path_mtu,
2179 template_interval,
2180 vrf_id=0,
2181 collector_port=4739,
2182 udp_checksum=0):
2183 return self.api(
2184 self.papi.set_ipfix_exporter,
2185 {
2186 'collector_address': collector_address,
2187 'collector_port': collector_port,
2188 'src_address': src_address,
2189 'vrf_id': vrf_id,
2190 'path_mtu': path_mtu,
2191 'template_interval': template_interval,
2192 'udp_checksum': udp_checksum,
2193 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002194
2195 def dhcp_proxy_config(self,
2196 dhcp_server,
2197 dhcp_src_address,
2198 rx_table_id=0,
2199 server_table_id=0,
2200 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002201 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002202 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002203 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002204 {
2205 'rx_vrf_id': rx_table_id,
2206 'server_vrf_id': server_table_id,
2207 'is_ipv6': is_ipv6,
2208 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002209 'dhcp_server': dhcp_server,
2210 'dhcp_src_address': dhcp_src_address,
2211 })
2212
2213 def dhcp_proxy_set_vss(self,
2214 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002215 vss_type=255,
2216 vpn_ascii_id="",
2217 oui=0,
2218 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002219 is_add=1,
2220 is_ip6=0):
2221 return self.api(
2222 self.papi.dhcp_proxy_set_vss,
2223 {
2224 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002225 'vss_type': vss_type,
2226 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002227 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002228 'vpn_index': vpn_index,
2229 'is_add': is_add,
2230 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002231 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002232
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002233 def dhcp_client(self,
2234 sw_if_index,
2235 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002236 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002237 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002238 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002239 want_dhcp_events=0):
2240 return self.api(
2241 self.papi.dhcp_client_config,
2242 {
2243 'sw_if_index': sw_if_index,
2244 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002245 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002246 'is_add': is_add,
2247 'want_dhcp_event': want_dhcp_events,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002248 'set_broadcast_flag': set_broadcast_flag,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002249 'pid': os.getpid(),
2250 })
2251
Neale Ranns32e1c012016-11-22 17:07:28 +00002252 def ip_mroute_add_del(self,
2253 src_address,
2254 grp_address,
2255 grp_address_length,
2256 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002257 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002258 next_hop_sw_if_index,
2259 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002260 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002261 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002262 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002263 is_add=1,
2264 is_ipv6=0,
2265 is_local=0):
2266 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002267 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002268 """
2269 return self.api(
2270 self.papi.ip_mroute_add_del,
2271 {'next_hop_sw_if_index': next_hop_sw_if_index,
2272 'entry_flags': e_flags,
2273 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002274 'table_id': table_id,
2275 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002276 'is_add': is_add,
2277 'is_ipv6': is_ipv6,
2278 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002279 'bier_imp': bier_imp,
2280 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002281 'grp_address_length': grp_address_length,
2282 'grp_address': grp_address,
2283 'src_address': src_address})
2284
2285 def mfib_signal_dump(self):
2286 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002287
2288 def ip_mfib_dump(self):
2289 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002290
Neale Rannsd792d9c2017-10-21 10:53:20 -07002291 def ip6_mfib_dump(self):
2292 return self.api(self.papi.ip6_mfib_dump, {})
2293
Filip Tehlar770e89e2017-01-31 10:39:16 +01002294 def lisp_enable_disable(self, is_enabled):
2295 return self.api(
2296 self.papi.lisp_enable_disable,
2297 {
2298 'is_en': is_enabled,
2299 })
2300
2301 def lisp_locator_set(self,
2302 ls_name,
2303 is_add=1):
2304 return self.api(
2305 self.papi.lisp_add_del_locator_set,
2306 {
2307 'is_add': is_add,
2308 'locator_set_name': ls_name
2309 })
2310
2311 def lisp_locator_set_dump(self):
2312 return self.api(self.papi.lisp_locator_set_dump, {})
2313
2314 def lisp_locator(self,
2315 ls_name,
2316 sw_if_index,
2317 priority=1,
2318 weight=1,
2319 is_add=1):
2320 return self.api(
2321 self.papi.lisp_add_del_locator,
2322 {
2323 'is_add': is_add,
2324 'locator_set_name': ls_name,
2325 'sw_if_index': sw_if_index,
2326 'priority': priority,
2327 'weight': weight
2328 })
2329
2330 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2331 return self.api(
2332 self.papi.lisp_locator_dump,
2333 {
2334 'is_index_set': is_index_set,
2335 'ls_name': ls_name,
2336 'ls_index': ls_index,
2337 })
2338
2339 def lisp_local_mapping(self,
2340 ls_name,
2341 eid_type,
2342 eid,
2343 prefix_len,
2344 vni=0,
2345 key_id=0,
2346 key="",
2347 is_add=1):
2348 return self.api(
2349 self.papi.lisp_add_del_local_eid,
2350 {
2351 'locator_set_name': ls_name,
2352 'is_add': is_add,
2353 'eid_type': eid_type,
2354 'eid': eid,
2355 'prefix_len': prefix_len,
2356 'vni': vni,
2357 'key_id': key_id,
2358 'key': key
2359 })
2360
2361 def lisp_eid_table_dump(self,
2362 eid_set=0,
2363 prefix_length=0,
2364 vni=0,
2365 eid_type=0,
2366 eid=None,
2367 filter_opt=0):
2368 return self.api(
2369 self.papi.lisp_eid_table_dump,
2370 {
2371 'eid_set': eid_set,
2372 'prefix_length': prefix_length,
2373 'vni': vni,
2374 'eid_type': eid_type,
2375 'eid': eid,
2376 'filter': filter_opt,
2377 })
2378
2379 def lisp_remote_mapping(self,
2380 eid_type,
2381 eid,
2382 eid_prefix_len=0,
2383 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002384 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002385 rlocs_num=0,
2386 is_src_dst=0,
2387 is_add=1):
2388 return self.api(
2389 self.papi.lisp_add_del_remote_mapping,
2390 {
2391 'is_add': is_add,
2392 'eid_type': eid_type,
2393 'eid': eid,
2394 'eid_len': eid_prefix_len,
2395 'rloc_num': rlocs_num,
2396 'rlocs': rlocs,
2397 'vni': vni,
2398 'is_src_dst': is_src_dst,
2399 })
2400
2401 def lisp_adjacency(self,
2402 leid,
2403 reid,
2404 leid_len,
2405 reid_len,
2406 eid_type,
2407 is_add=1,
2408 vni=0):
2409 return self.api(
2410 self.papi.lisp_add_del_adjacency,
2411 {
2412 'is_add': is_add,
2413 'vni': vni,
2414 'eid_type': eid_type,
2415 'leid': leid,
2416 'reid': reid,
2417 'leid_len': leid_len,
2418 'reid_len': reid_len,
2419 })
2420
2421 def lisp_adjacencies_get(self, vni=0):
2422 return self.api(
2423 self.papi.lisp_adjacencies_get,
2424 {
2425 'vni': vni
2426 })
Neale Ranns80823802017-02-20 18:23:41 -08002427
2428 def map_add_domain(self,
2429 ip6_prefix,
2430 ip6_prefix_len,
2431 ip6_src,
2432 ip6_src_prefix_len,
2433 ip4_prefix,
2434 ip4_prefix_len,
2435 ea_bits_len=0,
2436 psid_offset=0,
2437 psid_length=0,
2438 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002439 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002440 mtu=1280):
2441 return self.api(
2442 self.papi.map_add_domain,
2443 {
2444 'ip6_prefix': ip6_prefix,
2445 'ip6_prefix_len': ip6_prefix_len,
2446 'ip4_prefix': ip4_prefix,
2447 'ip4_prefix_len': ip4_prefix_len,
2448 'ip6_src': ip6_src,
2449 'ip6_src_prefix_len': ip6_src_prefix_len,
2450 'ea_bits_len': ea_bits_len,
2451 'psid_offset': psid_offset,
2452 'psid_length': psid_length,
2453 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002454 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002455 'mtu': mtu
2456 })
Hongjun Nief486b12017-04-12 19:21:16 +08002457
2458 def gtpu_add_del_tunnel(
2459 self,
2460 src_addr,
2461 dst_addr,
2462 is_add=1,
2463 is_ipv6=0,
2464 mcast_sw_if_index=0xFFFFFFFF,
2465 encap_vrf_id=0,
2466 decap_next_index=0xFFFFFFFF,
2467 teid=0):
2468 """
2469
2470 :param is_add: (Default value = 1)
2471 :param is_ipv6: (Default value = 0)
2472 :param src_addr:
2473 :param dst_addr:
2474 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2475 :param encap_vrf_id: (Default value = 0)
2476 :param decap_next_index: (Default value = 0xFFFFFFFF)
2477 :param teid: (Default value = 0)
2478
2479 """
2480 return self.api(self.papi.gtpu_add_del_tunnel,
2481 {'is_add': is_add,
2482 'is_ipv6': is_ipv6,
2483 'src_address': src_addr,
2484 'dst_address': dst_addr,
2485 'mcast_sw_if_index': mcast_sw_if_index,
2486 'encap_vrf_id': encap_vrf_id,
2487 'decap_next_index': decap_next_index,
2488 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002489
2490 def vxlan_gpe_add_del_tunnel(
2491 self,
2492 src_addr,
2493 dst_addr,
2494 mcast_sw_if_index=0xFFFFFFFF,
2495 is_add=1,
2496 is_ipv6=0,
2497 encap_vrf_id=0,
2498 decap_vrf_id=0,
2499 protocol=3,
2500 vni=0):
2501 """
2502
2503 :param local:
2504 :param remote:
2505 :param is_add: (Default value = 1)
2506 :param is_ipv6: (Default value = 0)
2507 :param encap_vrf_id: (Default value = 0)
2508 :param decap_vrf_id: (Default value = 0)
2509 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2510 :param protocol: (Default value = 3)
2511 :param vni: (Default value = 0)
2512
2513 """
2514 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2515 {'is_add': is_add,
2516 'is_ipv6': is_ipv6,
2517 'local': src_addr,
2518 'remote': dst_addr,
2519 'mcast_sw_if_index': mcast_sw_if_index,
2520 'encap_vrf_id': encap_vrf_id,
2521 'decap_vrf_id': decap_vrf_id,
2522 'protocol': protocol,
2523 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002524
2525 def pppoe_add_del_session(
2526 self,
2527 client_ip,
2528 client_mac,
2529 session_id=0,
2530 is_add=1,
2531 is_ipv6=0,
2532 decap_vrf_id=0):
2533 """
2534
2535 :param is_add: (Default value = 1)
2536 :param is_ipv6: (Default value = 0)
2537 :param client_ip:
2538 :param session_id: (Default value = 0)
2539 :param client_mac:
2540 :param decap_vrf_id: (Default value = 0)
2541
2542 """
2543 return self.api(self.papi.pppoe_add_del_session,
2544 {'is_add': is_add,
2545 'is_ipv6': is_ipv6,
2546 'session_id': session_id,
2547 'client_ip': client_ip,
2548 'decap_vrf_id': decap_vrf_id,
2549 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002550
2551 def sr_localsid_add_del(self,
2552 localsid_addr,
2553 behavior,
2554 nh_addr,
2555 is_del=0,
2556 end_psp=0,
2557 sw_if_index=0xFFFFFFFF,
2558 vlan_index=0,
2559 fib_table=0,
2560 ):
2561 """ Add/del IPv6 SR local-SID.
2562
2563 :param localsid_addr:
2564 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2565 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2566 :param nh_addr:
2567 :param is_del: (Default value = 0)
2568 :param end_psp: (Default value = 0)
2569 :param sw_if_index: (Default value = 0xFFFFFFFF)
2570 :param vlan_index: (Default value = 0)
2571 :param fib_table: (Default value = 0)
2572 """
2573 return self.api(
2574 self.papi.sr_localsid_add_del,
2575 {'is_del': is_del,
2576 'localsid_addr': localsid_addr,
2577 'end_psp': end_psp,
2578 'behavior': behavior,
2579 'sw_if_index': sw_if_index,
2580 'vlan_index': vlan_index,
2581 'fib_table': fib_table,
2582 'nh_addr': nh_addr
2583 }
2584 )
2585
2586 def sr_policy_add(
2587 self,
2588 bsid_addr,
2589 weight=1,
2590 is_encap=1,
2591 type=0,
2592 fib_table=0,
2593 n_segments=0,
2594 segments=[]):
2595 """
2596 :param bsid_addr: bindingSID of the SR Policy
2597 :param weight: weight of the sid list. optional. (default: 1)
2598 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2599 (default: Encap)
2600 :param type: type/behavior of the SR policy. (default or spray) \
2601 (default: default)
2602 :param fib_table: VRF where to install the FIB entry for the BSID \
2603 (default: 0)
2604 :param n_segments: number of segments \
2605 (default: 0)
2606 :param segments: a vector of IPv6 address composing the segment list \
2607 (default: [])
2608 """
2609 return self.api(
2610 self.papi.sr_policy_add,
2611 {'bsid_addr': bsid_addr,
2612 'weight': weight,
2613 'is_encap': is_encap,
2614 'type': type,
2615 'fib_table': fib_table,
2616 'n_segments': n_segments,
2617 'segments': segments
2618 }
2619 )
2620
2621 def sr_policy_del(
2622 self,
2623 bsid_addr,
2624 sr_policy_index=0):
2625 """
2626 :param bsid: bindingSID of the SR Policy
2627 :param sr_policy_index: index of the sr policy (default: 0)
2628 """
2629 return self.api(
2630 self.papi.sr_policy_del,
2631 {'bsid_addr': bsid_addr,
2632 'sr_policy_index': sr_policy_index
2633 })
2634
2635 def sr_steering_add_del(
2636 self,
2637 is_del,
2638 bsid_addr,
2639 sr_policy_index,
2640 table_id,
2641 prefix_addr,
2642 mask_width,
2643 sw_if_index,
2644 traffic_type):
2645 """
2646 Steer traffic L2 and L3 traffic through a given SR policy
2647
2648 :param is_del: delete or add
2649 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2650 :param sr_policy: is the index of the SR Policy (alt to bsid)
2651 :param table_id: is the VRF where to install the FIB entry for the BSID
2652 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2653 :param mask_width: is the mask for L3 traffic type
2654 :param sw_if_index: is the incoming interface for L2 traffic
2655 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2656 """
2657 return self.api(
2658 self.papi.sr_steering_add_del,
2659 {'is_del': is_del,
2660 'bsid_addr': bsid_addr,
2661 'sr_policy_index': sr_policy_index,
2662 'table_id': table_id,
2663 'prefix_addr': prefix_addr,
2664 'mask_width': mask_width,
2665 'sw_if_index': sw_if_index,
2666 'traffic_type': traffic_type
2667 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002668
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002669 def acl_add_replace(self, acl_index, r, tag='',
2670 expected_retval=0):
2671 """Add/replace an ACL
2672 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2673 :param acl_rule r: ACL rules array.
2674 :param str tag: symbolic tag (description) for this ACL.
2675 :param int count: number of rules.
2676 """
2677 return self.api(self.papi.acl_add_replace,
2678 {'acl_index': acl_index,
2679 'r': r,
2680 'count': len(r),
2681 'tag': tag},
2682 expected_retval=expected_retval)
2683
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002684 def acl_del(self, acl_index, expected_retval=0):
2685 """
2686
2687 :param acl_index:
2688 :return:
2689 """
2690 return self.api(self.papi.acl_del,
2691 {'acl_index': acl_index},
2692 expected_retval=expected_retval)
2693
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002694 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2695 expected_retval=0):
2696 return self.api(self.papi.acl_interface_set_acl_list,
2697 {'sw_if_index': sw_if_index,
2698 'count': len(acls),
2699 'n_input': n_input,
2700 'acls': acls},
2701 expected_retval=expected_retval)
2702
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002703 def acl_interface_set_etype_whitelist(self, sw_if_index,
2704 n_input, whitelist,
2705 expected_retval=0):
2706 return self.api(self.papi.acl_interface_set_etype_whitelist,
2707 {'sw_if_index': sw_if_index,
2708 'count': len(whitelist),
2709 'n_input': n_input,
2710 'whitelist': whitelist},
2711 expected_retval=expected_retval)
2712
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002713 def acl_interface_add_del(self,
2714 sw_if_index,
2715 acl_index,
2716 is_add=1):
2717 """ Add/Delete ACL to/from interface
2718
2719 :param sw_if_index:
2720 :param acl_index:
2721 :param is_add: (Default value = 1)
2722 """
2723
2724 return self.api(self.papi.acl_interface_add_del,
2725 {'is_add': is_add,
2726 'is_input': 1,
2727 'sw_if_index': sw_if_index,
2728 'acl_index': acl_index})
2729
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002730 def acl_dump(self, acl_index, expected_retval=0):
2731 return self.api(self.papi.acl_dump,
2732 {'acl_index': acl_index},
2733 expected_retval=expected_retval)
2734
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002735 def macip_acl_add(self, rules, tag=""):
2736 """ Add MACIP acl
2737
2738 :param rules: list of rules for given acl
2739 :param tag: acl tag
2740 """
2741
2742 return self.api(self.papi.macip_acl_add,
2743 {'r': rules,
2744 'count': len(rules),
2745 'tag': tag})
2746
Pavel Kotucek932f7412017-09-07 14:44:52 +02002747 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2748 """ Add MACIP acl
2749
2750 :param rules: list of rules for given acl
2751 :param tag: acl tag
2752 """
2753
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002754 return self.api(self.papi.macip_acl_add_replace,
2755 {'acl_index': acl_index,
2756 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002757 'count': len(rules),
2758 'tag': tag})
2759
2760 def macip_acl_del(self, acl_index):
2761 """
2762
2763 :param acl_index:
2764 :return:
2765 """
2766 return self.api(self.papi.macip_acl_del,
2767 {'acl_index': acl_index})
2768
2769 def macip_acl_interface_add_del(self,
2770 sw_if_index,
2771 acl_index,
2772 is_add=1):
2773 """ Add MACIP acl to interface
2774
2775 :param sw_if_index:
2776 :param acl_index:
2777 :param is_add: (Default value = 1)
2778 """
2779
2780 return self.api(self.papi.macip_acl_interface_add_del,
2781 {'is_add': is_add,
2782 'sw_if_index': sw_if_index,
2783 'acl_index': acl_index})
2784
2785 def macip_acl_interface_get(self):
2786 """ Return interface acls dump
2787 """
2788 return self.api(
2789 self.papi.macip_acl_interface_get, {})
2790
2791 def macip_acl_dump(self, acl_index=4294967295):
2792 """ Return MACIP acl dump
2793 """
2794
2795 return self.api(
2796 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002797
2798 def policer_add_del(self,
2799 name,
2800 cir,
2801 eir,
2802 cb,
2803 eb,
2804 is_add=1,
2805 rate_type=0,
2806 round_type=0,
2807 ptype=0,
2808 color_aware=0,
2809 conform_action_type=1,
2810 conform_dscp=0,
2811 exceed_action_type=0,
2812 exceed_dscp=0,
2813 violate_action_type=0,
2814 violate_dscp=0):
2815 return self.api(self.papi.policer_add_del,
2816 {'name': name,
2817 'cir': cir,
2818 'eir': eir,
2819 'cb': cb,
2820 'eb': eb,
2821 'is_add': is_add,
2822 'rate_type': rate_type,
2823 'round_type': round_type,
2824 'type': ptype,
2825 'color_aware': color_aware,
2826 'conform_action_type': conform_action_type,
2827 'conform_dscp': conform_dscp,
2828 'exceed_action_type': exceed_action_type,
2829 'exceed_dscp': exceed_dscp,
2830 'violate_action_type': violate_action_type,
2831 'violate_dscp': violate_dscp})
2832
2833 def ip_punt_police(self,
2834 policer_index,
2835 is_ip6=0,
2836 is_add=1):
2837 return self.api(self.papi.ip_punt_police,
2838 {'policer_index': policer_index,
2839 'is_add': is_add,
2840 'is_ip6': is_ip6})
2841
2842 def ip_punt_redirect(self,
2843 rx_sw_if_index,
2844 tx_sw_if_index,
2845 nh,
2846 is_ip6=0,
2847 is_add=1):
2848 return self.api(self.papi.ip_punt_redirect,
2849 {'rx_sw_if_index': rx_sw_if_index,
2850 'tx_sw_if_index': tx_sw_if_index,
2851 'nh': nh,
2852 'is_add': is_add,
2853 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002854
2855 def bier_table_add_del(self,
2856 bti,
2857 mpls_label,
2858 is_add=1):
2859 """ BIER Table add/del """
2860 return self.api(
2861 self.papi.bier_table_add_del,
2862 {'bt_tbl_id': {"bt_set": bti.set_id,
2863 "bt_sub_domain": bti.sub_domain_id,
2864 "bt_hdr_len_id": bti.hdr_len_id},
2865 'bt_label': mpls_label,
2866 'bt_is_add': is_add})
2867
2868 def bier_table_dump(self):
2869 return self.api(self.papi.bier_table_dump, {})
2870
2871 def bier_route_add_del(self,
2872 bti,
2873 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002874 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002875 is_add=1):
2876 """ BIER Route add/del """
2877 return self.api(
2878 self.papi.bier_route_add_del,
2879 {'br_tbl_id': {"bt_set": bti.set_id,
2880 "bt_sub_domain": bti.sub_domain_id,
2881 "bt_hdr_len_id": bti.hdr_len_id},
2882 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002883 'br_n_paths': len(paths),
2884 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002885 'br_is_add': is_add})
2886
2887 def bier_route_dump(self, bti):
2888 return self.api(
2889 self.papi.bier_route_dump,
2890 {'br_tbl_id': {"bt_set": bti.set_id,
2891 "bt_sub_domain": bti.sub_domain_id,
2892 "bt_hdr_len_id": bti.hdr_len_id}})
2893
2894 def bier_imp_add(self,
2895 bti,
2896 src,
2897 ibytes,
2898 is_add=1):
2899 """ BIER Imposition Add """
2900 return self.api(
2901 self.papi.bier_imp_add,
2902 {'bi_tbl_id': {"bt_set": bti.set_id,
2903 "bt_sub_domain": bti.sub_domain_id,
2904 "bt_hdr_len_id": bti.hdr_len_id},
2905 'bi_src': src,
2906 'bi_n_bytes': len(ibytes),
2907 'bi_bytes': ibytes})
2908
2909 def bier_imp_del(self, bi_index):
2910 """ BIER Imposition del """
2911 return self.api(
2912 self.papi.bier_imp_del,
2913 {'bi_index': bi_index})
2914
2915 def bier_imp_dump(self):
2916 return self.api(self.papi.bier_imp_dump, {})
2917
2918 def bier_disp_table_add_del(self,
2919 bdti,
2920 is_add=1):
2921 """ BIER Disposition Table add/del """
2922 return self.api(
2923 self.papi.bier_disp_table_add_del,
2924 {'bdt_tbl_id': bdti,
2925 'bdt_is_add': is_add})
2926
2927 def bier_disp_table_dump(self):
2928 return self.api(self.papi.bier_disp_table_dump, {})
2929
2930 def bier_disp_entry_add_del(self,
2931 bdti,
2932 bp,
2933 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002934 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002935 next_hop,
2936 next_hop_tbl_id=0,
2937 next_hop_rpf_id=~0,
2938 next_hop_is_ip4=1,
2939 is_add=1):
2940 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002941 lstack = []
2942 while (len(lstack) < 16):
2943 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002944 return self.api(
2945 self.papi.bier_disp_entry_add_del,
2946 {'bde_tbl_id': bdti,
2947 'bde_bp': bp,
2948 'bde_payload_proto': payload_proto,
2949 'bde_n_paths': 1,
2950 'bde_paths': [{'next_hop': next_hop,
2951 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002952 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002953 'rpf_id': next_hop_rpf_id,
2954 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002955 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002956 'bde_is_add': is_add})
2957
2958 def bier_disp_entry_dump(self, bdti):
2959 return self.api(
2960 self.papi.bier_disp_entry_dump,
2961 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002962
2963 def add_node_next(self, node_name, next_name):
2964 """ Set the next node for a given node request
2965
2966 :param node_name:
2967 :param next_name:
2968 """
2969 return self.api(self.papi.add_node_next,
2970 {'node_name': node_name,
2971 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08002972
2973 def session_enable_disable(self, is_enabled):
2974 return self.api(
2975 self.papi.session_enable_disable,
2976 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002977
2978 def ipsec_spd_add_del(self, spd_id, is_add=1):
2979 """ SPD add/del - Wrapper to add or del ipsec SPD
2980 Sample CLI : 'ipsec spd add 1'
2981
2982 :param spd_id - SPD ID to be created in the vpp . mandatory
2983 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2984 optional
2985 :returns: reply from the API
2986 """
2987 return self.api(
2988 self.papi.ipsec_spd_add_del, {
2989 'spd_id': spd_id, 'is_add': is_add})
2990
2991 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2992 """ IPSEC interface SPD add/del - \
2993 Wrapper to associate/disassociate SPD to interface in VPP
2994 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2995
2996 :param spd_id - SPD ID to associate with the interface . mandatory
2997 :param sw_if_index - Interface Index which needs to ipsec \
2998 association mandatory
2999 :param is_add - add(1) or del(0) association with interface \
3000 (Default 1 - add) . optional
3001 :returns: reply from the API
3002 """
3003 return self.api(
3004 self.papi.ipsec_interface_add_del_spd, {
3005 'spd_id': spd_id,
3006 'sw_if_index': sw_if_index, 'is_add': is_add})
3007
3008 def ipsec_sad_add_del_entry(self,
3009 sad_id,
3010 spi,
3011 tunnel_src_address='',
3012 tunnel_dst_address='',
3013 protocol=0,
3014 integrity_algorithm=2,
3015 integrity_key_length=0,
3016 integrity_key='C91KUR9GYMm5GfkEvNjX',
3017 crypto_algorithm=1,
3018 crypto_key_length=0,
3019 crypto_key='JPjyOWBeVEQiMe7h',
3020 is_add=1,
3021 is_tunnel=1):
3022 """ IPSEC SA add/del
3023 Sample CLI : 'ipsec sa add 10 spi 1001 esp \
3024 crypto-key 4a506a794f574265564551694d653768 \
3025 crypto-alg aes-cbc-128 \
3026 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3027 integ-alg sha1-96 tunnel-src 192.168.100.3 \
3028 tunnel-dst 192.168.100.2'
3029 Sample CLI : 'ipsec sa add 20 spi 2001 \
3030 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3031 integ-alg sha1-96'
3032
3033 :param sad_id - Security Association ID to be \
3034 created or deleted. mandatory
3035 :param spi - security param index of the SA in decimal. mandatory
3036 :param tunnel_src_address - incase of tunnel mode outer src address .\
3037 mandatory for tunnel mode
3038 :param tunnel_dst_address - incase of transport mode \
3039 outer dst address. mandatory for tunnel mode
3040 :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional
3041 :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\
3042 optional **
3043 :param integrity_key - value in string \
3044 (Default C91KUR9GYMm5GfkEvNjX).optional
3045 :param integrity_key_length - length of the key string in bytes\
3046 (Default 0 - integrity disabled). optional
3047 :param crypto_algorithm - value range 1-11 Default \
3048 (1- AES_CBC_128).optional **
3049 :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional
3050 :param crypto_key_length - length of the key string in bytes\
3051 (Default 0 - crypto disabled). optional
3052 :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\
3053 optional
3054 :param is_tunnel - tunnel mode (1) or transport mode(0) \
3055 (Default 1 - tunnel). optional
3056 :returns: reply from the API
3057 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3058 crypto and ipsec algorithms
3059 """
3060 return self.api(
3061 self.papi.ipsec_sad_add_del_entry,
3062 {'sad_id': sad_id,
3063 'spi': spi,
3064 'tunnel_src_address': tunnel_src_address,
3065 'tunnel_dst_address': tunnel_dst_address,
3066 'protocol': protocol,
3067 'integrity_algorithm': integrity_algorithm,
3068 'integrity_key_length': integrity_key_length,
3069 'integrity_key': integrity_key,
3070 'crypto_algorithm': crypto_algorithm,
3071 'crypto_key_length': crypto_key_length,
3072 'crypto_key': crypto_key,
3073 'is_add': is_add,
3074 'is_tunnel': is_tunnel})
3075
3076 def ipsec_spd_add_del_entry(self,
3077 spd_id,
3078 local_address_start,
3079 local_address_stop,
3080 remote_address_start,
3081 remote_address_stop,
3082 local_port_start=0,
3083 local_port_stop=65535,
3084 remote_port_start=0,
3085 remote_port_stop=65535,
3086 protocol=0,
3087 sa_id=10,
3088 policy=0,
3089 priority=100,
3090 is_outbound=1,
3091 is_add=1,
3092 is_ip_any=0):
3093 """ IPSEC policy SPD add/del -
3094 Wrapper to configure ipsec SPD policy entries in VPP
3095 Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \
3096 protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \
3097 remote-ip-range 192.168.3.3 - 192.168.3.3'
3098
3099 :param spd_id - SPD ID for the policy . mandatory
3100 :param local_address_start - local-ip-range start address . mandatory
3101 :param local_address_stop - local-ip-range stop address . mandatory
3102 :param remote_address_start - remote-ip-range start address . mandatory
3103 :param remote_address_stop - remote-ip-range stop address . mandatory
3104 :param local_port_start - (Default 0) . optional
3105 :param local_port_stop - (Default 65535). optional
3106 :param remote_port_start - (Default 0). optional
3107 :param remote_port_stop - (Default 65535). optional
3108 :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any).
3109 optional
3110 :param sa_id - Security Association ID for mapping it to SPD
3111 (default 10). optional
3112 :param policy - bypass(0), discard(1), resolve(2) or protect(3)action
3113 (Default 0 - bypass). optional
3114 :param priotity - value for the spd action (Default 100). optional
3115 :param is_outbound - flag for inbound(0) or outbound(1)
3116 (Default 1 - outbound). optional
3117 :param is_add flag - for addition(1) or deletion(0) of the spd
3118 (Default 1 - addtion). optional
3119 :returns: reply from the API
3120 """
3121 return self.api(
3122 self.papi.ipsec_spd_add_del_entry,
3123 {'spd_id': spd_id,
3124 'local_address_start': local_address_start,
3125 'local_address_stop': local_address_stop,
3126 'remote_address_start': remote_address_start,
3127 'remote_address_stop': remote_address_stop,
3128 'local_port_start': local_port_start,
3129 'local_port_stop': local_port_stop,
3130 'remote_port_start': remote_port_start,
3131 'remote_port_stop': remote_port_stop,
3132 'is_add': is_add,
3133 'protocol': protocol,
3134 'policy': policy,
3135 'priority': priority,
3136 'is_outbound': is_outbound,
3137 'sa_id': sa_id,
3138 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003139
3140 def app_namespace_add(self,
3141 namespace_id,
3142 ip4_fib_id=0,
3143 ip6_fib_id=0,
3144 sw_if_index=0xFFFFFFFF,
3145 secret=0):
3146 return self.api(
3147 self.papi.app_namespace_add_del,
3148 {'secret': secret,
3149 'sw_if_index': sw_if_index,
3150 'ip4_fib_id': ip4_fib_id,
3151 'ip6_fib_id': ip6_fib_id,
3152 'namespace_id': namespace_id,
3153 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003154
3155 def punt_socket_register(self, l4_port, pathname, header_version=1,
3156 is_ip4=1, l4_protocol=0x11):
3157 """ Punt to socket """
3158 return self.api(self.papi.punt_socket_register,
3159 {'is_ip4': is_ip4,
3160 'l4_protocol': l4_protocol,
3161 'l4_port': l4_port,
3162 'pathname': pathname,
3163 'header_version': header_version})
3164
3165 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3166 expire_walk_interval_ms, is_ip6=0):
3167 """ Set IP reassembly parameters """
3168 return self.api(self.papi.ip_reassembly_set,
3169 {'is_ip6': is_ip6,
3170 'timeout_ms': timeout_ms,
3171 'expire_walk_interval_ms': expire_walk_interval_ms,
3172 'max_reassemblies': max_reassemblies})
3173
3174 def ip_reassembly_get(self, is_ip6=0):
3175 """ Get IP reassembly parameters """
3176 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003177
3178 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3179 """ GBP endpoint Add/Del """
3180 return self.api(self.papi.gbp_endpoint_add_del,
3181 {'is_add': is_add,
3182 'endpoint': {
3183 'is_ip6': is_ip6,
3184 'sw_if_index': sw_if_index,
3185 'address': addr,
3186 'epg_id': epg}})
3187
3188 def gbp_endpoint_dump(self):
3189 """ GBP endpoint Dump """
3190 return self.api(self.papi.gbp_endpoint_dump, {})
3191
3192 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3193 """ GBP contract Add/Del """
3194 return self.api(self.papi.gbp_contract_add_del,
3195 {'is_add': is_add,
3196 'contract': {
3197 'acl_index': acl_index,
3198 'src_epg': src_epg,
3199 'dst_epg': dst_epg}})
3200
3201 def gbp_contract_dump(self):
3202 """ GBP contract Dump """
3203 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003204
Ole Troan298c6952018-03-08 12:30:43 +01003205 def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len,
3206 ip4_prefix, ip4_prefix_len, ip4_src,
3207 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003208 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003209 return self.api(self.papi.ipip_6rd_add_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003210 {'fib_index': fib_index,
3211 'ip6_prefix': ip6_prefix,
3212 'ip6_prefix_len': ip6_prefix_len,
3213 'ip4_prefix': ip4_prefix,
3214 'ip4_prefix_len': ip4_prefix_len,
3215 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003216 'security_check': security_check})
3217
Ole Troan298c6952018-03-08 12:30:43 +01003218 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003219 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003220 return self.api(self.papi.ipip_6rd_del_tunnel,
3221 {'sw_if_index': sw_if_index})
3222
3223 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
3224 instance=0xFFFFFFFF, fib_index=0):
3225 """ IPIP tunnel Add/Del """
3226 return self.api(self.papi.ipip_add_tunnel,
3227 {'is_ipv6': is_ipv6,
3228 'instance': instance,
3229 'src_address': src_address,
3230 'dst_address': dst_address,
3231 'fib_index': fib_index})
3232
3233 def ipip_del_tunnel(self, sw_if_index):
3234 """ IPIP tunnel Delete """
3235 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003236 {'sw_if_index': sw_if_index})