blob: 8e53333b6244793b9b3d8d76e4d00b75258ca9e3 [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
1123 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001124 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001125 {'mr_label': label,
1126 'mr_eos': eos,
1127 'mr_table_id': table_id,
1128 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001129 'mr_is_add': is_add,
1130 'mr_is_classify': is_classify,
1131 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001132 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001133 'mr_is_resolve_host': is_resolve_host,
1134 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001135 'mr_is_interface_rx': is_interface_rx,
1136 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001137 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001138 'mr_next_hop_weight': next_hop_weight,
1139 'mr_next_hop': next_hop_address,
1140 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1141 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1142 'mr_next_hop_table_id': next_hop_table_id,
1143 'mr_next_hop_via_label': next_hop_via_label,
1144 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001145
1146 def mpls_ip_bind_unbind(
1147 self,
1148 label,
1149 dst_address,
1150 dst_address_length,
1151 table_id=0,
1152 ip_table_id=0,
1153 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001154 is_bind=1):
1155 """
1156 """
1157 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001158 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001159 {'mb_mpls_table_id': table_id,
1160 'mb_label': label,
1161 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001162 'mb_is_bind': is_bind,
1163 'mb_is_ip4': is_ip4,
1164 'mb_address_length': dst_address_length,
1165 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001166
1167 def mpls_tunnel_add_del(
1168 self,
1169 tun_sw_if_index,
1170 next_hop_proto_is_ip4,
1171 next_hop_address,
1172 next_hop_sw_if_index=0xFFFFFFFF,
1173 next_hop_table_id=0,
1174 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001175 next_hop_n_out_labels=0,
1176 next_hop_out_label_stack=[],
1177 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001178 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001179 l2_only=0,
1180 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001181 """
1182
1183 :param dst_address_length:
1184 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1185 :param dst_address:
1186 :param next_hop_address:
1187 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1188 :param vrf_id: (Default value = 0)
1189 :param lookup_in_vrf: (Default value = 0)
1190 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001191 :param is_add: (Default value = 1)
1192 :param is_drop: (Default value = 0)
1193 :param is_ipv6: (Default value = 0)
1194 :param is_local: (Default value = 0)
1195 :param is_classify: (Default value = 0)
1196 :param is_multipath: (Default value = 0)
1197 :param is_resolve_host: (Default value = 0)
1198 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001199 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001200 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001201
1202 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001203 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001204 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001205 {'mt_sw_if_index': tun_sw_if_index,
1206 'mt_is_add': is_add,
1207 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001208 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001209 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1210 'mt_next_hop_weight': next_hop_weight,
1211 'mt_next_hop': next_hop_address,
1212 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1213 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1214 'mt_next_hop_table_id': next_hop_table_id,
1215 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001216
Matus Fabian2ba92e32017-08-21 07:05:03 -07001217 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001218 self,
1219 sw_if_index,
1220 is_inside=1,
1221 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001222 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001223
1224 :param sw_if_index: Software index of the interface
1225 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1226 :param is_add: 1 if add, 0 if delete (Default value = 1)
1227 """
1228 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001229 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001230 {'is_add': is_add,
1231 'is_inside': is_inside,
1232 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001233
Matus Fabian2ba92e32017-08-21 07:05:03 -07001234 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001235 self,
1236 sw_if_index,
1237 is_inside=1,
1238 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001239 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001240
1241 :param sw_if_index: Software index of the interface
1242 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1243 :param is_add: 1 if add, 0 if delete (Default value = 1)
1244 """
1245 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001246 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001247 {'is_add': is_add,
1248 'is_inside': is_inside,
1249 'sw_if_index': sw_if_index})
1250
Matus Fabian2ba92e32017-08-21 07:05:03 -07001251 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001252 self,
1253 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001254 external_ip=0,
1255 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001256 local_port=0,
1257 external_port=0,
1258 addr_only=1,
1259 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001260 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001261 twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001262 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001263 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001264 is_add=1):
1265 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001266
1267 :param local_ip: Local IP address
1268 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001269 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001270 :param local_port: Local port number (Default value = 0)
1271 :param external_port: External port number (Default value = 0)
1272 :param addr_only: 1 if address only mapping, 0 if address and port
1273 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001274 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001275 :param twice_nat: 1 if translate external host address and port
Matus Fabiane82488f2018-01-18 03:38:45 -08001276 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001277 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001278 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001279 """
1280 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001281 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001282 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001283 'addr_only': addr_only,
1284 'local_ip_address': local_ip,
1285 'external_ip_address': external_ip,
1286 'local_port': local_port,
1287 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001288 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001289 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001290 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001291 'twice_nat': twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001292 'out2in_only': out2in_only,
1293 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001294
Matus Fabianab7a8052017-11-28 04:29:41 -08001295 def nat44_add_del_identity_mapping(
1296 self,
1297 ip='0',
1298 sw_if_index=0xFFFFFFFF,
1299 port=0,
1300 addr_only=1,
1301 vrf_id=0,
1302 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001303 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001304 is_add=1):
1305 """Add/delete NAT44 identity mapping
1306
1307 :param ip: IP address (Default value = 0)
1308 :param sw_if_index: Interface instead of IP address
1309 :param port: Port number (Default value = 0)
1310 :param addr_only: 1 if address only mapping, 0 if address and port
1311 :param vrf_id: VRF ID
1312 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001313 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001314 :param is_add: 1 if add, 0 if delete (Default value = 1)
1315 """
1316 return self.api(
1317 self.papi.nat44_add_del_identity_mapping,
1318 {'is_add': is_add,
1319 'addr_only': addr_only,
1320 'ip_address': ip,
1321 'port': port,
1322 'sw_if_index': sw_if_index,
1323 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001324 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001325 'protocol': protocol})
1326
Matus Fabian2ba92e32017-08-21 07:05:03 -07001327 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001328 self,
1329 first_ip_address,
1330 last_ip_address,
1331 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001332 vrf_id=0xFFFFFFFF,
1333 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001334 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001335
1336 :param first_ip_address: First IP address
1337 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001338 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001339 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001340 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001341 """
1342 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001343 self.papi.nat44_add_del_address_range,
1344 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001345 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001346 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001347 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001348 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001349
Matus Fabian2ba92e32017-08-21 07:05:03 -07001350 def nat44_address_dump(self):
1351 """Dump NAT44 addresses
1352 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001353 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001354 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001355
Matus Fabian2ba92e32017-08-21 07:05:03 -07001356 def nat44_interface_dump(self):
1357 """Dump interfaces with NAT44 feature
1358 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001359 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001360 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001361
Matus Fabian2ba92e32017-08-21 07:05:03 -07001362 def nat44_interface_output_feature_dump(self):
1363 """Dump interfaces with NAT44 output feature
1364 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001365 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001366 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001367
Matus Fabian2ba92e32017-08-21 07:05:03 -07001368 def nat44_static_mapping_dump(self):
1369 """Dump NAT44 static mappings
1370 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001371 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001372 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001373
Matus Fabianab7a8052017-11-28 04:29:41 -08001374 def nat44_identity_mapping_dump(self):
1375 """Dump NAT44 identity mappings
1376 :return: Dictionary of NAT44 identity mappings
1377 """
1378 return self.api(self.papi.nat44_identity_mapping_dump, {})
1379
Matus Fabian2ba92e32017-08-21 07:05:03 -07001380 def nat_show_config(self):
1381 """Show NAT plugin config
1382 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001383 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001384 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001385
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001387 self,
1388 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001389 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001390 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001391 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001392
1393 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001394 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001395 :param is_add: 1 if add, 0 if delete (Default value = 1)
1396 """
Matus Fabianb932d262017-12-18 05:38:24 -08001397 return self.api(
1398 self.papi.nat44_add_del_interface_addr,
1399 {'is_add': is_add,
1400 'sw_if_index': sw_if_index,
1401 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001402
Matus Fabian2ba92e32017-08-21 07:05:03 -07001403 def nat44_interface_addr_dump(self):
1404 """Dump NAT44 addresses interfaces
1405 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001406 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001407 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001408
Matus Fabian2ba92e32017-08-21 07:05:03 -07001409 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001410 self,
1411 domain_id=1,
1412 src_port=4739,
1413 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001414 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001415
1416 :param domain_id: Observation domain ID (Default value = 1)
1417 :param src_port: Source port number (Default value = 4739)
1418 :param enable: 1 if enable, 0 if disable (Default value = 1)
1419 """
1420 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001421 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001422 {'domain_id': domain_id,
1423 'src_port': src_port,
1424 'enable': enable})
1425
Matus Fabian2ba92e32017-08-21 07:05:03 -07001426 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001427 self,
1428 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001429 vrf_id):
1430 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001431
1432 :param ip_address: ip adress of the user to be dumped
1433 :param cpu_index: cpu_index on which the user is
1434 :param vrf_id: VRF ID
1435 :return: Dictionary of S-NAT sessions
1436 """
1437 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001438 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001439 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001440 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001441
Matus Fabian2ba92e32017-08-21 07:05:03 -07001442 def nat44_user_dump(self):
1443 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001444
Matus Fabian2ba92e32017-08-21 07:05:03 -07001445 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001446 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001447 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001448
Matus Fabian704018c2017-09-04 02:17:18 -07001449 def nat44_add_del_lb_static_mapping(
1450 self,
1451 external_addr,
1452 external_port,
1453 protocol,
1454 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001455 twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001456 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001457 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001458 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001459 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001460 is_add=1):
1461 """Add/delete NAT44 load balancing static mapping
1462
Matus Fabianb932d262017-12-18 05:38:24 -08001463 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001464 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001465 :param is_add - 1 if add, 0 if delete
1466 """
1467 return self.api(
1468 self.papi.nat44_add_del_lb_static_mapping,
1469 {'is_add': is_add,
1470 'external_addr': external_addr,
1471 'external_port': external_port,
1472 'protocol': protocol,
1473 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001474 'twice_nat': twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001475 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001476 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001477 'local_num': local_num,
1478 'locals': locals})
1479
1480 def nat44_lb_static_mapping_dump(self):
1481 """Dump NAT44 load balancing static mappings
1482
1483 :return: Dictionary of NAT44 load balancing static mapping
1484 """
1485 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1486
Matus Fabian5ba86f72017-10-26 03:37:38 -07001487 def nat44_del_session(
1488 self,
1489 addr,
1490 port,
1491 protocol,
1492 vrf_id=0,
1493 is_in=1):
1494 """Delete NAT44 session
1495
1496 :param addr: IPv4 address
1497 :param por: port number
1498 :param protocol: IP protocol number
1499 :param vrf_id: VRF ID
1500 :param is_in: 1 if inside network addres and port pari, 0 if outside
1501 """
1502 return self.api(
1503 self.papi.nat44_del_session,
1504 {'address': addr,
1505 'port': port,
1506 'protocol': protocol,
1507 'vrf_id': vrf_id,
1508 'is_in': is_in})
1509
Juraj Sloboda7b929792017-11-23 13:20:48 +01001510 def nat44_forwarding_enable_disable(
1511 self,
1512 enable):
1513 """Enable/disable forwarding for NAT44
1514
1515 :param enable: 1 for enable, 0 for disable
1516 """
1517 return self.api(
1518 self.papi.nat44_forwarding_enable_disable,
1519 {'enable': enable})
1520
Matus Fabianefcd1e92017-08-15 06:59:19 -07001521 def nat_set_reass(
1522 self,
1523 timeout=2,
1524 max_reass=1024,
1525 max_frag=5,
1526 drop_frag=0,
1527 is_ip6=0):
1528 """Set NAT virtual fragmentation reassembly
1529
1530 :param timeout: reassembly timeout (Default 2sec)
1531 :param max_reass: maximum concurrent reassemblies (Default 1024)
1532 :param max_frag: maximum fragmets per reassembly (Default 5)
1533 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1534 :param is_ip6: 1 if IPv6, 0 if IPv4
1535 """
1536 return self.api(
1537 self.papi.nat_set_reass,
1538 {'timeout': timeout,
1539 'max_reass': max_reass,
1540 'max_frag': max_frag,
1541 'drop_frag': drop_frag,
1542 'is_ip6': is_ip6})
1543
1544 def nat_get_reass(self):
1545 """Get NAT virtual fragmentation reassembly configuration
1546
1547 :return: NAT virtual fragmentation reassembly configuration
1548 """
1549 return self.api(self.papi.nat_get_reass, {})
1550
1551 def nat_reass_dump(self):
1552 """Dump NAT virtual fragmentation reassemblies
1553
1554 :return: Dictionary of NAT virtual fragmentation reassemblies
1555 """
1556 return self.api(self.papi.nat_reass_dump, {})
1557
Matus Fabian2ba92e32017-08-21 07:05:03 -07001558 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001559 self,
1560 in_addr,
1561 in_plen,
1562 out_addr,
1563 out_plen,
1564 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001566
1567 :param is_add - 1 if add, 0 if delete
1568 :param in_addr - inside IP address
1569 :param in_plen - inside IP address prefix length
1570 :param out_addr - outside IP address
1571 :param out_plen - outside IP address prefix length
1572 """
1573 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001574 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001575 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001576 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001577 'in_addr': in_addr,
1578 'in_plen': in_plen,
1579 'out_addr': out_addr,
1580 'out_plen': out_plen})
1581
Matus Fabian2ba92e32017-08-21 07:05:03 -07001582 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001583 self,
1584 in_addr):
1585 """Get outside address and port range from inside address
1586
1587 :param in_addr - inside IP address
1588 """
1589 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001590 self.papi.nat_det_forward,
1591 {'in_addr': in_addr,
1592 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001593
Matus Fabian2ba92e32017-08-21 07:05:03 -07001594 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001595 self,
1596 out_addr,
1597 out_port):
1598 """Get inside address from outside address and port
1599
1600 :param out_addr - outside IP address
1601 :param out_port - outside port
1602 """
1603 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001604 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001605 {'out_addr': out_addr,
1606 'out_port': out_port})
1607
Matus Fabian2ba92e32017-08-21 07:05:03 -07001608 def nat_det_map_dump(self):
1609 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001610
Matus Fabian2ba92e32017-08-21 07:05:03 -07001611 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001612 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001613 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001614
Matus Fabian2ba92e32017-08-21 07:05:03 -07001615 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001616 self,
1617 udp=300,
1618 tcp_established=7440,
1619 tcp_transitory=240,
1620 icmp=60):
1621 """Set values of timeouts for deterministic NAT (in seconds)
1622
1623 :param udp - UDP timeout (Default value = 300)
1624 :param tcp_established - TCP established timeout (Default value = 7440)
1625 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1626 :param icmp - ICMP timeout (Default value = 60)
1627 """
1628 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001629 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001630 {'udp': udp,
1631 'tcp_established': tcp_established,
1632 'tcp_transitory': tcp_transitory,
1633 'icmp': icmp})
1634
Matus Fabian2ba92e32017-08-21 07:05:03 -07001635 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001636 """Get values of timeouts for deterministic NAT
1637
1638 :return: Timeouts for deterministic NAT (in seconds)
1639 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001640 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001641
Matus Fabian2ba92e32017-08-21 07:05:03 -07001642 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001643 self,
1644 out_addr,
1645 out_port,
1646 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001647 ext_port):
1648 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001649
1650 :param out_addr - outside IP address
1651 :param out_port - outside port
1652 :param ext_addr - external host IP address
1653 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001654 """
1655 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001656 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001657 {'out_addr': out_addr,
1658 'out_port': out_port,
1659 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001660 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001661
Matus Fabian2ba92e32017-08-21 07:05:03 -07001662 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001663 self,
1664 in_addr,
1665 in_port,
1666 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001667 ext_port):
1668 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001669
1670 :param in_addr - inside IP address
1671 :param in_port - inside port
1672 :param ext_addr - external host IP address
1673 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001674 """
1675 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001676 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001677 {'in_addr': in_addr,
1678 'in_port': in_port,
1679 'ext_addr': ext_addr,
1680 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001681 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001682
Matus Fabian2ba92e32017-08-21 07:05:03 -07001683 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001684 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001685 user_addr):
1686 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001687
1688 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001689 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001690 """
1691 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001692 self.papi.nat_det_session_dump,
1693 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001694 'user_addr': user_addr})
1695
Matus Fabian06596c52017-06-06 04:53:28 -07001696 def nat64_add_del_pool_addr_range(
1697 self,
1698 start_addr,
1699 end_addr,
1700 vrf_id=0xFFFFFFFF,
1701 is_add=1):
1702 """Add/del address range to NAT64 pool
1703
1704 :param start_addr: First IP address
1705 :param end_addr: Last IP address
1706 :param vrf_id: VRF id for the address range
1707 :param is_add: 1 if add, 0 if delete (Default value = 1)
1708 """
1709 return self.api(
1710 self.papi.nat64_add_del_pool_addr_range,
1711 {'start_addr': start_addr,
1712 'end_addr': end_addr,
1713 'vrf_id': vrf_id,
1714 'is_add': is_add})
1715
1716 def nat64_pool_addr_dump(self):
1717 """Dump NAT64 pool addresses
1718 :return: Dictionary of NAT64 pool addresses
1719 """
1720 return self.api(self.papi.nat64_pool_addr_dump, {})
1721
1722 def nat64_add_del_interface(
1723 self,
1724 sw_if_index,
1725 is_inside=1,
1726 is_add=1):
1727 """Enable/disable NAT64 feature on the interface
1728 :param sw_if_index: Index of the interface
1729 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1730 :param is_add: 1 if add, 0 if delete (Default value = 1)
1731 """
1732 return self.api(
1733 self.papi.nat64_add_del_interface,
1734 {'sw_if_index': sw_if_index,
1735 'is_inside': is_inside,
1736 'is_add': is_add})
1737
1738 def nat64_interface_dump(self):
1739 """Dump interfaces with NAT64 feature
1740 :return: Dictionary of interfaces with NAT64 feature
1741 """
1742 return self.api(self.papi.nat64_interface_dump, {})
1743
1744 def nat64_add_del_static_bib(
1745 self,
1746 in_ip,
1747 out_ip,
1748 in_port,
1749 out_port,
1750 protocol,
1751 vrf_id=0,
1752 is_add=1):
1753 """Add/delete S-NAT static BIB entry
1754
1755 :param in_ip: Inside IPv6 address
1756 :param out_ip: Outside IPv4 address
1757 :param in_port: Inside port number
1758 :param out_port: Outside port number
1759 :param protocol: IP protocol
1760 :param vrf_id: VRF ID (Default value = 0)
1761 :param is_add: 1 if add, 0 if delete (Default value = 1)
1762 """
1763 return self.api(
1764 self.papi.nat64_add_del_static_bib,
1765 {'i_addr': in_ip,
1766 'o_addr': out_ip,
1767 'i_port': in_port,
1768 'o_port': out_port,
1769 'vrf_id': vrf_id,
1770 'proto': protocol,
1771 'is_add': is_add})
1772
Matus Fabianab9a59c2017-08-16 05:37:36 -07001773 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001774 """Dump NAT64 BIB
1775
Matus Fabianab9a59c2017-08-16 05:37:36 -07001776 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001777 :returns: Dictionary of NAT64 BIB entries
1778 """
1779 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1780
1781 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1782 tcp_incoming_syn=6):
1783 """Set values of timeouts for NAT64 (in seconds)
1784
Matus Fabian428dc912017-06-21 06:15:18 -07001785 :param udpi: UDP timeout (Default value = 300)
1786 :param icmp: ICMP timeout (Default value = 60)
1787 :param tcp_trans: TCP transitory timeout (Default value = 240)
1788 :param tcp_est: TCP established timeout (Default value = 7440)
1789 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001790 """
1791 return self.api(
1792 self.papi.nat64_set_timeouts,
1793 {'udp': udp,
1794 'icmp': icmp,
1795 'tcp_trans': tcp_trans,
1796 'tcp_est': tcp_est,
1797 'tcp_incoming_syn': tcp_incoming_syn})
1798
1799 def nat64_get_timeouts(self):
1800 """Get values of timeouts for NAT64
1801
1802 :return: Timeouts for NAT64 (in seconds)
1803 """
1804 return self.api(self.papi.nat64_get_timeouts, {})
1805
Matus Fabianab9a59c2017-08-16 05:37:36 -07001806 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001807 """Dump NAT64 session table
1808
Matus Fabianab9a59c2017-08-16 05:37:36 -07001809 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001810 :returns: Dictionary of NAT64 sesstion table entries
1811 """
1812 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1813
Matus Fabian428dc912017-06-21 06:15:18 -07001814 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1815 """Add/del NAT64 prefix
1816
1817 :param prefix: NAT64 prefix
1818 :param plen: NAT64 prefix length
1819 :param vrf_id: VRF id of tenant (Default 0)
1820 :param is_add: 1 if add, 0 if delete (Default value = 1)
1821 """
1822 return self.api(
1823 self.papi.nat64_add_del_prefix,
1824 {'prefix': prefix,
1825 'prefix_len': plen,
1826 'vrf_id': vrf_id,
1827 'is_add': is_add})
1828
1829 def nat64_prefix_dump(self):
1830 """Dump NAT64 prefix
1831
1832 :returns: Dictionary of NAT64 prefixes
1833 """
1834 return self.api(self.papi.nat64_prefix_dump, {})
1835
Matus Fabian0938dcf2017-11-08 01:59:38 -08001836 def nat64_add_interface_addr(
1837 self,
1838 sw_if_index,
1839 is_add=1):
1840 """Add/del NAT64 address from interface
1841
1842 :param sw_if_index: Software index of the interface
1843 :param is_add: 1 if add, 0 if delete (Default value = 1)
1844 """
1845 return self.api(self.papi.nat64_add_del_interface_addr,
1846 {'is_add': is_add, 'sw_if_index': sw_if_index})
1847
Matus Fabian8ebe6252017-11-06 05:04:53 -08001848 def dslite_set_aftr_addr(self, ip6, ip4):
1849 """Set DS-Lite AFTR addresses
1850
1851 :param ip4: IPv4 address
1852 :param ip6: IPv6 address
1853 """
1854 return self.api(
1855 self.papi.dslite_set_aftr_addr,
1856 {'ip4_addr': ip4,
1857 'ip6_addr': ip6})
1858
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001859 def dslite_set_b4_addr(self, ip6, ip4):
1860 """Set DS-Lite B4 IPv6 address
1861
1862 :param ip4: IPv4 address
1863 :param ip6: IPv6 address
1864 """
1865 return self.api(
1866 self.papi.dslite_set_b4_addr,
1867 {'ip4_addr': ip4,
1868 'ip6_addr': ip6})
1869
Matus Fabian8ebe6252017-11-06 05:04:53 -08001870 def dslite_add_del_pool_addr_range(
1871 self,
1872 start_addr,
1873 end_addr,
1874 is_add=1):
1875 """Add/del address range to DS-Lite pool
1876
1877 :param start_addr: First IP address
1878 :param end_addr: Last IP address
1879 :param is_add: 1 if add, 0 if delete (Default value = 1)
1880 """
1881 return self.api(
1882 self.papi.dslite_add_del_pool_addr_range,
1883 {'start_addr': start_addr,
1884 'end_addr': end_addr,
1885 'is_add': is_add})
1886
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001887 def nat66_add_del_interface(
1888 self,
1889 sw_if_index,
1890 is_inside=1,
1891 is_add=1):
1892 """Enable/disable NAT66 feature on the interface
1893 :param sw_if_index: Index of the interface
1894 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1895 :param is_add: 1 if add, 0 if delete (Default value = 1)
1896 """
1897 return self.api(
1898 self.papi.nat66_add_del_interface,
1899 {'sw_if_index': sw_if_index,
1900 'is_inside': is_inside,
1901 'is_add': is_add})
1902
1903 def nat66_add_del_static_mapping(
1904 self,
1905 in_ip,
1906 out_ip,
1907 vrf_id=0,
1908 is_add=1):
1909 """Add/delete NAT66 static mapping
1910
1911 :param in_ip: Inside IPv6 address
1912 :param out_ip: Outside IPv6 address
1913 :param vrf_id: VRF ID (Default value = 0)
1914 :param is_add: 1 if add, 0 if delete (Default value = 1)
1915 """
1916 return self.api(
1917 self.papi.nat66_add_del_static_mapping,
1918 {'local_ip_address': in_ip,
1919 'external_ip_address': out_ip,
1920 'vrf_id': vrf_id,
1921 'is_add': is_add})
1922
1923 def nat66_interface_dump(self):
1924 """Dump interfaces with NAT66 feature
1925 :return: Dictionary of interfaces with NAT66 feature
1926 """
1927 return self.api(self.papi.nat66_interface_dump, {})
1928
1929 def nat66_static_mapping_dump(self):
1930 """Dump NAT66 static mappings
1931 :return: Dictionary of NAT66 static mappings
1932 """
1933 return self.api(self.papi.nat66_static_mapping_dump, {})
1934
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001935 def control_ping(self):
1936 self.api(self.papi.control_ping)
1937
1938 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001939 detect_mult, local_addr, peer_addr, is_ipv6=0,
1940 bfd_key_id=None, conf_key_id=None):
1941 if bfd_key_id is None:
1942 return self.api(self.papi.bfd_udp_add,
1943 {
1944 'sw_if_index': sw_if_index,
1945 'desired_min_tx': desired_min_tx,
1946 'required_min_rx': required_min_rx,
1947 'local_addr': local_addr,
1948 'peer_addr': peer_addr,
1949 'is_ipv6': is_ipv6,
1950 'detect_mult': detect_mult,
1951 })
1952 else:
1953 return self.api(self.papi.bfd_udp_add,
1954 {
1955 'sw_if_index': sw_if_index,
1956 'desired_min_tx': desired_min_tx,
1957 'required_min_rx': required_min_rx,
1958 'local_addr': local_addr,
1959 'peer_addr': peer_addr,
1960 'is_ipv6': is_ipv6,
1961 'detect_mult': detect_mult,
1962 'is_authenticated': 1,
1963 'bfd_key_id': bfd_key_id,
1964 'conf_key_id': conf_key_id,
1965 })
1966
Klement Sekeraa57a9702017-02-02 06:58:07 +01001967 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1968 detect_mult, local_addr, peer_addr, is_ipv6=0):
1969 return self.api(self.papi.bfd_udp_mod,
1970 {
1971 'sw_if_index': sw_if_index,
1972 'desired_min_tx': desired_min_tx,
1973 'required_min_rx': required_min_rx,
1974 'local_addr': local_addr,
1975 'peer_addr': peer_addr,
1976 'is_ipv6': is_ipv6,
1977 'detect_mult': detect_mult,
1978 })
1979
Klement Sekerab17dd962017-01-09 07:43:48 +01001980 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1981 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1982 is_delayed=False):
1983 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001984 {
1985 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001986 'local_addr': local_addr,
1987 'peer_addr': peer_addr,
1988 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001989 'is_delayed': 1 if is_delayed else 0,
1990 'bfd_key_id': bfd_key_id,
1991 'conf_key_id': conf_key_id,
1992 })
1993
1994 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1995 is_ipv6=0, is_delayed=False):
1996 return self.api(self.papi.bfd_udp_auth_deactivate,
1997 {
1998 'sw_if_index': sw_if_index,
1999 'local_addr': local_addr,
2000 'peer_addr': peer_addr,
2001 'is_ipv6': is_ipv6,
2002 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002003 })
2004
2005 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2006 return self.api(self.papi.bfd_udp_del,
2007 {
2008 'sw_if_index': sw_if_index,
2009 'local_addr': local_addr,
2010 'peer_addr': peer_addr,
2011 'is_ipv6': is_ipv6,
2012 })
2013
2014 def bfd_udp_session_dump(self):
2015 return self.api(self.papi.bfd_udp_session_dump, {})
2016
Klement Sekerab17dd962017-01-09 07:43:48 +01002017 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2018 peer_addr, is_ipv6=0):
2019 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002020 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002021 'sw_if_index': sw_if_index,
2022 'local_addr': local_addr,
2023 'peer_addr': peer_addr,
2024 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002025 })
2026
2027 def want_bfd_events(self, enable_disable=1):
2028 return self.api(self.papi.want_bfd_events, {
2029 'enable_disable': enable_disable,
2030 'pid': os.getpid(),
2031 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002032
Klement Sekerab17dd962017-01-09 07:43:48 +01002033 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2034 return self.api(self.papi.bfd_auth_set_key, {
2035 'conf_key_id': conf_key_id,
2036 'auth_type': auth_type,
2037 'key': key,
2038 'key_len': len(key),
2039 })
2040
2041 def bfd_auth_del_key(self, conf_key_id):
2042 return self.api(self.papi.bfd_auth_del_key, {
2043 'conf_key_id': conf_key_id,
2044 })
2045
2046 def bfd_auth_keys_dump(self):
2047 return self.api(self.papi.bfd_auth_keys_dump, {})
2048
Klement Sekera239790f2017-02-16 10:53:53 +01002049 def bfd_udp_set_echo_source(self, sw_if_index):
2050 return self.api(self.papi.bfd_udp_set_echo_source,
2051 {'sw_if_index': sw_if_index})
2052
Klement Sekera73884482017-02-23 09:26:30 +01002053 def bfd_udp_del_echo_source(self):
2054 return self.api(self.papi.bfd_udp_del_echo_source, {})
2055
Steve Shin7957d6e2016-12-19 09:24:50 -08002056 def classify_add_del_table(
2057 self,
2058 is_add,
2059 mask,
2060 match_n_vectors=1,
2061 table_index=0xFFFFFFFF,
2062 nbuckets=2,
2063 memory_size=2097152,
2064 skip_n_vectors=0,
2065 next_table_index=0xFFFFFFFF,
2066 miss_next_index=0xFFFFFFFF,
2067 current_data_flag=0,
2068 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002069 """
2070 :param is_add:
2071 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002072 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002073 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002074 :param nbuckets: (Default value = 2)
2075 :param memory_size: (Default value = 2097152)
2076 :param skip_n_vectors: (Default value = 0)
2077 :param next_table_index: (Default value = 0xFFFFFFFF)
2078 :param miss_next_index: (Default value = 0xFFFFFFFF)
2079 :param current_data_flag: (Default value = 0)
2080 :param current_data_offset: (Default value = 0)
2081 """
2082
2083 return self.api(
2084 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002085 {'is_add': is_add,
2086 'table_index': table_index,
2087 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002088 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002089 'skip_n_vectors': skip_n_vectors,
2090 'match_n_vectors': match_n_vectors,
2091 'next_table_index': next_table_index,
2092 'miss_next_index': miss_next_index,
2093 'current_data_flag': current_data_flag,
2094 'current_data_offset': current_data_offset,
2095 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002096
2097 def classify_add_del_session(
2098 self,
2099 is_add,
2100 table_index,
2101 match,
2102 opaque_index=0xFFFFFFFF,
2103 hit_next_index=0xFFFFFFFF,
2104 advance=0,
2105 action=0,
2106 metadata=0):
2107 """
2108 :param is_add:
2109 :param table_index:
2110 :param match:
2111 :param opaque_index: (Default value = 0xFFFFFFFF)
2112 :param hit_next_index: (Default value = 0xFFFFFFFF)
2113 :param advance: (Default value = 0)
2114 :param action: (Default value = 0)
2115 :param metadata: (Default value = 0)
2116 """
2117
2118 return self.api(
2119 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002120 {'is_add': is_add,
2121 'table_index': table_index,
2122 'hit_next_index': hit_next_index,
2123 'opaque_index': opaque_index,
2124 'advance': advance,
2125 'action': action,
2126 'metadata': metadata,
2127 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002128
2129 def input_acl_set_interface(
2130 self,
2131 is_add,
2132 sw_if_index,
2133 ip4_table_index=0xFFFFFFFF,
2134 ip6_table_index=0xFFFFFFFF,
2135 l2_table_index=0xFFFFFFFF):
2136 """
2137 :param is_add:
2138 :param sw_if_index:
2139 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2140 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2141 :param l2_table_index: (Default value = 0xFFFFFFFF)
2142 """
2143
2144 return self.api(
2145 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002146 {'sw_if_index': sw_if_index,
2147 'ip4_table_index': ip4_table_index,
2148 'ip6_table_index': ip6_table_index,
2149 'l2_table_index': l2_table_index,
2150 'is_add': is_add})
2151
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002152 def output_acl_set_interface(
2153 self,
2154 is_add,
2155 sw_if_index,
2156 ip4_table_index=0xFFFFFFFF,
2157 ip6_table_index=0xFFFFFFFF,
2158 l2_table_index=0xFFFFFFFF):
2159 """
2160 :param is_add:
2161 :param sw_if_index:
2162 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2163 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2164 :param l2_table_index: (Default value = 0xFFFFFFFF)
2165 """
2166
2167 return self.api(
2168 self.papi.output_acl_set_interface,
2169 {'sw_if_index': sw_if_index,
2170 'ip4_table_index': ip4_table_index,
2171 'ip6_table_index': ip6_table_index,
2172 'l2_table_index': l2_table_index,
2173 'is_add': is_add})
2174
Klement Sekera77fabdb2017-01-02 07:46:14 +01002175 def set_ipfix_exporter(
2176 self,
2177 collector_address,
2178 src_address,
2179 path_mtu,
2180 template_interval,
2181 vrf_id=0,
2182 collector_port=4739,
2183 udp_checksum=0):
2184 return self.api(
2185 self.papi.set_ipfix_exporter,
2186 {
2187 'collector_address': collector_address,
2188 'collector_port': collector_port,
2189 'src_address': src_address,
2190 'vrf_id': vrf_id,
2191 'path_mtu': path_mtu,
2192 'template_interval': template_interval,
2193 'udp_checksum': udp_checksum,
2194 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002195
2196 def dhcp_proxy_config(self,
2197 dhcp_server,
2198 dhcp_src_address,
2199 rx_table_id=0,
2200 server_table_id=0,
2201 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002202 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002203 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002204 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002205 {
2206 'rx_vrf_id': rx_table_id,
2207 'server_vrf_id': server_table_id,
2208 'is_ipv6': is_ipv6,
2209 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002210 'dhcp_server': dhcp_server,
2211 'dhcp_src_address': dhcp_src_address,
2212 })
2213
2214 def dhcp_proxy_set_vss(self,
2215 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002216 vss_type=255,
2217 vpn_ascii_id="",
2218 oui=0,
2219 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002220 is_add=1,
2221 is_ip6=0):
2222 return self.api(
2223 self.papi.dhcp_proxy_set_vss,
2224 {
2225 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002226 'vss_type': vss_type,
2227 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002228 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002229 'vpn_index': vpn_index,
2230 'is_add': is_add,
2231 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002232 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002233
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002234 def dhcp_client(self,
2235 sw_if_index,
2236 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002237 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002238 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002239 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002240 want_dhcp_events=0):
2241 return self.api(
2242 self.papi.dhcp_client_config,
2243 {
2244 'sw_if_index': sw_if_index,
2245 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002246 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002247 'is_add': is_add,
2248 'want_dhcp_event': want_dhcp_events,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002249 'set_broadcast_flag': set_broadcast_flag,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002250 'pid': os.getpid(),
2251 })
2252
Neale Ranns32e1c012016-11-22 17:07:28 +00002253 def ip_mroute_add_del(self,
2254 src_address,
2255 grp_address,
2256 grp_address_length,
2257 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002258 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002259 next_hop_sw_if_index,
2260 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002261 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002262 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002263 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002264 is_add=1,
2265 is_ipv6=0,
2266 is_local=0):
2267 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002268 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002269 """
2270 return self.api(
2271 self.papi.ip_mroute_add_del,
2272 {'next_hop_sw_if_index': next_hop_sw_if_index,
2273 'entry_flags': e_flags,
2274 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002275 'table_id': table_id,
2276 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002277 'is_add': is_add,
2278 'is_ipv6': is_ipv6,
2279 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002280 'bier_imp': bier_imp,
2281 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002282 'grp_address_length': grp_address_length,
2283 'grp_address': grp_address,
2284 'src_address': src_address})
2285
2286 def mfib_signal_dump(self):
2287 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002288
2289 def ip_mfib_dump(self):
2290 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002291
Neale Rannsd792d9c2017-10-21 10:53:20 -07002292 def ip6_mfib_dump(self):
2293 return self.api(self.papi.ip6_mfib_dump, {})
2294
Filip Tehlar770e89e2017-01-31 10:39:16 +01002295 def lisp_enable_disable(self, is_enabled):
2296 return self.api(
2297 self.papi.lisp_enable_disable,
2298 {
2299 'is_en': is_enabled,
2300 })
2301
2302 def lisp_locator_set(self,
2303 ls_name,
2304 is_add=1):
2305 return self.api(
2306 self.papi.lisp_add_del_locator_set,
2307 {
2308 'is_add': is_add,
2309 'locator_set_name': ls_name
2310 })
2311
2312 def lisp_locator_set_dump(self):
2313 return self.api(self.papi.lisp_locator_set_dump, {})
2314
2315 def lisp_locator(self,
2316 ls_name,
2317 sw_if_index,
2318 priority=1,
2319 weight=1,
2320 is_add=1):
2321 return self.api(
2322 self.papi.lisp_add_del_locator,
2323 {
2324 'is_add': is_add,
2325 'locator_set_name': ls_name,
2326 'sw_if_index': sw_if_index,
2327 'priority': priority,
2328 'weight': weight
2329 })
2330
2331 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2332 return self.api(
2333 self.papi.lisp_locator_dump,
2334 {
2335 'is_index_set': is_index_set,
2336 'ls_name': ls_name,
2337 'ls_index': ls_index,
2338 })
2339
2340 def lisp_local_mapping(self,
2341 ls_name,
2342 eid_type,
2343 eid,
2344 prefix_len,
2345 vni=0,
2346 key_id=0,
2347 key="",
2348 is_add=1):
2349 return self.api(
2350 self.papi.lisp_add_del_local_eid,
2351 {
2352 'locator_set_name': ls_name,
2353 'is_add': is_add,
2354 'eid_type': eid_type,
2355 'eid': eid,
2356 'prefix_len': prefix_len,
2357 'vni': vni,
2358 'key_id': key_id,
2359 'key': key
2360 })
2361
2362 def lisp_eid_table_dump(self,
2363 eid_set=0,
2364 prefix_length=0,
2365 vni=0,
2366 eid_type=0,
2367 eid=None,
2368 filter_opt=0):
2369 return self.api(
2370 self.papi.lisp_eid_table_dump,
2371 {
2372 'eid_set': eid_set,
2373 'prefix_length': prefix_length,
2374 'vni': vni,
2375 'eid_type': eid_type,
2376 'eid': eid,
2377 'filter': filter_opt,
2378 })
2379
2380 def lisp_remote_mapping(self,
2381 eid_type,
2382 eid,
2383 eid_prefix_len=0,
2384 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002385 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002386 rlocs_num=0,
2387 is_src_dst=0,
2388 is_add=1):
2389 return self.api(
2390 self.papi.lisp_add_del_remote_mapping,
2391 {
2392 'is_add': is_add,
2393 'eid_type': eid_type,
2394 'eid': eid,
2395 'eid_len': eid_prefix_len,
2396 'rloc_num': rlocs_num,
2397 'rlocs': rlocs,
2398 'vni': vni,
2399 'is_src_dst': is_src_dst,
2400 })
2401
2402 def lisp_adjacency(self,
2403 leid,
2404 reid,
2405 leid_len,
2406 reid_len,
2407 eid_type,
2408 is_add=1,
2409 vni=0):
2410 return self.api(
2411 self.papi.lisp_add_del_adjacency,
2412 {
2413 'is_add': is_add,
2414 'vni': vni,
2415 'eid_type': eid_type,
2416 'leid': leid,
2417 'reid': reid,
2418 'leid_len': leid_len,
2419 'reid_len': reid_len,
2420 })
2421
2422 def lisp_adjacencies_get(self, vni=0):
2423 return self.api(
2424 self.papi.lisp_adjacencies_get,
2425 {
2426 'vni': vni
2427 })
Neale Ranns80823802017-02-20 18:23:41 -08002428
2429 def map_add_domain(self,
2430 ip6_prefix,
2431 ip6_prefix_len,
2432 ip6_src,
2433 ip6_src_prefix_len,
2434 ip4_prefix,
2435 ip4_prefix_len,
2436 ea_bits_len=0,
2437 psid_offset=0,
2438 psid_length=0,
2439 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002440 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002441 mtu=1280):
2442 return self.api(
2443 self.papi.map_add_domain,
2444 {
2445 'ip6_prefix': ip6_prefix,
2446 'ip6_prefix_len': ip6_prefix_len,
2447 'ip4_prefix': ip4_prefix,
2448 'ip4_prefix_len': ip4_prefix_len,
2449 'ip6_src': ip6_src,
2450 'ip6_src_prefix_len': ip6_src_prefix_len,
2451 'ea_bits_len': ea_bits_len,
2452 'psid_offset': psid_offset,
2453 'psid_length': psid_length,
2454 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002455 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002456 'mtu': mtu
2457 })
Hongjun Nief486b12017-04-12 19:21:16 +08002458
2459 def gtpu_add_del_tunnel(
2460 self,
2461 src_addr,
2462 dst_addr,
2463 is_add=1,
2464 is_ipv6=0,
2465 mcast_sw_if_index=0xFFFFFFFF,
2466 encap_vrf_id=0,
2467 decap_next_index=0xFFFFFFFF,
2468 teid=0):
2469 """
2470
2471 :param is_add: (Default value = 1)
2472 :param is_ipv6: (Default value = 0)
2473 :param src_addr:
2474 :param dst_addr:
2475 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2476 :param encap_vrf_id: (Default value = 0)
2477 :param decap_next_index: (Default value = 0xFFFFFFFF)
2478 :param teid: (Default value = 0)
2479
2480 """
2481 return self.api(self.papi.gtpu_add_del_tunnel,
2482 {'is_add': is_add,
2483 'is_ipv6': is_ipv6,
2484 'src_address': src_addr,
2485 'dst_address': dst_addr,
2486 'mcast_sw_if_index': mcast_sw_if_index,
2487 'encap_vrf_id': encap_vrf_id,
2488 'decap_next_index': decap_next_index,
2489 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002490
2491 def vxlan_gpe_add_del_tunnel(
2492 self,
2493 src_addr,
2494 dst_addr,
2495 mcast_sw_if_index=0xFFFFFFFF,
2496 is_add=1,
2497 is_ipv6=0,
2498 encap_vrf_id=0,
2499 decap_vrf_id=0,
2500 protocol=3,
2501 vni=0):
2502 """
2503
2504 :param local:
2505 :param remote:
2506 :param is_add: (Default value = 1)
2507 :param is_ipv6: (Default value = 0)
2508 :param encap_vrf_id: (Default value = 0)
2509 :param decap_vrf_id: (Default value = 0)
2510 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2511 :param protocol: (Default value = 3)
2512 :param vni: (Default value = 0)
2513
2514 """
2515 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2516 {'is_add': is_add,
2517 'is_ipv6': is_ipv6,
2518 'local': src_addr,
2519 'remote': dst_addr,
2520 'mcast_sw_if_index': mcast_sw_if_index,
2521 'encap_vrf_id': encap_vrf_id,
2522 'decap_vrf_id': decap_vrf_id,
2523 'protocol': protocol,
2524 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002525
2526 def pppoe_add_del_session(
2527 self,
2528 client_ip,
2529 client_mac,
2530 session_id=0,
2531 is_add=1,
2532 is_ipv6=0,
2533 decap_vrf_id=0):
2534 """
2535
2536 :param is_add: (Default value = 1)
2537 :param is_ipv6: (Default value = 0)
2538 :param client_ip:
2539 :param session_id: (Default value = 0)
2540 :param client_mac:
2541 :param decap_vrf_id: (Default value = 0)
2542
2543 """
2544 return self.api(self.papi.pppoe_add_del_session,
2545 {'is_add': is_add,
2546 'is_ipv6': is_ipv6,
2547 'session_id': session_id,
2548 'client_ip': client_ip,
2549 'decap_vrf_id': decap_vrf_id,
2550 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002551
2552 def sr_localsid_add_del(self,
2553 localsid_addr,
2554 behavior,
2555 nh_addr,
2556 is_del=0,
2557 end_psp=0,
2558 sw_if_index=0xFFFFFFFF,
2559 vlan_index=0,
2560 fib_table=0,
2561 ):
2562 """ Add/del IPv6 SR local-SID.
2563
2564 :param localsid_addr:
2565 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2566 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2567 :param nh_addr:
2568 :param is_del: (Default value = 0)
2569 :param end_psp: (Default value = 0)
2570 :param sw_if_index: (Default value = 0xFFFFFFFF)
2571 :param vlan_index: (Default value = 0)
2572 :param fib_table: (Default value = 0)
2573 """
2574 return self.api(
2575 self.papi.sr_localsid_add_del,
2576 {'is_del': is_del,
2577 'localsid_addr': localsid_addr,
2578 'end_psp': end_psp,
2579 'behavior': behavior,
2580 'sw_if_index': sw_if_index,
2581 'vlan_index': vlan_index,
2582 'fib_table': fib_table,
2583 'nh_addr': nh_addr
2584 }
2585 )
2586
2587 def sr_policy_add(
2588 self,
2589 bsid_addr,
2590 weight=1,
2591 is_encap=1,
2592 type=0,
2593 fib_table=0,
2594 n_segments=0,
2595 segments=[]):
2596 """
2597 :param bsid_addr: bindingSID of the SR Policy
2598 :param weight: weight of the sid list. optional. (default: 1)
2599 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2600 (default: Encap)
2601 :param type: type/behavior of the SR policy. (default or spray) \
2602 (default: default)
2603 :param fib_table: VRF where to install the FIB entry for the BSID \
2604 (default: 0)
2605 :param n_segments: number of segments \
2606 (default: 0)
2607 :param segments: a vector of IPv6 address composing the segment list \
2608 (default: [])
2609 """
2610 return self.api(
2611 self.papi.sr_policy_add,
2612 {'bsid_addr': bsid_addr,
2613 'weight': weight,
2614 'is_encap': is_encap,
2615 'type': type,
2616 'fib_table': fib_table,
2617 'n_segments': n_segments,
2618 'segments': segments
2619 }
2620 )
2621
2622 def sr_policy_del(
2623 self,
2624 bsid_addr,
2625 sr_policy_index=0):
2626 """
2627 :param bsid: bindingSID of the SR Policy
2628 :param sr_policy_index: index of the sr policy (default: 0)
2629 """
2630 return self.api(
2631 self.papi.sr_policy_del,
2632 {'bsid_addr': bsid_addr,
2633 'sr_policy_index': sr_policy_index
2634 })
2635
2636 def sr_steering_add_del(
2637 self,
2638 is_del,
2639 bsid_addr,
2640 sr_policy_index,
2641 table_id,
2642 prefix_addr,
2643 mask_width,
2644 sw_if_index,
2645 traffic_type):
2646 """
2647 Steer traffic L2 and L3 traffic through a given SR policy
2648
2649 :param is_del: delete or add
2650 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2651 :param sr_policy: is the index of the SR Policy (alt to bsid)
2652 :param table_id: is the VRF where to install the FIB entry for the BSID
2653 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2654 :param mask_width: is the mask for L3 traffic type
2655 :param sw_if_index: is the incoming interface for L2 traffic
2656 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2657 """
2658 return self.api(
2659 self.papi.sr_steering_add_del,
2660 {'is_del': is_del,
2661 'bsid_addr': bsid_addr,
2662 'sr_policy_index': sr_policy_index,
2663 'table_id': table_id,
2664 'prefix_addr': prefix_addr,
2665 'mask_width': mask_width,
2666 'sw_if_index': sw_if_index,
2667 'traffic_type': traffic_type
2668 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002669
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002670 def acl_add_replace(self, acl_index, r, tag='',
2671 expected_retval=0):
2672 """Add/replace an ACL
2673 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2674 :param acl_rule r: ACL rules array.
2675 :param str tag: symbolic tag (description) for this ACL.
2676 :param int count: number of rules.
2677 """
2678 return self.api(self.papi.acl_add_replace,
2679 {'acl_index': acl_index,
2680 'r': r,
2681 'count': len(r),
2682 'tag': tag},
2683 expected_retval=expected_retval)
2684
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002685 def acl_del(self, acl_index, expected_retval=0):
2686 """
2687
2688 :param acl_index:
2689 :return:
2690 """
2691 return self.api(self.papi.acl_del,
2692 {'acl_index': acl_index},
2693 expected_retval=expected_retval)
2694
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002695 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2696 expected_retval=0):
2697 return self.api(self.papi.acl_interface_set_acl_list,
2698 {'sw_if_index': sw_if_index,
2699 'count': len(acls),
2700 'n_input': n_input,
2701 'acls': acls},
2702 expected_retval=expected_retval)
2703
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002704 def acl_interface_set_etype_whitelist(self, sw_if_index,
2705 n_input, whitelist,
2706 expected_retval=0):
2707 return self.api(self.papi.acl_interface_set_etype_whitelist,
2708 {'sw_if_index': sw_if_index,
2709 'count': len(whitelist),
2710 'n_input': n_input,
2711 'whitelist': whitelist},
2712 expected_retval=expected_retval)
2713
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002714 def acl_interface_add_del(self,
2715 sw_if_index,
2716 acl_index,
2717 is_add=1):
2718 """ Add/Delete ACL to/from interface
2719
2720 :param sw_if_index:
2721 :param acl_index:
2722 :param is_add: (Default value = 1)
2723 """
2724
2725 return self.api(self.papi.acl_interface_add_del,
2726 {'is_add': is_add,
2727 'is_input': 1,
2728 'sw_if_index': sw_if_index,
2729 'acl_index': acl_index})
2730
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002731 def acl_dump(self, acl_index, expected_retval=0):
2732 return self.api(self.papi.acl_dump,
2733 {'acl_index': acl_index},
2734 expected_retval=expected_retval)
2735
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002736 def macip_acl_add(self, rules, tag=""):
2737 """ Add MACIP acl
2738
2739 :param rules: list of rules for given acl
2740 :param tag: acl tag
2741 """
2742
2743 return self.api(self.papi.macip_acl_add,
2744 {'r': rules,
2745 'count': len(rules),
2746 'tag': tag})
2747
Pavel Kotucek932f7412017-09-07 14:44:52 +02002748 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2749 """ Add MACIP acl
2750
2751 :param rules: list of rules for given acl
2752 :param tag: acl tag
2753 """
2754
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002755 return self.api(self.papi.macip_acl_add_replace,
2756 {'acl_index': acl_index,
2757 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002758 'count': len(rules),
2759 'tag': tag})
2760
2761 def macip_acl_del(self, acl_index):
2762 """
2763
2764 :param acl_index:
2765 :return:
2766 """
2767 return self.api(self.papi.macip_acl_del,
2768 {'acl_index': acl_index})
2769
2770 def macip_acl_interface_add_del(self,
2771 sw_if_index,
2772 acl_index,
2773 is_add=1):
2774 """ Add MACIP acl to interface
2775
2776 :param sw_if_index:
2777 :param acl_index:
2778 :param is_add: (Default value = 1)
2779 """
2780
2781 return self.api(self.papi.macip_acl_interface_add_del,
2782 {'is_add': is_add,
2783 'sw_if_index': sw_if_index,
2784 'acl_index': acl_index})
2785
2786 def macip_acl_interface_get(self):
2787 """ Return interface acls dump
2788 """
2789 return self.api(
2790 self.papi.macip_acl_interface_get, {})
2791
2792 def macip_acl_dump(self, acl_index=4294967295):
2793 """ Return MACIP acl dump
2794 """
2795
2796 return self.api(
2797 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002798
2799 def policer_add_del(self,
2800 name,
2801 cir,
2802 eir,
2803 cb,
2804 eb,
2805 is_add=1,
2806 rate_type=0,
2807 round_type=0,
2808 ptype=0,
2809 color_aware=0,
2810 conform_action_type=1,
2811 conform_dscp=0,
2812 exceed_action_type=0,
2813 exceed_dscp=0,
2814 violate_action_type=0,
2815 violate_dscp=0):
2816 return self.api(self.papi.policer_add_del,
2817 {'name': name,
2818 'cir': cir,
2819 'eir': eir,
2820 'cb': cb,
2821 'eb': eb,
2822 'is_add': is_add,
2823 'rate_type': rate_type,
2824 'round_type': round_type,
2825 'type': ptype,
2826 'color_aware': color_aware,
2827 'conform_action_type': conform_action_type,
2828 'conform_dscp': conform_dscp,
2829 'exceed_action_type': exceed_action_type,
2830 'exceed_dscp': exceed_dscp,
2831 'violate_action_type': violate_action_type,
2832 'violate_dscp': violate_dscp})
2833
2834 def ip_punt_police(self,
2835 policer_index,
2836 is_ip6=0,
2837 is_add=1):
2838 return self.api(self.papi.ip_punt_police,
2839 {'policer_index': policer_index,
2840 'is_add': is_add,
2841 'is_ip6': is_ip6})
2842
2843 def ip_punt_redirect(self,
2844 rx_sw_if_index,
2845 tx_sw_if_index,
2846 nh,
2847 is_ip6=0,
2848 is_add=1):
2849 return self.api(self.papi.ip_punt_redirect,
2850 {'rx_sw_if_index': rx_sw_if_index,
2851 'tx_sw_if_index': tx_sw_if_index,
2852 'nh': nh,
2853 'is_add': is_add,
2854 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002855
2856 def bier_table_add_del(self,
2857 bti,
2858 mpls_label,
2859 is_add=1):
2860 """ BIER Table add/del """
2861 return self.api(
2862 self.papi.bier_table_add_del,
2863 {'bt_tbl_id': {"bt_set": bti.set_id,
2864 "bt_sub_domain": bti.sub_domain_id,
2865 "bt_hdr_len_id": bti.hdr_len_id},
2866 'bt_label': mpls_label,
2867 'bt_is_add': is_add})
2868
2869 def bier_table_dump(self):
2870 return self.api(self.papi.bier_table_dump, {})
2871
2872 def bier_route_add_del(self,
2873 bti,
2874 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002875 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002876 is_add=1):
2877 """ BIER Route add/del """
Neale Ranns91286372017-12-05 13:24:04 -08002878 br_paths = []
2879 for p in paths:
2880 br_paths.append({'next_hop': p.nh_addr,
2881 'weight': 1,
2882 'afi': 0,
2883 'preference': 0,
2884 'table_id': p.nh_table_id,
2885 'next_hop_id': p.next_hop_id,
2886 'is_udp_encap': p.is_udp_encap,
2887 'n_labels': len(p.nh_labels),
2888 'label_stack': p.nh_labels})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002889 return self.api(
2890 self.papi.bier_route_add_del,
2891 {'br_tbl_id': {"bt_set": bti.set_id,
2892 "bt_sub_domain": bti.sub_domain_id,
2893 "bt_hdr_len_id": bti.hdr_len_id},
2894 'br_bp': bp,
Neale Ranns91286372017-12-05 13:24:04 -08002895 'br_n_paths': len(br_paths),
2896 'br_paths': br_paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002897 'br_is_add': is_add})
2898
2899 def bier_route_dump(self, bti):
2900 return self.api(
2901 self.papi.bier_route_dump,
2902 {'br_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
2906 def bier_imp_add(self,
2907 bti,
2908 src,
2909 ibytes,
2910 is_add=1):
2911 """ BIER Imposition Add """
2912 return self.api(
2913 self.papi.bier_imp_add,
2914 {'bi_tbl_id': {"bt_set": bti.set_id,
2915 "bt_sub_domain": bti.sub_domain_id,
2916 "bt_hdr_len_id": bti.hdr_len_id},
2917 'bi_src': src,
2918 'bi_n_bytes': len(ibytes),
2919 'bi_bytes': ibytes})
2920
2921 def bier_imp_del(self, bi_index):
2922 """ BIER Imposition del """
2923 return self.api(
2924 self.papi.bier_imp_del,
2925 {'bi_index': bi_index})
2926
2927 def bier_imp_dump(self):
2928 return self.api(self.papi.bier_imp_dump, {})
2929
2930 def bier_disp_table_add_del(self,
2931 bdti,
2932 is_add=1):
2933 """ BIER Disposition Table add/del """
2934 return self.api(
2935 self.papi.bier_disp_table_add_del,
2936 {'bdt_tbl_id': bdti,
2937 'bdt_is_add': is_add})
2938
2939 def bier_disp_table_dump(self):
2940 return self.api(self.papi.bier_disp_table_dump, {})
2941
2942 def bier_disp_entry_add_del(self,
2943 bdti,
2944 bp,
2945 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002946 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002947 next_hop,
2948 next_hop_tbl_id=0,
2949 next_hop_rpf_id=~0,
2950 next_hop_is_ip4=1,
2951 is_add=1):
2952 """ BIER Route add/del """
2953 return self.api(
2954 self.papi.bier_disp_entry_add_del,
2955 {'bde_tbl_id': bdti,
2956 'bde_bp': bp,
2957 'bde_payload_proto': payload_proto,
2958 'bde_n_paths': 1,
2959 'bde_paths': [{'next_hop': next_hop,
2960 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002961 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002962 'rpf_id': next_hop_rpf_id,
2963 'n_labels': 0,
2964 'label_stack': [0]}],
2965 'bde_is_add': is_add})
2966
2967 def bier_disp_entry_dump(self, bdti):
2968 return self.api(
2969 self.papi.bier_disp_entry_dump,
2970 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002971
2972 def add_node_next(self, node_name, next_name):
2973 """ Set the next node for a given node request
2974
2975 :param node_name:
2976 :param next_name:
2977 """
2978 return self.api(self.papi.add_node_next,
2979 {'node_name': node_name,
2980 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08002981
2982 def session_enable_disable(self, is_enabled):
2983 return self.api(
2984 self.papi.session_enable_disable,
2985 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002986
2987 def ipsec_spd_add_del(self, spd_id, is_add=1):
2988 """ SPD add/del - Wrapper to add or del ipsec SPD
2989 Sample CLI : 'ipsec spd add 1'
2990
2991 :param spd_id - SPD ID to be created in the vpp . mandatory
2992 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2993 optional
2994 :returns: reply from the API
2995 """
2996 return self.api(
2997 self.papi.ipsec_spd_add_del, {
2998 'spd_id': spd_id, 'is_add': is_add})
2999
3000 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3001 """ IPSEC interface SPD add/del - \
3002 Wrapper to associate/disassociate SPD to interface in VPP
3003 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3004
3005 :param spd_id - SPD ID to associate with the interface . mandatory
3006 :param sw_if_index - Interface Index which needs to ipsec \
3007 association mandatory
3008 :param is_add - add(1) or del(0) association with interface \
3009 (Default 1 - add) . optional
3010 :returns: reply from the API
3011 """
3012 return self.api(
3013 self.papi.ipsec_interface_add_del_spd, {
3014 'spd_id': spd_id,
3015 'sw_if_index': sw_if_index, 'is_add': is_add})
3016
3017 def ipsec_sad_add_del_entry(self,
3018 sad_id,
3019 spi,
3020 tunnel_src_address='',
3021 tunnel_dst_address='',
3022 protocol=0,
3023 integrity_algorithm=2,
3024 integrity_key_length=0,
3025 integrity_key='C91KUR9GYMm5GfkEvNjX',
3026 crypto_algorithm=1,
3027 crypto_key_length=0,
3028 crypto_key='JPjyOWBeVEQiMe7h',
3029 is_add=1,
3030 is_tunnel=1):
3031 """ IPSEC SA add/del
3032 Sample CLI : 'ipsec sa add 10 spi 1001 esp \
3033 crypto-key 4a506a794f574265564551694d653768 \
3034 crypto-alg aes-cbc-128 \
3035 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3036 integ-alg sha1-96 tunnel-src 192.168.100.3 \
3037 tunnel-dst 192.168.100.2'
3038 Sample CLI : 'ipsec sa add 20 spi 2001 \
3039 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3040 integ-alg sha1-96'
3041
3042 :param sad_id - Security Association ID to be \
3043 created or deleted. mandatory
3044 :param spi - security param index of the SA in decimal. mandatory
3045 :param tunnel_src_address - incase of tunnel mode outer src address .\
3046 mandatory for tunnel mode
3047 :param tunnel_dst_address - incase of transport mode \
3048 outer dst address. mandatory for tunnel mode
3049 :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional
3050 :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\
3051 optional **
3052 :param integrity_key - value in string \
3053 (Default C91KUR9GYMm5GfkEvNjX).optional
3054 :param integrity_key_length - length of the key string in bytes\
3055 (Default 0 - integrity disabled). optional
3056 :param crypto_algorithm - value range 1-11 Default \
3057 (1- AES_CBC_128).optional **
3058 :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional
3059 :param crypto_key_length - length of the key string in bytes\
3060 (Default 0 - crypto disabled). optional
3061 :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\
3062 optional
3063 :param is_tunnel - tunnel mode (1) or transport mode(0) \
3064 (Default 1 - tunnel). optional
3065 :returns: reply from the API
3066 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3067 crypto and ipsec algorithms
3068 """
3069 return self.api(
3070 self.papi.ipsec_sad_add_del_entry,
3071 {'sad_id': sad_id,
3072 'spi': spi,
3073 'tunnel_src_address': tunnel_src_address,
3074 'tunnel_dst_address': tunnel_dst_address,
3075 'protocol': protocol,
3076 'integrity_algorithm': integrity_algorithm,
3077 'integrity_key_length': integrity_key_length,
3078 'integrity_key': integrity_key,
3079 'crypto_algorithm': crypto_algorithm,
3080 'crypto_key_length': crypto_key_length,
3081 'crypto_key': crypto_key,
3082 'is_add': is_add,
3083 'is_tunnel': is_tunnel})
3084
3085 def ipsec_spd_add_del_entry(self,
3086 spd_id,
3087 local_address_start,
3088 local_address_stop,
3089 remote_address_start,
3090 remote_address_stop,
3091 local_port_start=0,
3092 local_port_stop=65535,
3093 remote_port_start=0,
3094 remote_port_stop=65535,
3095 protocol=0,
3096 sa_id=10,
3097 policy=0,
3098 priority=100,
3099 is_outbound=1,
3100 is_add=1,
3101 is_ip_any=0):
3102 """ IPSEC policy SPD add/del -
3103 Wrapper to configure ipsec SPD policy entries in VPP
3104 Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \
3105 protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \
3106 remote-ip-range 192.168.3.3 - 192.168.3.3'
3107
3108 :param spd_id - SPD ID for the policy . mandatory
3109 :param local_address_start - local-ip-range start address . mandatory
3110 :param local_address_stop - local-ip-range stop address . mandatory
3111 :param remote_address_start - remote-ip-range start address . mandatory
3112 :param remote_address_stop - remote-ip-range stop address . mandatory
3113 :param local_port_start - (Default 0) . optional
3114 :param local_port_stop - (Default 65535). optional
3115 :param remote_port_start - (Default 0). optional
3116 :param remote_port_stop - (Default 65535). optional
3117 :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any).
3118 optional
3119 :param sa_id - Security Association ID for mapping it to SPD
3120 (default 10). optional
3121 :param policy - bypass(0), discard(1), resolve(2) or protect(3)action
3122 (Default 0 - bypass). optional
3123 :param priotity - value for the spd action (Default 100). optional
3124 :param is_outbound - flag for inbound(0) or outbound(1)
3125 (Default 1 - outbound). optional
3126 :param is_add flag - for addition(1) or deletion(0) of the spd
3127 (Default 1 - addtion). optional
3128 :returns: reply from the API
3129 """
3130 return self.api(
3131 self.papi.ipsec_spd_add_del_entry,
3132 {'spd_id': spd_id,
3133 'local_address_start': local_address_start,
3134 'local_address_stop': local_address_stop,
3135 'remote_address_start': remote_address_start,
3136 'remote_address_stop': remote_address_stop,
3137 'local_port_start': local_port_start,
3138 'local_port_stop': local_port_stop,
3139 'remote_port_start': remote_port_start,
3140 'remote_port_stop': remote_port_stop,
3141 'is_add': is_add,
3142 'protocol': protocol,
3143 'policy': policy,
3144 'priority': priority,
3145 'is_outbound': is_outbound,
3146 'sa_id': sa_id,
3147 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003148
3149 def app_namespace_add(self,
3150 namespace_id,
3151 ip4_fib_id=0,
3152 ip6_fib_id=0,
3153 sw_if_index=0xFFFFFFFF,
3154 secret=0):
3155 return self.api(
3156 self.papi.app_namespace_add_del,
3157 {'secret': secret,
3158 'sw_if_index': sw_if_index,
3159 'ip4_fib_id': ip4_fib_id,
3160 'ip6_fib_id': ip6_fib_id,
3161 'namespace_id': namespace_id,
3162 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003163
3164 def punt_socket_register(self, l4_port, pathname, header_version=1,
3165 is_ip4=1, l4_protocol=0x11):
3166 """ Punt to socket """
3167 return self.api(self.papi.punt_socket_register,
3168 {'is_ip4': is_ip4,
3169 'l4_protocol': l4_protocol,
3170 'l4_port': l4_port,
3171 'pathname': pathname,
3172 'header_version': header_version})
3173
3174 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3175 expire_walk_interval_ms, is_ip6=0):
3176 """ Set IP reassembly parameters """
3177 return self.api(self.papi.ip_reassembly_set,
3178 {'is_ip6': is_ip6,
3179 'timeout_ms': timeout_ms,
3180 'expire_walk_interval_ms': expire_walk_interval_ms,
3181 'max_reassemblies': max_reassemblies})
3182
3183 def ip_reassembly_get(self, is_ip6=0):
3184 """ Get IP reassembly parameters """
3185 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003186
3187 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3188 """ GBP endpoint Add/Del """
3189 return self.api(self.papi.gbp_endpoint_add_del,
3190 {'is_add': is_add,
3191 'endpoint': {
3192 'is_ip6': is_ip6,
3193 'sw_if_index': sw_if_index,
3194 'address': addr,
3195 'epg_id': epg}})
3196
3197 def gbp_endpoint_dump(self):
3198 """ GBP endpoint Dump """
3199 return self.api(self.papi.gbp_endpoint_dump, {})
3200
3201 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3202 """ GBP contract Add/Del """
3203 return self.api(self.papi.gbp_contract_add_del,
3204 {'is_add': is_add,
3205 'contract': {
3206 'acl_index': acl_index,
3207 'src_epg': src_epg,
3208 'dst_epg': dst_epg}})
3209
3210 def gbp_contract_dump(self):
3211 """ GBP contract Dump """
3212 return self.api(self.papi.gbp_contract_dump, {})