blob: 242f51cde625db709c0cdc11703cb4d704173213 [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,
365 vni=0):
366 """
367
368 :param dst_addr:
369 :param src_addr:
370 :param is_add: (Default value = 1)
371 :param is_ipv6: (Default value = 0)
372 :param encap_vrf_id: (Default value = 0)
373 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200374 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200375 :param vni: (Default value = 0)
376
377 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100378 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200379 {'is_add': is_add,
380 'is_ipv6': is_ipv6,
381 'src_address': src_addr,
382 'dst_address': dst_addr,
383 'mcast_sw_if_index': mcast_sw_if_index,
384 'encap_vrf_id': encap_vrf_id,
385 'decap_next_index': decap_next_index,
386 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387
Marco Varleseb598f1d2017-09-19 14:25:28 +0200388 def geneve_add_del_tunnel(
389 self,
390 local_addr,
391 remote_addr,
392 mcast_sw_if_index=0xFFFFFFFF,
393 is_add=1,
394 is_ipv6=0,
395 encap_vrf_id=0,
396 decap_next_index=0xFFFFFFFF,
397 vni=0):
398 """
399
400 :param remote_addr:
401 :param local_addr:
402 :param is_add: (Default value = 1)
403 :param is_ipv6: (Default value = 0)
404 :param encap_vrf_id: (Default value = 0)
405 :param decap_next_index: (Default value = 0xFFFFFFFF)
406 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
407 :param vni: (Default value = 0)
408
409 """
410 return self.api(self.papi.geneve_add_del_tunnel,
411 {'is_add': is_add,
412 'is_ipv6': is_ipv6,
413 'local_address': local_addr,
414 'remote_address': remote_addr,
415 'mcast_sw_if_index': mcast_sw_if_index,
416 'encap_vrf_id': encap_vrf_id,
417 'decap_next_index': decap_next_index,
418 'vni': vni})
419
Jan4af521d2016-11-15 17:05:00 +0100420 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
421 learn=1, arp_term=0, is_add=1):
422 """Create/delete bridge domain.
423
424 :param int bd_id: Bridge domain index.
425 :param int flood: Enable/disable bcast/mcast flooding in the BD.
426 (Default value = 1)
427 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
428 (Default value = 1)
429 :param int forward: Enable/disable forwarding on all interfaces in
430 the BD. (Default value = 1)
431 :param int learn: Enable/disable learning on all interfaces in the BD.
432 (Default value = 1)
433 :param int arp_term: Enable/disable arp termination in the BD.
434 (Default value = 1)
435 :param int is_add: Add or delete flag. (Default value = 1)
436 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100437 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200438 {'bd_id': bd_id,
439 'flood': flood,
440 'uu_flood': uu_flood,
441 'forward': forward,
442 'learn': learn,
443 'arp_term': arp_term,
444 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100445
Eyal Baric86e5922017-07-02 18:33:16 +0300446 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
447 return self.api(self.papi.bd_ip_mac_add_del,
448 {'bd_id': bd_id,
449 'is_add': is_add,
450 'is_ipv6': is_ipv6,
451 'ip_address': ip,
452 'mac_address': mac})
453
Eyal Bari20197482017-09-13 12:29:08 +0300454 def want_ip4_arp_events(self, enable_disable=1, address=0):
455 return self.api(self.papi.want_ip4_arp_events,
456 {'enable_disable': enable_disable,
457 'address': address,
458 'pid': os.getpid(), })
459
Eyal Baric125ecc2017-09-20 11:29:17 +0300460 def want_ip6_nd_events(self, enable_disable=1, address=0):
461 return self.api(self.papi.want_ip6_nd_events,
462 {'enable_disable': enable_disable,
463 'address': address,
464 'pid': os.getpid(), })
465
Eyal Bari24db0ec2017-09-27 21:43:51 +0300466 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
467 max_macs_in_event=0, learn_limit=0):
468 return self.api(self.papi.want_l2_macs_events,
469 {'enable_disable': enable_disable,
470 'scan_delay': scan_delay,
471 'max_macs_in_event': max_macs_in_event,
472 'learn_limit': learn_limit,
473 'pid': os.getpid(), })
474
Jan4af521d2016-11-15 17:05:00 +0100475 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
476 filter_mac=0, bvi_mac=0):
477 """Create/delete L2 FIB entry.
478
479 :param str mac: MAC address to create FIB entry for.
480 :param int bd_id: Bridge domain index.
481 :param int sw_if_index: Software interface index of the interface.
482 :param int is_add: Add or delete flag. (Default value = 1)
483 :param int static_mac: Set to 1 to create static MAC entry.
484 (Default value = 0)
485 :param int filter_mac: Set to 1 to drop packet that's source or
486 destination MAC address contains defined MAC address.
487 (Default value = 0)
488 :param int bvi_mac: Set to 1 to create entry that points to BVI
489 interface. (Default value = 0)
490 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100491 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200492 {'mac': self._convert_mac(mac),
493 'bd_id': bd_id,
494 'sw_if_index': sw_if_index,
495 'is_add': is_add,
496 'static_mac': static_mac,
497 'filter_mac': filter_mac,
498 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100499
Eyal Bari93b503e2017-05-15 10:13:15 +0300500 def l2fib_flush_int(self, sw_if_index):
501 """Flush L2 FIB entries for sw_if_index.
502
503 :param int sw_if_index: Software interface index of the interface.
504 """
505 return self.api(self.papi.l2fib_flush_int,
506 {'sw_if_index': sw_if_index})
507
508 def l2fib_flush_bd(self, bd_id):
509 """Flush L2 FIB entries for bd_id.
510
511 :param int sw_if_index: Bridge Domain id.
512 """
513 return self.api(self.papi.l2fib_flush_bd,
514 {'bd_id': bd_id})
515
516 def l2fib_flush_all(self):
517 """Flush all L2 FIB.
518 """
519 return self.api(self.papi.l2fib_flush_all, {})
520
Klement Sekeraf62ae122016-10-11 11:47:09 +0200521 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
522 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100523 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200524
Jan4af521d2016-11-15 17:05:00 +0100525 :param int sw_if_index: Software interface index of the interface.
526 :param int bd_id: Bridge domain index.
527 :param int shg: Split-horizon group index. (Default value = 0)
528 :param int bvi: Set interface as a bridge group virtual interface.
529 (Default value = 0)
530 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200531 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100532 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200533 {'rx_sw_if_index': sw_if_index,
534 'bd_id': bd_id,
535 'shg': shg,
536 'bvi': bvi,
537 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200538
Jan00dad122016-11-29 10:04:53 +0100539 def bridge_flags(self, bd_id, is_set, feature_bitmap):
540 """Enable/disable required feature of the bridge domain with defined ID.
541
542 :param int bd_id: Bridge domain ID.
543 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
544 :param int feature_bitmap: Bitmap value of the feature to be set:
545 - learn (1 << 0),
546 - forward (1 << 1),
547 - flood (1 << 2),
548 - uu-flood (1 << 3) or
549 - arp-term (1 << 4).
550 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100551 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200552 {'bd_id': bd_id,
553 'is_set': is_set,
554 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100555
556 def bridge_domain_dump(self, bd_id=0):
557 """
558
559 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
560 existing bridge domains returned)
561 :return: Dictionary of bridge domain(s) data.
562 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100563 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200564 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100565
Klement Sekeraf62ae122016-10-11 11:47:09 +0200566 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
567 enable):
568 """Create or delete unidirectional cross-connect from Tx interface to
569 Rx interface.
570
Jan4af521d2016-11-15 17:05:00 +0100571 :param int rx_sw_if_index: Software interface index of Rx interface.
572 :param int tx_sw_if_index: Software interface index of Tx interface.
573 :param int enable: Create cross-connect if equal to 1, delete
574 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200575
576 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100577 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200578 {'rx_sw_if_index': rx_sw_if_index,
579 'tx_sw_if_index': tx_sw_if_index,
580 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200581
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200582 def sw_interface_set_l2_tag_rewrite(
583 self,
584 sw_if_index,
585 vtr_oper,
586 push=0,
587 tag1=0,
588 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000589 """L2 interface vlan tag rewrite configure request
590 :param client_index - opaque cookie to identify the sender
591 :param context - sender context, to match reply w/ request
592 :param sw_if_index - interface the operation is applied to
593 :param vtr_op - Choose from l2_vtr_op_t enum values
594 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
595 :param tag1 - Needed for any push or translate vtr op
596 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
597
598 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100599 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200600 {'sw_if_index': sw_if_index,
601 'vtr_op': vtr_oper,
602 'push_dot1q': push,
603 'tag1': tag1,
604 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000605
Neale Ranns55d03782017-10-21 06:34:22 -0700606 def sw_interface_set_l2_emulation(
607 self,
608 sw_if_index,
609 enable=1):
610 """L2 Emulation
611 :param sw_if_index - interface the operation is applied to
612
613 """
614 return self.api(self.papi.l2_emulation,
615 {'sw_if_index': sw_if_index,
616 'enable': enable})
617
Neale Rannsa07bd702017-08-07 07:53:49 -0700618 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200619 """
620
621 :param admin_up_down:
622 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200623
624 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100625 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200626 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700627 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200628
629 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
630 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
631 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
632 """Create subinterface
633 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
634
635 :param sub_id: param inner_vlan:
636 :param sw_if_index:
637 :param outer_vlan:
638 :param inner_vlan:
639 :param no_tags: (Default value = 0)
640 :param one_tag: (Default value = 0)
641 :param two_tags: (Default value = 0)
642 :param dot1ad: (Default value = 0)
643 :param exact_match: (Default value = 0)
644 :param default_sub: (Default value = 0)
645 :param outer_vlan_id_any: (Default value = 0)
646 :param inner_vlan_id_any: (Default value = 0)
647
648 """
649 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100650 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200651 {'sw_if_index': sw_if_index,
652 'sub_id': sub_id,
653 'no_tags': no_tags,
654 'one_tag': one_tag,
655 'two_tags': two_tags,
656 'dot1ad': dot1ad,
657 'exact_match': exact_match,
658 'default_sub': default_sub,
659 'outer_vlan_id_any': outer_vlan_id_any,
660 'inner_vlan_id_any': inner_vlan_id_any,
661 'outer_vlan_id': outer_vlan,
662 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200663
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200664 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
665 """Create p2p ethernet subinterface
666
667 :param sw_if_index: main (parent) interface
668 :param remote_mac: client (remote) mac address
669
670 """
671 return self.api(
672 self.papi.p2p_ethernet_add,
673 {'parent_if_index': sw_if_index,
674 'remote_mac': remote_mac,
675 'subif_id': subif_id})
676
Neale Ranns177bbdc2016-11-15 09:46:51 +0000677 def delete_subif(self, sw_if_index):
678 """Delete subinterface
679
680 :param sw_if_index:
681 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100682 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200683 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000684
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200685 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
686 """Delete p2p ethernet subinterface
687
688 :param sw_if_index: main (parent) interface
689 :param remote_mac: client (remote) mac address
690
691 """
692 return self.api(
693 self.papi.p2p_ethernet_del,
694 {'parent_if_index': sw_if_index,
695 'remote_mac': remote_mac})
696
Klement Sekeraf62ae122016-10-11 11:47:09 +0200697 def create_vlan_subif(self, sw_if_index, vlan):
698 """
699
700 :param vlan:
701 :param sw_if_index:
702
703 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100704 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200705 {'sw_if_index': sw_if_index,
706 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200707
Matej Klotton0178d522016-11-04 11:11:44 +0100708 def create_loopback(self, mac=''):
709 """
710
711 :param mac: (Optional)
712 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100713 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200714 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100715
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100716 def delete_loopback(self, sw_if_index):
717 return self.api(self.papi.delete_loopback,
718 {'sw_if_index': sw_if_index, })
719
Neale Ranns15002542017-09-10 04:39:11 -0700720 def ip_table_add_del(self,
721 table_id,
722 is_add=1,
723 is_ipv6=0):
724 """
725
726 :param table_id
727 :param is_add: (Default value = 1)
728 :param is_ipv6: (Default value = 0)
729
730 """
731
732 return self.api(
733 self.papi.ip_table_add_del,
734 {'table_id': table_id,
735 'is_add': is_add,
736 'is_ipv6': is_ipv6})
737
Klement Sekeraf62ae122016-10-11 11:47:09 +0200738 def ip_add_del_route(
739 self,
740 dst_address,
741 dst_address_length,
742 next_hop_address,
743 next_hop_sw_if_index=0xFFFFFFFF,
744 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200745 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000746 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200747 next_hop_n_out_labels=0,
748 next_hop_out_label_stack=[],
749 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800750 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000751 is_resolve_host=0,
752 is_resolve_attached=0,
753 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200754 is_add=1,
755 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200756 is_unreach=0,
757 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200758 is_ipv6=0,
759 is_local=0,
760 is_classify=0,
761 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800762 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800763 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200764 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200765 """
766
767 :param dst_address_length:
768 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
769 :param dst_address:
770 :param next_hop_address:
771 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
772 :param vrf_id: (Default value = 0)
773 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200774 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200775 :param is_add: (Default value = 1)
776 :param is_drop: (Default value = 0)
777 :param is_ipv6: (Default value = 0)
778 :param is_local: (Default value = 0)
779 :param is_classify: (Default value = 0)
780 :param is_multipath: (Default value = 0)
781 :param is_resolve_host: (Default value = 0)
782 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800783 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700784 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200785 :param next_hop_weight: (Default value = 1)
786
787 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000788
Klement Sekeraf62ae122016-10-11 11:47:09 +0200789 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100790 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200791 {'next_hop_sw_if_index': next_hop_sw_if_index,
792 'table_id': table_id,
793 'classify_table_index': classify_table_index,
794 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200795 'is_add': is_add,
796 'is_drop': is_drop,
797 'is_unreach': is_unreach,
798 'is_prohibit': is_prohibit,
799 'is_ipv6': is_ipv6,
800 'is_local': is_local,
801 'is_classify': is_classify,
802 'is_multipath': is_multipath,
803 'is_resolve_host': is_resolve_host,
804 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800805 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700806 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800807 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200808 'next_hop_weight': next_hop_weight,
809 'dst_address_length': dst_address_length,
810 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800811 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200812 'next_hop_address': next_hop_address,
813 'next_hop_n_out_labels': next_hop_n_out_labels,
814 'next_hop_via_label': next_hop_via_label,
815 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100816
Matej Klotton16a14cd2016-12-07 15:09:13 +0100817 def ip_fib_dump(self):
818 return self.api(self.papi.ip_fib_dump, {})
819
Jan Gelety057bb8c2016-12-20 17:32:45 +0100820 def ip6_fib_dump(self):
821 return self.api(self.papi.ip6_fib_dump, {})
822
Matej Klotton0178d522016-11-04 11:11:44 +0100823 def ip_neighbor_add_del(self,
824 sw_if_index,
825 mac_address,
826 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100827 is_add=1,
828 is_ipv6=0,
829 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800830 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100831 ):
832 """ Add neighbor MAC to IPv4 or IPv6 address.
833
834 :param sw_if_index:
835 :param mac_address:
836 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100837 :param is_add: (Default value = 1)
838 :param is_ipv6: (Default value = 0)
839 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800840 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100841 """
842
843 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100844 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800845 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200846 'is_add': is_add,
847 'is_ipv6': is_ipv6,
848 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800849 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200850 'mac_address': mac_address,
851 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100852 }
Matej Klotton0178d522016-11-04 11:11:44 +0100853 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100854
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800855 def ip_neighbor_dump(self,
856 sw_if_index,
857 is_ipv6=0):
858 """ Return IP neighbor dump.
859
860 :param sw_if_index:
861 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
862 """
863
864 return self.api(
865 self.papi.ip_neighbor_dump,
866 {'is_ipv6': is_ipv6,
867 'sw_if_index': sw_if_index
868 }
869 )
870
871 def proxy_arp_add_del(self,
872 low_address,
873 hi_address,
874 vrf_id=0,
875 is_add=1):
876 """ Config Proxy Arp Range.
877
878 :param low_address: Start address in the rnage to Proxy for
879 :param hi_address: End address in the rnage to Proxy for
880 :param vrf_id: The VRF/table in which to proxy
881 """
882
883 return self.api(
884 self.papi.proxy_arp_add_del,
885 {'vrf_id': vrf_id,
886 'is_add': is_add,
887 'low_address': low_address,
888 'hi_address': hi_address,
889 }
890 )
891
892 def proxy_arp_intfc_enable_disable(self,
893 sw_if_index,
894 is_enable=1):
895 """ Enable/Disable an interface for proxy ARP requests
896
897 :param sw_if_index: Interface
898 :param enable_disable: Enable/Disable
899 """
900
901 return self.api(
902 self.papi.proxy_arp_intfc_enable_disable,
903 {'sw_if_index': sw_if_index,
904 'enable_disable': is_enable
905 }
906 )
907
Jane546d3b2016-12-08 13:10:03 +0100908 def reset_vrf(self,
909 vrf_id,
910 is_ipv6=0,
911 ):
912 """ Reset VRF (remove all routes etc.) request.
913
914 :param int vrf_id: ID of the FIB table / VRF to reset.
915 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
916 """
917
918 return self.api(
919 self.papi.reset_vrf,
920 {'vrf_id': vrf_id,
921 'is_ipv6': is_ipv6,
922 }
923 )
924
925 def reset_fib(self,
926 vrf_id,
927 is_ipv6=0,
928 ):
929 """ Reset VRF (remove all routes etc.) request.
930
931 :param int vrf_id: ID of the FIB table / VRF to reset.
932 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
933 """
934
935 return self.api(
936 self.papi.reset_fib,
937 {'vrf_id': vrf_id,
938 'is_ipv6': is_ipv6,
939 }
940 )
941
942 def ip_dump(self,
943 is_ipv6=0,
944 ):
945 """ Return IP dump.
946
947 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
948 """
949
950 return self.api(
951 self.papi.ip_dump,
952 {'is_ipv6': is_ipv6,
953 }
954 )
955
Klement Sekera7bb873a2016-11-18 07:38:42 +0100956 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300957 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100958 """
959
960 :param sw_if_index_from:
961 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100962 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300963 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100964 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100965 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200966 {'sw_if_index_from': sw_if_index_from,
967 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300968 'state': state,
969 'is_l2': is_l2,
970 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000971
972 def gre_tunnel_add_del(self,
973 src_address,
974 dst_address,
975 outer_fib_id=0,
976 is_teb=0,
977 is_add=1,
978 is_ip6=0):
979 """ Add a GRE tunnel
980
981 :param src_address:
982 :param dst_address:
983 :param outer_fib_id: (Default value = 0)
984 :param is_add: (Default value = 1)
985 :param is_ipv6: (Default value = 0)
986 :param is_teb: (Default value = 0)
987 """
988
989 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100990 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200991 {'is_add': is_add,
992 'is_ipv6': is_ip6,
993 'teb': is_teb,
994 'src_address': src_address,
995 'dst_address': dst_address,
996 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000997 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000998
Neale Ranns810086d2017-11-05 16:26:46 -0800999 def udp_encap_add_del(self,
1000 id,
1001 src_ip,
1002 dst_ip,
1003 src_port,
1004 dst_port,
1005 table_id=0,
1006 is_add=1,
1007 is_ip6=0):
1008 """ Add a GRE tunnel
1009 :param id: user provided ID
1010 :param src_ip:
1011 :param dst_ip:
1012 :param src_port:
1013 :param dst_port:
1014 :param outer_fib_id: (Default value = 0)
1015 :param is_add: (Default value = 1)
1016 :param is_ipv6: (Default value = 0)
1017 """
1018
1019 return self.api(
1020 self.papi.udp_encap_add_del,
1021 {'id': id,
1022 'is_add': is_add,
1023 'is_ip6': is_ip6,
1024 'src_ip': src_ip,
1025 'dst_ip': dst_ip,
1026 'src_port': src_port,
1027 'dst_port': dst_port,
1028 'table_id': table_id}
1029 )
1030
1031 def udp_encap_dump(self):
1032 return self.api(self.papi.udp_encap_dump, {})
1033
Neale Ranns5a8123b2017-01-26 01:18:23 -08001034 def mpls_fib_dump(self):
1035 return self.api(self.papi.mpls_fib_dump, {})
1036
Neale Ranns15002542017-09-10 04:39:11 -07001037 def mpls_table_add_del(
1038 self,
1039 table_id,
1040 is_add=1):
1041 """
1042
1043 :param table_id
1044 :param is_add: (Default value = 1)
1045
1046 """
1047
1048 return self.api(
1049 self.papi.mpls_table_add_del,
1050 {'mt_table_id': table_id,
1051 'mt_is_add': is_add})
1052
Neale Rannsad422ed2016-11-02 14:20:04 +00001053 def mpls_route_add_del(
1054 self,
1055 label,
1056 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001057 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001058 next_hop_address,
1059 next_hop_sw_if_index=0xFFFFFFFF,
1060 table_id=0,
1061 next_hop_table_id=0,
1062 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001063 next_hop_n_out_labels=0,
1064 next_hop_out_label_stack=[],
1065 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001066 is_resolve_host=0,
1067 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001068 is_interface_rx=0,
1069 is_rpf_id=0,
1070 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001071 is_add=1,
1072 is_drop=0,
1073 is_multipath=0,
1074 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001075 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001076 """
1077
1078 :param dst_address_length:
1079 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1080 :param dst_address:
1081 :param next_hop_address:
1082 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1083 :param vrf_id: (Default value = 0)
1084 :param lookup_in_vrf: (Default value = 0)
1085 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001086 :param is_add: (Default value = 1)
1087 :param is_drop: (Default value = 0)
1088 :param is_ipv6: (Default value = 0)
1089 :param is_local: (Default value = 0)
1090 :param is_classify: (Default value = 0)
1091 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001092 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001093 :param is_resolve_host: (Default value = 0)
1094 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001095 :param next_hop_weight: (Default value = 1)
1096
1097 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001098
1099 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001100 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001101 {'mr_label': label,
1102 'mr_eos': eos,
1103 'mr_table_id': table_id,
1104 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001105 'mr_is_add': is_add,
1106 'mr_is_classify': is_classify,
1107 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001108 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001109 'mr_is_resolve_host': is_resolve_host,
1110 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001111 'mr_is_interface_rx': is_interface_rx,
1112 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001113 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001114 'mr_next_hop_weight': next_hop_weight,
1115 'mr_next_hop': next_hop_address,
1116 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1117 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1118 'mr_next_hop_table_id': next_hop_table_id,
1119 'mr_next_hop_via_label': next_hop_via_label,
1120 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001121
1122 def mpls_ip_bind_unbind(
1123 self,
1124 label,
1125 dst_address,
1126 dst_address_length,
1127 table_id=0,
1128 ip_table_id=0,
1129 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001130 is_bind=1):
1131 """
1132 """
1133 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001134 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001135 {'mb_mpls_table_id': table_id,
1136 'mb_label': label,
1137 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001138 'mb_is_bind': is_bind,
1139 'mb_is_ip4': is_ip4,
1140 'mb_address_length': dst_address_length,
1141 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001142
1143 def mpls_tunnel_add_del(
1144 self,
1145 tun_sw_if_index,
1146 next_hop_proto_is_ip4,
1147 next_hop_address,
1148 next_hop_sw_if_index=0xFFFFFFFF,
1149 next_hop_table_id=0,
1150 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001151 next_hop_n_out_labels=0,
1152 next_hop_out_label_stack=[],
1153 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001154 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001155 l2_only=0,
1156 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001157 """
1158
1159 :param dst_address_length:
1160 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1161 :param dst_address:
1162 :param next_hop_address:
1163 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1164 :param vrf_id: (Default value = 0)
1165 :param lookup_in_vrf: (Default value = 0)
1166 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001167 :param is_add: (Default value = 1)
1168 :param is_drop: (Default value = 0)
1169 :param is_ipv6: (Default value = 0)
1170 :param is_local: (Default value = 0)
1171 :param is_classify: (Default value = 0)
1172 :param is_multipath: (Default value = 0)
1173 :param is_resolve_host: (Default value = 0)
1174 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001175 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001176 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001177
1178 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001179 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001180 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001181 {'mt_sw_if_index': tun_sw_if_index,
1182 'mt_is_add': is_add,
1183 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001184 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001185 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1186 'mt_next_hop_weight': next_hop_weight,
1187 'mt_next_hop': next_hop_address,
1188 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1189 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1190 'mt_next_hop_table_id': next_hop_table_id,
1191 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001192
Matus Fabian2ba92e32017-08-21 07:05:03 -07001193 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001194 self,
1195 sw_if_index,
1196 is_inside=1,
1197 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001198 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001199
1200 :param sw_if_index: Software index of the interface
1201 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1202 :param is_add: 1 if add, 0 if delete (Default value = 1)
1203 """
1204 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001205 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001206 {'is_add': is_add,
1207 'is_inside': is_inside,
1208 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001209
Matus Fabian2ba92e32017-08-21 07:05:03 -07001210 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001211 self,
1212 sw_if_index,
1213 is_inside=1,
1214 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001215 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001216
1217 :param sw_if_index: Software index of the interface
1218 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1219 :param is_add: 1 if add, 0 if delete (Default value = 1)
1220 """
1221 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001222 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001223 {'is_add': is_add,
1224 'is_inside': is_inside,
1225 'sw_if_index': sw_if_index})
1226
Matus Fabian2ba92e32017-08-21 07:05:03 -07001227 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001228 self,
1229 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001230 external_ip=0,
1231 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001232 local_port=0,
1233 external_port=0,
1234 addr_only=1,
1235 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001236 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001237 twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001238 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001239 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001240 is_add=1):
1241 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001242
1243 :param local_ip: Local IP address
1244 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001245 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001246 :param local_port: Local port number (Default value = 0)
1247 :param external_port: External port number (Default value = 0)
1248 :param addr_only: 1 if address only mapping, 0 if address and port
1249 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001250 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001251 :param twice_nat: 1 if translate external host address and port
Matus Fabiane82488f2018-01-18 03:38:45 -08001252 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001253 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001254 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001255 """
1256 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001257 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001258 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001259 'addr_only': addr_only,
1260 'local_ip_address': local_ip,
1261 'external_ip_address': external_ip,
1262 'local_port': local_port,
1263 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001264 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001265 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001266 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001267 'twice_nat': twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001268 'out2in_only': out2in_only,
1269 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001270
Matus Fabianab7a8052017-11-28 04:29:41 -08001271 def nat44_add_del_identity_mapping(
1272 self,
1273 ip='0',
1274 sw_if_index=0xFFFFFFFF,
1275 port=0,
1276 addr_only=1,
1277 vrf_id=0,
1278 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001279 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001280 is_add=1):
1281 """Add/delete NAT44 identity mapping
1282
1283 :param ip: IP address (Default value = 0)
1284 :param sw_if_index: Interface instead of IP address
1285 :param port: Port number (Default value = 0)
1286 :param addr_only: 1 if address only mapping, 0 if address and port
1287 :param vrf_id: VRF ID
1288 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001289 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001290 :param is_add: 1 if add, 0 if delete (Default value = 1)
1291 """
1292 return self.api(
1293 self.papi.nat44_add_del_identity_mapping,
1294 {'is_add': is_add,
1295 'addr_only': addr_only,
1296 'ip_address': ip,
1297 'port': port,
1298 'sw_if_index': sw_if_index,
1299 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001300 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001301 'protocol': protocol})
1302
Matus Fabian2ba92e32017-08-21 07:05:03 -07001303 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001304 self,
1305 first_ip_address,
1306 last_ip_address,
1307 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001308 vrf_id=0xFFFFFFFF,
1309 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001310 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001311
1312 :param first_ip_address: First IP address
1313 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001314 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001315 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001316 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001317 """
1318 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001319 self.papi.nat44_add_del_address_range,
1320 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001321 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001322 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001323 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001324 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001325
Matus Fabian2ba92e32017-08-21 07:05:03 -07001326 def nat44_address_dump(self):
1327 """Dump NAT44 addresses
1328 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001329 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001330 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001331
Matus Fabian2ba92e32017-08-21 07:05:03 -07001332 def nat44_interface_dump(self):
1333 """Dump interfaces with NAT44 feature
1334 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001335 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001336 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001337
Matus Fabian2ba92e32017-08-21 07:05:03 -07001338 def nat44_interface_output_feature_dump(self):
1339 """Dump interfaces with NAT44 output feature
1340 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001341 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001342 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001343
Matus Fabian2ba92e32017-08-21 07:05:03 -07001344 def nat44_static_mapping_dump(self):
1345 """Dump NAT44 static mappings
1346 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001347 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001348 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001349
Matus Fabianab7a8052017-11-28 04:29:41 -08001350 def nat44_identity_mapping_dump(self):
1351 """Dump NAT44 identity mappings
1352 :return: Dictionary of NAT44 identity mappings
1353 """
1354 return self.api(self.papi.nat44_identity_mapping_dump, {})
1355
Matus Fabian2ba92e32017-08-21 07:05:03 -07001356 def nat_show_config(self):
1357 """Show NAT plugin config
1358 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001359 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001360 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001361
Matus Fabian2ba92e32017-08-21 07:05:03 -07001362 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001363 self,
1364 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001365 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001366 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001367 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001368
1369 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001370 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001371 :param is_add: 1 if add, 0 if delete (Default value = 1)
1372 """
Matus Fabianb932d262017-12-18 05:38:24 -08001373 return self.api(
1374 self.papi.nat44_add_del_interface_addr,
1375 {'is_add': is_add,
1376 'sw_if_index': sw_if_index,
1377 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001378
Matus Fabian2ba92e32017-08-21 07:05:03 -07001379 def nat44_interface_addr_dump(self):
1380 """Dump NAT44 addresses interfaces
1381 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001382 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001383 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001384
Matus Fabian2ba92e32017-08-21 07:05:03 -07001385 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001386 self,
1387 domain_id=1,
1388 src_port=4739,
1389 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001390 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001391
1392 :param domain_id: Observation domain ID (Default value = 1)
1393 :param src_port: Source port number (Default value = 4739)
1394 :param enable: 1 if enable, 0 if disable (Default value = 1)
1395 """
1396 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001397 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001398 {'domain_id': domain_id,
1399 'src_port': src_port,
1400 'enable': enable})
1401
Matus Fabian2ba92e32017-08-21 07:05:03 -07001402 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001403 self,
1404 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001405 vrf_id):
1406 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001407
1408 :param ip_address: ip adress of the user to be dumped
1409 :param cpu_index: cpu_index on which the user is
1410 :param vrf_id: VRF ID
1411 :return: Dictionary of S-NAT sessions
1412 """
1413 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001414 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001415 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001416 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001417
Matus Fabian2ba92e32017-08-21 07:05:03 -07001418 def nat44_user_dump(self):
1419 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001420
Matus Fabian2ba92e32017-08-21 07:05:03 -07001421 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001422 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001423 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001424
Matus Fabian704018c2017-09-04 02:17:18 -07001425 def nat44_add_del_lb_static_mapping(
1426 self,
1427 external_addr,
1428 external_port,
1429 protocol,
1430 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001431 twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001432 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001433 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001434 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001435 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001436 is_add=1):
1437 """Add/delete NAT44 load balancing static mapping
1438
Matus Fabianb932d262017-12-18 05:38:24 -08001439 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001440 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001441 :param is_add - 1 if add, 0 if delete
1442 """
1443 return self.api(
1444 self.papi.nat44_add_del_lb_static_mapping,
1445 {'is_add': is_add,
1446 'external_addr': external_addr,
1447 'external_port': external_port,
1448 'protocol': protocol,
1449 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001450 'twice_nat': twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001451 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001452 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001453 'local_num': local_num,
1454 'locals': locals})
1455
1456 def nat44_lb_static_mapping_dump(self):
1457 """Dump NAT44 load balancing static mappings
1458
1459 :return: Dictionary of NAT44 load balancing static mapping
1460 """
1461 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1462
Matus Fabian5ba86f72017-10-26 03:37:38 -07001463 def nat44_del_session(
1464 self,
1465 addr,
1466 port,
1467 protocol,
1468 vrf_id=0,
1469 is_in=1):
1470 """Delete NAT44 session
1471
1472 :param addr: IPv4 address
1473 :param por: port number
1474 :param protocol: IP protocol number
1475 :param vrf_id: VRF ID
1476 :param is_in: 1 if inside network addres and port pari, 0 if outside
1477 """
1478 return self.api(
1479 self.papi.nat44_del_session,
1480 {'address': addr,
1481 'port': port,
1482 'protocol': protocol,
1483 'vrf_id': vrf_id,
1484 'is_in': is_in})
1485
Juraj Sloboda7b929792017-11-23 13:20:48 +01001486 def nat44_forwarding_enable_disable(
1487 self,
1488 enable):
1489 """Enable/disable forwarding for NAT44
1490
1491 :param enable: 1 for enable, 0 for disable
1492 """
1493 return self.api(
1494 self.papi.nat44_forwarding_enable_disable,
1495 {'enable': enable})
1496
Matus Fabianefcd1e92017-08-15 06:59:19 -07001497 def nat_set_reass(
1498 self,
1499 timeout=2,
1500 max_reass=1024,
1501 max_frag=5,
1502 drop_frag=0,
1503 is_ip6=0):
1504 """Set NAT virtual fragmentation reassembly
1505
1506 :param timeout: reassembly timeout (Default 2sec)
1507 :param max_reass: maximum concurrent reassemblies (Default 1024)
1508 :param max_frag: maximum fragmets per reassembly (Default 5)
1509 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1510 :param is_ip6: 1 if IPv6, 0 if IPv4
1511 """
1512 return self.api(
1513 self.papi.nat_set_reass,
1514 {'timeout': timeout,
1515 'max_reass': max_reass,
1516 'max_frag': max_frag,
1517 'drop_frag': drop_frag,
1518 'is_ip6': is_ip6})
1519
1520 def nat_get_reass(self):
1521 """Get NAT virtual fragmentation reassembly configuration
1522
1523 :return: NAT virtual fragmentation reassembly configuration
1524 """
1525 return self.api(self.papi.nat_get_reass, {})
1526
1527 def nat_reass_dump(self):
1528 """Dump NAT virtual fragmentation reassemblies
1529
1530 :return: Dictionary of NAT virtual fragmentation reassemblies
1531 """
1532 return self.api(self.papi.nat_reass_dump, {})
1533
Matus Fabian2ba92e32017-08-21 07:05:03 -07001534 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001535 self,
1536 in_addr,
1537 in_plen,
1538 out_addr,
1539 out_plen,
1540 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001541 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001542
1543 :param is_add - 1 if add, 0 if delete
1544 :param in_addr - inside IP address
1545 :param in_plen - inside IP address prefix length
1546 :param out_addr - outside IP address
1547 :param out_plen - outside IP address prefix length
1548 """
1549 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001550 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001551 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001552 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001553 'in_addr': in_addr,
1554 'in_plen': in_plen,
1555 'out_addr': out_addr,
1556 'out_plen': out_plen})
1557
Matus Fabian2ba92e32017-08-21 07:05:03 -07001558 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001559 self,
1560 in_addr):
1561 """Get outside address and port range from inside address
1562
1563 :param in_addr - inside IP address
1564 """
1565 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001566 self.papi.nat_det_forward,
1567 {'in_addr': in_addr,
1568 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001569
Matus Fabian2ba92e32017-08-21 07:05:03 -07001570 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001571 self,
1572 out_addr,
1573 out_port):
1574 """Get inside address from outside address and port
1575
1576 :param out_addr - outside IP address
1577 :param out_port - outside port
1578 """
1579 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001580 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001581 {'out_addr': out_addr,
1582 'out_port': out_port})
1583
Matus Fabian2ba92e32017-08-21 07:05:03 -07001584 def nat_det_map_dump(self):
1585 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001586
Matus Fabian2ba92e32017-08-21 07:05:03 -07001587 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001588 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001589 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001590
Matus Fabian2ba92e32017-08-21 07:05:03 -07001591 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001592 self,
1593 udp=300,
1594 tcp_established=7440,
1595 tcp_transitory=240,
1596 icmp=60):
1597 """Set values of timeouts for deterministic NAT (in seconds)
1598
1599 :param udp - UDP timeout (Default value = 300)
1600 :param tcp_established - TCP established timeout (Default value = 7440)
1601 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1602 :param icmp - ICMP timeout (Default value = 60)
1603 """
1604 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001605 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001606 {'udp': udp,
1607 'tcp_established': tcp_established,
1608 'tcp_transitory': tcp_transitory,
1609 'icmp': icmp})
1610
Matus Fabian2ba92e32017-08-21 07:05:03 -07001611 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001612 """Get values of timeouts for deterministic NAT
1613
1614 :return: Timeouts for deterministic NAT (in seconds)
1615 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001616 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001617
Matus Fabian2ba92e32017-08-21 07:05:03 -07001618 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001619 self,
1620 out_addr,
1621 out_port,
1622 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001623 ext_port):
1624 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001625
1626 :param out_addr - outside IP address
1627 :param out_port - outside port
1628 :param ext_addr - external host IP address
1629 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001630 """
1631 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001632 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001633 {'out_addr': out_addr,
1634 'out_port': out_port,
1635 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001636 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001637
Matus Fabian2ba92e32017-08-21 07:05:03 -07001638 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001639 self,
1640 in_addr,
1641 in_port,
1642 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001643 ext_port):
1644 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001645
1646 :param in_addr - inside IP address
1647 :param in_port - inside port
1648 :param ext_addr - external host IP address
1649 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001650 """
1651 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001652 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001653 {'in_addr': in_addr,
1654 'in_port': in_port,
1655 'ext_addr': ext_addr,
1656 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001657 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001658
Matus Fabian2ba92e32017-08-21 07:05:03 -07001659 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001660 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001661 user_addr):
1662 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001663
1664 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001665 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001666 """
1667 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001668 self.papi.nat_det_session_dump,
1669 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001670 'user_addr': user_addr})
1671
Matus Fabian06596c52017-06-06 04:53:28 -07001672 def nat64_add_del_pool_addr_range(
1673 self,
1674 start_addr,
1675 end_addr,
1676 vrf_id=0xFFFFFFFF,
1677 is_add=1):
1678 """Add/del address range to NAT64 pool
1679
1680 :param start_addr: First IP address
1681 :param end_addr: Last IP address
1682 :param vrf_id: VRF id for the address range
1683 :param is_add: 1 if add, 0 if delete (Default value = 1)
1684 """
1685 return self.api(
1686 self.papi.nat64_add_del_pool_addr_range,
1687 {'start_addr': start_addr,
1688 'end_addr': end_addr,
1689 'vrf_id': vrf_id,
1690 'is_add': is_add})
1691
1692 def nat64_pool_addr_dump(self):
1693 """Dump NAT64 pool addresses
1694 :return: Dictionary of NAT64 pool addresses
1695 """
1696 return self.api(self.papi.nat64_pool_addr_dump, {})
1697
1698 def nat64_add_del_interface(
1699 self,
1700 sw_if_index,
1701 is_inside=1,
1702 is_add=1):
1703 """Enable/disable NAT64 feature on the interface
1704 :param sw_if_index: Index of the interface
1705 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1706 :param is_add: 1 if add, 0 if delete (Default value = 1)
1707 """
1708 return self.api(
1709 self.papi.nat64_add_del_interface,
1710 {'sw_if_index': sw_if_index,
1711 'is_inside': is_inside,
1712 'is_add': is_add})
1713
1714 def nat64_interface_dump(self):
1715 """Dump interfaces with NAT64 feature
1716 :return: Dictionary of interfaces with NAT64 feature
1717 """
1718 return self.api(self.papi.nat64_interface_dump, {})
1719
1720 def nat64_add_del_static_bib(
1721 self,
1722 in_ip,
1723 out_ip,
1724 in_port,
1725 out_port,
1726 protocol,
1727 vrf_id=0,
1728 is_add=1):
1729 """Add/delete S-NAT static BIB entry
1730
1731 :param in_ip: Inside IPv6 address
1732 :param out_ip: Outside IPv4 address
1733 :param in_port: Inside port number
1734 :param out_port: Outside port number
1735 :param protocol: IP protocol
1736 :param vrf_id: VRF ID (Default value = 0)
1737 :param is_add: 1 if add, 0 if delete (Default value = 1)
1738 """
1739 return self.api(
1740 self.papi.nat64_add_del_static_bib,
1741 {'i_addr': in_ip,
1742 'o_addr': out_ip,
1743 'i_port': in_port,
1744 'o_port': out_port,
1745 'vrf_id': vrf_id,
1746 'proto': protocol,
1747 'is_add': is_add})
1748
Matus Fabianab9a59c2017-08-16 05:37:36 -07001749 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001750 """Dump NAT64 BIB
1751
Matus Fabianab9a59c2017-08-16 05:37:36 -07001752 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001753 :returns: Dictionary of NAT64 BIB entries
1754 """
1755 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1756
1757 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1758 tcp_incoming_syn=6):
1759 """Set values of timeouts for NAT64 (in seconds)
1760
Matus Fabian428dc912017-06-21 06:15:18 -07001761 :param udpi: UDP timeout (Default value = 300)
1762 :param icmp: ICMP timeout (Default value = 60)
1763 :param tcp_trans: TCP transitory timeout (Default value = 240)
1764 :param tcp_est: TCP established timeout (Default value = 7440)
1765 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001766 """
1767 return self.api(
1768 self.papi.nat64_set_timeouts,
1769 {'udp': udp,
1770 'icmp': icmp,
1771 'tcp_trans': tcp_trans,
1772 'tcp_est': tcp_est,
1773 'tcp_incoming_syn': tcp_incoming_syn})
1774
1775 def nat64_get_timeouts(self):
1776 """Get values of timeouts for NAT64
1777
1778 :return: Timeouts for NAT64 (in seconds)
1779 """
1780 return self.api(self.papi.nat64_get_timeouts, {})
1781
Matus Fabianab9a59c2017-08-16 05:37:36 -07001782 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001783 """Dump NAT64 session table
1784
Matus Fabianab9a59c2017-08-16 05:37:36 -07001785 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001786 :returns: Dictionary of NAT64 sesstion table entries
1787 """
1788 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1789
Matus Fabian428dc912017-06-21 06:15:18 -07001790 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1791 """Add/del NAT64 prefix
1792
1793 :param prefix: NAT64 prefix
1794 :param plen: NAT64 prefix length
1795 :param vrf_id: VRF id of tenant (Default 0)
1796 :param is_add: 1 if add, 0 if delete (Default value = 1)
1797 """
1798 return self.api(
1799 self.papi.nat64_add_del_prefix,
1800 {'prefix': prefix,
1801 'prefix_len': plen,
1802 'vrf_id': vrf_id,
1803 'is_add': is_add})
1804
1805 def nat64_prefix_dump(self):
1806 """Dump NAT64 prefix
1807
1808 :returns: Dictionary of NAT64 prefixes
1809 """
1810 return self.api(self.papi.nat64_prefix_dump, {})
1811
Matus Fabian0938dcf2017-11-08 01:59:38 -08001812 def nat64_add_interface_addr(
1813 self,
1814 sw_if_index,
1815 is_add=1):
1816 """Add/del NAT64 address from interface
1817
1818 :param sw_if_index: Software index of the interface
1819 :param is_add: 1 if add, 0 if delete (Default value = 1)
1820 """
1821 return self.api(self.papi.nat64_add_del_interface_addr,
1822 {'is_add': is_add, 'sw_if_index': sw_if_index})
1823
Matus Fabian8ebe6252017-11-06 05:04:53 -08001824 def dslite_set_aftr_addr(self, ip6, ip4):
1825 """Set DS-Lite AFTR addresses
1826
1827 :param ip4: IPv4 address
1828 :param ip6: IPv6 address
1829 """
1830 return self.api(
1831 self.papi.dslite_set_aftr_addr,
1832 {'ip4_addr': ip4,
1833 'ip6_addr': ip6})
1834
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001835 def dslite_set_b4_addr(self, ip6, ip4):
1836 """Set DS-Lite B4 IPv6 address
1837
1838 :param ip4: IPv4 address
1839 :param ip6: IPv6 address
1840 """
1841 return self.api(
1842 self.papi.dslite_set_b4_addr,
1843 {'ip4_addr': ip4,
1844 'ip6_addr': ip6})
1845
Matus Fabian8ebe6252017-11-06 05:04:53 -08001846 def dslite_add_del_pool_addr_range(
1847 self,
1848 start_addr,
1849 end_addr,
1850 is_add=1):
1851 """Add/del address range to DS-Lite pool
1852
1853 :param start_addr: First IP address
1854 :param end_addr: Last IP address
1855 :param is_add: 1 if add, 0 if delete (Default value = 1)
1856 """
1857 return self.api(
1858 self.papi.dslite_add_del_pool_addr_range,
1859 {'start_addr': start_addr,
1860 'end_addr': end_addr,
1861 'is_add': is_add})
1862
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001863 def nat66_add_del_interface(
1864 self,
1865 sw_if_index,
1866 is_inside=1,
1867 is_add=1):
1868 """Enable/disable NAT66 feature on the interface
1869 :param sw_if_index: Index of the interface
1870 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1871 :param is_add: 1 if add, 0 if delete (Default value = 1)
1872 """
1873 return self.api(
1874 self.papi.nat66_add_del_interface,
1875 {'sw_if_index': sw_if_index,
1876 'is_inside': is_inside,
1877 'is_add': is_add})
1878
1879 def nat66_add_del_static_mapping(
1880 self,
1881 in_ip,
1882 out_ip,
1883 vrf_id=0,
1884 is_add=1):
1885 """Add/delete NAT66 static mapping
1886
1887 :param in_ip: Inside IPv6 address
1888 :param out_ip: Outside IPv6 address
1889 :param vrf_id: VRF ID (Default value = 0)
1890 :param is_add: 1 if add, 0 if delete (Default value = 1)
1891 """
1892 return self.api(
1893 self.papi.nat66_add_del_static_mapping,
1894 {'local_ip_address': in_ip,
1895 'external_ip_address': out_ip,
1896 'vrf_id': vrf_id,
1897 'is_add': is_add})
1898
1899 def nat66_interface_dump(self):
1900 """Dump interfaces with NAT66 feature
1901 :return: Dictionary of interfaces with NAT66 feature
1902 """
1903 return self.api(self.papi.nat66_interface_dump, {})
1904
1905 def nat66_static_mapping_dump(self):
1906 """Dump NAT66 static mappings
1907 :return: Dictionary of NAT66 static mappings
1908 """
1909 return self.api(self.papi.nat66_static_mapping_dump, {})
1910
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001911 def control_ping(self):
1912 self.api(self.papi.control_ping)
1913
1914 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001915 detect_mult, local_addr, peer_addr, is_ipv6=0,
1916 bfd_key_id=None, conf_key_id=None):
1917 if bfd_key_id is None:
1918 return self.api(self.papi.bfd_udp_add,
1919 {
1920 'sw_if_index': sw_if_index,
1921 'desired_min_tx': desired_min_tx,
1922 'required_min_rx': required_min_rx,
1923 'local_addr': local_addr,
1924 'peer_addr': peer_addr,
1925 'is_ipv6': is_ipv6,
1926 'detect_mult': detect_mult,
1927 })
1928 else:
1929 return self.api(self.papi.bfd_udp_add,
1930 {
1931 'sw_if_index': sw_if_index,
1932 'desired_min_tx': desired_min_tx,
1933 'required_min_rx': required_min_rx,
1934 'local_addr': local_addr,
1935 'peer_addr': peer_addr,
1936 'is_ipv6': is_ipv6,
1937 'detect_mult': detect_mult,
1938 'is_authenticated': 1,
1939 'bfd_key_id': bfd_key_id,
1940 'conf_key_id': conf_key_id,
1941 })
1942
Klement Sekeraa57a9702017-02-02 06:58:07 +01001943 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1944 detect_mult, local_addr, peer_addr, is_ipv6=0):
1945 return self.api(self.papi.bfd_udp_mod,
1946 {
1947 'sw_if_index': sw_if_index,
1948 'desired_min_tx': desired_min_tx,
1949 'required_min_rx': required_min_rx,
1950 'local_addr': local_addr,
1951 'peer_addr': peer_addr,
1952 'is_ipv6': is_ipv6,
1953 'detect_mult': detect_mult,
1954 })
1955
Klement Sekerab17dd962017-01-09 07:43:48 +01001956 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1957 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1958 is_delayed=False):
1959 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001960 {
1961 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001962 'local_addr': local_addr,
1963 'peer_addr': peer_addr,
1964 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001965 'is_delayed': 1 if is_delayed else 0,
1966 'bfd_key_id': bfd_key_id,
1967 'conf_key_id': conf_key_id,
1968 })
1969
1970 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1971 is_ipv6=0, is_delayed=False):
1972 return self.api(self.papi.bfd_udp_auth_deactivate,
1973 {
1974 'sw_if_index': sw_if_index,
1975 'local_addr': local_addr,
1976 'peer_addr': peer_addr,
1977 'is_ipv6': is_ipv6,
1978 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001979 })
1980
1981 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1982 return self.api(self.papi.bfd_udp_del,
1983 {
1984 'sw_if_index': sw_if_index,
1985 'local_addr': local_addr,
1986 'peer_addr': peer_addr,
1987 'is_ipv6': is_ipv6,
1988 })
1989
1990 def bfd_udp_session_dump(self):
1991 return self.api(self.papi.bfd_udp_session_dump, {})
1992
Klement Sekerab17dd962017-01-09 07:43:48 +01001993 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1994 peer_addr, is_ipv6=0):
1995 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001996 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001997 'sw_if_index': sw_if_index,
1998 'local_addr': local_addr,
1999 'peer_addr': peer_addr,
2000 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002001 })
2002
2003 def want_bfd_events(self, enable_disable=1):
2004 return self.api(self.papi.want_bfd_events, {
2005 'enable_disable': enable_disable,
2006 'pid': os.getpid(),
2007 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002008
Klement Sekerab17dd962017-01-09 07:43:48 +01002009 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2010 return self.api(self.papi.bfd_auth_set_key, {
2011 'conf_key_id': conf_key_id,
2012 'auth_type': auth_type,
2013 'key': key,
2014 'key_len': len(key),
2015 })
2016
2017 def bfd_auth_del_key(self, conf_key_id):
2018 return self.api(self.papi.bfd_auth_del_key, {
2019 'conf_key_id': conf_key_id,
2020 })
2021
2022 def bfd_auth_keys_dump(self):
2023 return self.api(self.papi.bfd_auth_keys_dump, {})
2024
Klement Sekera239790f2017-02-16 10:53:53 +01002025 def bfd_udp_set_echo_source(self, sw_if_index):
2026 return self.api(self.papi.bfd_udp_set_echo_source,
2027 {'sw_if_index': sw_if_index})
2028
Klement Sekera73884482017-02-23 09:26:30 +01002029 def bfd_udp_del_echo_source(self):
2030 return self.api(self.papi.bfd_udp_del_echo_source, {})
2031
Steve Shin7957d6e2016-12-19 09:24:50 -08002032 def classify_add_del_table(
2033 self,
2034 is_add,
2035 mask,
2036 match_n_vectors=1,
2037 table_index=0xFFFFFFFF,
2038 nbuckets=2,
2039 memory_size=2097152,
2040 skip_n_vectors=0,
2041 next_table_index=0xFFFFFFFF,
2042 miss_next_index=0xFFFFFFFF,
2043 current_data_flag=0,
2044 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002045 """
2046 :param is_add:
2047 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002048 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002049 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002050 :param nbuckets: (Default value = 2)
2051 :param memory_size: (Default value = 2097152)
2052 :param skip_n_vectors: (Default value = 0)
2053 :param next_table_index: (Default value = 0xFFFFFFFF)
2054 :param miss_next_index: (Default value = 0xFFFFFFFF)
2055 :param current_data_flag: (Default value = 0)
2056 :param current_data_offset: (Default value = 0)
2057 """
2058
2059 return self.api(
2060 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002061 {'is_add': is_add,
2062 'table_index': table_index,
2063 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002064 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002065 'skip_n_vectors': skip_n_vectors,
2066 'match_n_vectors': match_n_vectors,
2067 'next_table_index': next_table_index,
2068 'miss_next_index': miss_next_index,
2069 'current_data_flag': current_data_flag,
2070 'current_data_offset': current_data_offset,
2071 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002072
2073 def classify_add_del_session(
2074 self,
2075 is_add,
2076 table_index,
2077 match,
2078 opaque_index=0xFFFFFFFF,
2079 hit_next_index=0xFFFFFFFF,
2080 advance=0,
2081 action=0,
2082 metadata=0):
2083 """
2084 :param is_add:
2085 :param table_index:
2086 :param match:
2087 :param opaque_index: (Default value = 0xFFFFFFFF)
2088 :param hit_next_index: (Default value = 0xFFFFFFFF)
2089 :param advance: (Default value = 0)
2090 :param action: (Default value = 0)
2091 :param metadata: (Default value = 0)
2092 """
2093
2094 return self.api(
2095 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002096 {'is_add': is_add,
2097 'table_index': table_index,
2098 'hit_next_index': hit_next_index,
2099 'opaque_index': opaque_index,
2100 'advance': advance,
2101 'action': action,
2102 'metadata': metadata,
2103 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002104
2105 def input_acl_set_interface(
2106 self,
2107 is_add,
2108 sw_if_index,
2109 ip4_table_index=0xFFFFFFFF,
2110 ip6_table_index=0xFFFFFFFF,
2111 l2_table_index=0xFFFFFFFF):
2112 """
2113 :param is_add:
2114 :param sw_if_index:
2115 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2116 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2117 :param l2_table_index: (Default value = 0xFFFFFFFF)
2118 """
2119
2120 return self.api(
2121 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002122 {'sw_if_index': sw_if_index,
2123 'ip4_table_index': ip4_table_index,
2124 'ip6_table_index': ip6_table_index,
2125 'l2_table_index': l2_table_index,
2126 'is_add': is_add})
2127
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002128 def output_acl_set_interface(
2129 self,
2130 is_add,
2131 sw_if_index,
2132 ip4_table_index=0xFFFFFFFF,
2133 ip6_table_index=0xFFFFFFFF,
2134 l2_table_index=0xFFFFFFFF):
2135 """
2136 :param is_add:
2137 :param sw_if_index:
2138 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2139 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2140 :param l2_table_index: (Default value = 0xFFFFFFFF)
2141 """
2142
2143 return self.api(
2144 self.papi.output_acl_set_interface,
2145 {'sw_if_index': sw_if_index,
2146 'ip4_table_index': ip4_table_index,
2147 'ip6_table_index': ip6_table_index,
2148 'l2_table_index': l2_table_index,
2149 'is_add': is_add})
2150
Klement Sekera77fabdb2017-01-02 07:46:14 +01002151 def set_ipfix_exporter(
2152 self,
2153 collector_address,
2154 src_address,
2155 path_mtu,
2156 template_interval,
2157 vrf_id=0,
2158 collector_port=4739,
2159 udp_checksum=0):
2160 return self.api(
2161 self.papi.set_ipfix_exporter,
2162 {
2163 'collector_address': collector_address,
2164 'collector_port': collector_port,
2165 'src_address': src_address,
2166 'vrf_id': vrf_id,
2167 'path_mtu': path_mtu,
2168 'template_interval': template_interval,
2169 'udp_checksum': udp_checksum,
2170 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002171
2172 def dhcp_proxy_config(self,
2173 dhcp_server,
2174 dhcp_src_address,
2175 rx_table_id=0,
2176 server_table_id=0,
2177 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002178 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002179 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002180 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002181 {
2182 'rx_vrf_id': rx_table_id,
2183 'server_vrf_id': server_table_id,
2184 'is_ipv6': is_ipv6,
2185 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002186 'dhcp_server': dhcp_server,
2187 'dhcp_src_address': dhcp_src_address,
2188 })
2189
2190 def dhcp_proxy_set_vss(self,
2191 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002192 vss_type=255,
2193 vpn_ascii_id="",
2194 oui=0,
2195 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002196 is_add=1,
2197 is_ip6=0):
2198 return self.api(
2199 self.papi.dhcp_proxy_set_vss,
2200 {
2201 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002202 'vss_type': vss_type,
2203 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002204 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002205 'vpn_index': vpn_index,
2206 'is_add': is_add,
2207 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002208 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002209
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002210 def dhcp_client(self,
2211 sw_if_index,
2212 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002213 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002214 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002215 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002216 want_dhcp_events=0):
2217 return self.api(
2218 self.papi.dhcp_client_config,
2219 {
2220 'sw_if_index': sw_if_index,
2221 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002222 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002223 'is_add': is_add,
2224 'want_dhcp_event': want_dhcp_events,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002225 'set_broadcast_flag': set_broadcast_flag,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002226 'pid': os.getpid(),
2227 })
2228
Neale Ranns32e1c012016-11-22 17:07:28 +00002229 def ip_mroute_add_del(self,
2230 src_address,
2231 grp_address,
2232 grp_address_length,
2233 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002234 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002235 next_hop_sw_if_index,
2236 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002237 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002238 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002239 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002240 is_add=1,
2241 is_ipv6=0,
2242 is_local=0):
2243 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002244 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002245 """
2246 return self.api(
2247 self.papi.ip_mroute_add_del,
2248 {'next_hop_sw_if_index': next_hop_sw_if_index,
2249 'entry_flags': e_flags,
2250 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002251 'table_id': table_id,
2252 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002253 'is_add': is_add,
2254 'is_ipv6': is_ipv6,
2255 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002256 'bier_imp': bier_imp,
2257 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002258 'grp_address_length': grp_address_length,
2259 'grp_address': grp_address,
2260 'src_address': src_address})
2261
2262 def mfib_signal_dump(self):
2263 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002264
2265 def ip_mfib_dump(self):
2266 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002267
Neale Rannsd792d9c2017-10-21 10:53:20 -07002268 def ip6_mfib_dump(self):
2269 return self.api(self.papi.ip6_mfib_dump, {})
2270
Filip Tehlar770e89e2017-01-31 10:39:16 +01002271 def lisp_enable_disable(self, is_enabled):
2272 return self.api(
2273 self.papi.lisp_enable_disable,
2274 {
2275 'is_en': is_enabled,
2276 })
2277
2278 def lisp_locator_set(self,
2279 ls_name,
2280 is_add=1):
2281 return self.api(
2282 self.papi.lisp_add_del_locator_set,
2283 {
2284 'is_add': is_add,
2285 'locator_set_name': ls_name
2286 })
2287
2288 def lisp_locator_set_dump(self):
2289 return self.api(self.papi.lisp_locator_set_dump, {})
2290
2291 def lisp_locator(self,
2292 ls_name,
2293 sw_if_index,
2294 priority=1,
2295 weight=1,
2296 is_add=1):
2297 return self.api(
2298 self.papi.lisp_add_del_locator,
2299 {
2300 'is_add': is_add,
2301 'locator_set_name': ls_name,
2302 'sw_if_index': sw_if_index,
2303 'priority': priority,
2304 'weight': weight
2305 })
2306
2307 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2308 return self.api(
2309 self.papi.lisp_locator_dump,
2310 {
2311 'is_index_set': is_index_set,
2312 'ls_name': ls_name,
2313 'ls_index': ls_index,
2314 })
2315
2316 def lisp_local_mapping(self,
2317 ls_name,
2318 eid_type,
2319 eid,
2320 prefix_len,
2321 vni=0,
2322 key_id=0,
2323 key="",
2324 is_add=1):
2325 return self.api(
2326 self.papi.lisp_add_del_local_eid,
2327 {
2328 'locator_set_name': ls_name,
2329 'is_add': is_add,
2330 'eid_type': eid_type,
2331 'eid': eid,
2332 'prefix_len': prefix_len,
2333 'vni': vni,
2334 'key_id': key_id,
2335 'key': key
2336 })
2337
2338 def lisp_eid_table_dump(self,
2339 eid_set=0,
2340 prefix_length=0,
2341 vni=0,
2342 eid_type=0,
2343 eid=None,
2344 filter_opt=0):
2345 return self.api(
2346 self.papi.lisp_eid_table_dump,
2347 {
2348 'eid_set': eid_set,
2349 'prefix_length': prefix_length,
2350 'vni': vni,
2351 'eid_type': eid_type,
2352 'eid': eid,
2353 'filter': filter_opt,
2354 })
2355
2356 def lisp_remote_mapping(self,
2357 eid_type,
2358 eid,
2359 eid_prefix_len=0,
2360 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002361 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002362 rlocs_num=0,
2363 is_src_dst=0,
2364 is_add=1):
2365 return self.api(
2366 self.papi.lisp_add_del_remote_mapping,
2367 {
2368 'is_add': is_add,
2369 'eid_type': eid_type,
2370 'eid': eid,
2371 'eid_len': eid_prefix_len,
2372 'rloc_num': rlocs_num,
2373 'rlocs': rlocs,
2374 'vni': vni,
2375 'is_src_dst': is_src_dst,
2376 })
2377
2378 def lisp_adjacency(self,
2379 leid,
2380 reid,
2381 leid_len,
2382 reid_len,
2383 eid_type,
2384 is_add=1,
2385 vni=0):
2386 return self.api(
2387 self.papi.lisp_add_del_adjacency,
2388 {
2389 'is_add': is_add,
2390 'vni': vni,
2391 'eid_type': eid_type,
2392 'leid': leid,
2393 'reid': reid,
2394 'leid_len': leid_len,
2395 'reid_len': reid_len,
2396 })
2397
2398 def lisp_adjacencies_get(self, vni=0):
2399 return self.api(
2400 self.papi.lisp_adjacencies_get,
2401 {
2402 'vni': vni
2403 })
Neale Ranns80823802017-02-20 18:23:41 -08002404
2405 def map_add_domain(self,
2406 ip6_prefix,
2407 ip6_prefix_len,
2408 ip6_src,
2409 ip6_src_prefix_len,
2410 ip4_prefix,
2411 ip4_prefix_len,
2412 ea_bits_len=0,
2413 psid_offset=0,
2414 psid_length=0,
2415 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002416 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002417 mtu=1280):
2418 return self.api(
2419 self.papi.map_add_domain,
2420 {
2421 'ip6_prefix': ip6_prefix,
2422 'ip6_prefix_len': ip6_prefix_len,
2423 'ip4_prefix': ip4_prefix,
2424 'ip4_prefix_len': ip4_prefix_len,
2425 'ip6_src': ip6_src,
2426 'ip6_src_prefix_len': ip6_src_prefix_len,
2427 'ea_bits_len': ea_bits_len,
2428 'psid_offset': psid_offset,
2429 'psid_length': psid_length,
2430 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002431 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002432 'mtu': mtu
2433 })
Hongjun Nief486b12017-04-12 19:21:16 +08002434
2435 def gtpu_add_del_tunnel(
2436 self,
2437 src_addr,
2438 dst_addr,
2439 is_add=1,
2440 is_ipv6=0,
2441 mcast_sw_if_index=0xFFFFFFFF,
2442 encap_vrf_id=0,
2443 decap_next_index=0xFFFFFFFF,
2444 teid=0):
2445 """
2446
2447 :param is_add: (Default value = 1)
2448 :param is_ipv6: (Default value = 0)
2449 :param src_addr:
2450 :param dst_addr:
2451 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2452 :param encap_vrf_id: (Default value = 0)
2453 :param decap_next_index: (Default value = 0xFFFFFFFF)
2454 :param teid: (Default value = 0)
2455
2456 """
2457 return self.api(self.papi.gtpu_add_del_tunnel,
2458 {'is_add': is_add,
2459 'is_ipv6': is_ipv6,
2460 'src_address': src_addr,
2461 'dst_address': dst_addr,
2462 'mcast_sw_if_index': mcast_sw_if_index,
2463 'encap_vrf_id': encap_vrf_id,
2464 'decap_next_index': decap_next_index,
2465 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002466
2467 def vxlan_gpe_add_del_tunnel(
2468 self,
2469 src_addr,
2470 dst_addr,
2471 mcast_sw_if_index=0xFFFFFFFF,
2472 is_add=1,
2473 is_ipv6=0,
2474 encap_vrf_id=0,
2475 decap_vrf_id=0,
2476 protocol=3,
2477 vni=0):
2478 """
2479
2480 :param local:
2481 :param remote:
2482 :param is_add: (Default value = 1)
2483 :param is_ipv6: (Default value = 0)
2484 :param encap_vrf_id: (Default value = 0)
2485 :param decap_vrf_id: (Default value = 0)
2486 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2487 :param protocol: (Default value = 3)
2488 :param vni: (Default value = 0)
2489
2490 """
2491 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2492 {'is_add': is_add,
2493 'is_ipv6': is_ipv6,
2494 'local': src_addr,
2495 'remote': dst_addr,
2496 'mcast_sw_if_index': mcast_sw_if_index,
2497 'encap_vrf_id': encap_vrf_id,
2498 'decap_vrf_id': decap_vrf_id,
2499 'protocol': protocol,
2500 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002501
2502 def pppoe_add_del_session(
2503 self,
2504 client_ip,
2505 client_mac,
2506 session_id=0,
2507 is_add=1,
2508 is_ipv6=0,
2509 decap_vrf_id=0):
2510 """
2511
2512 :param is_add: (Default value = 1)
2513 :param is_ipv6: (Default value = 0)
2514 :param client_ip:
2515 :param session_id: (Default value = 0)
2516 :param client_mac:
2517 :param decap_vrf_id: (Default value = 0)
2518
2519 """
2520 return self.api(self.papi.pppoe_add_del_session,
2521 {'is_add': is_add,
2522 'is_ipv6': is_ipv6,
2523 'session_id': session_id,
2524 'client_ip': client_ip,
2525 'decap_vrf_id': decap_vrf_id,
2526 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002527
2528 def sr_localsid_add_del(self,
2529 localsid_addr,
2530 behavior,
2531 nh_addr,
2532 is_del=0,
2533 end_psp=0,
2534 sw_if_index=0xFFFFFFFF,
2535 vlan_index=0,
2536 fib_table=0,
2537 ):
2538 """ Add/del IPv6 SR local-SID.
2539
2540 :param localsid_addr:
2541 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2542 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2543 :param nh_addr:
2544 :param is_del: (Default value = 0)
2545 :param end_psp: (Default value = 0)
2546 :param sw_if_index: (Default value = 0xFFFFFFFF)
2547 :param vlan_index: (Default value = 0)
2548 :param fib_table: (Default value = 0)
2549 """
2550 return self.api(
2551 self.papi.sr_localsid_add_del,
2552 {'is_del': is_del,
2553 'localsid_addr': localsid_addr,
2554 'end_psp': end_psp,
2555 'behavior': behavior,
2556 'sw_if_index': sw_if_index,
2557 'vlan_index': vlan_index,
2558 'fib_table': fib_table,
2559 'nh_addr': nh_addr
2560 }
2561 )
2562
2563 def sr_policy_add(
2564 self,
2565 bsid_addr,
2566 weight=1,
2567 is_encap=1,
2568 type=0,
2569 fib_table=0,
2570 n_segments=0,
2571 segments=[]):
2572 """
2573 :param bsid_addr: bindingSID of the SR Policy
2574 :param weight: weight of the sid list. optional. (default: 1)
2575 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2576 (default: Encap)
2577 :param type: type/behavior of the SR policy. (default or spray) \
2578 (default: default)
2579 :param fib_table: VRF where to install the FIB entry for the BSID \
2580 (default: 0)
2581 :param n_segments: number of segments \
2582 (default: 0)
2583 :param segments: a vector of IPv6 address composing the segment list \
2584 (default: [])
2585 """
2586 return self.api(
2587 self.papi.sr_policy_add,
2588 {'bsid_addr': bsid_addr,
2589 'weight': weight,
2590 'is_encap': is_encap,
2591 'type': type,
2592 'fib_table': fib_table,
2593 'n_segments': n_segments,
2594 'segments': segments
2595 }
2596 )
2597
2598 def sr_policy_del(
2599 self,
2600 bsid_addr,
2601 sr_policy_index=0):
2602 """
2603 :param bsid: bindingSID of the SR Policy
2604 :param sr_policy_index: index of the sr policy (default: 0)
2605 """
2606 return self.api(
2607 self.papi.sr_policy_del,
2608 {'bsid_addr': bsid_addr,
2609 'sr_policy_index': sr_policy_index
2610 })
2611
2612 def sr_steering_add_del(
2613 self,
2614 is_del,
2615 bsid_addr,
2616 sr_policy_index,
2617 table_id,
2618 prefix_addr,
2619 mask_width,
2620 sw_if_index,
2621 traffic_type):
2622 """
2623 Steer traffic L2 and L3 traffic through a given SR policy
2624
2625 :param is_del: delete or add
2626 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2627 :param sr_policy: is the index of the SR Policy (alt to bsid)
2628 :param table_id: is the VRF where to install the FIB entry for the BSID
2629 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2630 :param mask_width: is the mask for L3 traffic type
2631 :param sw_if_index: is the incoming interface for L2 traffic
2632 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2633 """
2634 return self.api(
2635 self.papi.sr_steering_add_del,
2636 {'is_del': is_del,
2637 'bsid_addr': bsid_addr,
2638 'sr_policy_index': sr_policy_index,
2639 'table_id': table_id,
2640 'prefix_addr': prefix_addr,
2641 'mask_width': mask_width,
2642 'sw_if_index': sw_if_index,
2643 'traffic_type': traffic_type
2644 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002645
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002646 def acl_add_replace(self, acl_index, r, tag='',
2647 expected_retval=0):
2648 """Add/replace an ACL
2649 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2650 :param acl_rule r: ACL rules array.
2651 :param str tag: symbolic tag (description) for this ACL.
2652 :param int count: number of rules.
2653 """
2654 return self.api(self.papi.acl_add_replace,
2655 {'acl_index': acl_index,
2656 'r': r,
2657 'count': len(r),
2658 'tag': tag},
2659 expected_retval=expected_retval)
2660
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002661 def acl_del(self, acl_index, expected_retval=0):
2662 """
2663
2664 :param acl_index:
2665 :return:
2666 """
2667 return self.api(self.papi.acl_del,
2668 {'acl_index': acl_index},
2669 expected_retval=expected_retval)
2670
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002671 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2672 expected_retval=0):
2673 return self.api(self.papi.acl_interface_set_acl_list,
2674 {'sw_if_index': sw_if_index,
2675 'count': len(acls),
2676 'n_input': n_input,
2677 'acls': acls},
2678 expected_retval=expected_retval)
2679
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002680 def acl_interface_add_del(self,
2681 sw_if_index,
2682 acl_index,
2683 is_add=1):
2684 """ Add/Delete ACL to/from interface
2685
2686 :param sw_if_index:
2687 :param acl_index:
2688 :param is_add: (Default value = 1)
2689 """
2690
2691 return self.api(self.papi.acl_interface_add_del,
2692 {'is_add': is_add,
2693 'is_input': 1,
2694 'sw_if_index': sw_if_index,
2695 'acl_index': acl_index})
2696
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002697 def acl_dump(self, acl_index, expected_retval=0):
2698 return self.api(self.papi.acl_dump,
2699 {'acl_index': acl_index},
2700 expected_retval=expected_retval)
2701
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002702 def macip_acl_add(self, rules, tag=""):
2703 """ Add MACIP acl
2704
2705 :param rules: list of rules for given acl
2706 :param tag: acl tag
2707 """
2708
2709 return self.api(self.papi.macip_acl_add,
2710 {'r': rules,
2711 'count': len(rules),
2712 'tag': tag})
2713
Pavel Kotucek932f7412017-09-07 14:44:52 +02002714 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2715 """ Add MACIP acl
2716
2717 :param rules: list of rules for given acl
2718 :param tag: acl tag
2719 """
2720
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002721 return self.api(self.papi.macip_acl_add_replace,
2722 {'acl_index': acl_index,
2723 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002724 'count': len(rules),
2725 'tag': tag})
2726
2727 def macip_acl_del(self, acl_index):
2728 """
2729
2730 :param acl_index:
2731 :return:
2732 """
2733 return self.api(self.papi.macip_acl_del,
2734 {'acl_index': acl_index})
2735
2736 def macip_acl_interface_add_del(self,
2737 sw_if_index,
2738 acl_index,
2739 is_add=1):
2740 """ Add MACIP acl to interface
2741
2742 :param sw_if_index:
2743 :param acl_index:
2744 :param is_add: (Default value = 1)
2745 """
2746
2747 return self.api(self.papi.macip_acl_interface_add_del,
2748 {'is_add': is_add,
2749 'sw_if_index': sw_if_index,
2750 'acl_index': acl_index})
2751
2752 def macip_acl_interface_get(self):
2753 """ Return interface acls dump
2754 """
2755 return self.api(
2756 self.papi.macip_acl_interface_get, {})
2757
2758 def macip_acl_dump(self, acl_index=4294967295):
2759 """ Return MACIP acl dump
2760 """
2761
2762 return self.api(
2763 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002764
2765 def policer_add_del(self,
2766 name,
2767 cir,
2768 eir,
2769 cb,
2770 eb,
2771 is_add=1,
2772 rate_type=0,
2773 round_type=0,
2774 ptype=0,
2775 color_aware=0,
2776 conform_action_type=1,
2777 conform_dscp=0,
2778 exceed_action_type=0,
2779 exceed_dscp=0,
2780 violate_action_type=0,
2781 violate_dscp=0):
2782 return self.api(self.papi.policer_add_del,
2783 {'name': name,
2784 'cir': cir,
2785 'eir': eir,
2786 'cb': cb,
2787 'eb': eb,
2788 'is_add': is_add,
2789 'rate_type': rate_type,
2790 'round_type': round_type,
2791 'type': ptype,
2792 'color_aware': color_aware,
2793 'conform_action_type': conform_action_type,
2794 'conform_dscp': conform_dscp,
2795 'exceed_action_type': exceed_action_type,
2796 'exceed_dscp': exceed_dscp,
2797 'violate_action_type': violate_action_type,
2798 'violate_dscp': violate_dscp})
2799
2800 def ip_punt_police(self,
2801 policer_index,
2802 is_ip6=0,
2803 is_add=1):
2804 return self.api(self.papi.ip_punt_police,
2805 {'policer_index': policer_index,
2806 'is_add': is_add,
2807 'is_ip6': is_ip6})
2808
2809 def ip_punt_redirect(self,
2810 rx_sw_if_index,
2811 tx_sw_if_index,
2812 nh,
2813 is_ip6=0,
2814 is_add=1):
2815 return self.api(self.papi.ip_punt_redirect,
2816 {'rx_sw_if_index': rx_sw_if_index,
2817 'tx_sw_if_index': tx_sw_if_index,
2818 'nh': nh,
2819 'is_add': is_add,
2820 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002821
2822 def bier_table_add_del(self,
2823 bti,
2824 mpls_label,
2825 is_add=1):
2826 """ BIER Table add/del """
2827 return self.api(
2828 self.papi.bier_table_add_del,
2829 {'bt_tbl_id': {"bt_set": bti.set_id,
2830 "bt_sub_domain": bti.sub_domain_id,
2831 "bt_hdr_len_id": bti.hdr_len_id},
2832 'bt_label': mpls_label,
2833 'bt_is_add': is_add})
2834
2835 def bier_table_dump(self):
2836 return self.api(self.papi.bier_table_dump, {})
2837
2838 def bier_route_add_del(self,
2839 bti,
2840 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002841 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002842 is_add=1):
2843 """ BIER Route add/del """
Neale Ranns91286372017-12-05 13:24:04 -08002844 br_paths = []
2845 for p in paths:
2846 br_paths.append({'next_hop': p.nh_addr,
2847 'weight': 1,
2848 'afi': 0,
2849 'preference': 0,
2850 'table_id': p.nh_table_id,
2851 'next_hop_id': p.next_hop_id,
2852 'is_udp_encap': p.is_udp_encap,
2853 'n_labels': len(p.nh_labels),
2854 'label_stack': p.nh_labels})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002855 return self.api(
2856 self.papi.bier_route_add_del,
2857 {'br_tbl_id': {"bt_set": bti.set_id,
2858 "bt_sub_domain": bti.sub_domain_id,
2859 "bt_hdr_len_id": bti.hdr_len_id},
2860 'br_bp': bp,
Neale Ranns91286372017-12-05 13:24:04 -08002861 'br_n_paths': len(br_paths),
2862 'br_paths': br_paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002863 'br_is_add': is_add})
2864
2865 def bier_route_dump(self, bti):
2866 return self.api(
2867 self.papi.bier_route_dump,
2868 {'br_tbl_id': {"bt_set": bti.set_id,
2869 "bt_sub_domain": bti.sub_domain_id,
2870 "bt_hdr_len_id": bti.hdr_len_id}})
2871
2872 def bier_imp_add(self,
2873 bti,
2874 src,
2875 ibytes,
2876 is_add=1):
2877 """ BIER Imposition Add """
2878 return self.api(
2879 self.papi.bier_imp_add,
2880 {'bi_tbl_id': {"bt_set": bti.set_id,
2881 "bt_sub_domain": bti.sub_domain_id,
2882 "bt_hdr_len_id": bti.hdr_len_id},
2883 'bi_src': src,
2884 'bi_n_bytes': len(ibytes),
2885 'bi_bytes': ibytes})
2886
2887 def bier_imp_del(self, bi_index):
2888 """ BIER Imposition del """
2889 return self.api(
2890 self.papi.bier_imp_del,
2891 {'bi_index': bi_index})
2892
2893 def bier_imp_dump(self):
2894 return self.api(self.papi.bier_imp_dump, {})
2895
2896 def bier_disp_table_add_del(self,
2897 bdti,
2898 is_add=1):
2899 """ BIER Disposition Table add/del """
2900 return self.api(
2901 self.papi.bier_disp_table_add_del,
2902 {'bdt_tbl_id': bdti,
2903 'bdt_is_add': is_add})
2904
2905 def bier_disp_table_dump(self):
2906 return self.api(self.papi.bier_disp_table_dump, {})
2907
2908 def bier_disp_entry_add_del(self,
2909 bdti,
2910 bp,
2911 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002912 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002913 next_hop,
2914 next_hop_tbl_id=0,
2915 next_hop_rpf_id=~0,
2916 next_hop_is_ip4=1,
2917 is_add=1):
2918 """ BIER Route add/del """
2919 return self.api(
2920 self.papi.bier_disp_entry_add_del,
2921 {'bde_tbl_id': bdti,
2922 'bde_bp': bp,
2923 'bde_payload_proto': payload_proto,
2924 'bde_n_paths': 1,
2925 'bde_paths': [{'next_hop': next_hop,
2926 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002927 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002928 'rpf_id': next_hop_rpf_id,
2929 'n_labels': 0,
2930 'label_stack': [0]}],
2931 'bde_is_add': is_add})
2932
2933 def bier_disp_entry_dump(self, bdti):
2934 return self.api(
2935 self.papi.bier_disp_entry_dump,
2936 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002937
2938 def add_node_next(self, node_name, next_name):
2939 """ Set the next node for a given node request
2940
2941 :param node_name:
2942 :param next_name:
2943 """
2944 return self.api(self.papi.add_node_next,
2945 {'node_name': node_name,
2946 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08002947
2948 def session_enable_disable(self, is_enabled):
2949 return self.api(
2950 self.papi.session_enable_disable,
2951 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002952
2953 def ipsec_spd_add_del(self, spd_id, is_add=1):
2954 """ SPD add/del - Wrapper to add or del ipsec SPD
2955 Sample CLI : 'ipsec spd add 1'
2956
2957 :param spd_id - SPD ID to be created in the vpp . mandatory
2958 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2959 optional
2960 :returns: reply from the API
2961 """
2962 return self.api(
2963 self.papi.ipsec_spd_add_del, {
2964 'spd_id': spd_id, 'is_add': is_add})
2965
2966 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2967 """ IPSEC interface SPD add/del - \
2968 Wrapper to associate/disassociate SPD to interface in VPP
2969 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2970
2971 :param spd_id - SPD ID to associate with the interface . mandatory
2972 :param sw_if_index - Interface Index which needs to ipsec \
2973 association mandatory
2974 :param is_add - add(1) or del(0) association with interface \
2975 (Default 1 - add) . optional
2976 :returns: reply from the API
2977 """
2978 return self.api(
2979 self.papi.ipsec_interface_add_del_spd, {
2980 'spd_id': spd_id,
2981 'sw_if_index': sw_if_index, 'is_add': is_add})
2982
2983 def ipsec_sad_add_del_entry(self,
2984 sad_id,
2985 spi,
2986 tunnel_src_address='',
2987 tunnel_dst_address='',
2988 protocol=0,
2989 integrity_algorithm=2,
2990 integrity_key_length=0,
2991 integrity_key='C91KUR9GYMm5GfkEvNjX',
2992 crypto_algorithm=1,
2993 crypto_key_length=0,
2994 crypto_key='JPjyOWBeVEQiMe7h',
2995 is_add=1,
2996 is_tunnel=1):
2997 """ IPSEC SA add/del
2998 Sample CLI : 'ipsec sa add 10 spi 1001 esp \
2999 crypto-key 4a506a794f574265564551694d653768 \
3000 crypto-alg aes-cbc-128 \
3001 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3002 integ-alg sha1-96 tunnel-src 192.168.100.3 \
3003 tunnel-dst 192.168.100.2'
3004 Sample CLI : 'ipsec sa add 20 spi 2001 \
3005 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3006 integ-alg sha1-96'
3007
3008 :param sad_id - Security Association ID to be \
3009 created or deleted. mandatory
3010 :param spi - security param index of the SA in decimal. mandatory
3011 :param tunnel_src_address - incase of tunnel mode outer src address .\
3012 mandatory for tunnel mode
3013 :param tunnel_dst_address - incase of transport mode \
3014 outer dst address. mandatory for tunnel mode
3015 :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional
3016 :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\
3017 optional **
3018 :param integrity_key - value in string \
3019 (Default C91KUR9GYMm5GfkEvNjX).optional
3020 :param integrity_key_length - length of the key string in bytes\
3021 (Default 0 - integrity disabled). optional
3022 :param crypto_algorithm - value range 1-11 Default \
3023 (1- AES_CBC_128).optional **
3024 :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional
3025 :param crypto_key_length - length of the key string in bytes\
3026 (Default 0 - crypto disabled). optional
3027 :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\
3028 optional
3029 :param is_tunnel - tunnel mode (1) or transport mode(0) \
3030 (Default 1 - tunnel). optional
3031 :returns: reply from the API
3032 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3033 crypto and ipsec algorithms
3034 """
3035 return self.api(
3036 self.papi.ipsec_sad_add_del_entry,
3037 {'sad_id': sad_id,
3038 'spi': spi,
3039 'tunnel_src_address': tunnel_src_address,
3040 'tunnel_dst_address': tunnel_dst_address,
3041 'protocol': protocol,
3042 'integrity_algorithm': integrity_algorithm,
3043 'integrity_key_length': integrity_key_length,
3044 'integrity_key': integrity_key,
3045 'crypto_algorithm': crypto_algorithm,
3046 'crypto_key_length': crypto_key_length,
3047 'crypto_key': crypto_key,
3048 'is_add': is_add,
3049 'is_tunnel': is_tunnel})
3050
3051 def ipsec_spd_add_del_entry(self,
3052 spd_id,
3053 local_address_start,
3054 local_address_stop,
3055 remote_address_start,
3056 remote_address_stop,
3057 local_port_start=0,
3058 local_port_stop=65535,
3059 remote_port_start=0,
3060 remote_port_stop=65535,
3061 protocol=0,
3062 sa_id=10,
3063 policy=0,
3064 priority=100,
3065 is_outbound=1,
3066 is_add=1,
3067 is_ip_any=0):
3068 """ IPSEC policy SPD add/del -
3069 Wrapper to configure ipsec SPD policy entries in VPP
3070 Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \
3071 protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \
3072 remote-ip-range 192.168.3.3 - 192.168.3.3'
3073
3074 :param spd_id - SPD ID for the policy . mandatory
3075 :param local_address_start - local-ip-range start address . mandatory
3076 :param local_address_stop - local-ip-range stop address . mandatory
3077 :param remote_address_start - remote-ip-range start address . mandatory
3078 :param remote_address_stop - remote-ip-range stop address . mandatory
3079 :param local_port_start - (Default 0) . optional
3080 :param local_port_stop - (Default 65535). optional
3081 :param remote_port_start - (Default 0). optional
3082 :param remote_port_stop - (Default 65535). optional
3083 :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any).
3084 optional
3085 :param sa_id - Security Association ID for mapping it to SPD
3086 (default 10). optional
3087 :param policy - bypass(0), discard(1), resolve(2) or protect(3)action
3088 (Default 0 - bypass). optional
3089 :param priotity - value for the spd action (Default 100). optional
3090 :param is_outbound - flag for inbound(0) or outbound(1)
3091 (Default 1 - outbound). optional
3092 :param is_add flag - for addition(1) or deletion(0) of the spd
3093 (Default 1 - addtion). optional
3094 :returns: reply from the API
3095 """
3096 return self.api(
3097 self.papi.ipsec_spd_add_del_entry,
3098 {'spd_id': spd_id,
3099 'local_address_start': local_address_start,
3100 'local_address_stop': local_address_stop,
3101 'remote_address_start': remote_address_start,
3102 'remote_address_stop': remote_address_stop,
3103 'local_port_start': local_port_start,
3104 'local_port_stop': local_port_stop,
3105 'remote_port_start': remote_port_start,
3106 'remote_port_stop': remote_port_stop,
3107 'is_add': is_add,
3108 'protocol': protocol,
3109 'policy': policy,
3110 'priority': priority,
3111 'is_outbound': is_outbound,
3112 'sa_id': sa_id,
3113 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003114
3115 def app_namespace_add(self,
3116 namespace_id,
3117 ip4_fib_id=0,
3118 ip6_fib_id=0,
3119 sw_if_index=0xFFFFFFFF,
3120 secret=0):
3121 return self.api(
3122 self.papi.app_namespace_add_del,
3123 {'secret': secret,
3124 'sw_if_index': sw_if_index,
3125 'ip4_fib_id': ip4_fib_id,
3126 'ip6_fib_id': ip6_fib_id,
3127 'namespace_id': namespace_id,
3128 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003129
3130 def punt_socket_register(self, l4_port, pathname, header_version=1,
3131 is_ip4=1, l4_protocol=0x11):
3132 """ Punt to socket """
3133 return self.api(self.papi.punt_socket_register,
3134 {'is_ip4': is_ip4,
3135 'l4_protocol': l4_protocol,
3136 'l4_port': l4_port,
3137 'pathname': pathname,
3138 'header_version': header_version})
3139
3140 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3141 expire_walk_interval_ms, is_ip6=0):
3142 """ Set IP reassembly parameters """
3143 return self.api(self.papi.ip_reassembly_set,
3144 {'is_ip6': is_ip6,
3145 'timeout_ms': timeout_ms,
3146 'expire_walk_interval_ms': expire_walk_interval_ms,
3147 'max_reassemblies': max_reassemblies})
3148
3149 def ip_reassembly_get(self, is_ip6=0):
3150 """ Get IP reassembly parameters """
3151 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})