blob: f7047eaf58f9207865b4c478851847c98530df77 [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
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 Rannsad422ed2016-11-02 14:20:04 +0000738 is_resolve_host=0,
739 is_resolve_attached=0,
740 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200741 is_add=1,
742 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200743 is_unreach=0,
744 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200745 is_ipv6=0,
746 is_local=0,
747 is_classify=0,
748 is_multipath=0,
Neale Ranns6f631152017-10-03 08:20:21 -0700749 is_l2_bridged=0,
Neale Ranns054c03a2017-10-13 05:15:07 -0700750 is_source_lookup=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000751 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200752 """
753
754 :param dst_address_length:
755 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
756 :param dst_address:
757 :param next_hop_address:
758 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
759 :param vrf_id: (Default value = 0)
760 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200761 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200762 :param is_add: (Default value = 1)
763 :param is_drop: (Default value = 0)
764 :param is_ipv6: (Default value = 0)
765 :param is_local: (Default value = 0)
766 :param is_classify: (Default value = 0)
767 :param is_multipath: (Default value = 0)
768 :param is_resolve_host: (Default value = 0)
769 :param is_resolve_attached: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700770 :param is_l2_bridged: (Default value = 0)
771 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200772 :param not_last: (Default value = 0)
773 :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,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200795 'not_last': not_last,
796 'next_hop_weight': next_hop_weight,
797 'dst_address_length': dst_address_length,
798 'dst_address': dst_address,
799 'next_hop_address': next_hop_address,
800 'next_hop_n_out_labels': next_hop_n_out_labels,
801 'next_hop_via_label': next_hop_via_label,
802 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100803
Matej Klotton16a14cd2016-12-07 15:09:13 +0100804 def ip_fib_dump(self):
805 return self.api(self.papi.ip_fib_dump, {})
806
Jan Gelety057bb8c2016-12-20 17:32:45 +0100807 def ip6_fib_dump(self):
808 return self.api(self.papi.ip6_fib_dump, {})
809
Matej Klotton0178d522016-11-04 11:11:44 +0100810 def ip_neighbor_add_del(self,
811 sw_if_index,
812 mac_address,
813 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100814 is_add=1,
815 is_ipv6=0,
816 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800817 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100818 ):
819 """ Add neighbor MAC to IPv4 or IPv6 address.
820
821 :param sw_if_index:
822 :param mac_address:
823 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100824 :param is_add: (Default value = 1)
825 :param is_ipv6: (Default value = 0)
826 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800827 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100828 """
829
830 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100831 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800832 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200833 'is_add': is_add,
834 'is_ipv6': is_ipv6,
835 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800836 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200837 'mac_address': mac_address,
838 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100839 }
Matej Klotton0178d522016-11-04 11:11:44 +0100840 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100841
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800842 def ip_neighbor_dump(self,
843 sw_if_index,
844 is_ipv6=0):
845 """ Return IP neighbor dump.
846
847 :param sw_if_index:
848 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
849 """
850
851 return self.api(
852 self.papi.ip_neighbor_dump,
853 {'is_ipv6': is_ipv6,
854 'sw_if_index': sw_if_index
855 }
856 )
857
858 def proxy_arp_add_del(self,
859 low_address,
860 hi_address,
861 vrf_id=0,
862 is_add=1):
863 """ Config Proxy Arp Range.
864
865 :param low_address: Start address in the rnage to Proxy for
866 :param hi_address: End address in the rnage to Proxy for
867 :param vrf_id: The VRF/table in which to proxy
868 """
869
870 return self.api(
871 self.papi.proxy_arp_add_del,
872 {'vrf_id': vrf_id,
873 'is_add': is_add,
874 'low_address': low_address,
875 'hi_address': hi_address,
876 }
877 )
878
879 def proxy_arp_intfc_enable_disable(self,
880 sw_if_index,
881 is_enable=1):
882 """ Enable/Disable an interface for proxy ARP requests
883
884 :param sw_if_index: Interface
885 :param enable_disable: Enable/Disable
886 """
887
888 return self.api(
889 self.papi.proxy_arp_intfc_enable_disable,
890 {'sw_if_index': sw_if_index,
891 'enable_disable': is_enable
892 }
893 )
894
Jane546d3b2016-12-08 13:10:03 +0100895 def reset_vrf(self,
896 vrf_id,
897 is_ipv6=0,
898 ):
899 """ Reset VRF (remove all routes etc.) request.
900
901 :param int vrf_id: ID of the FIB table / VRF to reset.
902 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
903 """
904
905 return self.api(
906 self.papi.reset_vrf,
907 {'vrf_id': vrf_id,
908 'is_ipv6': is_ipv6,
909 }
910 )
911
912 def reset_fib(self,
913 vrf_id,
914 is_ipv6=0,
915 ):
916 """ Reset VRF (remove all routes etc.) request.
917
918 :param int vrf_id: ID of the FIB table / VRF to reset.
919 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
920 """
921
922 return self.api(
923 self.papi.reset_fib,
924 {'vrf_id': vrf_id,
925 'is_ipv6': is_ipv6,
926 }
927 )
928
929 def ip_dump(self,
930 is_ipv6=0,
931 ):
932 """ Return IP dump.
933
934 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
935 """
936
937 return self.api(
938 self.papi.ip_dump,
939 {'is_ipv6': is_ipv6,
940 }
941 )
942
Klement Sekera7bb873a2016-11-18 07:38:42 +0100943 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300944 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100945 """
946
947 :param sw_if_index_from:
948 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100949 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300950 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100951 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100952 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200953 {'sw_if_index_from': sw_if_index_from,
954 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300955 'state': state,
956 'is_l2': is_l2,
957 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000958
959 def gre_tunnel_add_del(self,
960 src_address,
961 dst_address,
962 outer_fib_id=0,
963 is_teb=0,
964 is_add=1,
965 is_ip6=0):
966 """ Add a GRE tunnel
967
968 :param src_address:
969 :param dst_address:
970 :param outer_fib_id: (Default value = 0)
971 :param is_add: (Default value = 1)
972 :param is_ipv6: (Default value = 0)
973 :param is_teb: (Default value = 0)
974 """
975
976 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100977 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200978 {'is_add': is_add,
979 'is_ipv6': is_ip6,
980 'teb': is_teb,
981 'src_address': src_address,
982 'dst_address': dst_address,
983 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000984 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000985
Neale Ranns5a8123b2017-01-26 01:18:23 -0800986 def mpls_fib_dump(self):
987 return self.api(self.papi.mpls_fib_dump, {})
988
Neale Ranns15002542017-09-10 04:39:11 -0700989 def mpls_table_add_del(
990 self,
991 table_id,
992 is_add=1):
993 """
994
995 :param table_id
996 :param is_add: (Default value = 1)
997
998 """
999
1000 return self.api(
1001 self.papi.mpls_table_add_del,
1002 {'mt_table_id': table_id,
1003 'mt_is_add': is_add})
1004
Neale Rannsad422ed2016-11-02 14:20:04 +00001005 def mpls_route_add_del(
1006 self,
1007 label,
1008 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001009 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001010 next_hop_address,
1011 next_hop_sw_if_index=0xFFFFFFFF,
1012 table_id=0,
1013 next_hop_table_id=0,
1014 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001015 next_hop_n_out_labels=0,
1016 next_hop_out_label_stack=[],
1017 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001018 is_resolve_host=0,
1019 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001020 is_interface_rx=0,
1021 is_rpf_id=0,
1022 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001023 is_add=1,
1024 is_drop=0,
1025 is_multipath=0,
1026 classify_table_index=0xFFFFFFFF,
1027 is_classify=0,
1028 not_last=0):
1029 """
1030
1031 :param dst_address_length:
1032 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1033 :param dst_address:
1034 :param next_hop_address:
1035 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1036 :param vrf_id: (Default value = 0)
1037 :param lookup_in_vrf: (Default value = 0)
1038 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001039 :param is_add: (Default value = 1)
1040 :param is_drop: (Default value = 0)
1041 :param is_ipv6: (Default value = 0)
1042 :param is_local: (Default value = 0)
1043 :param is_classify: (Default value = 0)
1044 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001045 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001046 :param is_resolve_host: (Default value = 0)
1047 :param is_resolve_attached: (Default value = 0)
1048 :param not_last: (Default value = 0)
1049 :param next_hop_weight: (Default value = 1)
1050
1051 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001052
1053 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001054 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001055 {'mr_label': label,
1056 'mr_eos': eos,
1057 'mr_table_id': table_id,
1058 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001059 'mr_is_add': is_add,
1060 'mr_is_classify': is_classify,
1061 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001062 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001063 'mr_is_resolve_host': is_resolve_host,
1064 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001065 'mr_is_interface_rx': is_interface_rx,
1066 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001067 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001068 'mr_next_hop_weight': next_hop_weight,
1069 'mr_next_hop': next_hop_address,
1070 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1071 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1072 'mr_next_hop_table_id': next_hop_table_id,
1073 'mr_next_hop_via_label': next_hop_via_label,
1074 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001075
1076 def mpls_ip_bind_unbind(
1077 self,
1078 label,
1079 dst_address,
1080 dst_address_length,
1081 table_id=0,
1082 ip_table_id=0,
1083 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001084 is_bind=1):
1085 """
1086 """
1087 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001088 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001089 {'mb_mpls_table_id': table_id,
1090 'mb_label': label,
1091 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001092 'mb_is_bind': is_bind,
1093 'mb_is_ip4': is_ip4,
1094 'mb_address_length': dst_address_length,
1095 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001096
1097 def mpls_tunnel_add_del(
1098 self,
1099 tun_sw_if_index,
1100 next_hop_proto_is_ip4,
1101 next_hop_address,
1102 next_hop_sw_if_index=0xFFFFFFFF,
1103 next_hop_table_id=0,
1104 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001105 next_hop_n_out_labels=0,
1106 next_hop_out_label_stack=[],
1107 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001108 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001109 l2_only=0,
1110 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001111 """
1112
1113 :param dst_address_length:
1114 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1115 :param dst_address:
1116 :param next_hop_address:
1117 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1118 :param vrf_id: (Default value = 0)
1119 :param lookup_in_vrf: (Default value = 0)
1120 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001121 :param is_add: (Default value = 1)
1122 :param is_drop: (Default value = 0)
1123 :param is_ipv6: (Default value = 0)
1124 :param is_local: (Default value = 0)
1125 :param is_classify: (Default value = 0)
1126 :param is_multipath: (Default value = 0)
1127 :param is_resolve_host: (Default value = 0)
1128 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001129 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001130 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001131
1132 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001133 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001134 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001135 {'mt_sw_if_index': tun_sw_if_index,
1136 'mt_is_add': is_add,
1137 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001138 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001139 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1140 'mt_next_hop_weight': next_hop_weight,
1141 'mt_next_hop': next_hop_address,
1142 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1143 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1144 'mt_next_hop_table_id': next_hop_table_id,
1145 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001146
Matus Fabian2ba92e32017-08-21 07:05:03 -07001147 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001148 self,
1149 sw_if_index,
1150 is_inside=1,
1151 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001152 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001153
1154 :param sw_if_index: Software index of the interface
1155 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1156 :param is_add: 1 if add, 0 if delete (Default value = 1)
1157 """
1158 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001159 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001160 {'is_add': is_add,
1161 'is_inside': is_inside,
1162 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001163
Matus Fabian2ba92e32017-08-21 07:05:03 -07001164 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001165 self,
1166 sw_if_index,
1167 is_inside=1,
1168 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001169 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001170
1171 :param sw_if_index: Software index of the interface
1172 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1173 :param is_add: 1 if add, 0 if delete (Default value = 1)
1174 """
1175 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001176 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001177 {'is_add': is_add,
1178 'is_inside': is_inside,
1179 'sw_if_index': sw_if_index})
1180
Matus Fabian2ba92e32017-08-21 07:05:03 -07001181 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001182 self,
1183 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001184 external_ip=0,
1185 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001186 local_port=0,
1187 external_port=0,
1188 addr_only=1,
1189 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001190 protocol=0,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001191 is_add=1):
1192 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001193
1194 :param local_ip: Local IP address
1195 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001196 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001197 :param local_port: Local port number (Default value = 0)
1198 :param external_port: External port number (Default value = 0)
1199 :param addr_only: 1 if address only mapping, 0 if address and port
1200 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001201 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001202 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001203 """
1204 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001205 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001206 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001207 'addr_only': addr_only,
1208 'local_ip_address': local_ip,
1209 'external_ip_address': external_ip,
1210 'local_port': local_port,
1211 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001212 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001213 'vrf_id': vrf_id,
1214 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001215
Matus Fabian2ba92e32017-08-21 07:05:03 -07001216 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001217 self,
1218 first_ip_address,
1219 last_ip_address,
1220 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001221 vrf_id=0xFFFFFFFF):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001222 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001223
1224 :param first_ip_address: First IP address
1225 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001226 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001227 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001228 """
1229 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001230 self.papi.nat44_add_del_address_range,
1231 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001232 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001233 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001234 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001235
Matus Fabian2ba92e32017-08-21 07:05:03 -07001236 def nat44_address_dump(self):
1237 """Dump NAT44 addresses
1238 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001239 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001240 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001241
Matus Fabian2ba92e32017-08-21 07:05:03 -07001242 def nat44_interface_dump(self):
1243 """Dump interfaces with NAT44 feature
1244 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001245 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001246 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001247
Matus Fabian2ba92e32017-08-21 07:05:03 -07001248 def nat44_interface_output_feature_dump(self):
1249 """Dump interfaces with NAT44 output feature
1250 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001251 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001252 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001253
Matus Fabian2ba92e32017-08-21 07:05:03 -07001254 def nat44_static_mapping_dump(self):
1255 """Dump NAT44 static mappings
1256 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001257 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001258 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001259
Matus Fabian2ba92e32017-08-21 07:05:03 -07001260 def nat_show_config(self):
1261 """Show NAT plugin config
1262 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001263 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001264 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001265
Matus Fabian2ba92e32017-08-21 07:05:03 -07001266 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001267 self,
1268 sw_if_index,
1269 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001270 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001271
1272 :param sw_if_index: Software index of the interface
1273 :param is_add: 1 if add, 0 if delete (Default value = 1)
1274 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001275 return self.api(self.papi.nat44_add_del_interface_addr,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001276 {'is_add': is_add, 'sw_if_index': sw_if_index})
1277
Matus Fabian2ba92e32017-08-21 07:05:03 -07001278 def nat44_interface_addr_dump(self):
1279 """Dump NAT44 addresses interfaces
1280 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001281 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001282 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001283
Matus Fabian2ba92e32017-08-21 07:05:03 -07001284 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001285 self,
1286 domain_id=1,
1287 src_port=4739,
1288 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001289 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001290
1291 :param domain_id: Observation domain ID (Default value = 1)
1292 :param src_port: Source port number (Default value = 4739)
1293 :param enable: 1 if enable, 0 if disable (Default value = 1)
1294 """
1295 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001296 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001297 {'domain_id': domain_id,
1298 'src_port': src_port,
1299 'enable': enable})
1300
Matus Fabian2ba92e32017-08-21 07:05:03 -07001301 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001302 self,
1303 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001304 vrf_id):
1305 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001306
1307 :param ip_address: ip adress of the user to be dumped
1308 :param cpu_index: cpu_index on which the user is
1309 :param vrf_id: VRF ID
1310 :return: Dictionary of S-NAT sessions
1311 """
1312 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001313 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001314 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001315 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001316
Matus Fabian2ba92e32017-08-21 07:05:03 -07001317 def nat44_user_dump(self):
1318 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001319
Matus Fabian2ba92e32017-08-21 07:05:03 -07001320 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001321 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001322 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001323
Matus Fabian704018c2017-09-04 02:17:18 -07001324 def nat44_add_del_lb_static_mapping(
1325 self,
1326 external_addr,
1327 external_port,
1328 protocol,
1329 vrf_id=0,
1330 local_num=0,
1331 locals=None,
1332 is_add=1):
1333 """Add/delete NAT44 load balancing static mapping
1334
1335 :param is_add - 1 if add, 0 if delete
1336 """
1337 return self.api(
1338 self.papi.nat44_add_del_lb_static_mapping,
1339 {'is_add': is_add,
1340 'external_addr': external_addr,
1341 'external_port': external_port,
1342 'protocol': protocol,
1343 'vrf_id': vrf_id,
1344 'local_num': local_num,
1345 'locals': locals})
1346
1347 def nat44_lb_static_mapping_dump(self):
1348 """Dump NAT44 load balancing static mappings
1349
1350 :return: Dictionary of NAT44 load balancing static mapping
1351 """
1352 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1353
Matus Fabian2ba92e32017-08-21 07:05:03 -07001354 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001355 self,
1356 in_addr,
1357 in_plen,
1358 out_addr,
1359 out_plen,
1360 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001361 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001362
1363 :param is_add - 1 if add, 0 if delete
1364 :param in_addr - inside IP address
1365 :param in_plen - inside IP address prefix length
1366 :param out_addr - outside IP address
1367 :param out_plen - outside IP address prefix length
1368 """
1369 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001370 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001371 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001372 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001373 'in_addr': in_addr,
1374 'in_plen': in_plen,
1375 'out_addr': out_addr,
1376 'out_plen': out_plen})
1377
Matus Fabian2ba92e32017-08-21 07:05:03 -07001378 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001379 self,
1380 in_addr):
1381 """Get outside address and port range from inside address
1382
1383 :param in_addr - inside IP address
1384 """
1385 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 self.papi.nat_det_forward,
1387 {'in_addr': in_addr,
1388 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001389
Matus Fabian2ba92e32017-08-21 07:05:03 -07001390 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001391 self,
1392 out_addr,
1393 out_port):
1394 """Get inside address from outside address and port
1395
1396 :param out_addr - outside IP address
1397 :param out_port - outside port
1398 """
1399 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001400 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001401 {'out_addr': out_addr,
1402 'out_port': out_port})
1403
Matus Fabian2ba92e32017-08-21 07:05:03 -07001404 def nat_det_map_dump(self):
1405 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001406
Matus Fabian2ba92e32017-08-21 07:05:03 -07001407 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001408 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001409 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001410
Matus Fabian2ba92e32017-08-21 07:05:03 -07001411 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001412 self,
1413 udp=300,
1414 tcp_established=7440,
1415 tcp_transitory=240,
1416 icmp=60):
1417 """Set values of timeouts for deterministic NAT (in seconds)
1418
1419 :param udp - UDP timeout (Default value = 300)
1420 :param tcp_established - TCP established timeout (Default value = 7440)
1421 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1422 :param icmp - ICMP timeout (Default value = 60)
1423 """
1424 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001425 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001426 {'udp': udp,
1427 'tcp_established': tcp_established,
1428 'tcp_transitory': tcp_transitory,
1429 'icmp': icmp})
1430
Matus Fabian2ba92e32017-08-21 07:05:03 -07001431 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001432 """Get values of timeouts for deterministic NAT
1433
1434 :return: Timeouts for deterministic NAT (in seconds)
1435 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001436 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001437
Matus Fabian2ba92e32017-08-21 07:05:03 -07001438 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001439 self,
1440 out_addr,
1441 out_port,
1442 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001443 ext_port):
1444 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001445
1446 :param out_addr - outside IP address
1447 :param out_port - outside port
1448 :param ext_addr - external host IP address
1449 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001450 """
1451 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001452 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001453 {'out_addr': out_addr,
1454 'out_port': out_port,
1455 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001456 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001457
Matus Fabian2ba92e32017-08-21 07:05:03 -07001458 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001459 self,
1460 in_addr,
1461 in_port,
1462 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001463 ext_port):
1464 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001465
1466 :param in_addr - inside IP address
1467 :param in_port - inside port
1468 :param ext_addr - external host IP address
1469 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001470 """
1471 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001472 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001473 {'in_addr': in_addr,
1474 'in_port': in_port,
1475 'ext_addr': ext_addr,
1476 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001477 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001478
Matus Fabian2ba92e32017-08-21 07:05:03 -07001479 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001480 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001481 user_addr):
1482 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001483
1484 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001485 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001486 """
1487 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001488 self.papi.nat_det_session_dump,
1489 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001490 'user_addr': user_addr})
1491
Matus Fabian06596c52017-06-06 04:53:28 -07001492 def nat64_add_del_pool_addr_range(
1493 self,
1494 start_addr,
1495 end_addr,
1496 vrf_id=0xFFFFFFFF,
1497 is_add=1):
1498 """Add/del address range to NAT64 pool
1499
1500 :param start_addr: First IP address
1501 :param end_addr: Last IP address
1502 :param vrf_id: VRF id for the address range
1503 :param is_add: 1 if add, 0 if delete (Default value = 1)
1504 """
1505 return self.api(
1506 self.papi.nat64_add_del_pool_addr_range,
1507 {'start_addr': start_addr,
1508 'end_addr': end_addr,
1509 'vrf_id': vrf_id,
1510 'is_add': is_add})
1511
1512 def nat64_pool_addr_dump(self):
1513 """Dump NAT64 pool addresses
1514 :return: Dictionary of NAT64 pool addresses
1515 """
1516 return self.api(self.papi.nat64_pool_addr_dump, {})
1517
1518 def nat64_add_del_interface(
1519 self,
1520 sw_if_index,
1521 is_inside=1,
1522 is_add=1):
1523 """Enable/disable NAT64 feature on the interface
1524 :param sw_if_index: Index of the interface
1525 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1526 :param is_add: 1 if add, 0 if delete (Default value = 1)
1527 """
1528 return self.api(
1529 self.papi.nat64_add_del_interface,
1530 {'sw_if_index': sw_if_index,
1531 'is_inside': is_inside,
1532 'is_add': is_add})
1533
1534 def nat64_interface_dump(self):
1535 """Dump interfaces with NAT64 feature
1536 :return: Dictionary of interfaces with NAT64 feature
1537 """
1538 return self.api(self.papi.nat64_interface_dump, {})
1539
1540 def nat64_add_del_static_bib(
1541 self,
1542 in_ip,
1543 out_ip,
1544 in_port,
1545 out_port,
1546 protocol,
1547 vrf_id=0,
1548 is_add=1):
1549 """Add/delete S-NAT static BIB entry
1550
1551 :param in_ip: Inside IPv6 address
1552 :param out_ip: Outside IPv4 address
1553 :param in_port: Inside port number
1554 :param out_port: Outside port number
1555 :param protocol: IP protocol
1556 :param vrf_id: VRF ID (Default value = 0)
1557 :param is_add: 1 if add, 0 if delete (Default value = 1)
1558 """
1559 return self.api(
1560 self.papi.nat64_add_del_static_bib,
1561 {'i_addr': in_ip,
1562 'o_addr': out_ip,
1563 'i_port': in_port,
1564 'o_port': out_port,
1565 'vrf_id': vrf_id,
1566 'proto': protocol,
1567 'is_add': is_add})
1568
Matus Fabianab9a59c2017-08-16 05:37:36 -07001569 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001570 """Dump NAT64 BIB
1571
Matus Fabianab9a59c2017-08-16 05:37:36 -07001572 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001573 :returns: Dictionary of NAT64 BIB entries
1574 """
1575 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1576
1577 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1578 tcp_incoming_syn=6):
1579 """Set values of timeouts for NAT64 (in seconds)
1580
Matus Fabian428dc912017-06-21 06:15:18 -07001581 :param udpi: UDP timeout (Default value = 300)
1582 :param icmp: ICMP timeout (Default value = 60)
1583 :param tcp_trans: TCP transitory timeout (Default value = 240)
1584 :param tcp_est: TCP established timeout (Default value = 7440)
1585 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001586 """
1587 return self.api(
1588 self.papi.nat64_set_timeouts,
1589 {'udp': udp,
1590 'icmp': icmp,
1591 'tcp_trans': tcp_trans,
1592 'tcp_est': tcp_est,
1593 'tcp_incoming_syn': tcp_incoming_syn})
1594
1595 def nat64_get_timeouts(self):
1596 """Get values of timeouts for NAT64
1597
1598 :return: Timeouts for NAT64 (in seconds)
1599 """
1600 return self.api(self.papi.nat64_get_timeouts, {})
1601
Matus Fabianab9a59c2017-08-16 05:37:36 -07001602 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001603 """Dump NAT64 session table
1604
Matus Fabianab9a59c2017-08-16 05:37:36 -07001605 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001606 :returns: Dictionary of NAT64 sesstion table entries
1607 """
1608 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1609
Matus Fabian428dc912017-06-21 06:15:18 -07001610 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1611 """Add/del NAT64 prefix
1612
1613 :param prefix: NAT64 prefix
1614 :param plen: NAT64 prefix length
1615 :param vrf_id: VRF id of tenant (Default 0)
1616 :param is_add: 1 if add, 0 if delete (Default value = 1)
1617 """
1618 return self.api(
1619 self.papi.nat64_add_del_prefix,
1620 {'prefix': prefix,
1621 'prefix_len': plen,
1622 'vrf_id': vrf_id,
1623 'is_add': is_add})
1624
1625 def nat64_prefix_dump(self):
1626 """Dump NAT64 prefix
1627
1628 :returns: Dictionary of NAT64 prefixes
1629 """
1630 return self.api(self.papi.nat64_prefix_dump, {})
1631
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001632 def control_ping(self):
1633 self.api(self.papi.control_ping)
1634
1635 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001636 detect_mult, local_addr, peer_addr, is_ipv6=0,
1637 bfd_key_id=None, conf_key_id=None):
1638 if bfd_key_id is None:
1639 return self.api(self.papi.bfd_udp_add,
1640 {
1641 'sw_if_index': sw_if_index,
1642 'desired_min_tx': desired_min_tx,
1643 'required_min_rx': required_min_rx,
1644 'local_addr': local_addr,
1645 'peer_addr': peer_addr,
1646 'is_ipv6': is_ipv6,
1647 'detect_mult': detect_mult,
1648 })
1649 else:
1650 return self.api(self.papi.bfd_udp_add,
1651 {
1652 'sw_if_index': sw_if_index,
1653 'desired_min_tx': desired_min_tx,
1654 'required_min_rx': required_min_rx,
1655 'local_addr': local_addr,
1656 'peer_addr': peer_addr,
1657 'is_ipv6': is_ipv6,
1658 'detect_mult': detect_mult,
1659 'is_authenticated': 1,
1660 'bfd_key_id': bfd_key_id,
1661 'conf_key_id': conf_key_id,
1662 })
1663
Klement Sekeraa57a9702017-02-02 06:58:07 +01001664 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1665 detect_mult, local_addr, peer_addr, is_ipv6=0):
1666 return self.api(self.papi.bfd_udp_mod,
1667 {
1668 'sw_if_index': sw_if_index,
1669 'desired_min_tx': desired_min_tx,
1670 'required_min_rx': required_min_rx,
1671 'local_addr': local_addr,
1672 'peer_addr': peer_addr,
1673 'is_ipv6': is_ipv6,
1674 'detect_mult': detect_mult,
1675 })
1676
Klement Sekerab17dd962017-01-09 07:43:48 +01001677 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1678 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1679 is_delayed=False):
1680 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001681 {
1682 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001683 'local_addr': local_addr,
1684 'peer_addr': peer_addr,
1685 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001686 'is_delayed': 1 if is_delayed else 0,
1687 'bfd_key_id': bfd_key_id,
1688 'conf_key_id': conf_key_id,
1689 })
1690
1691 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1692 is_ipv6=0, is_delayed=False):
1693 return self.api(self.papi.bfd_udp_auth_deactivate,
1694 {
1695 'sw_if_index': sw_if_index,
1696 'local_addr': local_addr,
1697 'peer_addr': peer_addr,
1698 'is_ipv6': is_ipv6,
1699 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001700 })
1701
1702 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1703 return self.api(self.papi.bfd_udp_del,
1704 {
1705 'sw_if_index': sw_if_index,
1706 'local_addr': local_addr,
1707 'peer_addr': peer_addr,
1708 'is_ipv6': is_ipv6,
1709 })
1710
1711 def bfd_udp_session_dump(self):
1712 return self.api(self.papi.bfd_udp_session_dump, {})
1713
Klement Sekerab17dd962017-01-09 07:43:48 +01001714 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1715 peer_addr, is_ipv6=0):
1716 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001717 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001718 'sw_if_index': sw_if_index,
1719 'local_addr': local_addr,
1720 'peer_addr': peer_addr,
1721 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001722 })
1723
1724 def want_bfd_events(self, enable_disable=1):
1725 return self.api(self.papi.want_bfd_events, {
1726 'enable_disable': enable_disable,
1727 'pid': os.getpid(),
1728 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001729
Klement Sekerab17dd962017-01-09 07:43:48 +01001730 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1731 return self.api(self.papi.bfd_auth_set_key, {
1732 'conf_key_id': conf_key_id,
1733 'auth_type': auth_type,
1734 'key': key,
1735 'key_len': len(key),
1736 })
1737
1738 def bfd_auth_del_key(self, conf_key_id):
1739 return self.api(self.papi.bfd_auth_del_key, {
1740 'conf_key_id': conf_key_id,
1741 })
1742
1743 def bfd_auth_keys_dump(self):
1744 return self.api(self.papi.bfd_auth_keys_dump, {})
1745
Klement Sekera239790f2017-02-16 10:53:53 +01001746 def bfd_udp_set_echo_source(self, sw_if_index):
1747 return self.api(self.papi.bfd_udp_set_echo_source,
1748 {'sw_if_index': sw_if_index})
1749
Klement Sekera73884482017-02-23 09:26:30 +01001750 def bfd_udp_del_echo_source(self):
1751 return self.api(self.papi.bfd_udp_del_echo_source, {})
1752
Steve Shin7957d6e2016-12-19 09:24:50 -08001753 def classify_add_del_table(
1754 self,
1755 is_add,
1756 mask,
1757 match_n_vectors=1,
1758 table_index=0xFFFFFFFF,
1759 nbuckets=2,
1760 memory_size=2097152,
1761 skip_n_vectors=0,
1762 next_table_index=0xFFFFFFFF,
1763 miss_next_index=0xFFFFFFFF,
1764 current_data_flag=0,
1765 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001766 """
1767 :param is_add:
1768 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001769 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001770 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001771 :param nbuckets: (Default value = 2)
1772 :param memory_size: (Default value = 2097152)
1773 :param skip_n_vectors: (Default value = 0)
1774 :param next_table_index: (Default value = 0xFFFFFFFF)
1775 :param miss_next_index: (Default value = 0xFFFFFFFF)
1776 :param current_data_flag: (Default value = 0)
1777 :param current_data_offset: (Default value = 0)
1778 """
1779
1780 return self.api(
1781 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001782 {'is_add': is_add,
1783 'table_index': table_index,
1784 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001785 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001786 'skip_n_vectors': skip_n_vectors,
1787 'match_n_vectors': match_n_vectors,
1788 'next_table_index': next_table_index,
1789 'miss_next_index': miss_next_index,
1790 'current_data_flag': current_data_flag,
1791 'current_data_offset': current_data_offset,
1792 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001793
1794 def classify_add_del_session(
1795 self,
1796 is_add,
1797 table_index,
1798 match,
1799 opaque_index=0xFFFFFFFF,
1800 hit_next_index=0xFFFFFFFF,
1801 advance=0,
1802 action=0,
1803 metadata=0):
1804 """
1805 :param is_add:
1806 :param table_index:
1807 :param match:
1808 :param opaque_index: (Default value = 0xFFFFFFFF)
1809 :param hit_next_index: (Default value = 0xFFFFFFFF)
1810 :param advance: (Default value = 0)
1811 :param action: (Default value = 0)
1812 :param metadata: (Default value = 0)
1813 """
1814
1815 return self.api(
1816 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001817 {'is_add': is_add,
1818 'table_index': table_index,
1819 'hit_next_index': hit_next_index,
1820 'opaque_index': opaque_index,
1821 'advance': advance,
1822 'action': action,
1823 'metadata': metadata,
1824 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001825
1826 def input_acl_set_interface(
1827 self,
1828 is_add,
1829 sw_if_index,
1830 ip4_table_index=0xFFFFFFFF,
1831 ip6_table_index=0xFFFFFFFF,
1832 l2_table_index=0xFFFFFFFF):
1833 """
1834 :param is_add:
1835 :param sw_if_index:
1836 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1837 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1838 :param l2_table_index: (Default value = 0xFFFFFFFF)
1839 """
1840
1841 return self.api(
1842 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001843 {'sw_if_index': sw_if_index,
1844 'ip4_table_index': ip4_table_index,
1845 'ip6_table_index': ip6_table_index,
1846 'l2_table_index': l2_table_index,
1847 'is_add': is_add})
1848
1849 def set_ipfix_exporter(
1850 self,
1851 collector_address,
1852 src_address,
1853 path_mtu,
1854 template_interval,
1855 vrf_id=0,
1856 collector_port=4739,
1857 udp_checksum=0):
1858 return self.api(
1859 self.papi.set_ipfix_exporter,
1860 {
1861 'collector_address': collector_address,
1862 'collector_port': collector_port,
1863 'src_address': src_address,
1864 'vrf_id': vrf_id,
1865 'path_mtu': path_mtu,
1866 'template_interval': template_interval,
1867 'udp_checksum': udp_checksum,
1868 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001869
1870 def dhcp_proxy_config(self,
1871 dhcp_server,
1872 dhcp_src_address,
1873 rx_table_id=0,
1874 server_table_id=0,
1875 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001876 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001877 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001878 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001879 {
1880 'rx_vrf_id': rx_table_id,
1881 'server_vrf_id': server_table_id,
1882 'is_ipv6': is_ipv6,
1883 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001884 'dhcp_server': dhcp_server,
1885 'dhcp_src_address': dhcp_src_address,
1886 })
1887
1888 def dhcp_proxy_set_vss(self,
1889 table_id,
1890 fib_id,
1891 oui,
1892 is_add=1,
1893 is_ip6=0):
1894 return self.api(
1895 self.papi.dhcp_proxy_set_vss,
1896 {
1897 'tbl_id': table_id,
1898 'fib_id': fib_id,
1899 'is_ipv6': is_ip6,
1900 'is_add': is_add,
1901 'oui': oui,
1902 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001903
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001904 def dhcp_client(self,
1905 sw_if_index,
1906 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001907 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001908 is_add=1,
1909 want_dhcp_events=0):
1910 return self.api(
1911 self.papi.dhcp_client_config,
1912 {
1913 'sw_if_index': sw_if_index,
1914 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001915 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001916 'is_add': is_add,
1917 'want_dhcp_event': want_dhcp_events,
1918 'pid': os.getpid(),
1919 })
1920
Neale Ranns32e1c012016-11-22 17:07:28 +00001921 def ip_mroute_add_del(self,
1922 src_address,
1923 grp_address,
1924 grp_address_length,
1925 e_flags,
1926 next_hop_sw_if_index,
1927 i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001928 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001929 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001930 is_add=1,
1931 is_ipv6=0,
1932 is_local=0):
1933 """
1934 """
1935 return self.api(
1936 self.papi.ip_mroute_add_del,
1937 {'next_hop_sw_if_index': next_hop_sw_if_index,
1938 'entry_flags': e_flags,
1939 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001940 'table_id': table_id,
1941 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001942 'is_add': is_add,
1943 'is_ipv6': is_ipv6,
1944 'is_local': is_local,
1945 'grp_address_length': grp_address_length,
1946 'grp_address': grp_address,
1947 'src_address': src_address})
1948
1949 def mfib_signal_dump(self):
1950 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001951
1952 def ip_mfib_dump(self):
1953 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001954
1955 def lisp_enable_disable(self, is_enabled):
1956 return self.api(
1957 self.papi.lisp_enable_disable,
1958 {
1959 'is_en': is_enabled,
1960 })
1961
1962 def lisp_locator_set(self,
1963 ls_name,
1964 is_add=1):
1965 return self.api(
1966 self.papi.lisp_add_del_locator_set,
1967 {
1968 'is_add': is_add,
1969 'locator_set_name': ls_name
1970 })
1971
1972 def lisp_locator_set_dump(self):
1973 return self.api(self.papi.lisp_locator_set_dump, {})
1974
1975 def lisp_locator(self,
1976 ls_name,
1977 sw_if_index,
1978 priority=1,
1979 weight=1,
1980 is_add=1):
1981 return self.api(
1982 self.papi.lisp_add_del_locator,
1983 {
1984 'is_add': is_add,
1985 'locator_set_name': ls_name,
1986 'sw_if_index': sw_if_index,
1987 'priority': priority,
1988 'weight': weight
1989 })
1990
1991 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1992 return self.api(
1993 self.papi.lisp_locator_dump,
1994 {
1995 'is_index_set': is_index_set,
1996 'ls_name': ls_name,
1997 'ls_index': ls_index,
1998 })
1999
2000 def lisp_local_mapping(self,
2001 ls_name,
2002 eid_type,
2003 eid,
2004 prefix_len,
2005 vni=0,
2006 key_id=0,
2007 key="",
2008 is_add=1):
2009 return self.api(
2010 self.papi.lisp_add_del_local_eid,
2011 {
2012 'locator_set_name': ls_name,
2013 'is_add': is_add,
2014 'eid_type': eid_type,
2015 'eid': eid,
2016 'prefix_len': prefix_len,
2017 'vni': vni,
2018 'key_id': key_id,
2019 'key': key
2020 })
2021
2022 def lisp_eid_table_dump(self,
2023 eid_set=0,
2024 prefix_length=0,
2025 vni=0,
2026 eid_type=0,
2027 eid=None,
2028 filter_opt=0):
2029 return self.api(
2030 self.papi.lisp_eid_table_dump,
2031 {
2032 'eid_set': eid_set,
2033 'prefix_length': prefix_length,
2034 'vni': vni,
2035 'eid_type': eid_type,
2036 'eid': eid,
2037 'filter': filter_opt,
2038 })
2039
2040 def lisp_remote_mapping(self,
2041 eid_type,
2042 eid,
2043 eid_prefix_len=0,
2044 vni=0,
2045 rlocs=None,
2046 rlocs_num=0,
2047 is_src_dst=0,
2048 is_add=1):
2049 return self.api(
2050 self.papi.lisp_add_del_remote_mapping,
2051 {
2052 'is_add': is_add,
2053 'eid_type': eid_type,
2054 'eid': eid,
2055 'eid_len': eid_prefix_len,
2056 'rloc_num': rlocs_num,
2057 'rlocs': rlocs,
2058 'vni': vni,
2059 'is_src_dst': is_src_dst,
2060 })
2061
2062 def lisp_adjacency(self,
2063 leid,
2064 reid,
2065 leid_len,
2066 reid_len,
2067 eid_type,
2068 is_add=1,
2069 vni=0):
2070 return self.api(
2071 self.papi.lisp_add_del_adjacency,
2072 {
2073 'is_add': is_add,
2074 'vni': vni,
2075 'eid_type': eid_type,
2076 'leid': leid,
2077 'reid': reid,
2078 'leid_len': leid_len,
2079 'reid_len': reid_len,
2080 })
2081
2082 def lisp_adjacencies_get(self, vni=0):
2083 return self.api(
2084 self.papi.lisp_adjacencies_get,
2085 {
2086 'vni': vni
2087 })
Neale Ranns80823802017-02-20 18:23:41 -08002088
2089 def map_add_domain(self,
2090 ip6_prefix,
2091 ip6_prefix_len,
2092 ip6_src,
2093 ip6_src_prefix_len,
2094 ip4_prefix,
2095 ip4_prefix_len,
2096 ea_bits_len=0,
2097 psid_offset=0,
2098 psid_length=0,
2099 is_translation=0,
2100 mtu=1280):
2101 return self.api(
2102 self.papi.map_add_domain,
2103 {
2104 'ip6_prefix': ip6_prefix,
2105 'ip6_prefix_len': ip6_prefix_len,
2106 'ip4_prefix': ip4_prefix,
2107 'ip4_prefix_len': ip4_prefix_len,
2108 'ip6_src': ip6_src,
2109 'ip6_src_prefix_len': ip6_src_prefix_len,
2110 'ea_bits_len': ea_bits_len,
2111 'psid_offset': psid_offset,
2112 'psid_length': psid_length,
2113 'is_translation': is_translation,
2114 'mtu': mtu
2115 })
Hongjun Nief486b12017-04-12 19:21:16 +08002116
2117 def gtpu_add_del_tunnel(
2118 self,
2119 src_addr,
2120 dst_addr,
2121 is_add=1,
2122 is_ipv6=0,
2123 mcast_sw_if_index=0xFFFFFFFF,
2124 encap_vrf_id=0,
2125 decap_next_index=0xFFFFFFFF,
2126 teid=0):
2127 """
2128
2129 :param is_add: (Default value = 1)
2130 :param is_ipv6: (Default value = 0)
2131 :param src_addr:
2132 :param dst_addr:
2133 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2134 :param encap_vrf_id: (Default value = 0)
2135 :param decap_next_index: (Default value = 0xFFFFFFFF)
2136 :param teid: (Default value = 0)
2137
2138 """
2139 return self.api(self.papi.gtpu_add_del_tunnel,
2140 {'is_add': is_add,
2141 'is_ipv6': is_ipv6,
2142 'src_address': src_addr,
2143 'dst_address': dst_addr,
2144 'mcast_sw_if_index': mcast_sw_if_index,
2145 'encap_vrf_id': encap_vrf_id,
2146 'decap_next_index': decap_next_index,
2147 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002148
2149 def vxlan_gpe_add_del_tunnel(
2150 self,
2151 src_addr,
2152 dst_addr,
2153 mcast_sw_if_index=0xFFFFFFFF,
2154 is_add=1,
2155 is_ipv6=0,
2156 encap_vrf_id=0,
2157 decap_vrf_id=0,
2158 protocol=3,
2159 vni=0):
2160 """
2161
2162 :param local:
2163 :param remote:
2164 :param is_add: (Default value = 1)
2165 :param is_ipv6: (Default value = 0)
2166 :param encap_vrf_id: (Default value = 0)
2167 :param decap_vrf_id: (Default value = 0)
2168 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2169 :param protocol: (Default value = 3)
2170 :param vni: (Default value = 0)
2171
2172 """
2173 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2174 {'is_add': is_add,
2175 'is_ipv6': is_ipv6,
2176 'local': src_addr,
2177 'remote': dst_addr,
2178 'mcast_sw_if_index': mcast_sw_if_index,
2179 'encap_vrf_id': encap_vrf_id,
2180 'decap_vrf_id': decap_vrf_id,
2181 'protocol': protocol,
2182 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002183
2184 def pppoe_add_del_session(
2185 self,
2186 client_ip,
2187 client_mac,
2188 session_id=0,
2189 is_add=1,
2190 is_ipv6=0,
2191 decap_vrf_id=0):
2192 """
2193
2194 :param is_add: (Default value = 1)
2195 :param is_ipv6: (Default value = 0)
2196 :param client_ip:
2197 :param session_id: (Default value = 0)
2198 :param client_mac:
2199 :param decap_vrf_id: (Default value = 0)
2200
2201 """
2202 return self.api(self.papi.pppoe_add_del_session,
2203 {'is_add': is_add,
2204 'is_ipv6': is_ipv6,
2205 'session_id': session_id,
2206 'client_ip': client_ip,
2207 'decap_vrf_id': decap_vrf_id,
2208 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002209
2210 def sr_localsid_add_del(self,
2211 localsid_addr,
2212 behavior,
2213 nh_addr,
2214 is_del=0,
2215 end_psp=0,
2216 sw_if_index=0xFFFFFFFF,
2217 vlan_index=0,
2218 fib_table=0,
2219 ):
2220 """ Add/del IPv6 SR local-SID.
2221
2222 :param localsid_addr:
2223 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2224 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2225 :param nh_addr:
2226 :param is_del: (Default value = 0)
2227 :param end_psp: (Default value = 0)
2228 :param sw_if_index: (Default value = 0xFFFFFFFF)
2229 :param vlan_index: (Default value = 0)
2230 :param fib_table: (Default value = 0)
2231 """
2232 return self.api(
2233 self.papi.sr_localsid_add_del,
2234 {'is_del': is_del,
2235 'localsid_addr': localsid_addr,
2236 'end_psp': end_psp,
2237 'behavior': behavior,
2238 'sw_if_index': sw_if_index,
2239 'vlan_index': vlan_index,
2240 'fib_table': fib_table,
2241 'nh_addr': nh_addr
2242 }
2243 )
2244
2245 def sr_policy_add(
2246 self,
2247 bsid_addr,
2248 weight=1,
2249 is_encap=1,
2250 type=0,
2251 fib_table=0,
2252 n_segments=0,
2253 segments=[]):
2254 """
2255 :param bsid_addr: bindingSID of the SR Policy
2256 :param weight: weight of the sid list. optional. (default: 1)
2257 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2258 (default: Encap)
2259 :param type: type/behavior of the SR policy. (default or spray) \
2260 (default: default)
2261 :param fib_table: VRF where to install the FIB entry for the BSID \
2262 (default: 0)
2263 :param n_segments: number of segments \
2264 (default: 0)
2265 :param segments: a vector of IPv6 address composing the segment list \
2266 (default: [])
2267 """
2268 return self.api(
2269 self.papi.sr_policy_add,
2270 {'bsid_addr': bsid_addr,
2271 'weight': weight,
2272 'is_encap': is_encap,
2273 'type': type,
2274 'fib_table': fib_table,
2275 'n_segments': n_segments,
2276 'segments': segments
2277 }
2278 )
2279
2280 def sr_policy_del(
2281 self,
2282 bsid_addr,
2283 sr_policy_index=0):
2284 """
2285 :param bsid: bindingSID of the SR Policy
2286 :param sr_policy_index: index of the sr policy (default: 0)
2287 """
2288 return self.api(
2289 self.papi.sr_policy_del,
2290 {'bsid_addr': bsid_addr,
2291 'sr_policy_index': sr_policy_index
2292 })
2293
2294 def sr_steering_add_del(
2295 self,
2296 is_del,
2297 bsid_addr,
2298 sr_policy_index,
2299 table_id,
2300 prefix_addr,
2301 mask_width,
2302 sw_if_index,
2303 traffic_type):
2304 """
2305 Steer traffic L2 and L3 traffic through a given SR policy
2306
2307 :param is_del: delete or add
2308 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2309 :param sr_policy: is the index of the SR Policy (alt to bsid)
2310 :param table_id: is the VRF where to install the FIB entry for the BSID
2311 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2312 :param mask_width: is the mask for L3 traffic type
2313 :param sw_if_index: is the incoming interface for L2 traffic
2314 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2315 """
2316 return self.api(
2317 self.papi.sr_steering_add_del,
2318 {'is_del': is_del,
2319 'bsid_addr': bsid_addr,
2320 'sr_policy_index': sr_policy_index,
2321 'table_id': table_id,
2322 'prefix_addr': prefix_addr,
2323 'mask_width': mask_width,
2324 'sw_if_index': sw_if_index,
2325 'traffic_type': traffic_type
2326 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002327
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002328 def acl_add_replace(self, acl_index, r, tag='',
2329 expected_retval=0):
2330 """Add/replace an ACL
2331 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2332 :param acl_rule r: ACL rules array.
2333 :param str tag: symbolic tag (description) for this ACL.
2334 :param int count: number of rules.
2335 """
2336 return self.api(self.papi.acl_add_replace,
2337 {'acl_index': acl_index,
2338 'r': r,
2339 'count': len(r),
2340 'tag': tag},
2341 expected_retval=expected_retval)
2342
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002343 def acl_del(self, acl_index, expected_retval=0):
2344 """
2345
2346 :param acl_index:
2347 :return:
2348 """
2349 return self.api(self.papi.acl_del,
2350 {'acl_index': acl_index},
2351 expected_retval=expected_retval)
2352
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002353 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2354 expected_retval=0):
2355 return self.api(self.papi.acl_interface_set_acl_list,
2356 {'sw_if_index': sw_if_index,
2357 'count': len(acls),
2358 'n_input': n_input,
2359 'acls': acls},
2360 expected_retval=expected_retval)
2361
2362 def acl_dump(self, acl_index, expected_retval=0):
2363 return self.api(self.papi.acl_dump,
2364 {'acl_index': acl_index},
2365 expected_retval=expected_retval)
2366
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002367 def macip_acl_add(self, rules, tag=""):
2368 """ Add MACIP acl
2369
2370 :param rules: list of rules for given acl
2371 :param tag: acl tag
2372 """
2373
2374 return self.api(self.papi.macip_acl_add,
2375 {'r': rules,
2376 'count': len(rules),
2377 'tag': tag})
2378
Pavel Kotucek932f7412017-09-07 14:44:52 +02002379 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2380 """ Add MACIP acl
2381
2382 :param rules: list of rules for given acl
2383 :param tag: acl tag
2384 """
2385
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002386 return self.api(self.papi.macip_acl_add_replace,
2387 {'acl_index': acl_index,
2388 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002389 'count': len(rules),
2390 'tag': tag})
2391
2392 def macip_acl_del(self, acl_index):
2393 """
2394
2395 :param acl_index:
2396 :return:
2397 """
2398 return self.api(self.papi.macip_acl_del,
2399 {'acl_index': acl_index})
2400
2401 def macip_acl_interface_add_del(self,
2402 sw_if_index,
2403 acl_index,
2404 is_add=1):
2405 """ Add MACIP acl to interface
2406
2407 :param sw_if_index:
2408 :param acl_index:
2409 :param is_add: (Default value = 1)
2410 """
2411
2412 return self.api(self.papi.macip_acl_interface_add_del,
2413 {'is_add': is_add,
2414 'sw_if_index': sw_if_index,
2415 'acl_index': acl_index})
2416
2417 def macip_acl_interface_get(self):
2418 """ Return interface acls dump
2419 """
2420 return self.api(
2421 self.papi.macip_acl_interface_get, {})
2422
2423 def macip_acl_dump(self, acl_index=4294967295):
2424 """ Return MACIP acl dump
2425 """
2426
2427 return self.api(
2428 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002429
2430 def policer_add_del(self,
2431 name,
2432 cir,
2433 eir,
2434 cb,
2435 eb,
2436 is_add=1,
2437 rate_type=0,
2438 round_type=0,
2439 ptype=0,
2440 color_aware=0,
2441 conform_action_type=1,
2442 conform_dscp=0,
2443 exceed_action_type=0,
2444 exceed_dscp=0,
2445 violate_action_type=0,
2446 violate_dscp=0):
2447 return self.api(self.papi.policer_add_del,
2448 {'name': name,
2449 'cir': cir,
2450 'eir': eir,
2451 'cb': cb,
2452 'eb': eb,
2453 'is_add': is_add,
2454 'rate_type': rate_type,
2455 'round_type': round_type,
2456 'type': ptype,
2457 'color_aware': color_aware,
2458 'conform_action_type': conform_action_type,
2459 'conform_dscp': conform_dscp,
2460 'exceed_action_type': exceed_action_type,
2461 'exceed_dscp': exceed_dscp,
2462 'violate_action_type': violate_action_type,
2463 'violate_dscp': violate_dscp})
2464
2465 def ip_punt_police(self,
2466 policer_index,
2467 is_ip6=0,
2468 is_add=1):
2469 return self.api(self.papi.ip_punt_police,
2470 {'policer_index': policer_index,
2471 'is_add': is_add,
2472 'is_ip6': is_ip6})
2473
2474 def ip_punt_redirect(self,
2475 rx_sw_if_index,
2476 tx_sw_if_index,
2477 nh,
2478 is_ip6=0,
2479 is_add=1):
2480 return self.api(self.papi.ip_punt_redirect,
2481 {'rx_sw_if_index': rx_sw_if_index,
2482 'tx_sw_if_index': tx_sw_if_index,
2483 'nh': nh,
2484 'is_add': is_add,
2485 'is_ip6': is_ip6})