blob: 71e7aea11f3834bcb89226152e947522967a6b3d [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):
198 return int(mac.replace(":", ""), 16) << 16
199
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
Jan4af521d2016-11-15 17:05:00 +0100388 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
389 learn=1, arp_term=0, is_add=1):
390 """Create/delete bridge domain.
391
392 :param int bd_id: Bridge domain index.
393 :param int flood: Enable/disable bcast/mcast flooding in the BD.
394 (Default value = 1)
395 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
396 (Default value = 1)
397 :param int forward: Enable/disable forwarding on all interfaces in
398 the BD. (Default value = 1)
399 :param int learn: Enable/disable learning on all interfaces in the BD.
400 (Default value = 1)
401 :param int arp_term: Enable/disable arp termination in the BD.
402 (Default value = 1)
403 :param int is_add: Add or delete flag. (Default value = 1)
404 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100405 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200406 {'bd_id': bd_id,
407 'flood': flood,
408 'uu_flood': uu_flood,
409 'forward': forward,
410 'learn': learn,
411 'arp_term': arp_term,
412 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100413
Eyal Baric86e5922017-07-02 18:33:16 +0300414 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
415 return self.api(self.papi.bd_ip_mac_add_del,
416 {'bd_id': bd_id,
417 'is_add': is_add,
418 'is_ipv6': is_ipv6,
419 'ip_address': ip,
420 'mac_address': mac})
421
Eyal Bari20197482017-09-13 12:29:08 +0300422 def want_ip4_arp_events(self, enable_disable=1, address=0):
423 return self.api(self.papi.want_ip4_arp_events,
424 {'enable_disable': enable_disable,
425 'address': address,
426 'pid': os.getpid(), })
427
Eyal Baric125ecc2017-09-20 11:29:17 +0300428 def want_ip6_nd_events(self, enable_disable=1, address=0):
429 return self.api(self.papi.want_ip6_nd_events,
430 {'enable_disable': enable_disable,
431 'address': address,
432 'pid': os.getpid(), })
433
Jan4af521d2016-11-15 17:05:00 +0100434 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
435 filter_mac=0, bvi_mac=0):
436 """Create/delete L2 FIB entry.
437
438 :param str mac: MAC address to create FIB entry for.
439 :param int bd_id: Bridge domain index.
440 :param int sw_if_index: Software interface index of the interface.
441 :param int is_add: Add or delete flag. (Default value = 1)
442 :param int static_mac: Set to 1 to create static MAC entry.
443 (Default value = 0)
444 :param int filter_mac: Set to 1 to drop packet that's source or
445 destination MAC address contains defined MAC address.
446 (Default value = 0)
447 :param int bvi_mac: Set to 1 to create entry that points to BVI
448 interface. (Default value = 0)
449 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100450 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200451 {'mac': self._convert_mac(mac),
452 'bd_id': bd_id,
453 'sw_if_index': sw_if_index,
454 'is_add': is_add,
455 'static_mac': static_mac,
456 'filter_mac': filter_mac,
457 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100458
Eyal Bari93b503e2017-05-15 10:13:15 +0300459 def l2fib_flush_int(self, sw_if_index):
460 """Flush L2 FIB entries for sw_if_index.
461
462 :param int sw_if_index: Software interface index of the interface.
463 """
464 return self.api(self.papi.l2fib_flush_int,
465 {'sw_if_index': sw_if_index})
466
467 def l2fib_flush_bd(self, bd_id):
468 """Flush L2 FIB entries for bd_id.
469
470 :param int sw_if_index: Bridge Domain id.
471 """
472 return self.api(self.papi.l2fib_flush_bd,
473 {'bd_id': bd_id})
474
475 def l2fib_flush_all(self):
476 """Flush all L2 FIB.
477 """
478 return self.api(self.papi.l2fib_flush_all, {})
479
Klement Sekeraf62ae122016-10-11 11:47:09 +0200480 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
481 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100482 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200483
Jan4af521d2016-11-15 17:05:00 +0100484 :param int sw_if_index: Software interface index of the interface.
485 :param int bd_id: Bridge domain index.
486 :param int shg: Split-horizon group index. (Default value = 0)
487 :param int bvi: Set interface as a bridge group virtual interface.
488 (Default value = 0)
489 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200490 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100491 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200492 {'rx_sw_if_index': sw_if_index,
493 'bd_id': bd_id,
494 'shg': shg,
495 'bvi': bvi,
496 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200497
Jan00dad122016-11-29 10:04:53 +0100498 def bridge_flags(self, bd_id, is_set, feature_bitmap):
499 """Enable/disable required feature of the bridge domain with defined ID.
500
501 :param int bd_id: Bridge domain ID.
502 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
503 :param int feature_bitmap: Bitmap value of the feature to be set:
504 - learn (1 << 0),
505 - forward (1 << 1),
506 - flood (1 << 2),
507 - uu-flood (1 << 3) or
508 - arp-term (1 << 4).
509 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100510 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200511 {'bd_id': bd_id,
512 'is_set': is_set,
513 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100514
515 def bridge_domain_dump(self, bd_id=0):
516 """
517
518 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
519 existing bridge domains returned)
520 :return: Dictionary of bridge domain(s) data.
521 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100522 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200523 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100524
Klement Sekeraf62ae122016-10-11 11:47:09 +0200525 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
526 enable):
527 """Create or delete unidirectional cross-connect from Tx interface to
528 Rx interface.
529
Jan4af521d2016-11-15 17:05:00 +0100530 :param int rx_sw_if_index: Software interface index of Rx interface.
531 :param int tx_sw_if_index: Software interface index of Tx interface.
532 :param int enable: Create cross-connect if equal to 1, delete
533 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200534
535 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100536 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200537 {'rx_sw_if_index': rx_sw_if_index,
538 'tx_sw_if_index': tx_sw_if_index,
539 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200540
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200541 def sw_interface_set_l2_tag_rewrite(
542 self,
543 sw_if_index,
544 vtr_oper,
545 push=0,
546 tag1=0,
547 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000548 """L2 interface vlan tag rewrite configure request
549 :param client_index - opaque cookie to identify the sender
550 :param context - sender context, to match reply w/ request
551 :param sw_if_index - interface the operation is applied to
552 :param vtr_op - Choose from l2_vtr_op_t enum values
553 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
554 :param tag1 - Needed for any push or translate vtr op
555 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
556
557 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100558 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200559 {'sw_if_index': sw_if_index,
560 'vtr_op': vtr_oper,
561 'push_dot1q': push,
562 'tag1': tag1,
563 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000564
Neale Rannsa07bd702017-08-07 07:53:49 -0700565 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200566 """
567
568 :param admin_up_down:
569 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200570
571 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100572 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200573 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700574 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200575
576 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
577 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
578 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
579 """Create subinterface
580 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
581
582 :param sub_id: param inner_vlan:
583 :param sw_if_index:
584 :param outer_vlan:
585 :param inner_vlan:
586 :param no_tags: (Default value = 0)
587 :param one_tag: (Default value = 0)
588 :param two_tags: (Default value = 0)
589 :param dot1ad: (Default value = 0)
590 :param exact_match: (Default value = 0)
591 :param default_sub: (Default value = 0)
592 :param outer_vlan_id_any: (Default value = 0)
593 :param inner_vlan_id_any: (Default value = 0)
594
595 """
596 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100597 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200598 {'sw_if_index': sw_if_index,
599 'sub_id': sub_id,
600 'no_tags': no_tags,
601 'one_tag': one_tag,
602 'two_tags': two_tags,
603 'dot1ad': dot1ad,
604 'exact_match': exact_match,
605 'default_sub': default_sub,
606 'outer_vlan_id_any': outer_vlan_id_any,
607 'inner_vlan_id_any': inner_vlan_id_any,
608 'outer_vlan_id': outer_vlan,
609 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200610
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200611 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
612 """Create p2p ethernet subinterface
613
614 :param sw_if_index: main (parent) interface
615 :param remote_mac: client (remote) mac address
616
617 """
618 return self.api(
619 self.papi.p2p_ethernet_add,
620 {'parent_if_index': sw_if_index,
621 'remote_mac': remote_mac,
622 'subif_id': subif_id})
623
Neale Ranns177bbdc2016-11-15 09:46:51 +0000624 def delete_subif(self, sw_if_index):
625 """Delete subinterface
626
627 :param sw_if_index:
628 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100629 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200630 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000631
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200632 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
633 """Delete p2p ethernet subinterface
634
635 :param sw_if_index: main (parent) interface
636 :param remote_mac: client (remote) mac address
637
638 """
639 return self.api(
640 self.papi.p2p_ethernet_del,
641 {'parent_if_index': sw_if_index,
642 'remote_mac': remote_mac})
643
Klement Sekeraf62ae122016-10-11 11:47:09 +0200644 def create_vlan_subif(self, sw_if_index, vlan):
645 """
646
647 :param vlan:
648 :param sw_if_index:
649
650 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100651 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200652 {'sw_if_index': sw_if_index,
653 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200654
Matej Klotton0178d522016-11-04 11:11:44 +0100655 def create_loopback(self, mac=''):
656 """
657
658 :param mac: (Optional)
659 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100660 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200661 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100662
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100663 def delete_loopback(self, sw_if_index):
664 return self.api(self.papi.delete_loopback,
665 {'sw_if_index': sw_if_index, })
666
Neale Ranns15002542017-09-10 04:39:11 -0700667 def ip_table_add_del(self,
668 table_id,
669 is_add=1,
670 is_ipv6=0):
671 """
672
673 :param table_id
674 :param is_add: (Default value = 1)
675 :param is_ipv6: (Default value = 0)
676
677 """
678
679 return self.api(
680 self.papi.ip_table_add_del,
681 {'table_id': table_id,
682 'is_add': is_add,
683 'is_ipv6': is_ipv6})
684
Klement Sekeraf62ae122016-10-11 11:47:09 +0200685 def ip_add_del_route(
686 self,
687 dst_address,
688 dst_address_length,
689 next_hop_address,
690 next_hop_sw_if_index=0xFFFFFFFF,
691 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200692 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000693 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200694 next_hop_n_out_labels=0,
695 next_hop_out_label_stack=[],
696 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000697 is_resolve_host=0,
698 is_resolve_attached=0,
699 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200700 is_add=1,
701 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200702 is_unreach=0,
703 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200704 is_ipv6=0,
705 is_local=0,
706 is_classify=0,
707 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000708 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200709 """
710
711 :param dst_address_length:
712 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
713 :param dst_address:
714 :param next_hop_address:
715 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
716 :param vrf_id: (Default value = 0)
717 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200718 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200719 :param is_add: (Default value = 1)
720 :param is_drop: (Default value = 0)
721 :param is_ipv6: (Default value = 0)
722 :param is_local: (Default value = 0)
723 :param is_classify: (Default value = 0)
724 :param is_multipath: (Default value = 0)
725 :param is_resolve_host: (Default value = 0)
726 :param is_resolve_attached: (Default value = 0)
727 :param not_last: (Default value = 0)
728 :param next_hop_weight: (Default value = 1)
729
730 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000731
Klement Sekeraf62ae122016-10-11 11:47:09 +0200732 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100733 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200734 {'next_hop_sw_if_index': next_hop_sw_if_index,
735 'table_id': table_id,
736 'classify_table_index': classify_table_index,
737 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200738 'is_add': is_add,
739 'is_drop': is_drop,
740 'is_unreach': is_unreach,
741 'is_prohibit': is_prohibit,
742 'is_ipv6': is_ipv6,
743 'is_local': is_local,
744 'is_classify': is_classify,
745 'is_multipath': is_multipath,
746 'is_resolve_host': is_resolve_host,
747 'is_resolve_attached': is_resolve_attached,
748 'not_last': not_last,
749 'next_hop_weight': next_hop_weight,
750 'dst_address_length': dst_address_length,
751 'dst_address': dst_address,
752 'next_hop_address': next_hop_address,
753 'next_hop_n_out_labels': next_hop_n_out_labels,
754 'next_hop_via_label': next_hop_via_label,
755 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100756
Matej Klotton16a14cd2016-12-07 15:09:13 +0100757 def ip_fib_dump(self):
758 return self.api(self.papi.ip_fib_dump, {})
759
Jan Gelety057bb8c2016-12-20 17:32:45 +0100760 def ip6_fib_dump(self):
761 return self.api(self.papi.ip6_fib_dump, {})
762
Matej Klotton0178d522016-11-04 11:11:44 +0100763 def ip_neighbor_add_del(self,
764 sw_if_index,
765 mac_address,
766 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100767 is_add=1,
768 is_ipv6=0,
769 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800770 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100771 ):
772 """ Add neighbor MAC to IPv4 or IPv6 address.
773
774 :param sw_if_index:
775 :param mac_address:
776 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100777 :param is_add: (Default value = 1)
778 :param is_ipv6: (Default value = 0)
779 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800780 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100781 """
782
783 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100784 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800785 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200786 'is_add': is_add,
787 'is_ipv6': is_ipv6,
788 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800789 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200790 'mac_address': mac_address,
791 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100792 }
Matej Klotton0178d522016-11-04 11:11:44 +0100793 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100794
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800795 def ip_neighbor_dump(self,
796 sw_if_index,
797 is_ipv6=0):
798 """ Return IP neighbor dump.
799
800 :param sw_if_index:
801 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
802 """
803
804 return self.api(
805 self.papi.ip_neighbor_dump,
806 {'is_ipv6': is_ipv6,
807 'sw_if_index': sw_if_index
808 }
809 )
810
811 def proxy_arp_add_del(self,
812 low_address,
813 hi_address,
814 vrf_id=0,
815 is_add=1):
816 """ Config Proxy Arp Range.
817
818 :param low_address: Start address in the rnage to Proxy for
819 :param hi_address: End address in the rnage to Proxy for
820 :param vrf_id: The VRF/table in which to proxy
821 """
822
823 return self.api(
824 self.papi.proxy_arp_add_del,
825 {'vrf_id': vrf_id,
826 'is_add': is_add,
827 'low_address': low_address,
828 'hi_address': hi_address,
829 }
830 )
831
832 def proxy_arp_intfc_enable_disable(self,
833 sw_if_index,
834 is_enable=1):
835 """ Enable/Disable an interface for proxy ARP requests
836
837 :param sw_if_index: Interface
838 :param enable_disable: Enable/Disable
839 """
840
841 return self.api(
842 self.papi.proxy_arp_intfc_enable_disable,
843 {'sw_if_index': sw_if_index,
844 'enable_disable': is_enable
845 }
846 )
847
Jane546d3b2016-12-08 13:10:03 +0100848 def reset_vrf(self,
849 vrf_id,
850 is_ipv6=0,
851 ):
852 """ Reset VRF (remove all routes etc.) request.
853
854 :param int vrf_id: ID of the FIB table / VRF to reset.
855 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
856 """
857
858 return self.api(
859 self.papi.reset_vrf,
860 {'vrf_id': vrf_id,
861 'is_ipv6': is_ipv6,
862 }
863 )
864
865 def reset_fib(self,
866 vrf_id,
867 is_ipv6=0,
868 ):
869 """ Reset VRF (remove all routes etc.) request.
870
871 :param int vrf_id: ID of the FIB table / VRF to reset.
872 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
873 """
874
875 return self.api(
876 self.papi.reset_fib,
877 {'vrf_id': vrf_id,
878 'is_ipv6': is_ipv6,
879 }
880 )
881
882 def ip_dump(self,
883 is_ipv6=0,
884 ):
885 """ Return IP dump.
886
887 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
888 """
889
890 return self.api(
891 self.papi.ip_dump,
892 {'is_ipv6': is_ipv6,
893 }
894 )
895
Klement Sekera7bb873a2016-11-18 07:38:42 +0100896 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300897 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100898 """
899
900 :param sw_if_index_from:
901 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100902 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300903 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100904 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100905 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200906 {'sw_if_index_from': sw_if_index_from,
907 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300908 'state': state,
909 'is_l2': is_l2,
910 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000911
912 def gre_tunnel_add_del(self,
913 src_address,
914 dst_address,
915 outer_fib_id=0,
916 is_teb=0,
917 is_add=1,
918 is_ip6=0):
919 """ Add a GRE tunnel
920
921 :param src_address:
922 :param dst_address:
923 :param outer_fib_id: (Default value = 0)
924 :param is_add: (Default value = 1)
925 :param is_ipv6: (Default value = 0)
926 :param is_teb: (Default value = 0)
927 """
928
929 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100930 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200931 {'is_add': is_add,
932 'is_ipv6': is_ip6,
933 'teb': is_teb,
934 'src_address': src_address,
935 'dst_address': dst_address,
936 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000937 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000938
Neale Ranns5a8123b2017-01-26 01:18:23 -0800939 def mpls_fib_dump(self):
940 return self.api(self.papi.mpls_fib_dump, {})
941
Neale Ranns15002542017-09-10 04:39:11 -0700942 def mpls_table_add_del(
943 self,
944 table_id,
945 is_add=1):
946 """
947
948 :param table_id
949 :param is_add: (Default value = 1)
950
951 """
952
953 return self.api(
954 self.papi.mpls_table_add_del,
955 {'mt_table_id': table_id,
956 'mt_is_add': is_add})
957
Neale Rannsad422ed2016-11-02 14:20:04 +0000958 def mpls_route_add_del(
959 self,
960 label,
961 eos,
Neale Rannsda78f952017-05-24 09:15:43 -0700962 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000963 next_hop_address,
964 next_hop_sw_if_index=0xFFFFFFFF,
965 table_id=0,
966 next_hop_table_id=0,
967 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200968 next_hop_n_out_labels=0,
969 next_hop_out_label_stack=[],
970 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000971 is_resolve_host=0,
972 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800973 is_interface_rx=0,
974 is_rpf_id=0,
975 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000976 is_add=1,
977 is_drop=0,
978 is_multipath=0,
979 classify_table_index=0xFFFFFFFF,
980 is_classify=0,
981 not_last=0):
982 """
983
984 :param dst_address_length:
985 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
986 :param dst_address:
987 :param next_hop_address:
988 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
989 :param vrf_id: (Default value = 0)
990 :param lookup_in_vrf: (Default value = 0)
991 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000992 :param is_add: (Default value = 1)
993 :param is_drop: (Default value = 0)
994 :param is_ipv6: (Default value = 0)
995 :param is_local: (Default value = 0)
996 :param is_classify: (Default value = 0)
997 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800998 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000999 :param is_resolve_host: (Default value = 0)
1000 :param is_resolve_attached: (Default value = 0)
1001 :param not_last: (Default value = 0)
1002 :param next_hop_weight: (Default value = 1)
1003
1004 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001005
1006 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001007 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001008 {'mr_label': label,
1009 'mr_eos': eos,
1010 'mr_table_id': table_id,
1011 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001012 'mr_is_add': is_add,
1013 'mr_is_classify': is_classify,
1014 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001015 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001016 'mr_is_resolve_host': is_resolve_host,
1017 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001018 'mr_is_interface_rx': is_interface_rx,
1019 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001020 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001021 'mr_next_hop_weight': next_hop_weight,
1022 'mr_next_hop': next_hop_address,
1023 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1024 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1025 'mr_next_hop_table_id': next_hop_table_id,
1026 'mr_next_hop_via_label': next_hop_via_label,
1027 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001028
1029 def mpls_ip_bind_unbind(
1030 self,
1031 label,
1032 dst_address,
1033 dst_address_length,
1034 table_id=0,
1035 ip_table_id=0,
1036 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001037 is_bind=1):
1038 """
1039 """
1040 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001041 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001042 {'mb_mpls_table_id': table_id,
1043 'mb_label': label,
1044 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001045 'mb_is_bind': is_bind,
1046 'mb_is_ip4': is_ip4,
1047 'mb_address_length': dst_address_length,
1048 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001049
1050 def mpls_tunnel_add_del(
1051 self,
1052 tun_sw_if_index,
1053 next_hop_proto_is_ip4,
1054 next_hop_address,
1055 next_hop_sw_if_index=0xFFFFFFFF,
1056 next_hop_table_id=0,
1057 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001058 next_hop_n_out_labels=0,
1059 next_hop_out_label_stack=[],
1060 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001061 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001062 l2_only=0,
1063 is_multicast=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)
1080 :param is_resolve_host: (Default value = 0)
1081 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001082 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001083 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001084
1085 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001086 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001087 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001088 {'mt_sw_if_index': tun_sw_if_index,
1089 'mt_is_add': is_add,
1090 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001091 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001092 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1093 'mt_next_hop_weight': next_hop_weight,
1094 'mt_next_hop': next_hop_address,
1095 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1096 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1097 'mt_next_hop_table_id': next_hop_table_id,
1098 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001099
Matus Fabian2ba92e32017-08-21 07:05:03 -07001100 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001101 self,
1102 sw_if_index,
1103 is_inside=1,
1104 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001105 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001106
1107 :param sw_if_index: Software index of the interface
1108 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1109 :param is_add: 1 if add, 0 if delete (Default value = 1)
1110 """
1111 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001112 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001113 {'is_add': is_add,
1114 'is_inside': is_inside,
1115 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001116
Matus Fabian2ba92e32017-08-21 07:05:03 -07001117 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001118 self,
1119 sw_if_index,
1120 is_inside=1,
1121 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001122 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001123
1124 :param sw_if_index: Software index of the interface
1125 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1126 :param is_add: 1 if add, 0 if delete (Default value = 1)
1127 """
1128 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001129 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001130 {'is_add': is_add,
1131 'is_inside': is_inside,
1132 'sw_if_index': sw_if_index})
1133
Matus Fabian2ba92e32017-08-21 07:05:03 -07001134 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001135 self,
1136 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001137 external_ip=0,
1138 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001139 local_port=0,
1140 external_port=0,
1141 addr_only=1,
1142 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001143 protocol=0,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001144 is_add=1):
1145 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001146
1147 :param local_ip: Local IP address
1148 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001149 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001150 :param local_port: Local port number (Default value = 0)
1151 :param external_port: External port number (Default value = 0)
1152 :param addr_only: 1 if address only mapping, 0 if address and port
1153 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001154 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001155 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001156 """
1157 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001158 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001159 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001160 'addr_only': addr_only,
1161 'local_ip_address': local_ip,
1162 'external_ip_address': external_ip,
1163 'local_port': local_port,
1164 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001165 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001166 'vrf_id': vrf_id,
1167 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001168
Matus Fabian2ba92e32017-08-21 07:05:03 -07001169 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001170 self,
1171 first_ip_address,
1172 last_ip_address,
1173 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001174 vrf_id=0xFFFFFFFF):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001175 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001176
1177 :param first_ip_address: First IP address
1178 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001179 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001180 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001181 """
1182 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001183 self.papi.nat44_add_del_address_range,
1184 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001185 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001186 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001187 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001188
Matus Fabian2ba92e32017-08-21 07:05:03 -07001189 def nat44_address_dump(self):
1190 """Dump NAT44 addresses
1191 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001192 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001193 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001194
Matus Fabian2ba92e32017-08-21 07:05:03 -07001195 def nat44_interface_dump(self):
1196 """Dump interfaces with NAT44 feature
1197 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001198 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001199 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001200
Matus Fabian2ba92e32017-08-21 07:05:03 -07001201 def nat44_interface_output_feature_dump(self):
1202 """Dump interfaces with NAT44 output feature
1203 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001204 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001205 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001206
Matus Fabian2ba92e32017-08-21 07:05:03 -07001207 def nat44_static_mapping_dump(self):
1208 """Dump NAT44 static mappings
1209 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001210 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001211 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001212
Matus Fabian2ba92e32017-08-21 07:05:03 -07001213 def nat_show_config(self):
1214 """Show NAT plugin config
1215 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001216 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001217 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001218
Matus Fabian2ba92e32017-08-21 07:05:03 -07001219 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001220 self,
1221 sw_if_index,
1222 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001223 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001224
1225 :param sw_if_index: Software index of the interface
1226 :param is_add: 1 if add, 0 if delete (Default value = 1)
1227 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001228 return self.api(self.papi.nat44_add_del_interface_addr,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001229 {'is_add': is_add, 'sw_if_index': sw_if_index})
1230
Matus Fabian2ba92e32017-08-21 07:05:03 -07001231 def nat44_interface_addr_dump(self):
1232 """Dump NAT44 addresses interfaces
1233 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001234 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001235 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001236
Matus Fabian2ba92e32017-08-21 07:05:03 -07001237 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001238 self,
1239 domain_id=1,
1240 src_port=4739,
1241 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001242 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001243
1244 :param domain_id: Observation domain ID (Default value = 1)
1245 :param src_port: Source port number (Default value = 4739)
1246 :param enable: 1 if enable, 0 if disable (Default value = 1)
1247 """
1248 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001249 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001250 {'domain_id': domain_id,
1251 'src_port': src_port,
1252 'enable': enable})
1253
Matus Fabian2ba92e32017-08-21 07:05:03 -07001254 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001255 self,
1256 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001257 vrf_id):
1258 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001259
1260 :param ip_address: ip adress of the user to be dumped
1261 :param cpu_index: cpu_index on which the user is
1262 :param vrf_id: VRF ID
1263 :return: Dictionary of S-NAT sessions
1264 """
1265 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001266 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001267 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001268 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001269
Matus Fabian2ba92e32017-08-21 07:05:03 -07001270 def nat44_user_dump(self):
1271 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001272
Matus Fabian2ba92e32017-08-21 07:05:03 -07001273 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001274 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001275 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001276
Matus Fabian704018c2017-09-04 02:17:18 -07001277 def nat44_add_del_lb_static_mapping(
1278 self,
1279 external_addr,
1280 external_port,
1281 protocol,
1282 vrf_id=0,
1283 local_num=0,
1284 locals=None,
1285 is_add=1):
1286 """Add/delete NAT44 load balancing static mapping
1287
1288 :param is_add - 1 if add, 0 if delete
1289 """
1290 return self.api(
1291 self.papi.nat44_add_del_lb_static_mapping,
1292 {'is_add': is_add,
1293 'external_addr': external_addr,
1294 'external_port': external_port,
1295 'protocol': protocol,
1296 'vrf_id': vrf_id,
1297 'local_num': local_num,
1298 'locals': locals})
1299
1300 def nat44_lb_static_mapping_dump(self):
1301 """Dump NAT44 load balancing static mappings
1302
1303 :return: Dictionary of NAT44 load balancing static mapping
1304 """
1305 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1306
Matus Fabian2ba92e32017-08-21 07:05:03 -07001307 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001308 self,
1309 in_addr,
1310 in_plen,
1311 out_addr,
1312 out_plen,
1313 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001314 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001315
1316 :param is_add - 1 if add, 0 if delete
1317 :param in_addr - inside IP address
1318 :param in_plen - inside IP address prefix length
1319 :param out_addr - outside IP address
1320 :param out_plen - outside IP address prefix length
1321 """
1322 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001323 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001324 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001325 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001326 'in_addr': in_addr,
1327 'in_plen': in_plen,
1328 'out_addr': out_addr,
1329 'out_plen': out_plen})
1330
Matus Fabian2ba92e32017-08-21 07:05:03 -07001331 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001332 self,
1333 in_addr):
1334 """Get outside address and port range from inside address
1335
1336 :param in_addr - inside IP address
1337 """
1338 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001339 self.papi.nat_det_forward,
1340 {'in_addr': in_addr,
1341 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001342
Matus Fabian2ba92e32017-08-21 07:05:03 -07001343 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001344 self,
1345 out_addr,
1346 out_port):
1347 """Get inside address from outside address and port
1348
1349 :param out_addr - outside IP address
1350 :param out_port - outside port
1351 """
1352 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001353 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001354 {'out_addr': out_addr,
1355 'out_port': out_port})
1356
Matus Fabian2ba92e32017-08-21 07:05:03 -07001357 def nat_det_map_dump(self):
1358 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001359
Matus Fabian2ba92e32017-08-21 07:05:03 -07001360 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001361 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001362 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001363
Matus Fabian2ba92e32017-08-21 07:05:03 -07001364 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001365 self,
1366 udp=300,
1367 tcp_established=7440,
1368 tcp_transitory=240,
1369 icmp=60):
1370 """Set values of timeouts for deterministic NAT (in seconds)
1371
1372 :param udp - UDP timeout (Default value = 300)
1373 :param tcp_established - TCP established timeout (Default value = 7440)
1374 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1375 :param icmp - ICMP timeout (Default value = 60)
1376 """
1377 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001378 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001379 {'udp': udp,
1380 'tcp_established': tcp_established,
1381 'tcp_transitory': tcp_transitory,
1382 'icmp': icmp})
1383
Matus Fabian2ba92e32017-08-21 07:05:03 -07001384 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001385 """Get values of timeouts for deterministic NAT
1386
1387 :return: Timeouts for deterministic NAT (in seconds)
1388 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001389 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001390
Matus Fabian2ba92e32017-08-21 07:05:03 -07001391 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001392 self,
1393 out_addr,
1394 out_port,
1395 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001396 ext_port):
1397 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001398
1399 :param out_addr - outside IP address
1400 :param out_port - outside port
1401 :param ext_addr - external host IP address
1402 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001403 """
1404 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001405 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001406 {'out_addr': out_addr,
1407 'out_port': out_port,
1408 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001409 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001410
Matus Fabian2ba92e32017-08-21 07:05:03 -07001411 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001412 self,
1413 in_addr,
1414 in_port,
1415 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001416 ext_port):
1417 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001418
1419 :param in_addr - inside IP address
1420 :param in_port - inside port
1421 :param ext_addr - external host IP address
1422 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001423 """
1424 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001425 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001426 {'in_addr': in_addr,
1427 'in_port': in_port,
1428 'ext_addr': ext_addr,
1429 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001430 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001431
Matus Fabian2ba92e32017-08-21 07:05:03 -07001432 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001433 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001434 user_addr):
1435 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001436
1437 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001438 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001439 """
1440 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001441 self.papi.nat_det_session_dump,
1442 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001443 'user_addr': user_addr})
1444
Matus Fabian06596c52017-06-06 04:53:28 -07001445 def nat64_add_del_pool_addr_range(
1446 self,
1447 start_addr,
1448 end_addr,
1449 vrf_id=0xFFFFFFFF,
1450 is_add=1):
1451 """Add/del address range to NAT64 pool
1452
1453 :param start_addr: First IP address
1454 :param end_addr: Last IP address
1455 :param vrf_id: VRF id for the address range
1456 :param is_add: 1 if add, 0 if delete (Default value = 1)
1457 """
1458 return self.api(
1459 self.papi.nat64_add_del_pool_addr_range,
1460 {'start_addr': start_addr,
1461 'end_addr': end_addr,
1462 'vrf_id': vrf_id,
1463 'is_add': is_add})
1464
1465 def nat64_pool_addr_dump(self):
1466 """Dump NAT64 pool addresses
1467 :return: Dictionary of NAT64 pool addresses
1468 """
1469 return self.api(self.papi.nat64_pool_addr_dump, {})
1470
1471 def nat64_add_del_interface(
1472 self,
1473 sw_if_index,
1474 is_inside=1,
1475 is_add=1):
1476 """Enable/disable NAT64 feature on the interface
1477 :param sw_if_index: Index of the interface
1478 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1479 :param is_add: 1 if add, 0 if delete (Default value = 1)
1480 """
1481 return self.api(
1482 self.papi.nat64_add_del_interface,
1483 {'sw_if_index': sw_if_index,
1484 'is_inside': is_inside,
1485 'is_add': is_add})
1486
1487 def nat64_interface_dump(self):
1488 """Dump interfaces with NAT64 feature
1489 :return: Dictionary of interfaces with NAT64 feature
1490 """
1491 return self.api(self.papi.nat64_interface_dump, {})
1492
1493 def nat64_add_del_static_bib(
1494 self,
1495 in_ip,
1496 out_ip,
1497 in_port,
1498 out_port,
1499 protocol,
1500 vrf_id=0,
1501 is_add=1):
1502 """Add/delete S-NAT static BIB entry
1503
1504 :param in_ip: Inside IPv6 address
1505 :param out_ip: Outside IPv4 address
1506 :param in_port: Inside port number
1507 :param out_port: Outside port number
1508 :param protocol: IP protocol
1509 :param vrf_id: VRF ID (Default value = 0)
1510 :param is_add: 1 if add, 0 if delete (Default value = 1)
1511 """
1512 return self.api(
1513 self.papi.nat64_add_del_static_bib,
1514 {'i_addr': in_ip,
1515 'o_addr': out_ip,
1516 'i_port': in_port,
1517 'o_port': out_port,
1518 'vrf_id': vrf_id,
1519 'proto': protocol,
1520 'is_add': is_add})
1521
Matus Fabianab9a59c2017-08-16 05:37:36 -07001522 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001523 """Dump NAT64 BIB
1524
Matus Fabianab9a59c2017-08-16 05:37:36 -07001525 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001526 :returns: Dictionary of NAT64 BIB entries
1527 """
1528 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1529
1530 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1531 tcp_incoming_syn=6):
1532 """Set values of timeouts for NAT64 (in seconds)
1533
Matus Fabian428dc912017-06-21 06:15:18 -07001534 :param udpi: UDP timeout (Default value = 300)
1535 :param icmp: ICMP timeout (Default value = 60)
1536 :param tcp_trans: TCP transitory timeout (Default value = 240)
1537 :param tcp_est: TCP established timeout (Default value = 7440)
1538 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001539 """
1540 return self.api(
1541 self.papi.nat64_set_timeouts,
1542 {'udp': udp,
1543 'icmp': icmp,
1544 'tcp_trans': tcp_trans,
1545 'tcp_est': tcp_est,
1546 'tcp_incoming_syn': tcp_incoming_syn})
1547
1548 def nat64_get_timeouts(self):
1549 """Get values of timeouts for NAT64
1550
1551 :return: Timeouts for NAT64 (in seconds)
1552 """
1553 return self.api(self.papi.nat64_get_timeouts, {})
1554
Matus Fabianab9a59c2017-08-16 05:37:36 -07001555 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001556 """Dump NAT64 session table
1557
Matus Fabianab9a59c2017-08-16 05:37:36 -07001558 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001559 :returns: Dictionary of NAT64 sesstion table entries
1560 """
1561 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1562
Matus Fabian428dc912017-06-21 06:15:18 -07001563 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1564 """Add/del NAT64 prefix
1565
1566 :param prefix: NAT64 prefix
1567 :param plen: NAT64 prefix length
1568 :param vrf_id: VRF id of tenant (Default 0)
1569 :param is_add: 1 if add, 0 if delete (Default value = 1)
1570 """
1571 return self.api(
1572 self.papi.nat64_add_del_prefix,
1573 {'prefix': prefix,
1574 'prefix_len': plen,
1575 'vrf_id': vrf_id,
1576 'is_add': is_add})
1577
1578 def nat64_prefix_dump(self):
1579 """Dump NAT64 prefix
1580
1581 :returns: Dictionary of NAT64 prefixes
1582 """
1583 return self.api(self.papi.nat64_prefix_dump, {})
1584
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001585 def control_ping(self):
1586 self.api(self.papi.control_ping)
1587
1588 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001589 detect_mult, local_addr, peer_addr, is_ipv6=0,
1590 bfd_key_id=None, conf_key_id=None):
1591 if bfd_key_id is None:
1592 return self.api(self.papi.bfd_udp_add,
1593 {
1594 'sw_if_index': sw_if_index,
1595 'desired_min_tx': desired_min_tx,
1596 'required_min_rx': required_min_rx,
1597 'local_addr': local_addr,
1598 'peer_addr': peer_addr,
1599 'is_ipv6': is_ipv6,
1600 'detect_mult': detect_mult,
1601 })
1602 else:
1603 return self.api(self.papi.bfd_udp_add,
1604 {
1605 'sw_if_index': sw_if_index,
1606 'desired_min_tx': desired_min_tx,
1607 'required_min_rx': required_min_rx,
1608 'local_addr': local_addr,
1609 'peer_addr': peer_addr,
1610 'is_ipv6': is_ipv6,
1611 'detect_mult': detect_mult,
1612 'is_authenticated': 1,
1613 'bfd_key_id': bfd_key_id,
1614 'conf_key_id': conf_key_id,
1615 })
1616
Klement Sekeraa57a9702017-02-02 06:58:07 +01001617 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1618 detect_mult, local_addr, peer_addr, is_ipv6=0):
1619 return self.api(self.papi.bfd_udp_mod,
1620 {
1621 'sw_if_index': sw_if_index,
1622 'desired_min_tx': desired_min_tx,
1623 'required_min_rx': required_min_rx,
1624 'local_addr': local_addr,
1625 'peer_addr': peer_addr,
1626 'is_ipv6': is_ipv6,
1627 'detect_mult': detect_mult,
1628 })
1629
Klement Sekerab17dd962017-01-09 07:43:48 +01001630 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1631 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1632 is_delayed=False):
1633 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001634 {
1635 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001636 'local_addr': local_addr,
1637 'peer_addr': peer_addr,
1638 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001639 'is_delayed': 1 if is_delayed else 0,
1640 'bfd_key_id': bfd_key_id,
1641 'conf_key_id': conf_key_id,
1642 })
1643
1644 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1645 is_ipv6=0, is_delayed=False):
1646 return self.api(self.papi.bfd_udp_auth_deactivate,
1647 {
1648 'sw_if_index': sw_if_index,
1649 'local_addr': local_addr,
1650 'peer_addr': peer_addr,
1651 'is_ipv6': is_ipv6,
1652 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001653 })
1654
1655 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1656 return self.api(self.papi.bfd_udp_del,
1657 {
1658 'sw_if_index': sw_if_index,
1659 'local_addr': local_addr,
1660 'peer_addr': peer_addr,
1661 'is_ipv6': is_ipv6,
1662 })
1663
1664 def bfd_udp_session_dump(self):
1665 return self.api(self.papi.bfd_udp_session_dump, {})
1666
Klement Sekerab17dd962017-01-09 07:43:48 +01001667 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1668 peer_addr, is_ipv6=0):
1669 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001670 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001671 'sw_if_index': sw_if_index,
1672 'local_addr': local_addr,
1673 'peer_addr': peer_addr,
1674 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001675 })
1676
1677 def want_bfd_events(self, enable_disable=1):
1678 return self.api(self.papi.want_bfd_events, {
1679 'enable_disable': enable_disable,
1680 'pid': os.getpid(),
1681 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001682
Klement Sekerab17dd962017-01-09 07:43:48 +01001683 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1684 return self.api(self.papi.bfd_auth_set_key, {
1685 'conf_key_id': conf_key_id,
1686 'auth_type': auth_type,
1687 'key': key,
1688 'key_len': len(key),
1689 })
1690
1691 def bfd_auth_del_key(self, conf_key_id):
1692 return self.api(self.papi.bfd_auth_del_key, {
1693 'conf_key_id': conf_key_id,
1694 })
1695
1696 def bfd_auth_keys_dump(self):
1697 return self.api(self.papi.bfd_auth_keys_dump, {})
1698
Klement Sekera239790f2017-02-16 10:53:53 +01001699 def bfd_udp_set_echo_source(self, sw_if_index):
1700 return self.api(self.papi.bfd_udp_set_echo_source,
1701 {'sw_if_index': sw_if_index})
1702
Klement Sekera73884482017-02-23 09:26:30 +01001703 def bfd_udp_del_echo_source(self):
1704 return self.api(self.papi.bfd_udp_del_echo_source, {})
1705
Steve Shin7957d6e2016-12-19 09:24:50 -08001706 def classify_add_del_table(
1707 self,
1708 is_add,
1709 mask,
1710 match_n_vectors=1,
1711 table_index=0xFFFFFFFF,
1712 nbuckets=2,
1713 memory_size=2097152,
1714 skip_n_vectors=0,
1715 next_table_index=0xFFFFFFFF,
1716 miss_next_index=0xFFFFFFFF,
1717 current_data_flag=0,
1718 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001719 """
1720 :param is_add:
1721 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001722 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001723 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001724 :param nbuckets: (Default value = 2)
1725 :param memory_size: (Default value = 2097152)
1726 :param skip_n_vectors: (Default value = 0)
1727 :param next_table_index: (Default value = 0xFFFFFFFF)
1728 :param miss_next_index: (Default value = 0xFFFFFFFF)
1729 :param current_data_flag: (Default value = 0)
1730 :param current_data_offset: (Default value = 0)
1731 """
1732
1733 return self.api(
1734 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001735 {'is_add': is_add,
1736 'table_index': table_index,
1737 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001738 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001739 'skip_n_vectors': skip_n_vectors,
1740 'match_n_vectors': match_n_vectors,
1741 'next_table_index': next_table_index,
1742 'miss_next_index': miss_next_index,
1743 'current_data_flag': current_data_flag,
1744 'current_data_offset': current_data_offset,
1745 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001746
1747 def classify_add_del_session(
1748 self,
1749 is_add,
1750 table_index,
1751 match,
1752 opaque_index=0xFFFFFFFF,
1753 hit_next_index=0xFFFFFFFF,
1754 advance=0,
1755 action=0,
1756 metadata=0):
1757 """
1758 :param is_add:
1759 :param table_index:
1760 :param match:
1761 :param opaque_index: (Default value = 0xFFFFFFFF)
1762 :param hit_next_index: (Default value = 0xFFFFFFFF)
1763 :param advance: (Default value = 0)
1764 :param action: (Default value = 0)
1765 :param metadata: (Default value = 0)
1766 """
1767
1768 return self.api(
1769 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001770 {'is_add': is_add,
1771 'table_index': table_index,
1772 'hit_next_index': hit_next_index,
1773 'opaque_index': opaque_index,
1774 'advance': advance,
1775 'action': action,
1776 'metadata': metadata,
1777 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001778
1779 def input_acl_set_interface(
1780 self,
1781 is_add,
1782 sw_if_index,
1783 ip4_table_index=0xFFFFFFFF,
1784 ip6_table_index=0xFFFFFFFF,
1785 l2_table_index=0xFFFFFFFF):
1786 """
1787 :param is_add:
1788 :param sw_if_index:
1789 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1790 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1791 :param l2_table_index: (Default value = 0xFFFFFFFF)
1792 """
1793
1794 return self.api(
1795 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001796 {'sw_if_index': sw_if_index,
1797 'ip4_table_index': ip4_table_index,
1798 'ip6_table_index': ip6_table_index,
1799 'l2_table_index': l2_table_index,
1800 'is_add': is_add})
1801
1802 def set_ipfix_exporter(
1803 self,
1804 collector_address,
1805 src_address,
1806 path_mtu,
1807 template_interval,
1808 vrf_id=0,
1809 collector_port=4739,
1810 udp_checksum=0):
1811 return self.api(
1812 self.papi.set_ipfix_exporter,
1813 {
1814 'collector_address': collector_address,
1815 'collector_port': collector_port,
1816 'src_address': src_address,
1817 'vrf_id': vrf_id,
1818 'path_mtu': path_mtu,
1819 'template_interval': template_interval,
1820 'udp_checksum': udp_checksum,
1821 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001822
1823 def dhcp_proxy_config(self,
1824 dhcp_server,
1825 dhcp_src_address,
1826 rx_table_id=0,
1827 server_table_id=0,
1828 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001829 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001830 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001831 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001832 {
1833 'rx_vrf_id': rx_table_id,
1834 'server_vrf_id': server_table_id,
1835 'is_ipv6': is_ipv6,
1836 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001837 'dhcp_server': dhcp_server,
1838 'dhcp_src_address': dhcp_src_address,
1839 })
1840
1841 def dhcp_proxy_set_vss(self,
1842 table_id,
1843 fib_id,
1844 oui,
1845 is_add=1,
1846 is_ip6=0):
1847 return self.api(
1848 self.papi.dhcp_proxy_set_vss,
1849 {
1850 'tbl_id': table_id,
1851 'fib_id': fib_id,
1852 'is_ipv6': is_ip6,
1853 'is_add': is_add,
1854 'oui': oui,
1855 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001856
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001857 def dhcp_client(self,
1858 sw_if_index,
1859 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001860 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001861 is_add=1,
1862 want_dhcp_events=0):
1863 return self.api(
1864 self.papi.dhcp_client_config,
1865 {
1866 'sw_if_index': sw_if_index,
1867 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001868 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001869 'is_add': is_add,
1870 'want_dhcp_event': want_dhcp_events,
1871 'pid': os.getpid(),
1872 })
1873
Neale Ranns32e1c012016-11-22 17:07:28 +00001874 def ip_mroute_add_del(self,
1875 src_address,
1876 grp_address,
1877 grp_address_length,
1878 e_flags,
1879 next_hop_sw_if_index,
1880 i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001881 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001882 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001883 is_add=1,
1884 is_ipv6=0,
1885 is_local=0):
1886 """
1887 """
1888 return self.api(
1889 self.papi.ip_mroute_add_del,
1890 {'next_hop_sw_if_index': next_hop_sw_if_index,
1891 'entry_flags': e_flags,
1892 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001893 'table_id': table_id,
1894 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001895 'is_add': is_add,
1896 'is_ipv6': is_ipv6,
1897 'is_local': is_local,
1898 'grp_address_length': grp_address_length,
1899 'grp_address': grp_address,
1900 'src_address': src_address})
1901
1902 def mfib_signal_dump(self):
1903 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001904
1905 def ip_mfib_dump(self):
1906 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001907
1908 def lisp_enable_disable(self, is_enabled):
1909 return self.api(
1910 self.papi.lisp_enable_disable,
1911 {
1912 'is_en': is_enabled,
1913 })
1914
1915 def lisp_locator_set(self,
1916 ls_name,
1917 is_add=1):
1918 return self.api(
1919 self.papi.lisp_add_del_locator_set,
1920 {
1921 'is_add': is_add,
1922 'locator_set_name': ls_name
1923 })
1924
1925 def lisp_locator_set_dump(self):
1926 return self.api(self.papi.lisp_locator_set_dump, {})
1927
1928 def lisp_locator(self,
1929 ls_name,
1930 sw_if_index,
1931 priority=1,
1932 weight=1,
1933 is_add=1):
1934 return self.api(
1935 self.papi.lisp_add_del_locator,
1936 {
1937 'is_add': is_add,
1938 'locator_set_name': ls_name,
1939 'sw_if_index': sw_if_index,
1940 'priority': priority,
1941 'weight': weight
1942 })
1943
1944 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1945 return self.api(
1946 self.papi.lisp_locator_dump,
1947 {
1948 'is_index_set': is_index_set,
1949 'ls_name': ls_name,
1950 'ls_index': ls_index,
1951 })
1952
1953 def lisp_local_mapping(self,
1954 ls_name,
1955 eid_type,
1956 eid,
1957 prefix_len,
1958 vni=0,
1959 key_id=0,
1960 key="",
1961 is_add=1):
1962 return self.api(
1963 self.papi.lisp_add_del_local_eid,
1964 {
1965 'locator_set_name': ls_name,
1966 'is_add': is_add,
1967 'eid_type': eid_type,
1968 'eid': eid,
1969 'prefix_len': prefix_len,
1970 'vni': vni,
1971 'key_id': key_id,
1972 'key': key
1973 })
1974
1975 def lisp_eid_table_dump(self,
1976 eid_set=0,
1977 prefix_length=0,
1978 vni=0,
1979 eid_type=0,
1980 eid=None,
1981 filter_opt=0):
1982 return self.api(
1983 self.papi.lisp_eid_table_dump,
1984 {
1985 'eid_set': eid_set,
1986 'prefix_length': prefix_length,
1987 'vni': vni,
1988 'eid_type': eid_type,
1989 'eid': eid,
1990 'filter': filter_opt,
1991 })
1992
1993 def lisp_remote_mapping(self,
1994 eid_type,
1995 eid,
1996 eid_prefix_len=0,
1997 vni=0,
1998 rlocs=None,
1999 rlocs_num=0,
2000 is_src_dst=0,
2001 is_add=1):
2002 return self.api(
2003 self.papi.lisp_add_del_remote_mapping,
2004 {
2005 'is_add': is_add,
2006 'eid_type': eid_type,
2007 'eid': eid,
2008 'eid_len': eid_prefix_len,
2009 'rloc_num': rlocs_num,
2010 'rlocs': rlocs,
2011 'vni': vni,
2012 'is_src_dst': is_src_dst,
2013 })
2014
2015 def lisp_adjacency(self,
2016 leid,
2017 reid,
2018 leid_len,
2019 reid_len,
2020 eid_type,
2021 is_add=1,
2022 vni=0):
2023 return self.api(
2024 self.papi.lisp_add_del_adjacency,
2025 {
2026 'is_add': is_add,
2027 'vni': vni,
2028 'eid_type': eid_type,
2029 'leid': leid,
2030 'reid': reid,
2031 'leid_len': leid_len,
2032 'reid_len': reid_len,
2033 })
2034
2035 def lisp_adjacencies_get(self, vni=0):
2036 return self.api(
2037 self.papi.lisp_adjacencies_get,
2038 {
2039 'vni': vni
2040 })
Neale Ranns80823802017-02-20 18:23:41 -08002041
2042 def map_add_domain(self,
2043 ip6_prefix,
2044 ip6_prefix_len,
2045 ip6_src,
2046 ip6_src_prefix_len,
2047 ip4_prefix,
2048 ip4_prefix_len,
2049 ea_bits_len=0,
2050 psid_offset=0,
2051 psid_length=0,
2052 is_translation=0,
2053 mtu=1280):
2054 return self.api(
2055 self.papi.map_add_domain,
2056 {
2057 'ip6_prefix': ip6_prefix,
2058 'ip6_prefix_len': ip6_prefix_len,
2059 'ip4_prefix': ip4_prefix,
2060 'ip4_prefix_len': ip4_prefix_len,
2061 'ip6_src': ip6_src,
2062 'ip6_src_prefix_len': ip6_src_prefix_len,
2063 'ea_bits_len': ea_bits_len,
2064 'psid_offset': psid_offset,
2065 'psid_length': psid_length,
2066 'is_translation': is_translation,
2067 'mtu': mtu
2068 })
Hongjun Nief486b12017-04-12 19:21:16 +08002069
2070 def gtpu_add_del_tunnel(
2071 self,
2072 src_addr,
2073 dst_addr,
2074 is_add=1,
2075 is_ipv6=0,
2076 mcast_sw_if_index=0xFFFFFFFF,
2077 encap_vrf_id=0,
2078 decap_next_index=0xFFFFFFFF,
2079 teid=0):
2080 """
2081
2082 :param is_add: (Default value = 1)
2083 :param is_ipv6: (Default value = 0)
2084 :param src_addr:
2085 :param dst_addr:
2086 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2087 :param encap_vrf_id: (Default value = 0)
2088 :param decap_next_index: (Default value = 0xFFFFFFFF)
2089 :param teid: (Default value = 0)
2090
2091 """
2092 return self.api(self.papi.gtpu_add_del_tunnel,
2093 {'is_add': is_add,
2094 'is_ipv6': is_ipv6,
2095 'src_address': src_addr,
2096 'dst_address': dst_addr,
2097 'mcast_sw_if_index': mcast_sw_if_index,
2098 'encap_vrf_id': encap_vrf_id,
2099 'decap_next_index': decap_next_index,
2100 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002101
2102 def vxlan_gpe_add_del_tunnel(
2103 self,
2104 src_addr,
2105 dst_addr,
2106 mcast_sw_if_index=0xFFFFFFFF,
2107 is_add=1,
2108 is_ipv6=0,
2109 encap_vrf_id=0,
2110 decap_vrf_id=0,
2111 protocol=3,
2112 vni=0):
2113 """
2114
2115 :param local:
2116 :param remote:
2117 :param is_add: (Default value = 1)
2118 :param is_ipv6: (Default value = 0)
2119 :param encap_vrf_id: (Default value = 0)
2120 :param decap_vrf_id: (Default value = 0)
2121 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2122 :param protocol: (Default value = 3)
2123 :param vni: (Default value = 0)
2124
2125 """
2126 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2127 {'is_add': is_add,
2128 'is_ipv6': is_ipv6,
2129 'local': src_addr,
2130 'remote': dst_addr,
2131 'mcast_sw_if_index': mcast_sw_if_index,
2132 'encap_vrf_id': encap_vrf_id,
2133 'decap_vrf_id': decap_vrf_id,
2134 'protocol': protocol,
2135 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002136
2137 def pppoe_add_del_session(
2138 self,
2139 client_ip,
2140 client_mac,
2141 session_id=0,
2142 is_add=1,
2143 is_ipv6=0,
2144 decap_vrf_id=0):
2145 """
2146
2147 :param is_add: (Default value = 1)
2148 :param is_ipv6: (Default value = 0)
2149 :param client_ip:
2150 :param session_id: (Default value = 0)
2151 :param client_mac:
2152 :param decap_vrf_id: (Default value = 0)
2153
2154 """
2155 return self.api(self.papi.pppoe_add_del_session,
2156 {'is_add': is_add,
2157 'is_ipv6': is_ipv6,
2158 'session_id': session_id,
2159 'client_ip': client_ip,
2160 'decap_vrf_id': decap_vrf_id,
2161 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002162
2163 def sr_localsid_add_del(self,
2164 localsid_addr,
2165 behavior,
2166 nh_addr,
2167 is_del=0,
2168 end_psp=0,
2169 sw_if_index=0xFFFFFFFF,
2170 vlan_index=0,
2171 fib_table=0,
2172 ):
2173 """ Add/del IPv6 SR local-SID.
2174
2175 :param localsid_addr:
2176 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2177 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2178 :param nh_addr:
2179 :param is_del: (Default value = 0)
2180 :param end_psp: (Default value = 0)
2181 :param sw_if_index: (Default value = 0xFFFFFFFF)
2182 :param vlan_index: (Default value = 0)
2183 :param fib_table: (Default value = 0)
2184 """
2185 return self.api(
2186 self.papi.sr_localsid_add_del,
2187 {'is_del': is_del,
2188 'localsid_addr': localsid_addr,
2189 'end_psp': end_psp,
2190 'behavior': behavior,
2191 'sw_if_index': sw_if_index,
2192 'vlan_index': vlan_index,
2193 'fib_table': fib_table,
2194 'nh_addr': nh_addr
2195 }
2196 )
2197
2198 def sr_policy_add(
2199 self,
2200 bsid_addr,
2201 weight=1,
2202 is_encap=1,
2203 type=0,
2204 fib_table=0,
2205 n_segments=0,
2206 segments=[]):
2207 """
2208 :param bsid_addr: bindingSID of the SR Policy
2209 :param weight: weight of the sid list. optional. (default: 1)
2210 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2211 (default: Encap)
2212 :param type: type/behavior of the SR policy. (default or spray) \
2213 (default: default)
2214 :param fib_table: VRF where to install the FIB entry for the BSID \
2215 (default: 0)
2216 :param n_segments: number of segments \
2217 (default: 0)
2218 :param segments: a vector of IPv6 address composing the segment list \
2219 (default: [])
2220 """
2221 return self.api(
2222 self.papi.sr_policy_add,
2223 {'bsid_addr': bsid_addr,
2224 'weight': weight,
2225 'is_encap': is_encap,
2226 'type': type,
2227 'fib_table': fib_table,
2228 'n_segments': n_segments,
2229 'segments': segments
2230 }
2231 )
2232
2233 def sr_policy_del(
2234 self,
2235 bsid_addr,
2236 sr_policy_index=0):
2237 """
2238 :param bsid: bindingSID of the SR Policy
2239 :param sr_policy_index: index of the sr policy (default: 0)
2240 """
2241 return self.api(
2242 self.papi.sr_policy_del,
2243 {'bsid_addr': bsid_addr,
2244 'sr_policy_index': sr_policy_index
2245 })
2246
2247 def sr_steering_add_del(
2248 self,
2249 is_del,
2250 bsid_addr,
2251 sr_policy_index,
2252 table_id,
2253 prefix_addr,
2254 mask_width,
2255 sw_if_index,
2256 traffic_type):
2257 """
2258 Steer traffic L2 and L3 traffic through a given SR policy
2259
2260 :param is_del: delete or add
2261 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2262 :param sr_policy: is the index of the SR Policy (alt to bsid)
2263 :param table_id: is the VRF where to install the FIB entry for the BSID
2264 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2265 :param mask_width: is the mask for L3 traffic type
2266 :param sw_if_index: is the incoming interface for L2 traffic
2267 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2268 """
2269 return self.api(
2270 self.papi.sr_steering_add_del,
2271 {'is_del': is_del,
2272 'bsid_addr': bsid_addr,
2273 'sr_policy_index': sr_policy_index,
2274 'table_id': table_id,
2275 'prefix_addr': prefix_addr,
2276 'mask_width': mask_width,
2277 'sw_if_index': sw_if_index,
2278 'traffic_type': traffic_type
2279 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002280
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002281 def macip_acl_add(self, rules, tag=""):
2282 """ Add MACIP acl
2283
2284 :param rules: list of rules for given acl
2285 :param tag: acl tag
2286 """
2287
2288 return self.api(self.papi.macip_acl_add,
2289 {'r': rules,
2290 'count': len(rules),
2291 'tag': tag})
2292
Pavel Kotucek932f7412017-09-07 14:44:52 +02002293 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2294 """ Add MACIP acl
2295
2296 :param rules: list of rules for given acl
2297 :param tag: acl tag
2298 """
2299
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002300 return self.api(self.papi.macip_acl_add_replace,
2301 {'acl_index': acl_index,
2302 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002303 'count': len(rules),
2304 'tag': tag})
2305
2306 def macip_acl_del(self, acl_index):
2307 """
2308
2309 :param acl_index:
2310 :return:
2311 """
2312 return self.api(self.papi.macip_acl_del,
2313 {'acl_index': acl_index})
2314
2315 def macip_acl_interface_add_del(self,
2316 sw_if_index,
2317 acl_index,
2318 is_add=1):
2319 """ Add MACIP acl to interface
2320
2321 :param sw_if_index:
2322 :param acl_index:
2323 :param is_add: (Default value = 1)
2324 """
2325
2326 return self.api(self.papi.macip_acl_interface_add_del,
2327 {'is_add': is_add,
2328 'sw_if_index': sw_if_index,
2329 'acl_index': acl_index})
2330
2331 def macip_acl_interface_get(self):
2332 """ Return interface acls dump
2333 """
2334 return self.api(
2335 self.papi.macip_acl_interface_get, {})
2336
2337 def macip_acl_dump(self, acl_index=4294967295):
2338 """ Return MACIP acl dump
2339 """
2340
2341 return self.api(
2342 self.papi.macip_acl_dump, {'acl_index': acl_index})