blob: f8bca82163194041c89df7d5c4ab3aee2f0cda04 [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 Rannsa07bd702017-08-07 07:53:49 -0700606 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200607 """
608
609 :param admin_up_down:
610 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200611
612 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100613 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200614 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700615 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200616
617 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
618 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
619 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
620 """Create subinterface
621 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
622
623 :param sub_id: param inner_vlan:
624 :param sw_if_index:
625 :param outer_vlan:
626 :param inner_vlan:
627 :param no_tags: (Default value = 0)
628 :param one_tag: (Default value = 0)
629 :param two_tags: (Default value = 0)
630 :param dot1ad: (Default value = 0)
631 :param exact_match: (Default value = 0)
632 :param default_sub: (Default value = 0)
633 :param outer_vlan_id_any: (Default value = 0)
634 :param inner_vlan_id_any: (Default value = 0)
635
636 """
637 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100638 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200639 {'sw_if_index': sw_if_index,
640 'sub_id': sub_id,
641 'no_tags': no_tags,
642 'one_tag': one_tag,
643 'two_tags': two_tags,
644 'dot1ad': dot1ad,
645 'exact_match': exact_match,
646 'default_sub': default_sub,
647 'outer_vlan_id_any': outer_vlan_id_any,
648 'inner_vlan_id_any': inner_vlan_id_any,
649 'outer_vlan_id': outer_vlan,
650 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200651
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200652 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
653 """Create p2p ethernet subinterface
654
655 :param sw_if_index: main (parent) interface
656 :param remote_mac: client (remote) mac address
657
658 """
659 return self.api(
660 self.papi.p2p_ethernet_add,
661 {'parent_if_index': sw_if_index,
662 'remote_mac': remote_mac,
663 'subif_id': subif_id})
664
Neale Ranns177bbdc2016-11-15 09:46:51 +0000665 def delete_subif(self, sw_if_index):
666 """Delete subinterface
667
668 :param sw_if_index:
669 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100670 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200671 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000672
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200673 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
674 """Delete p2p ethernet subinterface
675
676 :param sw_if_index: main (parent) interface
677 :param remote_mac: client (remote) mac address
678
679 """
680 return self.api(
681 self.papi.p2p_ethernet_del,
682 {'parent_if_index': sw_if_index,
683 'remote_mac': remote_mac})
684
Klement Sekeraf62ae122016-10-11 11:47:09 +0200685 def create_vlan_subif(self, sw_if_index, vlan):
686 """
687
688 :param vlan:
689 :param sw_if_index:
690
691 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100692 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200693 {'sw_if_index': sw_if_index,
694 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200695
Matej Klotton0178d522016-11-04 11:11:44 +0100696 def create_loopback(self, mac=''):
697 """
698
699 :param mac: (Optional)
700 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100701 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200702 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100703
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100704 def delete_loopback(self, sw_if_index):
705 return self.api(self.papi.delete_loopback,
706 {'sw_if_index': sw_if_index, })
707
Neale Ranns15002542017-09-10 04:39:11 -0700708 def ip_table_add_del(self,
709 table_id,
710 is_add=1,
711 is_ipv6=0):
712 """
713
714 :param table_id
715 :param is_add: (Default value = 1)
716 :param is_ipv6: (Default value = 0)
717
718 """
719
720 return self.api(
721 self.papi.ip_table_add_del,
722 {'table_id': table_id,
723 'is_add': is_add,
724 'is_ipv6': is_ipv6})
725
Klement Sekeraf62ae122016-10-11 11:47:09 +0200726 def ip_add_del_route(
727 self,
728 dst_address,
729 dst_address_length,
730 next_hop_address,
731 next_hop_sw_if_index=0xFFFFFFFF,
732 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200733 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000734 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200735 next_hop_n_out_labels=0,
736 next_hop_out_label_stack=[],
737 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800738 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000739 is_resolve_host=0,
740 is_resolve_attached=0,
741 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200742 is_add=1,
743 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200744 is_unreach=0,
745 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200746 is_ipv6=0,
747 is_local=0,
748 is_classify=0,
749 is_multipath=0,
Neale Ranns6f631152017-10-03 08:20:21 -0700750 is_l2_bridged=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800751 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200752 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200753 """
754
755 :param dst_address_length:
756 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
757 :param dst_address:
758 :param next_hop_address:
759 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
760 :param vrf_id: (Default value = 0)
761 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200762 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200763 :param is_add: (Default value = 1)
764 :param is_drop: (Default value = 0)
765 :param is_ipv6: (Default value = 0)
766 :param is_local: (Default value = 0)
767 :param is_classify: (Default value = 0)
768 :param is_multipath: (Default value = 0)
769 :param is_resolve_host: (Default value = 0)
770 :param is_resolve_attached: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700771 :param is_l2_bridged: (Default value = 0)
772 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200773 :param next_hop_weight: (Default value = 1)
774
775 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000776
Klement Sekeraf62ae122016-10-11 11:47:09 +0200777 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100778 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200779 {'next_hop_sw_if_index': next_hop_sw_if_index,
780 'table_id': table_id,
781 'classify_table_index': classify_table_index,
782 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200783 'is_add': is_add,
784 'is_drop': is_drop,
785 'is_unreach': is_unreach,
786 'is_prohibit': is_prohibit,
787 'is_ipv6': is_ipv6,
788 'is_local': is_local,
789 'is_classify': is_classify,
790 'is_multipath': is_multipath,
791 'is_resolve_host': is_resolve_host,
792 'is_resolve_attached': is_resolve_attached,
Neale Ranns6f631152017-10-03 08:20:21 -0700793 'is_l2_bridged': is_l2_bridged,
Neale Ranns054c03a2017-10-13 05:15:07 -0700794 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800795 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200796 'next_hop_weight': next_hop_weight,
797 'dst_address_length': dst_address_length,
798 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800799 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200800 'next_hop_address': next_hop_address,
801 'next_hop_n_out_labels': next_hop_n_out_labels,
802 'next_hop_via_label': next_hop_via_label,
803 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100804
Matej Klotton16a14cd2016-12-07 15:09:13 +0100805 def ip_fib_dump(self):
806 return self.api(self.papi.ip_fib_dump, {})
807
Jan Gelety057bb8c2016-12-20 17:32:45 +0100808 def ip6_fib_dump(self):
809 return self.api(self.papi.ip6_fib_dump, {})
810
Matej Klotton0178d522016-11-04 11:11:44 +0100811 def ip_neighbor_add_del(self,
812 sw_if_index,
813 mac_address,
814 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100815 is_add=1,
816 is_ipv6=0,
817 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800818 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100819 ):
820 """ Add neighbor MAC to IPv4 or IPv6 address.
821
822 :param sw_if_index:
823 :param mac_address:
824 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100825 :param is_add: (Default value = 1)
826 :param is_ipv6: (Default value = 0)
827 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800828 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100829 """
830
831 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100832 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800833 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200834 'is_add': is_add,
835 'is_ipv6': is_ipv6,
836 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800837 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200838 'mac_address': mac_address,
839 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100840 }
Matej Klotton0178d522016-11-04 11:11:44 +0100841 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100842
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800843 def ip_neighbor_dump(self,
844 sw_if_index,
845 is_ipv6=0):
846 """ Return IP neighbor dump.
847
848 :param sw_if_index:
849 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
850 """
851
852 return self.api(
853 self.papi.ip_neighbor_dump,
854 {'is_ipv6': is_ipv6,
855 'sw_if_index': sw_if_index
856 }
857 )
858
859 def proxy_arp_add_del(self,
860 low_address,
861 hi_address,
862 vrf_id=0,
863 is_add=1):
864 """ Config Proxy Arp Range.
865
866 :param low_address: Start address in the rnage to Proxy for
867 :param hi_address: End address in the rnage to Proxy for
868 :param vrf_id: The VRF/table in which to proxy
869 """
870
871 return self.api(
872 self.papi.proxy_arp_add_del,
873 {'vrf_id': vrf_id,
874 'is_add': is_add,
875 'low_address': low_address,
876 'hi_address': hi_address,
877 }
878 )
879
880 def proxy_arp_intfc_enable_disable(self,
881 sw_if_index,
882 is_enable=1):
883 """ Enable/Disable an interface for proxy ARP requests
884
885 :param sw_if_index: Interface
886 :param enable_disable: Enable/Disable
887 """
888
889 return self.api(
890 self.papi.proxy_arp_intfc_enable_disable,
891 {'sw_if_index': sw_if_index,
892 'enable_disable': is_enable
893 }
894 )
895
Jane546d3b2016-12-08 13:10:03 +0100896 def reset_vrf(self,
897 vrf_id,
898 is_ipv6=0,
899 ):
900 """ Reset VRF (remove all routes etc.) request.
901
902 :param int vrf_id: ID of the FIB table / VRF to reset.
903 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
904 """
905
906 return self.api(
907 self.papi.reset_vrf,
908 {'vrf_id': vrf_id,
909 'is_ipv6': is_ipv6,
910 }
911 )
912
913 def reset_fib(self,
914 vrf_id,
915 is_ipv6=0,
916 ):
917 """ Reset VRF (remove all routes etc.) request.
918
919 :param int vrf_id: ID of the FIB table / VRF to reset.
920 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
921 """
922
923 return self.api(
924 self.papi.reset_fib,
925 {'vrf_id': vrf_id,
926 'is_ipv6': is_ipv6,
927 }
928 )
929
930 def ip_dump(self,
931 is_ipv6=0,
932 ):
933 """ Return IP dump.
934
935 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
936 """
937
938 return self.api(
939 self.papi.ip_dump,
940 {'is_ipv6': is_ipv6,
941 }
942 )
943
Klement Sekera7bb873a2016-11-18 07:38:42 +0100944 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300945 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100946 """
947
948 :param sw_if_index_from:
949 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100950 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300951 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100952 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100953 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200954 {'sw_if_index_from': sw_if_index_from,
955 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300956 'state': state,
957 'is_l2': is_l2,
958 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000959
960 def gre_tunnel_add_del(self,
961 src_address,
962 dst_address,
963 outer_fib_id=0,
964 is_teb=0,
965 is_add=1,
966 is_ip6=0):
967 """ Add a GRE tunnel
968
969 :param src_address:
970 :param dst_address:
971 :param outer_fib_id: (Default value = 0)
972 :param is_add: (Default value = 1)
973 :param is_ipv6: (Default value = 0)
974 :param is_teb: (Default value = 0)
975 """
976
977 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100978 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200979 {'is_add': is_add,
980 'is_ipv6': is_ip6,
981 'teb': is_teb,
982 'src_address': src_address,
983 'dst_address': dst_address,
984 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000985 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000986
Neale Ranns810086d2017-11-05 16:26:46 -0800987 def udp_encap_add_del(self,
988 id,
989 src_ip,
990 dst_ip,
991 src_port,
992 dst_port,
993 table_id=0,
994 is_add=1,
995 is_ip6=0):
996 """ Add a GRE tunnel
997 :param id: user provided ID
998 :param src_ip:
999 :param dst_ip:
1000 :param src_port:
1001 :param dst_port:
1002 :param outer_fib_id: (Default value = 0)
1003 :param is_add: (Default value = 1)
1004 :param is_ipv6: (Default value = 0)
1005 """
1006
1007 return self.api(
1008 self.papi.udp_encap_add_del,
1009 {'id': id,
1010 'is_add': is_add,
1011 'is_ip6': is_ip6,
1012 'src_ip': src_ip,
1013 'dst_ip': dst_ip,
1014 'src_port': src_port,
1015 'dst_port': dst_port,
1016 'table_id': table_id}
1017 )
1018
1019 def udp_encap_dump(self):
1020 return self.api(self.papi.udp_encap_dump, {})
1021
Neale Ranns5a8123b2017-01-26 01:18:23 -08001022 def mpls_fib_dump(self):
1023 return self.api(self.papi.mpls_fib_dump, {})
1024
Neale Ranns15002542017-09-10 04:39:11 -07001025 def mpls_table_add_del(
1026 self,
1027 table_id,
1028 is_add=1):
1029 """
1030
1031 :param table_id
1032 :param is_add: (Default value = 1)
1033
1034 """
1035
1036 return self.api(
1037 self.papi.mpls_table_add_del,
1038 {'mt_table_id': table_id,
1039 'mt_is_add': is_add})
1040
Neale Rannsad422ed2016-11-02 14:20:04 +00001041 def mpls_route_add_del(
1042 self,
1043 label,
1044 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001045 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001046 next_hop_address,
1047 next_hop_sw_if_index=0xFFFFFFFF,
1048 table_id=0,
1049 next_hop_table_id=0,
1050 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001051 next_hop_n_out_labels=0,
1052 next_hop_out_label_stack=[],
1053 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001054 is_resolve_host=0,
1055 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001056 is_interface_rx=0,
1057 is_rpf_id=0,
1058 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001059 is_add=1,
1060 is_drop=0,
1061 is_multipath=0,
1062 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001063 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001064 """
1065
1066 :param dst_address_length:
1067 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1068 :param dst_address:
1069 :param next_hop_address:
1070 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1071 :param vrf_id: (Default value = 0)
1072 :param lookup_in_vrf: (Default value = 0)
1073 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001074 :param is_add: (Default value = 1)
1075 :param is_drop: (Default value = 0)
1076 :param is_ipv6: (Default value = 0)
1077 :param is_local: (Default value = 0)
1078 :param is_classify: (Default value = 0)
1079 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001080 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001081 :param is_resolve_host: (Default value = 0)
1082 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001083 :param next_hop_weight: (Default value = 1)
1084
1085 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001086
1087 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001088 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001089 {'mr_label': label,
1090 'mr_eos': eos,
1091 'mr_table_id': table_id,
1092 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001093 'mr_is_add': is_add,
1094 'mr_is_classify': is_classify,
1095 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001096 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001097 'mr_is_resolve_host': is_resolve_host,
1098 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001099 'mr_is_interface_rx': is_interface_rx,
1100 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001101 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001102 'mr_next_hop_weight': next_hop_weight,
1103 'mr_next_hop': next_hop_address,
1104 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1105 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1106 'mr_next_hop_table_id': next_hop_table_id,
1107 'mr_next_hop_via_label': next_hop_via_label,
1108 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001109
1110 def mpls_ip_bind_unbind(
1111 self,
1112 label,
1113 dst_address,
1114 dst_address_length,
1115 table_id=0,
1116 ip_table_id=0,
1117 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001118 is_bind=1):
1119 """
1120 """
1121 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001122 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001123 {'mb_mpls_table_id': table_id,
1124 'mb_label': label,
1125 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001126 'mb_is_bind': is_bind,
1127 'mb_is_ip4': is_ip4,
1128 'mb_address_length': dst_address_length,
1129 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001130
1131 def mpls_tunnel_add_del(
1132 self,
1133 tun_sw_if_index,
1134 next_hop_proto_is_ip4,
1135 next_hop_address,
1136 next_hop_sw_if_index=0xFFFFFFFF,
1137 next_hop_table_id=0,
1138 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001139 next_hop_n_out_labels=0,
1140 next_hop_out_label_stack=[],
1141 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001142 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001143 l2_only=0,
1144 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001145 """
1146
1147 :param dst_address_length:
1148 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1149 :param dst_address:
1150 :param next_hop_address:
1151 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1152 :param vrf_id: (Default value = 0)
1153 :param lookup_in_vrf: (Default value = 0)
1154 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001155 :param is_add: (Default value = 1)
1156 :param is_drop: (Default value = 0)
1157 :param is_ipv6: (Default value = 0)
1158 :param is_local: (Default value = 0)
1159 :param is_classify: (Default value = 0)
1160 :param is_multipath: (Default value = 0)
1161 :param is_resolve_host: (Default value = 0)
1162 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001163 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001164 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001165
1166 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001167 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001168 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001169 {'mt_sw_if_index': tun_sw_if_index,
1170 'mt_is_add': is_add,
1171 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001172 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001173 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1174 'mt_next_hop_weight': next_hop_weight,
1175 'mt_next_hop': next_hop_address,
1176 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1177 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1178 'mt_next_hop_table_id': next_hop_table_id,
1179 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001180
Matus Fabian2ba92e32017-08-21 07:05:03 -07001181 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001182 self,
1183 sw_if_index,
1184 is_inside=1,
1185 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001186 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001187
1188 :param sw_if_index: Software index of the interface
1189 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1190 :param is_add: 1 if add, 0 if delete (Default value = 1)
1191 """
1192 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001193 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001194 {'is_add': is_add,
1195 'is_inside': is_inside,
1196 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001197
Matus Fabian2ba92e32017-08-21 07:05:03 -07001198 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001199 self,
1200 sw_if_index,
1201 is_inside=1,
1202 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001203 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001204
1205 :param sw_if_index: Software index of the interface
1206 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1207 :param is_add: 1 if add, 0 if delete (Default value = 1)
1208 """
1209 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001210 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001211 {'is_add': is_add,
1212 'is_inside': is_inside,
1213 'sw_if_index': sw_if_index})
1214
Matus Fabian2ba92e32017-08-21 07:05:03 -07001215 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001216 self,
1217 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001218 external_ip=0,
1219 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001220 local_port=0,
1221 external_port=0,
1222 addr_only=1,
1223 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001224 protocol=0,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001225 is_add=1):
1226 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001227
1228 :param local_ip: Local IP address
1229 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001230 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001231 :param local_port: Local port number (Default value = 0)
1232 :param external_port: External port number (Default value = 0)
1233 :param addr_only: 1 if address only mapping, 0 if address and port
1234 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001235 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001236 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001237 """
1238 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001239 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001240 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001241 'addr_only': addr_only,
1242 'local_ip_address': local_ip,
1243 'external_ip_address': external_ip,
1244 'local_port': local_port,
1245 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001246 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001247 'vrf_id': vrf_id,
1248 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001249
Matus Fabianab7a8052017-11-28 04:29:41 -08001250 def nat44_add_del_identity_mapping(
1251 self,
1252 ip='0',
1253 sw_if_index=0xFFFFFFFF,
1254 port=0,
1255 addr_only=1,
1256 vrf_id=0,
1257 protocol=0,
1258 is_add=1):
1259 """Add/delete NAT44 identity mapping
1260
1261 :param ip: IP address (Default value = 0)
1262 :param sw_if_index: Interface instead of IP address
1263 :param port: Port number (Default value = 0)
1264 :param addr_only: 1 if address only mapping, 0 if address and port
1265 :param vrf_id: VRF ID
1266 :param protocol: IP protocol (Default value = 0)
1267 :param is_add: 1 if add, 0 if delete (Default value = 1)
1268 """
1269 return self.api(
1270 self.papi.nat44_add_del_identity_mapping,
1271 {'is_add': is_add,
1272 'addr_only': addr_only,
1273 'ip_address': ip,
1274 'port': port,
1275 'sw_if_index': sw_if_index,
1276 'vrf_id': vrf_id,
1277 'protocol': protocol})
1278
Matus Fabian2ba92e32017-08-21 07:05:03 -07001279 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001280 self,
1281 first_ip_address,
1282 last_ip_address,
1283 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001284 vrf_id=0xFFFFFFFF):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001285 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001286
1287 :param first_ip_address: First IP address
1288 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001289 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001290 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001291 """
1292 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001293 self.papi.nat44_add_del_address_range,
1294 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001295 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001296 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001297 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001298
Matus Fabian2ba92e32017-08-21 07:05:03 -07001299 def nat44_address_dump(self):
1300 """Dump NAT44 addresses
1301 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001302 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001303 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001304
Matus Fabian2ba92e32017-08-21 07:05:03 -07001305 def nat44_interface_dump(self):
1306 """Dump interfaces with NAT44 feature
1307 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001308 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001309 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001310
Matus Fabian2ba92e32017-08-21 07:05:03 -07001311 def nat44_interface_output_feature_dump(self):
1312 """Dump interfaces with NAT44 output feature
1313 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001314 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001315 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001316
Matus Fabian2ba92e32017-08-21 07:05:03 -07001317 def nat44_static_mapping_dump(self):
1318 """Dump NAT44 static mappings
1319 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001320 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001321 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001322
Matus Fabianab7a8052017-11-28 04:29:41 -08001323 def nat44_identity_mapping_dump(self):
1324 """Dump NAT44 identity mappings
1325 :return: Dictionary of NAT44 identity mappings
1326 """
1327 return self.api(self.papi.nat44_identity_mapping_dump, {})
1328
Matus Fabian2ba92e32017-08-21 07:05:03 -07001329 def nat_show_config(self):
1330 """Show NAT plugin config
1331 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001332 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001333 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001334
Matus Fabian2ba92e32017-08-21 07:05:03 -07001335 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001336 self,
1337 sw_if_index,
1338 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001339 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001340
1341 :param sw_if_index: Software index of the interface
1342 :param is_add: 1 if add, 0 if delete (Default value = 1)
1343 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001344 return self.api(self.papi.nat44_add_del_interface_addr,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001345 {'is_add': is_add, 'sw_if_index': sw_if_index})
1346
Matus Fabian2ba92e32017-08-21 07:05:03 -07001347 def nat44_interface_addr_dump(self):
1348 """Dump NAT44 addresses interfaces
1349 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001350 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001351 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001352
Matus Fabian2ba92e32017-08-21 07:05:03 -07001353 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001354 self,
1355 domain_id=1,
1356 src_port=4739,
1357 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001358 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001359
1360 :param domain_id: Observation domain ID (Default value = 1)
1361 :param src_port: Source port number (Default value = 4739)
1362 :param enable: 1 if enable, 0 if disable (Default value = 1)
1363 """
1364 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001365 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001366 {'domain_id': domain_id,
1367 'src_port': src_port,
1368 'enable': enable})
1369
Matus Fabian2ba92e32017-08-21 07:05:03 -07001370 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001371 self,
1372 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001373 vrf_id):
1374 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001375
1376 :param ip_address: ip adress of the user to be dumped
1377 :param cpu_index: cpu_index on which the user is
1378 :param vrf_id: VRF ID
1379 :return: Dictionary of S-NAT sessions
1380 """
1381 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001382 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001383 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001384 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001385
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 def nat44_user_dump(self):
1387 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001388
Matus Fabian2ba92e32017-08-21 07:05:03 -07001389 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001390 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001391 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001392
Matus Fabian704018c2017-09-04 02:17:18 -07001393 def nat44_add_del_lb_static_mapping(
1394 self,
1395 external_addr,
1396 external_port,
1397 protocol,
1398 vrf_id=0,
1399 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001400 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001401 is_add=1):
1402 """Add/delete NAT44 load balancing static mapping
1403
1404 :param is_add - 1 if add, 0 if delete
1405 """
1406 return self.api(
1407 self.papi.nat44_add_del_lb_static_mapping,
1408 {'is_add': is_add,
1409 'external_addr': external_addr,
1410 'external_port': external_port,
1411 'protocol': protocol,
1412 'vrf_id': vrf_id,
1413 'local_num': local_num,
1414 'locals': locals})
1415
1416 def nat44_lb_static_mapping_dump(self):
1417 """Dump NAT44 load balancing static mappings
1418
1419 :return: Dictionary of NAT44 load balancing static mapping
1420 """
1421 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1422
Matus Fabian5ba86f72017-10-26 03:37:38 -07001423 def nat44_del_session(
1424 self,
1425 addr,
1426 port,
1427 protocol,
1428 vrf_id=0,
1429 is_in=1):
1430 """Delete NAT44 session
1431
1432 :param addr: IPv4 address
1433 :param por: port number
1434 :param protocol: IP protocol number
1435 :param vrf_id: VRF ID
1436 :param is_in: 1 if inside network addres and port pari, 0 if outside
1437 """
1438 return self.api(
1439 self.papi.nat44_del_session,
1440 {'address': addr,
1441 'port': port,
1442 'protocol': protocol,
1443 'vrf_id': vrf_id,
1444 'is_in': is_in})
1445
Matus Fabianefcd1e92017-08-15 06:59:19 -07001446 def nat_set_reass(
1447 self,
1448 timeout=2,
1449 max_reass=1024,
1450 max_frag=5,
1451 drop_frag=0,
1452 is_ip6=0):
1453 """Set NAT virtual fragmentation reassembly
1454
1455 :param timeout: reassembly timeout (Default 2sec)
1456 :param max_reass: maximum concurrent reassemblies (Default 1024)
1457 :param max_frag: maximum fragmets per reassembly (Default 5)
1458 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1459 :param is_ip6: 1 if IPv6, 0 if IPv4
1460 """
1461 return self.api(
1462 self.papi.nat_set_reass,
1463 {'timeout': timeout,
1464 'max_reass': max_reass,
1465 'max_frag': max_frag,
1466 'drop_frag': drop_frag,
1467 'is_ip6': is_ip6})
1468
1469 def nat_get_reass(self):
1470 """Get NAT virtual fragmentation reassembly configuration
1471
1472 :return: NAT virtual fragmentation reassembly configuration
1473 """
1474 return self.api(self.papi.nat_get_reass, {})
1475
1476 def nat_reass_dump(self):
1477 """Dump NAT virtual fragmentation reassemblies
1478
1479 :return: Dictionary of NAT virtual fragmentation reassemblies
1480 """
1481 return self.api(self.papi.nat_reass_dump, {})
1482
Matus Fabian2ba92e32017-08-21 07:05:03 -07001483 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001484 self,
1485 in_addr,
1486 in_plen,
1487 out_addr,
1488 out_plen,
1489 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001490 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001491
1492 :param is_add - 1 if add, 0 if delete
1493 :param in_addr - inside IP address
1494 :param in_plen - inside IP address prefix length
1495 :param out_addr - outside IP address
1496 :param out_plen - outside IP address prefix length
1497 """
1498 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001499 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001500 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001501 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001502 'in_addr': in_addr,
1503 'in_plen': in_plen,
1504 'out_addr': out_addr,
1505 'out_plen': out_plen})
1506
Matus Fabian2ba92e32017-08-21 07:05:03 -07001507 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001508 self,
1509 in_addr):
1510 """Get outside address and port range from inside address
1511
1512 :param in_addr - inside IP address
1513 """
1514 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001515 self.papi.nat_det_forward,
1516 {'in_addr': in_addr,
1517 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001518
Matus Fabian2ba92e32017-08-21 07:05:03 -07001519 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001520 self,
1521 out_addr,
1522 out_port):
1523 """Get inside address from outside address and port
1524
1525 :param out_addr - outside IP address
1526 :param out_port - outside port
1527 """
1528 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001529 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001530 {'out_addr': out_addr,
1531 'out_port': out_port})
1532
Matus Fabian2ba92e32017-08-21 07:05:03 -07001533 def nat_det_map_dump(self):
1534 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001535
Matus Fabian2ba92e32017-08-21 07:05:03 -07001536 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001537 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001538 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001539
Matus Fabian2ba92e32017-08-21 07:05:03 -07001540 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001541 self,
1542 udp=300,
1543 tcp_established=7440,
1544 tcp_transitory=240,
1545 icmp=60):
1546 """Set values of timeouts for deterministic NAT (in seconds)
1547
1548 :param udp - UDP timeout (Default value = 300)
1549 :param tcp_established - TCP established timeout (Default value = 7440)
1550 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1551 :param icmp - ICMP timeout (Default value = 60)
1552 """
1553 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001554 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001555 {'udp': udp,
1556 'tcp_established': tcp_established,
1557 'tcp_transitory': tcp_transitory,
1558 'icmp': icmp})
1559
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001561 """Get values of timeouts for deterministic NAT
1562
1563 :return: Timeouts for deterministic NAT (in seconds)
1564 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001566
Matus Fabian2ba92e32017-08-21 07:05:03 -07001567 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001568 self,
1569 out_addr,
1570 out_port,
1571 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001572 ext_port):
1573 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001574
1575 :param out_addr - outside IP address
1576 :param out_port - outside port
1577 :param ext_addr - external host IP address
1578 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001579 """
1580 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001582 {'out_addr': out_addr,
1583 'out_port': out_port,
1584 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001585 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001586
Matus Fabian2ba92e32017-08-21 07:05:03 -07001587 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001588 self,
1589 in_addr,
1590 in_port,
1591 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001592 ext_port):
1593 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001594
1595 :param in_addr - inside IP address
1596 :param in_port - inside port
1597 :param ext_addr - external host IP address
1598 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001599 """
1600 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001601 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001602 {'in_addr': in_addr,
1603 'in_port': in_port,
1604 'ext_addr': ext_addr,
1605 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001606 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001607
Matus Fabian2ba92e32017-08-21 07:05:03 -07001608 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001609 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001610 user_addr):
1611 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001612
1613 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001614 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001615 """
1616 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001617 self.papi.nat_det_session_dump,
1618 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001619 'user_addr': user_addr})
1620
Matus Fabian06596c52017-06-06 04:53:28 -07001621 def nat64_add_del_pool_addr_range(
1622 self,
1623 start_addr,
1624 end_addr,
1625 vrf_id=0xFFFFFFFF,
1626 is_add=1):
1627 """Add/del address range to NAT64 pool
1628
1629 :param start_addr: First IP address
1630 :param end_addr: Last IP address
1631 :param vrf_id: VRF id for the address range
1632 :param is_add: 1 if add, 0 if delete (Default value = 1)
1633 """
1634 return self.api(
1635 self.papi.nat64_add_del_pool_addr_range,
1636 {'start_addr': start_addr,
1637 'end_addr': end_addr,
1638 'vrf_id': vrf_id,
1639 'is_add': is_add})
1640
1641 def nat64_pool_addr_dump(self):
1642 """Dump NAT64 pool addresses
1643 :return: Dictionary of NAT64 pool addresses
1644 """
1645 return self.api(self.papi.nat64_pool_addr_dump, {})
1646
1647 def nat64_add_del_interface(
1648 self,
1649 sw_if_index,
1650 is_inside=1,
1651 is_add=1):
1652 """Enable/disable NAT64 feature on the interface
1653 :param sw_if_index: Index of the interface
1654 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1655 :param is_add: 1 if add, 0 if delete (Default value = 1)
1656 """
1657 return self.api(
1658 self.papi.nat64_add_del_interface,
1659 {'sw_if_index': sw_if_index,
1660 'is_inside': is_inside,
1661 'is_add': is_add})
1662
1663 def nat64_interface_dump(self):
1664 """Dump interfaces with NAT64 feature
1665 :return: Dictionary of interfaces with NAT64 feature
1666 """
1667 return self.api(self.papi.nat64_interface_dump, {})
1668
1669 def nat64_add_del_static_bib(
1670 self,
1671 in_ip,
1672 out_ip,
1673 in_port,
1674 out_port,
1675 protocol,
1676 vrf_id=0,
1677 is_add=1):
1678 """Add/delete S-NAT static BIB entry
1679
1680 :param in_ip: Inside IPv6 address
1681 :param out_ip: Outside IPv4 address
1682 :param in_port: Inside port number
1683 :param out_port: Outside port number
1684 :param protocol: IP protocol
1685 :param vrf_id: VRF ID (Default value = 0)
1686 :param is_add: 1 if add, 0 if delete (Default value = 1)
1687 """
1688 return self.api(
1689 self.papi.nat64_add_del_static_bib,
1690 {'i_addr': in_ip,
1691 'o_addr': out_ip,
1692 'i_port': in_port,
1693 'o_port': out_port,
1694 'vrf_id': vrf_id,
1695 'proto': protocol,
1696 'is_add': is_add})
1697
Matus Fabianab9a59c2017-08-16 05:37:36 -07001698 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001699 """Dump NAT64 BIB
1700
Matus Fabianab9a59c2017-08-16 05:37:36 -07001701 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001702 :returns: Dictionary of NAT64 BIB entries
1703 """
1704 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1705
1706 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1707 tcp_incoming_syn=6):
1708 """Set values of timeouts for NAT64 (in seconds)
1709
Matus Fabian428dc912017-06-21 06:15:18 -07001710 :param udpi: UDP timeout (Default value = 300)
1711 :param icmp: ICMP timeout (Default value = 60)
1712 :param tcp_trans: TCP transitory timeout (Default value = 240)
1713 :param tcp_est: TCP established timeout (Default value = 7440)
1714 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001715 """
1716 return self.api(
1717 self.papi.nat64_set_timeouts,
1718 {'udp': udp,
1719 'icmp': icmp,
1720 'tcp_trans': tcp_trans,
1721 'tcp_est': tcp_est,
1722 'tcp_incoming_syn': tcp_incoming_syn})
1723
1724 def nat64_get_timeouts(self):
1725 """Get values of timeouts for NAT64
1726
1727 :return: Timeouts for NAT64 (in seconds)
1728 """
1729 return self.api(self.papi.nat64_get_timeouts, {})
1730
Matus Fabianab9a59c2017-08-16 05:37:36 -07001731 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001732 """Dump NAT64 session table
1733
Matus Fabianab9a59c2017-08-16 05:37:36 -07001734 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001735 :returns: Dictionary of NAT64 sesstion table entries
1736 """
1737 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1738
Matus Fabian428dc912017-06-21 06:15:18 -07001739 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1740 """Add/del NAT64 prefix
1741
1742 :param prefix: NAT64 prefix
1743 :param plen: NAT64 prefix length
1744 :param vrf_id: VRF id of tenant (Default 0)
1745 :param is_add: 1 if add, 0 if delete (Default value = 1)
1746 """
1747 return self.api(
1748 self.papi.nat64_add_del_prefix,
1749 {'prefix': prefix,
1750 'prefix_len': plen,
1751 'vrf_id': vrf_id,
1752 'is_add': is_add})
1753
1754 def nat64_prefix_dump(self):
1755 """Dump NAT64 prefix
1756
1757 :returns: Dictionary of NAT64 prefixes
1758 """
1759 return self.api(self.papi.nat64_prefix_dump, {})
1760
Matus Fabian0938dcf2017-11-08 01:59:38 -08001761 def nat64_add_interface_addr(
1762 self,
1763 sw_if_index,
1764 is_add=1):
1765 """Add/del NAT64 address from interface
1766
1767 :param sw_if_index: Software index of the interface
1768 :param is_add: 1 if add, 0 if delete (Default value = 1)
1769 """
1770 return self.api(self.papi.nat64_add_del_interface_addr,
1771 {'is_add': is_add, 'sw_if_index': sw_if_index})
1772
Matus Fabian8ebe6252017-11-06 05:04:53 -08001773 def dslite_set_aftr_addr(self, ip6, ip4):
1774 """Set DS-Lite AFTR addresses
1775
1776 :param ip4: IPv4 address
1777 :param ip6: IPv6 address
1778 """
1779 return self.api(
1780 self.papi.dslite_set_aftr_addr,
1781 {'ip4_addr': ip4,
1782 'ip6_addr': ip6})
1783
1784 def dslite_add_del_pool_addr_range(
1785 self,
1786 start_addr,
1787 end_addr,
1788 is_add=1):
1789 """Add/del address range to DS-Lite pool
1790
1791 :param start_addr: First IP address
1792 :param end_addr: Last IP address
1793 :param is_add: 1 if add, 0 if delete (Default value = 1)
1794 """
1795 return self.api(
1796 self.papi.dslite_add_del_pool_addr_range,
1797 {'start_addr': start_addr,
1798 'end_addr': end_addr,
1799 'is_add': is_add})
1800
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001801 def control_ping(self):
1802 self.api(self.papi.control_ping)
1803
1804 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001805 detect_mult, local_addr, peer_addr, is_ipv6=0,
1806 bfd_key_id=None, conf_key_id=None):
1807 if bfd_key_id is None:
1808 return self.api(self.papi.bfd_udp_add,
1809 {
1810 'sw_if_index': sw_if_index,
1811 'desired_min_tx': desired_min_tx,
1812 'required_min_rx': required_min_rx,
1813 'local_addr': local_addr,
1814 'peer_addr': peer_addr,
1815 'is_ipv6': is_ipv6,
1816 'detect_mult': detect_mult,
1817 })
1818 else:
1819 return self.api(self.papi.bfd_udp_add,
1820 {
1821 'sw_if_index': sw_if_index,
1822 'desired_min_tx': desired_min_tx,
1823 'required_min_rx': required_min_rx,
1824 'local_addr': local_addr,
1825 'peer_addr': peer_addr,
1826 'is_ipv6': is_ipv6,
1827 'detect_mult': detect_mult,
1828 'is_authenticated': 1,
1829 'bfd_key_id': bfd_key_id,
1830 'conf_key_id': conf_key_id,
1831 })
1832
Klement Sekeraa57a9702017-02-02 06:58:07 +01001833 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1834 detect_mult, local_addr, peer_addr, is_ipv6=0):
1835 return self.api(self.papi.bfd_udp_mod,
1836 {
1837 'sw_if_index': sw_if_index,
1838 'desired_min_tx': desired_min_tx,
1839 'required_min_rx': required_min_rx,
1840 'local_addr': local_addr,
1841 'peer_addr': peer_addr,
1842 'is_ipv6': is_ipv6,
1843 'detect_mult': detect_mult,
1844 })
1845
Klement Sekerab17dd962017-01-09 07:43:48 +01001846 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1847 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1848 is_delayed=False):
1849 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001850 {
1851 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001852 'local_addr': local_addr,
1853 'peer_addr': peer_addr,
1854 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001855 'is_delayed': 1 if is_delayed else 0,
1856 'bfd_key_id': bfd_key_id,
1857 'conf_key_id': conf_key_id,
1858 })
1859
1860 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1861 is_ipv6=0, is_delayed=False):
1862 return self.api(self.papi.bfd_udp_auth_deactivate,
1863 {
1864 'sw_if_index': sw_if_index,
1865 'local_addr': local_addr,
1866 'peer_addr': peer_addr,
1867 'is_ipv6': is_ipv6,
1868 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001869 })
1870
1871 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1872 return self.api(self.papi.bfd_udp_del,
1873 {
1874 'sw_if_index': sw_if_index,
1875 'local_addr': local_addr,
1876 'peer_addr': peer_addr,
1877 'is_ipv6': is_ipv6,
1878 })
1879
1880 def bfd_udp_session_dump(self):
1881 return self.api(self.papi.bfd_udp_session_dump, {})
1882
Klement Sekerab17dd962017-01-09 07:43:48 +01001883 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1884 peer_addr, is_ipv6=0):
1885 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001886 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001887 'sw_if_index': sw_if_index,
1888 'local_addr': local_addr,
1889 'peer_addr': peer_addr,
1890 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001891 })
1892
1893 def want_bfd_events(self, enable_disable=1):
1894 return self.api(self.papi.want_bfd_events, {
1895 'enable_disable': enable_disable,
1896 'pid': os.getpid(),
1897 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001898
Klement Sekerab17dd962017-01-09 07:43:48 +01001899 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1900 return self.api(self.papi.bfd_auth_set_key, {
1901 'conf_key_id': conf_key_id,
1902 'auth_type': auth_type,
1903 'key': key,
1904 'key_len': len(key),
1905 })
1906
1907 def bfd_auth_del_key(self, conf_key_id):
1908 return self.api(self.papi.bfd_auth_del_key, {
1909 'conf_key_id': conf_key_id,
1910 })
1911
1912 def bfd_auth_keys_dump(self):
1913 return self.api(self.papi.bfd_auth_keys_dump, {})
1914
Klement Sekera239790f2017-02-16 10:53:53 +01001915 def bfd_udp_set_echo_source(self, sw_if_index):
1916 return self.api(self.papi.bfd_udp_set_echo_source,
1917 {'sw_if_index': sw_if_index})
1918
Klement Sekera73884482017-02-23 09:26:30 +01001919 def bfd_udp_del_echo_source(self):
1920 return self.api(self.papi.bfd_udp_del_echo_source, {})
1921
Steve Shin7957d6e2016-12-19 09:24:50 -08001922 def classify_add_del_table(
1923 self,
1924 is_add,
1925 mask,
1926 match_n_vectors=1,
1927 table_index=0xFFFFFFFF,
1928 nbuckets=2,
1929 memory_size=2097152,
1930 skip_n_vectors=0,
1931 next_table_index=0xFFFFFFFF,
1932 miss_next_index=0xFFFFFFFF,
1933 current_data_flag=0,
1934 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001935 """
1936 :param is_add:
1937 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001938 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001939 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001940 :param nbuckets: (Default value = 2)
1941 :param memory_size: (Default value = 2097152)
1942 :param skip_n_vectors: (Default value = 0)
1943 :param next_table_index: (Default value = 0xFFFFFFFF)
1944 :param miss_next_index: (Default value = 0xFFFFFFFF)
1945 :param current_data_flag: (Default value = 0)
1946 :param current_data_offset: (Default value = 0)
1947 """
1948
1949 return self.api(
1950 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001951 {'is_add': is_add,
1952 'table_index': table_index,
1953 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001954 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001955 'skip_n_vectors': skip_n_vectors,
1956 'match_n_vectors': match_n_vectors,
1957 'next_table_index': next_table_index,
1958 'miss_next_index': miss_next_index,
1959 'current_data_flag': current_data_flag,
1960 'current_data_offset': current_data_offset,
1961 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001962
1963 def classify_add_del_session(
1964 self,
1965 is_add,
1966 table_index,
1967 match,
1968 opaque_index=0xFFFFFFFF,
1969 hit_next_index=0xFFFFFFFF,
1970 advance=0,
1971 action=0,
1972 metadata=0):
1973 """
1974 :param is_add:
1975 :param table_index:
1976 :param match:
1977 :param opaque_index: (Default value = 0xFFFFFFFF)
1978 :param hit_next_index: (Default value = 0xFFFFFFFF)
1979 :param advance: (Default value = 0)
1980 :param action: (Default value = 0)
1981 :param metadata: (Default value = 0)
1982 """
1983
1984 return self.api(
1985 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001986 {'is_add': is_add,
1987 'table_index': table_index,
1988 'hit_next_index': hit_next_index,
1989 'opaque_index': opaque_index,
1990 'advance': advance,
1991 'action': action,
1992 'metadata': metadata,
1993 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001994
1995 def input_acl_set_interface(
1996 self,
1997 is_add,
1998 sw_if_index,
1999 ip4_table_index=0xFFFFFFFF,
2000 ip6_table_index=0xFFFFFFFF,
2001 l2_table_index=0xFFFFFFFF):
2002 """
2003 :param is_add:
2004 :param sw_if_index:
2005 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2006 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2007 :param l2_table_index: (Default value = 0xFFFFFFFF)
2008 """
2009
2010 return self.api(
2011 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002012 {'sw_if_index': sw_if_index,
2013 'ip4_table_index': ip4_table_index,
2014 'ip6_table_index': ip6_table_index,
2015 'l2_table_index': l2_table_index,
2016 'is_add': is_add})
2017
2018 def set_ipfix_exporter(
2019 self,
2020 collector_address,
2021 src_address,
2022 path_mtu,
2023 template_interval,
2024 vrf_id=0,
2025 collector_port=4739,
2026 udp_checksum=0):
2027 return self.api(
2028 self.papi.set_ipfix_exporter,
2029 {
2030 'collector_address': collector_address,
2031 'collector_port': collector_port,
2032 'src_address': src_address,
2033 'vrf_id': vrf_id,
2034 'path_mtu': path_mtu,
2035 'template_interval': template_interval,
2036 'udp_checksum': udp_checksum,
2037 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002038
2039 def dhcp_proxy_config(self,
2040 dhcp_server,
2041 dhcp_src_address,
2042 rx_table_id=0,
2043 server_table_id=0,
2044 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002045 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002046 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002047 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002048 {
2049 'rx_vrf_id': rx_table_id,
2050 'server_vrf_id': server_table_id,
2051 'is_ipv6': is_ipv6,
2052 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002053 'dhcp_server': dhcp_server,
2054 'dhcp_src_address': dhcp_src_address,
2055 })
2056
2057 def dhcp_proxy_set_vss(self,
2058 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002059 vss_type=255,
2060 vpn_ascii_id="",
2061 oui=0,
2062 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002063 is_add=1,
2064 is_ip6=0):
2065 return self.api(
2066 self.papi.dhcp_proxy_set_vss,
2067 {
2068 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002069 'vss_type': vss_type,
2070 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002071 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002072 'vpn_index': vpn_index,
2073 'is_add': is_add,
2074 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002075 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002076
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002077 def dhcp_client(self,
2078 sw_if_index,
2079 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002080 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002081 is_add=1,
2082 want_dhcp_events=0):
2083 return self.api(
2084 self.papi.dhcp_client_config,
2085 {
2086 'sw_if_index': sw_if_index,
2087 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002088 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002089 'is_add': is_add,
2090 'want_dhcp_event': want_dhcp_events,
2091 'pid': os.getpid(),
2092 })
2093
Neale Ranns32e1c012016-11-22 17:07:28 +00002094 def ip_mroute_add_del(self,
2095 src_address,
2096 grp_address,
2097 grp_address_length,
2098 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002099 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002100 next_hop_sw_if_index,
2101 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002102 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002103 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002104 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002105 is_add=1,
2106 is_ipv6=0,
2107 is_local=0):
2108 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002109 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002110 """
2111 return self.api(
2112 self.papi.ip_mroute_add_del,
2113 {'next_hop_sw_if_index': next_hop_sw_if_index,
2114 'entry_flags': e_flags,
2115 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002116 'table_id': table_id,
2117 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002118 'is_add': is_add,
2119 'is_ipv6': is_ipv6,
2120 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002121 'bier_imp': bier_imp,
2122 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002123 'grp_address_length': grp_address_length,
2124 'grp_address': grp_address,
2125 'src_address': src_address})
2126
2127 def mfib_signal_dump(self):
2128 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002129
2130 def ip_mfib_dump(self):
2131 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002132
Neale Rannsd792d9c2017-10-21 10:53:20 -07002133 def ip6_mfib_dump(self):
2134 return self.api(self.papi.ip6_mfib_dump, {})
2135
Filip Tehlar770e89e2017-01-31 10:39:16 +01002136 def lisp_enable_disable(self, is_enabled):
2137 return self.api(
2138 self.papi.lisp_enable_disable,
2139 {
2140 'is_en': is_enabled,
2141 })
2142
2143 def lisp_locator_set(self,
2144 ls_name,
2145 is_add=1):
2146 return self.api(
2147 self.papi.lisp_add_del_locator_set,
2148 {
2149 'is_add': is_add,
2150 'locator_set_name': ls_name
2151 })
2152
2153 def lisp_locator_set_dump(self):
2154 return self.api(self.papi.lisp_locator_set_dump, {})
2155
2156 def lisp_locator(self,
2157 ls_name,
2158 sw_if_index,
2159 priority=1,
2160 weight=1,
2161 is_add=1):
2162 return self.api(
2163 self.papi.lisp_add_del_locator,
2164 {
2165 'is_add': is_add,
2166 'locator_set_name': ls_name,
2167 'sw_if_index': sw_if_index,
2168 'priority': priority,
2169 'weight': weight
2170 })
2171
2172 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2173 return self.api(
2174 self.papi.lisp_locator_dump,
2175 {
2176 'is_index_set': is_index_set,
2177 'ls_name': ls_name,
2178 'ls_index': ls_index,
2179 })
2180
2181 def lisp_local_mapping(self,
2182 ls_name,
2183 eid_type,
2184 eid,
2185 prefix_len,
2186 vni=0,
2187 key_id=0,
2188 key="",
2189 is_add=1):
2190 return self.api(
2191 self.papi.lisp_add_del_local_eid,
2192 {
2193 'locator_set_name': ls_name,
2194 'is_add': is_add,
2195 'eid_type': eid_type,
2196 'eid': eid,
2197 'prefix_len': prefix_len,
2198 'vni': vni,
2199 'key_id': key_id,
2200 'key': key
2201 })
2202
2203 def lisp_eid_table_dump(self,
2204 eid_set=0,
2205 prefix_length=0,
2206 vni=0,
2207 eid_type=0,
2208 eid=None,
2209 filter_opt=0):
2210 return self.api(
2211 self.papi.lisp_eid_table_dump,
2212 {
2213 'eid_set': eid_set,
2214 'prefix_length': prefix_length,
2215 'vni': vni,
2216 'eid_type': eid_type,
2217 'eid': eid,
2218 'filter': filter_opt,
2219 })
2220
2221 def lisp_remote_mapping(self,
2222 eid_type,
2223 eid,
2224 eid_prefix_len=0,
2225 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002226 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002227 rlocs_num=0,
2228 is_src_dst=0,
2229 is_add=1):
2230 return self.api(
2231 self.papi.lisp_add_del_remote_mapping,
2232 {
2233 'is_add': is_add,
2234 'eid_type': eid_type,
2235 'eid': eid,
2236 'eid_len': eid_prefix_len,
2237 'rloc_num': rlocs_num,
2238 'rlocs': rlocs,
2239 'vni': vni,
2240 'is_src_dst': is_src_dst,
2241 })
2242
2243 def lisp_adjacency(self,
2244 leid,
2245 reid,
2246 leid_len,
2247 reid_len,
2248 eid_type,
2249 is_add=1,
2250 vni=0):
2251 return self.api(
2252 self.papi.lisp_add_del_adjacency,
2253 {
2254 'is_add': is_add,
2255 'vni': vni,
2256 'eid_type': eid_type,
2257 'leid': leid,
2258 'reid': reid,
2259 'leid_len': leid_len,
2260 'reid_len': reid_len,
2261 })
2262
2263 def lisp_adjacencies_get(self, vni=0):
2264 return self.api(
2265 self.papi.lisp_adjacencies_get,
2266 {
2267 'vni': vni
2268 })
Neale Ranns80823802017-02-20 18:23:41 -08002269
2270 def map_add_domain(self,
2271 ip6_prefix,
2272 ip6_prefix_len,
2273 ip6_src,
2274 ip6_src_prefix_len,
2275 ip4_prefix,
2276 ip4_prefix_len,
2277 ea_bits_len=0,
2278 psid_offset=0,
2279 psid_length=0,
2280 is_translation=0,
2281 mtu=1280):
2282 return self.api(
2283 self.papi.map_add_domain,
2284 {
2285 'ip6_prefix': ip6_prefix,
2286 'ip6_prefix_len': ip6_prefix_len,
2287 'ip4_prefix': ip4_prefix,
2288 'ip4_prefix_len': ip4_prefix_len,
2289 'ip6_src': ip6_src,
2290 'ip6_src_prefix_len': ip6_src_prefix_len,
2291 'ea_bits_len': ea_bits_len,
2292 'psid_offset': psid_offset,
2293 'psid_length': psid_length,
2294 'is_translation': is_translation,
2295 'mtu': mtu
2296 })
Hongjun Nief486b12017-04-12 19:21:16 +08002297
2298 def gtpu_add_del_tunnel(
2299 self,
2300 src_addr,
2301 dst_addr,
2302 is_add=1,
2303 is_ipv6=0,
2304 mcast_sw_if_index=0xFFFFFFFF,
2305 encap_vrf_id=0,
2306 decap_next_index=0xFFFFFFFF,
2307 teid=0):
2308 """
2309
2310 :param is_add: (Default value = 1)
2311 :param is_ipv6: (Default value = 0)
2312 :param src_addr:
2313 :param dst_addr:
2314 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2315 :param encap_vrf_id: (Default value = 0)
2316 :param decap_next_index: (Default value = 0xFFFFFFFF)
2317 :param teid: (Default value = 0)
2318
2319 """
2320 return self.api(self.papi.gtpu_add_del_tunnel,
2321 {'is_add': is_add,
2322 'is_ipv6': is_ipv6,
2323 'src_address': src_addr,
2324 'dst_address': dst_addr,
2325 'mcast_sw_if_index': mcast_sw_if_index,
2326 'encap_vrf_id': encap_vrf_id,
2327 'decap_next_index': decap_next_index,
2328 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002329
2330 def vxlan_gpe_add_del_tunnel(
2331 self,
2332 src_addr,
2333 dst_addr,
2334 mcast_sw_if_index=0xFFFFFFFF,
2335 is_add=1,
2336 is_ipv6=0,
2337 encap_vrf_id=0,
2338 decap_vrf_id=0,
2339 protocol=3,
2340 vni=0):
2341 """
2342
2343 :param local:
2344 :param remote:
2345 :param is_add: (Default value = 1)
2346 :param is_ipv6: (Default value = 0)
2347 :param encap_vrf_id: (Default value = 0)
2348 :param decap_vrf_id: (Default value = 0)
2349 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2350 :param protocol: (Default value = 3)
2351 :param vni: (Default value = 0)
2352
2353 """
2354 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2355 {'is_add': is_add,
2356 'is_ipv6': is_ipv6,
2357 'local': src_addr,
2358 'remote': dst_addr,
2359 'mcast_sw_if_index': mcast_sw_if_index,
2360 'encap_vrf_id': encap_vrf_id,
2361 'decap_vrf_id': decap_vrf_id,
2362 'protocol': protocol,
2363 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002364
2365 def pppoe_add_del_session(
2366 self,
2367 client_ip,
2368 client_mac,
2369 session_id=0,
2370 is_add=1,
2371 is_ipv6=0,
2372 decap_vrf_id=0):
2373 """
2374
2375 :param is_add: (Default value = 1)
2376 :param is_ipv6: (Default value = 0)
2377 :param client_ip:
2378 :param session_id: (Default value = 0)
2379 :param client_mac:
2380 :param decap_vrf_id: (Default value = 0)
2381
2382 """
2383 return self.api(self.papi.pppoe_add_del_session,
2384 {'is_add': is_add,
2385 'is_ipv6': is_ipv6,
2386 'session_id': session_id,
2387 'client_ip': client_ip,
2388 'decap_vrf_id': decap_vrf_id,
2389 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002390
2391 def sr_localsid_add_del(self,
2392 localsid_addr,
2393 behavior,
2394 nh_addr,
2395 is_del=0,
2396 end_psp=0,
2397 sw_if_index=0xFFFFFFFF,
2398 vlan_index=0,
2399 fib_table=0,
2400 ):
2401 """ Add/del IPv6 SR local-SID.
2402
2403 :param localsid_addr:
2404 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2405 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2406 :param nh_addr:
2407 :param is_del: (Default value = 0)
2408 :param end_psp: (Default value = 0)
2409 :param sw_if_index: (Default value = 0xFFFFFFFF)
2410 :param vlan_index: (Default value = 0)
2411 :param fib_table: (Default value = 0)
2412 """
2413 return self.api(
2414 self.papi.sr_localsid_add_del,
2415 {'is_del': is_del,
2416 'localsid_addr': localsid_addr,
2417 'end_psp': end_psp,
2418 'behavior': behavior,
2419 'sw_if_index': sw_if_index,
2420 'vlan_index': vlan_index,
2421 'fib_table': fib_table,
2422 'nh_addr': nh_addr
2423 }
2424 )
2425
2426 def sr_policy_add(
2427 self,
2428 bsid_addr,
2429 weight=1,
2430 is_encap=1,
2431 type=0,
2432 fib_table=0,
2433 n_segments=0,
2434 segments=[]):
2435 """
2436 :param bsid_addr: bindingSID of the SR Policy
2437 :param weight: weight of the sid list. optional. (default: 1)
2438 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2439 (default: Encap)
2440 :param type: type/behavior of the SR policy. (default or spray) \
2441 (default: default)
2442 :param fib_table: VRF where to install the FIB entry for the BSID \
2443 (default: 0)
2444 :param n_segments: number of segments \
2445 (default: 0)
2446 :param segments: a vector of IPv6 address composing the segment list \
2447 (default: [])
2448 """
2449 return self.api(
2450 self.papi.sr_policy_add,
2451 {'bsid_addr': bsid_addr,
2452 'weight': weight,
2453 'is_encap': is_encap,
2454 'type': type,
2455 'fib_table': fib_table,
2456 'n_segments': n_segments,
2457 'segments': segments
2458 }
2459 )
2460
2461 def sr_policy_del(
2462 self,
2463 bsid_addr,
2464 sr_policy_index=0):
2465 """
2466 :param bsid: bindingSID of the SR Policy
2467 :param sr_policy_index: index of the sr policy (default: 0)
2468 """
2469 return self.api(
2470 self.papi.sr_policy_del,
2471 {'bsid_addr': bsid_addr,
2472 'sr_policy_index': sr_policy_index
2473 })
2474
2475 def sr_steering_add_del(
2476 self,
2477 is_del,
2478 bsid_addr,
2479 sr_policy_index,
2480 table_id,
2481 prefix_addr,
2482 mask_width,
2483 sw_if_index,
2484 traffic_type):
2485 """
2486 Steer traffic L2 and L3 traffic through a given SR policy
2487
2488 :param is_del: delete or add
2489 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2490 :param sr_policy: is the index of the SR Policy (alt to bsid)
2491 :param table_id: is the VRF where to install the FIB entry for the BSID
2492 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2493 :param mask_width: is the mask for L3 traffic type
2494 :param sw_if_index: is the incoming interface for L2 traffic
2495 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2496 """
2497 return self.api(
2498 self.papi.sr_steering_add_del,
2499 {'is_del': is_del,
2500 'bsid_addr': bsid_addr,
2501 'sr_policy_index': sr_policy_index,
2502 'table_id': table_id,
2503 'prefix_addr': prefix_addr,
2504 'mask_width': mask_width,
2505 'sw_if_index': sw_if_index,
2506 'traffic_type': traffic_type
2507 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002508
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002509 def acl_add_replace(self, acl_index, r, tag='',
2510 expected_retval=0):
2511 """Add/replace an ACL
2512 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2513 :param acl_rule r: ACL rules array.
2514 :param str tag: symbolic tag (description) for this ACL.
2515 :param int count: number of rules.
2516 """
2517 return self.api(self.papi.acl_add_replace,
2518 {'acl_index': acl_index,
2519 'r': r,
2520 'count': len(r),
2521 'tag': tag},
2522 expected_retval=expected_retval)
2523
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002524 def acl_del(self, acl_index, expected_retval=0):
2525 """
2526
2527 :param acl_index:
2528 :return:
2529 """
2530 return self.api(self.papi.acl_del,
2531 {'acl_index': acl_index},
2532 expected_retval=expected_retval)
2533
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002534 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2535 expected_retval=0):
2536 return self.api(self.papi.acl_interface_set_acl_list,
2537 {'sw_if_index': sw_if_index,
2538 'count': len(acls),
2539 'n_input': n_input,
2540 'acls': acls},
2541 expected_retval=expected_retval)
2542
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002543 def acl_interface_add_del(self,
2544 sw_if_index,
2545 acl_index,
2546 is_add=1):
2547 """ Add/Delete ACL to/from interface
2548
2549 :param sw_if_index:
2550 :param acl_index:
2551 :param is_add: (Default value = 1)
2552 """
2553
2554 return self.api(self.papi.acl_interface_add_del,
2555 {'is_add': is_add,
2556 'is_input': 1,
2557 'sw_if_index': sw_if_index,
2558 'acl_index': acl_index})
2559
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002560 def acl_dump(self, acl_index, expected_retval=0):
2561 return self.api(self.papi.acl_dump,
2562 {'acl_index': acl_index},
2563 expected_retval=expected_retval)
2564
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002565 def macip_acl_add(self, rules, tag=""):
2566 """ Add MACIP acl
2567
2568 :param rules: list of rules for given acl
2569 :param tag: acl tag
2570 """
2571
2572 return self.api(self.papi.macip_acl_add,
2573 {'r': rules,
2574 'count': len(rules),
2575 'tag': tag})
2576
Pavel Kotucek932f7412017-09-07 14:44:52 +02002577 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2578 """ Add MACIP acl
2579
2580 :param rules: list of rules for given acl
2581 :param tag: acl tag
2582 """
2583
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002584 return self.api(self.papi.macip_acl_add_replace,
2585 {'acl_index': acl_index,
2586 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002587 'count': len(rules),
2588 'tag': tag})
2589
2590 def macip_acl_del(self, acl_index):
2591 """
2592
2593 :param acl_index:
2594 :return:
2595 """
2596 return self.api(self.papi.macip_acl_del,
2597 {'acl_index': acl_index})
2598
2599 def macip_acl_interface_add_del(self,
2600 sw_if_index,
2601 acl_index,
2602 is_add=1):
2603 """ Add MACIP acl to interface
2604
2605 :param sw_if_index:
2606 :param acl_index:
2607 :param is_add: (Default value = 1)
2608 """
2609
2610 return self.api(self.papi.macip_acl_interface_add_del,
2611 {'is_add': is_add,
2612 'sw_if_index': sw_if_index,
2613 'acl_index': acl_index})
2614
2615 def macip_acl_interface_get(self):
2616 """ Return interface acls dump
2617 """
2618 return self.api(
2619 self.papi.macip_acl_interface_get, {})
2620
2621 def macip_acl_dump(self, acl_index=4294967295):
2622 """ Return MACIP acl dump
2623 """
2624
2625 return self.api(
2626 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002627
2628 def policer_add_del(self,
2629 name,
2630 cir,
2631 eir,
2632 cb,
2633 eb,
2634 is_add=1,
2635 rate_type=0,
2636 round_type=0,
2637 ptype=0,
2638 color_aware=0,
2639 conform_action_type=1,
2640 conform_dscp=0,
2641 exceed_action_type=0,
2642 exceed_dscp=0,
2643 violate_action_type=0,
2644 violate_dscp=0):
2645 return self.api(self.papi.policer_add_del,
2646 {'name': name,
2647 'cir': cir,
2648 'eir': eir,
2649 'cb': cb,
2650 'eb': eb,
2651 'is_add': is_add,
2652 'rate_type': rate_type,
2653 'round_type': round_type,
2654 'type': ptype,
2655 'color_aware': color_aware,
2656 'conform_action_type': conform_action_type,
2657 'conform_dscp': conform_dscp,
2658 'exceed_action_type': exceed_action_type,
2659 'exceed_dscp': exceed_dscp,
2660 'violate_action_type': violate_action_type,
2661 'violate_dscp': violate_dscp})
2662
2663 def ip_punt_police(self,
2664 policer_index,
2665 is_ip6=0,
2666 is_add=1):
2667 return self.api(self.papi.ip_punt_police,
2668 {'policer_index': policer_index,
2669 'is_add': is_add,
2670 'is_ip6': is_ip6})
2671
2672 def ip_punt_redirect(self,
2673 rx_sw_if_index,
2674 tx_sw_if_index,
2675 nh,
2676 is_ip6=0,
2677 is_add=1):
2678 return self.api(self.papi.ip_punt_redirect,
2679 {'rx_sw_if_index': rx_sw_if_index,
2680 'tx_sw_if_index': tx_sw_if_index,
2681 'nh': nh,
2682 'is_add': is_add,
2683 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002684
2685 def bier_table_add_del(self,
2686 bti,
2687 mpls_label,
2688 is_add=1):
2689 """ BIER Table add/del """
2690 return self.api(
2691 self.papi.bier_table_add_del,
2692 {'bt_tbl_id': {"bt_set": bti.set_id,
2693 "bt_sub_domain": bti.sub_domain_id,
2694 "bt_hdr_len_id": bti.hdr_len_id},
2695 'bt_label': mpls_label,
2696 'bt_is_add': is_add})
2697
2698 def bier_table_dump(self):
2699 return self.api(self.papi.bier_table_dump, {})
2700
2701 def bier_route_add_del(self,
2702 bti,
2703 bp,
2704 next_hop,
2705 next_hop_label,
2706 next_hop_table_id,
2707 next_hop_is_ip4=1,
2708 is_add=1):
2709 """ BIER Route add/del """
2710 return self.api(
2711 self.papi.bier_route_add_del,
2712 {'br_tbl_id': {"bt_set": bti.set_id,
2713 "bt_sub_domain": bti.sub_domain_id,
2714 "bt_hdr_len_id": bti.hdr_len_id},
2715 'br_bp': bp,
2716 'br_n_paths': 1,
2717 'br_paths': [{'next_hop': next_hop,
2718 'afi': 0,
2719 'n_labels': 1,
2720 'table_id': next_hop_table_id,
2721 'label_stack': [next_hop_label]}],
2722 'br_is_add': is_add})
2723
2724 def bier_route_dump(self, bti):
2725 return self.api(
2726 self.papi.bier_route_dump,
2727 {'br_tbl_id': {"bt_set": bti.set_id,
2728 "bt_sub_domain": bti.sub_domain_id,
2729 "bt_hdr_len_id": bti.hdr_len_id}})
2730
2731 def bier_imp_add(self,
2732 bti,
2733 src,
2734 ibytes,
2735 is_add=1):
2736 """ BIER Imposition Add """
2737 return self.api(
2738 self.papi.bier_imp_add,
2739 {'bi_tbl_id': {"bt_set": bti.set_id,
2740 "bt_sub_domain": bti.sub_domain_id,
2741 "bt_hdr_len_id": bti.hdr_len_id},
2742 'bi_src': src,
2743 'bi_n_bytes': len(ibytes),
2744 'bi_bytes': ibytes})
2745
2746 def bier_imp_del(self, bi_index):
2747 """ BIER Imposition del """
2748 return self.api(
2749 self.papi.bier_imp_del,
2750 {'bi_index': bi_index})
2751
2752 def bier_imp_dump(self):
2753 return self.api(self.papi.bier_imp_dump, {})
2754
2755 def bier_disp_table_add_del(self,
2756 bdti,
2757 is_add=1):
2758 """ BIER Disposition Table add/del """
2759 return self.api(
2760 self.papi.bier_disp_table_add_del,
2761 {'bdt_tbl_id': bdti,
2762 'bdt_is_add': is_add})
2763
2764 def bier_disp_table_dump(self):
2765 return self.api(self.papi.bier_disp_table_dump, {})
2766
2767 def bier_disp_entry_add_del(self,
2768 bdti,
2769 bp,
2770 payload_proto,
2771 next_hop,
2772 next_hop_tbl_id=0,
2773 next_hop_rpf_id=~0,
2774 next_hop_is_ip4=1,
2775 is_add=1):
2776 """ BIER Route add/del """
2777 return self.api(
2778 self.papi.bier_disp_entry_add_del,
2779 {'bde_tbl_id': bdti,
2780 'bde_bp': bp,
2781 'bde_payload_proto': payload_proto,
2782 'bde_n_paths': 1,
2783 'bde_paths': [{'next_hop': next_hop,
2784 'table_id': next_hop_tbl_id,
2785 'afi': 0,
2786 'rpf_id': next_hop_rpf_id,
2787 'n_labels': 0,
2788 'label_stack': [0]}],
2789 'bde_is_add': is_add})
2790
2791 def bier_disp_entry_dump(self, bdti):
2792 return self.api(
2793 self.papi.bier_disp_entry_dump,
2794 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002795
2796 def add_node_next(self, node_name, next_name):
2797 """ Set the next node for a given node request
2798
2799 :param node_name:
2800 :param next_name:
2801 """
2802 return self.api(self.papi.add_node_next,
2803 {'node_name': node_name,
2804 'next_name': next_name})