blob: b63a26583da8d339236501ff50b89e4734d19e7f [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:
104 self.test_class.logger.debug("Expecting event within %ss",
105 timeout)
106 else:
107 self.test_class.logger.debug("Expecting event '%s' within %ss",
108 name, timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100109 if self._events:
110 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200111 limit = time.time() + timeout
112 while time.time() < limit:
113 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100114 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200115 if name and type(e).__name__ != name:
116 raise Exception(
117 "Unexpected event received: %s, expected: %s" %
118 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100119 self.test_class.logger.debug("Returning event %s:%s" %
120 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200121 return e
122 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200123 raise Exception("Event did not occur within timeout")
124
125 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200127 # FIXME use the name instead of relying on type(e).__name__ ?
128 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100129 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200130 self._events.append(event)
131
Klement Sekeraf62ae122016-10-11 11:47:09 +0200132 def connect(self):
133 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100134 self.vpp.connect(self.name, self.shm_prefix)
135 self.papi = self.vpp.api
136 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200137
138 def disconnect(self):
139 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100140 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200141
142 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200144 Call the appropriate hooks before and after the API call
145
146 :param api_fn: API function to call
147 :param api_args: tuple of API function arguments
148 :param expected_retval: Expected return value (Default value = 0)
149 :returns: reply from the API
150
151 """
152 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100153 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100154 if self._expect_api_retval == self._negative:
155 if hasattr(reply, 'retval') and reply.retval >= 0:
156 msg = "API call passed unexpectedly: expected negative "\
157 "return value instead of %d in %s" % \
158 (reply.retval, repr(reply))
159 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100160 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100161 elif self._expect_api_retval == self._zero:
162 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700163 msg = "API call failed, expected %d return value instead "\
164 "of %d in %s" % (expected_retval, reply.retval,
165 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100166 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100167 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100168 else:
169 raise Exception("Internal error, unexpected value for "
170 "self._expect_api_retval %s" %
171 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200172 self.hook.after_api(api_fn.__name__, api_args)
173 return reply
174
175 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100176 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200177
178 :param cli: CLI to execute
179 :returns: CLI output
180
181 """
182 self.hook.before_cli(cli)
183 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100184 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200185 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200186 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100187 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188
Jan49c0fca2016-10-26 15:44:27 +0200189 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100190 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200191
192 :param cli: CLI to execute
193 :returns: CLI output
194 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600195 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200196
Jan4af521d2016-11-15 17:05:00 +0100197 def _convert_mac(self, mac):
198 return int(mac.replace(":", ""), 16) << 16
199
Klement Sekeraf62ae122016-10-11 11:47:09 +0200200 def show_version(self):
201 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100202 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203
204 def pg_create_interface(self, pg_index):
205 """
206
207 :param pg_index:
208
209 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100210 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200211 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212
213 def sw_interface_dump(self, filter=None):
214 """
215
216 :param filter: (Default value = None)
217
218 """
219 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100222 args = {}
223 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200224
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000225 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100226 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000227
228 :param sw_if_index:
229 :param is_ipv6:
230 :param table_id:
231
232 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100233 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
235 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000236
Klement Sekeraf62ae122016-10-11 11:47:09 +0200237 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
238 is_ipv6=0, is_add=1, del_all=0):
239 """
240
241 :param addr: param is_ipv6: (Default value = 0)
242 :param sw_if_index:
243 :param addr_len:
244 :param is_ipv6: (Default value = 0)
245 :param is_add: (Default value = 1)
246 :param del_all: (Default value = 0)
247
248 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100249 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200250 {'sw_if_index': sw_if_index,
251 'is_add': is_add,
252 'is_ipv6': is_ipv6,
253 'del_all': del_all,
254 'address_length': addr_len,
255 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200256
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800257 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
258 is_add=1):
259 """ Set the Interface to be unnumbered
260
261 :param is_add: (Default value = 1)
262 :param sw_if_index - interface That will be unnumbered
263 :param ip_sw_if_index - interface with an IP addres
264
265 """
266 return self.api(self.papi.sw_interface_set_unnumbered,
267 {'sw_if_index': ip_sw_if_index,
268 'unnumbered_sw_if_index': sw_if_index,
269 'is_add': is_add})
270
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000271 def sw_interface_enable_disable_mpls(self, sw_if_index,
272 is_enable=1):
273 """
274 Enable/Disable MPLS on the interface
275 :param sw_if_index:
276 :param is_enable: (Default value = 1)
277
278 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100279 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200280 {'sw_if_index': sw_if_index,
281 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000282
Jan Gelety057bb8c2016-12-20 17:32:45 +0100283 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100284 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100285 {'sw_if_index': sw_if_index,
286 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200287
Neale Ranns227038a2017-04-21 01:07:59 -0700288 def set_ip_flow_hash(self,
289 table_id,
290 src=1,
291 dst=1,
292 sport=1,
293 dport=1,
294 proto=1,
295 reverse=0,
296 is_ip6=0):
297 return self.api(self.papi.set_ip_flow_hash,
298 {'vrf_id': table_id,
299 'src': src,
300 'dst': dst,
301 'dport': dport,
302 'sport': sport,
303 'proto': proto,
304 'reverse': reverse,
305 'is_ipv6': is_ip6})
306
Neale Ranns3f844d02017-02-18 00:03:54 -0800307 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
308 return self.api(self.papi.ip6nd_proxy_add_del,
309 {'address': address,
310 'sw_if_index': sw_if_index,
311 'is_del': is_del})
312
Neale Ranns75152282017-01-09 01:00:45 -0800313 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000314 no,
Neale Ranns75152282017-01-09 01:00:45 -0800315 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000316 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800317 return self.api(self.papi.sw_interface_ip6nd_ra_config,
318 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000319 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100320 'suppress': suppress,
321 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800322
Neale Ranns87df12d2017-02-18 08:16:41 -0800323 def ip6_sw_interface_ra_prefix(self,
324 sw_if_index,
325 address,
326 address_length,
327 use_default=0,
328 no_advertise=0,
329 off_link=0,
330 no_autoconfig=0,
331 no_onlink=0,
332 is_no=0,
333 val_lifetime=0xffffffff,
334 pref_lifetime=0xffffffff):
335 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
336 {'sw_if_index': sw_if_index,
337 'address': address,
338 'address_length': address_length,
339 'use_default': use_default,
340 'no_advertise': no_advertise,
341 'off_link': off_link,
342 'no_autoconfig': no_autoconfig,
343 'no_onlink': no_onlink,
344 'is_no': is_no,
345 'val_lifetime': val_lifetime,
346 'pref_lifetime': pref_lifetime})
347
Neale Ranns75152282017-01-09 01:00:45 -0800348 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
349 """
350 Enable/Disable An interface for IPv6
351 """
352 return self.api(self.papi.sw_interface_ip6_enable_disable,
353 {'sw_if_index': sw_if_index,
354 'enable': enable})
355
Klement Sekeraf62ae122016-10-11 11:47:09 +0200356 def vxlan_add_del_tunnel(
357 self,
358 src_addr,
359 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200360 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200361 is_add=1,
362 is_ipv6=0,
363 encap_vrf_id=0,
364 decap_next_index=0xFFFFFFFF,
365 vni=0):
366 """
367
368 :param dst_addr:
369 :param src_addr:
370 :param is_add: (Default value = 1)
371 :param is_ipv6: (Default value = 0)
372 :param encap_vrf_id: (Default value = 0)
373 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200374 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200375 :param vni: (Default value = 0)
376
377 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100378 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200379 {'is_add': is_add,
380 'is_ipv6': is_ipv6,
381 'src_address': src_addr,
382 'dst_address': dst_addr,
383 'mcast_sw_if_index': mcast_sw_if_index,
384 'encap_vrf_id': encap_vrf_id,
385 'decap_next_index': decap_next_index,
386 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387
Jan4af521d2016-11-15 17:05:00 +0100388 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
389 learn=1, arp_term=0, is_add=1):
390 """Create/delete bridge domain.
391
392 :param int bd_id: Bridge domain index.
393 :param int flood: Enable/disable bcast/mcast flooding in the BD.
394 (Default value = 1)
395 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
396 (Default value = 1)
397 :param int forward: Enable/disable forwarding on all interfaces in
398 the BD. (Default value = 1)
399 :param int learn: Enable/disable learning on all interfaces in the BD.
400 (Default value = 1)
401 :param int arp_term: Enable/disable arp termination in the BD.
402 (Default value = 1)
403 :param int is_add: Add or delete flag. (Default value = 1)
404 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100405 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200406 {'bd_id': bd_id,
407 'flood': flood,
408 'uu_flood': uu_flood,
409 'forward': forward,
410 'learn': learn,
411 'arp_term': arp_term,
412 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100413
Eyal Baric86e5922017-07-02 18:33:16 +0300414 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
415 return self.api(self.papi.bd_ip_mac_add_del,
416 {'bd_id': bd_id,
417 'is_add': is_add,
418 'is_ipv6': is_ipv6,
419 'ip_address': ip,
420 'mac_address': mac})
421
Jan4af521d2016-11-15 17:05:00 +0100422 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
423 filter_mac=0, bvi_mac=0):
424 """Create/delete L2 FIB entry.
425
426 :param str mac: MAC address to create FIB entry for.
427 :param int bd_id: Bridge domain index.
428 :param int sw_if_index: Software interface index of the interface.
429 :param int is_add: Add or delete flag. (Default value = 1)
430 :param int static_mac: Set to 1 to create static MAC entry.
431 (Default value = 0)
432 :param int filter_mac: Set to 1 to drop packet that's source or
433 destination MAC address contains defined MAC address.
434 (Default value = 0)
435 :param int bvi_mac: Set to 1 to create entry that points to BVI
436 interface. (Default value = 0)
437 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100438 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200439 {'mac': self._convert_mac(mac),
440 'bd_id': bd_id,
441 'sw_if_index': sw_if_index,
442 'is_add': is_add,
443 'static_mac': static_mac,
444 'filter_mac': filter_mac,
445 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100446
Eyal Bari93b503e2017-05-15 10:13:15 +0300447 def l2fib_flush_int(self, sw_if_index):
448 """Flush L2 FIB entries for sw_if_index.
449
450 :param int sw_if_index: Software interface index of the interface.
451 """
452 return self.api(self.papi.l2fib_flush_int,
453 {'sw_if_index': sw_if_index})
454
455 def l2fib_flush_bd(self, bd_id):
456 """Flush L2 FIB entries for bd_id.
457
458 :param int sw_if_index: Bridge Domain id.
459 """
460 return self.api(self.papi.l2fib_flush_bd,
461 {'bd_id': bd_id})
462
463 def l2fib_flush_all(self):
464 """Flush all L2 FIB.
465 """
466 return self.api(self.papi.l2fib_flush_all, {})
467
Klement Sekeraf62ae122016-10-11 11:47:09 +0200468 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
469 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100470 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200471
Jan4af521d2016-11-15 17:05:00 +0100472 :param int sw_if_index: Software interface index of the interface.
473 :param int bd_id: Bridge domain index.
474 :param int shg: Split-horizon group index. (Default value = 0)
475 :param int bvi: Set interface as a bridge group virtual interface.
476 (Default value = 0)
477 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200478 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100479 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200480 {'rx_sw_if_index': sw_if_index,
481 'bd_id': bd_id,
482 'shg': shg,
483 'bvi': bvi,
484 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200485
Jan00dad122016-11-29 10:04:53 +0100486 def bridge_flags(self, bd_id, is_set, feature_bitmap):
487 """Enable/disable required feature of the bridge domain with defined ID.
488
489 :param int bd_id: Bridge domain ID.
490 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
491 :param int feature_bitmap: Bitmap value of the feature to be set:
492 - learn (1 << 0),
493 - forward (1 << 1),
494 - flood (1 << 2),
495 - uu-flood (1 << 3) or
496 - arp-term (1 << 4).
497 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100498 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200499 {'bd_id': bd_id,
500 'is_set': is_set,
501 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100502
503 def bridge_domain_dump(self, bd_id=0):
504 """
505
506 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
507 existing bridge domains returned)
508 :return: Dictionary of bridge domain(s) data.
509 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100510 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200511 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100512
Klement Sekeraf62ae122016-10-11 11:47:09 +0200513 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
514 enable):
515 """Create or delete unidirectional cross-connect from Tx interface to
516 Rx interface.
517
Jan4af521d2016-11-15 17:05:00 +0100518 :param int rx_sw_if_index: Software interface index of Rx interface.
519 :param int tx_sw_if_index: Software interface index of Tx interface.
520 :param int enable: Create cross-connect if equal to 1, delete
521 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200522
523 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100524 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200525 {'rx_sw_if_index': rx_sw_if_index,
526 'tx_sw_if_index': tx_sw_if_index,
527 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200528
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200529 def sw_interface_set_l2_tag_rewrite(
530 self,
531 sw_if_index,
532 vtr_oper,
533 push=0,
534 tag1=0,
535 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000536 """L2 interface vlan tag rewrite configure request
537 :param client_index - opaque cookie to identify the sender
538 :param context - sender context, to match reply w/ request
539 :param sw_if_index - interface the operation is applied to
540 :param vtr_op - Choose from l2_vtr_op_t enum values
541 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
542 :param tag1 - Needed for any push or translate vtr op
543 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
544
545 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100546 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200547 {'sw_if_index': sw_if_index,
548 'vtr_op': vtr_oper,
549 'push_dot1q': push,
550 'tag1': tag1,
551 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000552
Neale Rannsa07bd702017-08-07 07:53:49 -0700553 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200554 """
555
556 :param admin_up_down:
557 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200558
559 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100560 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200561 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700562 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200563
564 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
565 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
566 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
567 """Create subinterface
568 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
569
570 :param sub_id: param inner_vlan:
571 :param sw_if_index:
572 :param outer_vlan:
573 :param inner_vlan:
574 :param no_tags: (Default value = 0)
575 :param one_tag: (Default value = 0)
576 :param two_tags: (Default value = 0)
577 :param dot1ad: (Default value = 0)
578 :param exact_match: (Default value = 0)
579 :param default_sub: (Default value = 0)
580 :param outer_vlan_id_any: (Default value = 0)
581 :param inner_vlan_id_any: (Default value = 0)
582
583 """
584 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100585 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200586 {'sw_if_index': sw_if_index,
587 'sub_id': sub_id,
588 'no_tags': no_tags,
589 'one_tag': one_tag,
590 'two_tags': two_tags,
591 'dot1ad': dot1ad,
592 'exact_match': exact_match,
593 'default_sub': default_sub,
594 'outer_vlan_id_any': outer_vlan_id_any,
595 'inner_vlan_id_any': inner_vlan_id_any,
596 'outer_vlan_id': outer_vlan,
597 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200598
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200599 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
600 """Create p2p ethernet subinterface
601
602 :param sw_if_index: main (parent) interface
603 :param remote_mac: client (remote) mac address
604
605 """
606 return self.api(
607 self.papi.p2p_ethernet_add,
608 {'parent_if_index': sw_if_index,
609 'remote_mac': remote_mac,
610 'subif_id': subif_id})
611
Neale Ranns177bbdc2016-11-15 09:46:51 +0000612 def delete_subif(self, sw_if_index):
613 """Delete subinterface
614
615 :param sw_if_index:
616 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100617 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200618 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000619
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200620 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
621 """Delete p2p ethernet subinterface
622
623 :param sw_if_index: main (parent) interface
624 :param remote_mac: client (remote) mac address
625
626 """
627 return self.api(
628 self.papi.p2p_ethernet_del,
629 {'parent_if_index': sw_if_index,
630 'remote_mac': remote_mac})
631
Klement Sekeraf62ae122016-10-11 11:47:09 +0200632 def create_vlan_subif(self, sw_if_index, vlan):
633 """
634
635 :param vlan:
636 :param sw_if_index:
637
638 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100639 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200640 {'sw_if_index': sw_if_index,
641 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200642
Matej Klotton0178d522016-11-04 11:11:44 +0100643 def create_loopback(self, mac=''):
644 """
645
646 :param mac: (Optional)
647 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100648 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200649 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100650
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100651 def delete_loopback(self, sw_if_index):
652 return self.api(self.papi.delete_loopback,
653 {'sw_if_index': sw_if_index, })
654
Neale Ranns15002542017-09-10 04:39:11 -0700655 def ip_table_add_del(self,
656 table_id,
657 is_add=1,
658 is_ipv6=0):
659 """
660
661 :param table_id
662 :param is_add: (Default value = 1)
663 :param is_ipv6: (Default value = 0)
664
665 """
666
667 return self.api(
668 self.papi.ip_table_add_del,
669 {'table_id': table_id,
670 'is_add': is_add,
671 'is_ipv6': is_ipv6})
672
Klement Sekeraf62ae122016-10-11 11:47:09 +0200673 def ip_add_del_route(
674 self,
675 dst_address,
676 dst_address_length,
677 next_hop_address,
678 next_hop_sw_if_index=0xFFFFFFFF,
679 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200680 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000681 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200682 next_hop_n_out_labels=0,
683 next_hop_out_label_stack=[],
684 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000685 is_resolve_host=0,
686 is_resolve_attached=0,
687 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200688 is_add=1,
689 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200690 is_unreach=0,
691 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200692 is_ipv6=0,
693 is_local=0,
694 is_classify=0,
695 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000696 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200697 """
698
699 :param dst_address_length:
700 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
701 :param dst_address:
702 :param next_hop_address:
703 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
704 :param vrf_id: (Default value = 0)
705 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200706 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200707 :param is_add: (Default value = 1)
708 :param is_drop: (Default value = 0)
709 :param is_ipv6: (Default value = 0)
710 :param is_local: (Default value = 0)
711 :param is_classify: (Default value = 0)
712 :param is_multipath: (Default value = 0)
713 :param is_resolve_host: (Default value = 0)
714 :param is_resolve_attached: (Default value = 0)
715 :param not_last: (Default value = 0)
716 :param next_hop_weight: (Default value = 1)
717
718 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000719
Klement Sekeraf62ae122016-10-11 11:47:09 +0200720 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100721 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200722 {'next_hop_sw_if_index': next_hop_sw_if_index,
723 'table_id': table_id,
724 'classify_table_index': classify_table_index,
725 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200726 'is_add': is_add,
727 'is_drop': is_drop,
728 'is_unreach': is_unreach,
729 'is_prohibit': is_prohibit,
730 'is_ipv6': is_ipv6,
731 'is_local': is_local,
732 'is_classify': is_classify,
733 'is_multipath': is_multipath,
734 'is_resolve_host': is_resolve_host,
735 'is_resolve_attached': is_resolve_attached,
736 'not_last': not_last,
737 'next_hop_weight': next_hop_weight,
738 'dst_address_length': dst_address_length,
739 'dst_address': dst_address,
740 'next_hop_address': next_hop_address,
741 'next_hop_n_out_labels': next_hop_n_out_labels,
742 'next_hop_via_label': next_hop_via_label,
743 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100744
Matej Klotton16a14cd2016-12-07 15:09:13 +0100745 def ip_fib_dump(self):
746 return self.api(self.papi.ip_fib_dump, {})
747
Jan Gelety057bb8c2016-12-20 17:32:45 +0100748 def ip6_fib_dump(self):
749 return self.api(self.papi.ip6_fib_dump, {})
750
Matej Klotton0178d522016-11-04 11:11:44 +0100751 def ip_neighbor_add_del(self,
752 sw_if_index,
753 mac_address,
754 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100755 is_add=1,
756 is_ipv6=0,
757 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800758 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100759 ):
760 """ Add neighbor MAC to IPv4 or IPv6 address.
761
762 :param sw_if_index:
763 :param mac_address:
764 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100765 :param is_add: (Default value = 1)
766 :param is_ipv6: (Default value = 0)
767 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800768 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100769 """
770
771 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100772 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800773 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200774 'is_add': is_add,
775 'is_ipv6': is_ipv6,
776 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800777 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200778 'mac_address': mac_address,
779 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100780 }
Matej Klotton0178d522016-11-04 11:11:44 +0100781 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100782
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800783 def ip_neighbor_dump(self,
784 sw_if_index,
785 is_ipv6=0):
786 """ Return IP neighbor dump.
787
788 :param sw_if_index:
789 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
790 """
791
792 return self.api(
793 self.papi.ip_neighbor_dump,
794 {'is_ipv6': is_ipv6,
795 'sw_if_index': sw_if_index
796 }
797 )
798
799 def proxy_arp_add_del(self,
800 low_address,
801 hi_address,
802 vrf_id=0,
803 is_add=1):
804 """ Config Proxy Arp Range.
805
806 :param low_address: Start address in the rnage to Proxy for
807 :param hi_address: End address in the rnage to Proxy for
808 :param vrf_id: The VRF/table in which to proxy
809 """
810
811 return self.api(
812 self.papi.proxy_arp_add_del,
813 {'vrf_id': vrf_id,
814 'is_add': is_add,
815 'low_address': low_address,
816 'hi_address': hi_address,
817 }
818 )
819
820 def proxy_arp_intfc_enable_disable(self,
821 sw_if_index,
822 is_enable=1):
823 """ Enable/Disable an interface for proxy ARP requests
824
825 :param sw_if_index: Interface
826 :param enable_disable: Enable/Disable
827 """
828
829 return self.api(
830 self.papi.proxy_arp_intfc_enable_disable,
831 {'sw_if_index': sw_if_index,
832 'enable_disable': is_enable
833 }
834 )
835
Jane546d3b2016-12-08 13:10:03 +0100836 def reset_vrf(self,
837 vrf_id,
838 is_ipv6=0,
839 ):
840 """ Reset VRF (remove all routes etc.) request.
841
842 :param int vrf_id: ID of the FIB table / VRF to reset.
843 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
844 """
845
846 return self.api(
847 self.papi.reset_vrf,
848 {'vrf_id': vrf_id,
849 'is_ipv6': is_ipv6,
850 }
851 )
852
853 def reset_fib(self,
854 vrf_id,
855 is_ipv6=0,
856 ):
857 """ Reset VRF (remove all routes etc.) request.
858
859 :param int vrf_id: ID of the FIB table / VRF to reset.
860 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
861 """
862
863 return self.api(
864 self.papi.reset_fib,
865 {'vrf_id': vrf_id,
866 'is_ipv6': is_ipv6,
867 }
868 )
869
870 def ip_dump(self,
871 is_ipv6=0,
872 ):
873 """ Return IP dump.
874
875 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
876 """
877
878 return self.api(
879 self.papi.ip_dump,
880 {'is_ipv6': is_ipv6,
881 }
882 )
883
Klement Sekera7bb873a2016-11-18 07:38:42 +0100884 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300885 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100886 """
887
888 :param sw_if_index_from:
889 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100890 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300891 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100892 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100893 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200894 {'sw_if_index_from': sw_if_index_from,
895 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300896 'state': state,
897 'is_l2': is_l2,
898 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000899
900 def gre_tunnel_add_del(self,
901 src_address,
902 dst_address,
903 outer_fib_id=0,
904 is_teb=0,
905 is_add=1,
906 is_ip6=0):
907 """ Add a GRE tunnel
908
909 :param src_address:
910 :param dst_address:
911 :param outer_fib_id: (Default value = 0)
912 :param is_add: (Default value = 1)
913 :param is_ipv6: (Default value = 0)
914 :param is_teb: (Default value = 0)
915 """
916
917 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100918 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200919 {'is_add': is_add,
920 'is_ipv6': is_ip6,
921 'teb': is_teb,
922 'src_address': src_address,
923 'dst_address': dst_address,
924 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000925 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000926
Neale Ranns5a8123b2017-01-26 01:18:23 -0800927 def mpls_fib_dump(self):
928 return self.api(self.papi.mpls_fib_dump, {})
929
Neale Ranns15002542017-09-10 04:39:11 -0700930 def mpls_table_add_del(
931 self,
932 table_id,
933 is_add=1):
934 """
935
936 :param table_id
937 :param is_add: (Default value = 1)
938
939 """
940
941 return self.api(
942 self.papi.mpls_table_add_del,
943 {'mt_table_id': table_id,
944 'mt_is_add': is_add})
945
Neale Rannsad422ed2016-11-02 14:20:04 +0000946 def mpls_route_add_del(
947 self,
948 label,
949 eos,
Neale Rannsda78f952017-05-24 09:15:43 -0700950 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000951 next_hop_address,
952 next_hop_sw_if_index=0xFFFFFFFF,
953 table_id=0,
954 next_hop_table_id=0,
955 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200956 next_hop_n_out_labels=0,
957 next_hop_out_label_stack=[],
958 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000959 is_resolve_host=0,
960 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800961 is_interface_rx=0,
962 is_rpf_id=0,
963 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000964 is_add=1,
965 is_drop=0,
966 is_multipath=0,
967 classify_table_index=0xFFFFFFFF,
968 is_classify=0,
969 not_last=0):
970 """
971
972 :param dst_address_length:
973 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
974 :param dst_address:
975 :param next_hop_address:
976 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
977 :param vrf_id: (Default value = 0)
978 :param lookup_in_vrf: (Default value = 0)
979 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000980 :param is_add: (Default value = 1)
981 :param is_drop: (Default value = 0)
982 :param is_ipv6: (Default value = 0)
983 :param is_local: (Default value = 0)
984 :param is_classify: (Default value = 0)
985 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800986 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000987 :param is_resolve_host: (Default value = 0)
988 :param is_resolve_attached: (Default value = 0)
989 :param not_last: (Default value = 0)
990 :param next_hop_weight: (Default value = 1)
991
992 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000993
994 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100995 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200996 {'mr_label': label,
997 'mr_eos': eos,
998 'mr_table_id': table_id,
999 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001000 'mr_is_add': is_add,
1001 'mr_is_classify': is_classify,
1002 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001003 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001004 'mr_is_resolve_host': is_resolve_host,
1005 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001006 'mr_is_interface_rx': is_interface_rx,
1007 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001008 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001009 'mr_next_hop_weight': next_hop_weight,
1010 'mr_next_hop': next_hop_address,
1011 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1012 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1013 'mr_next_hop_table_id': next_hop_table_id,
1014 'mr_next_hop_via_label': next_hop_via_label,
1015 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001016
1017 def mpls_ip_bind_unbind(
1018 self,
1019 label,
1020 dst_address,
1021 dst_address_length,
1022 table_id=0,
1023 ip_table_id=0,
1024 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001025 is_bind=1):
1026 """
1027 """
1028 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001029 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001030 {'mb_mpls_table_id': table_id,
1031 'mb_label': label,
1032 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001033 'mb_is_bind': is_bind,
1034 'mb_is_ip4': is_ip4,
1035 'mb_address_length': dst_address_length,
1036 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001037
1038 def mpls_tunnel_add_del(
1039 self,
1040 tun_sw_if_index,
1041 next_hop_proto_is_ip4,
1042 next_hop_address,
1043 next_hop_sw_if_index=0xFFFFFFFF,
1044 next_hop_table_id=0,
1045 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001046 next_hop_n_out_labels=0,
1047 next_hop_out_label_stack=[],
1048 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001049 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001050 l2_only=0,
1051 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001052 """
1053
1054 :param dst_address_length:
1055 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1056 :param dst_address:
1057 :param next_hop_address:
1058 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1059 :param vrf_id: (Default value = 0)
1060 :param lookup_in_vrf: (Default value = 0)
1061 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001062 :param is_add: (Default value = 1)
1063 :param is_drop: (Default value = 0)
1064 :param is_ipv6: (Default value = 0)
1065 :param is_local: (Default value = 0)
1066 :param is_classify: (Default value = 0)
1067 :param is_multipath: (Default value = 0)
1068 :param is_resolve_host: (Default value = 0)
1069 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001070 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001071 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001072
1073 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001074 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001075 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001076 {'mt_sw_if_index': tun_sw_if_index,
1077 'mt_is_add': is_add,
1078 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001079 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001080 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1081 'mt_next_hop_weight': next_hop_weight,
1082 'mt_next_hop': next_hop_address,
1083 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1084 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1085 'mt_next_hop_table_id': next_hop_table_id,
1086 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001087
Matus Fabian2ba92e32017-08-21 07:05:03 -07001088 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001089 self,
1090 sw_if_index,
1091 is_inside=1,
1092 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001093 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001094
1095 :param sw_if_index: Software index of the interface
1096 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1097 :param is_add: 1 if add, 0 if delete (Default value = 1)
1098 """
1099 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001100 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001101 {'is_add': is_add,
1102 'is_inside': is_inside,
1103 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001104
Matus Fabian2ba92e32017-08-21 07:05:03 -07001105 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001106 self,
1107 sw_if_index,
1108 is_inside=1,
1109 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001110 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001111
1112 :param sw_if_index: Software index of the interface
1113 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1114 :param is_add: 1 if add, 0 if delete (Default value = 1)
1115 """
1116 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001117 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001118 {'is_add': is_add,
1119 'is_inside': is_inside,
1120 'sw_if_index': sw_if_index})
1121
Matus Fabian2ba92e32017-08-21 07:05:03 -07001122 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001123 self,
1124 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001125 external_ip=0,
1126 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001127 local_port=0,
1128 external_port=0,
1129 addr_only=1,
1130 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001131 protocol=0,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001132 is_add=1):
1133 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001134
1135 :param local_ip: Local IP address
1136 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001137 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001138 :param local_port: Local port number (Default value = 0)
1139 :param external_port: External port number (Default value = 0)
1140 :param addr_only: 1 if address only mapping, 0 if address and port
1141 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001142 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001143 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001144 """
1145 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001146 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001147 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001148 'addr_only': addr_only,
1149 'local_ip_address': local_ip,
1150 'external_ip_address': external_ip,
1151 'local_port': local_port,
1152 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001153 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001154 'vrf_id': vrf_id,
1155 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001156
Matus Fabian2ba92e32017-08-21 07:05:03 -07001157 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001158 self,
1159 first_ip_address,
1160 last_ip_address,
1161 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001162 vrf_id=0xFFFFFFFF):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001163 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001164
1165 :param first_ip_address: First IP address
1166 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001167 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001168 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001169 """
1170 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001171 self.papi.nat44_add_del_address_range,
1172 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001173 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001174 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001175 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001176
Matus Fabian2ba92e32017-08-21 07:05:03 -07001177 def nat44_address_dump(self):
1178 """Dump NAT44 addresses
1179 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001180 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001181 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001182
Matus Fabian2ba92e32017-08-21 07:05:03 -07001183 def nat44_interface_dump(self):
1184 """Dump interfaces with NAT44 feature
1185 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001186 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001187 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001188
Matus Fabian2ba92e32017-08-21 07:05:03 -07001189 def nat44_interface_output_feature_dump(self):
1190 """Dump interfaces with NAT44 output feature
1191 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001192 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001193 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001194
Matus Fabian2ba92e32017-08-21 07:05:03 -07001195 def nat44_static_mapping_dump(self):
1196 """Dump NAT44 static mappings
1197 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001198 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001199 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001200
Matus Fabian2ba92e32017-08-21 07:05:03 -07001201 def nat_show_config(self):
1202 """Show NAT plugin config
1203 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001204 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001205 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001206
Matus Fabian2ba92e32017-08-21 07:05:03 -07001207 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001208 self,
1209 sw_if_index,
1210 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001211 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001212
1213 :param sw_if_index: Software index of the interface
1214 :param is_add: 1 if add, 0 if delete (Default value = 1)
1215 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001216 return self.api(self.papi.nat44_add_del_interface_addr,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001217 {'is_add': is_add, 'sw_if_index': sw_if_index})
1218
Matus Fabian2ba92e32017-08-21 07:05:03 -07001219 def nat44_interface_addr_dump(self):
1220 """Dump NAT44 addresses interfaces
1221 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001222 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001223 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001224
Matus Fabian2ba92e32017-08-21 07:05:03 -07001225 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001226 self,
1227 domain_id=1,
1228 src_port=4739,
1229 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001230 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001231
1232 :param domain_id: Observation domain ID (Default value = 1)
1233 :param src_port: Source port number (Default value = 4739)
1234 :param enable: 1 if enable, 0 if disable (Default value = 1)
1235 """
1236 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001237 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001238 {'domain_id': domain_id,
1239 'src_port': src_port,
1240 'enable': enable})
1241
Matus Fabian2ba92e32017-08-21 07:05:03 -07001242 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001243 self,
1244 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001245 vrf_id):
1246 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001247
1248 :param ip_address: ip adress of the user to be dumped
1249 :param cpu_index: cpu_index on which the user is
1250 :param vrf_id: VRF ID
1251 :return: Dictionary of S-NAT sessions
1252 """
1253 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001254 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001255 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001256 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001257
Matus Fabian2ba92e32017-08-21 07:05:03 -07001258 def nat44_user_dump(self):
1259 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001260
Matus Fabian2ba92e32017-08-21 07:05:03 -07001261 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001262 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001263 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001264
Matus Fabian704018c2017-09-04 02:17:18 -07001265 def nat44_add_del_lb_static_mapping(
1266 self,
1267 external_addr,
1268 external_port,
1269 protocol,
1270 vrf_id=0,
1271 local_num=0,
1272 locals=None,
1273 is_add=1):
1274 """Add/delete NAT44 load balancing static mapping
1275
1276 :param is_add - 1 if add, 0 if delete
1277 """
1278 return self.api(
1279 self.papi.nat44_add_del_lb_static_mapping,
1280 {'is_add': is_add,
1281 'external_addr': external_addr,
1282 'external_port': external_port,
1283 'protocol': protocol,
1284 'vrf_id': vrf_id,
1285 'local_num': local_num,
1286 'locals': locals})
1287
1288 def nat44_lb_static_mapping_dump(self):
1289 """Dump NAT44 load balancing static mappings
1290
1291 :return: Dictionary of NAT44 load balancing static mapping
1292 """
1293 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1294
Matus Fabian2ba92e32017-08-21 07:05:03 -07001295 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001296 self,
1297 in_addr,
1298 in_plen,
1299 out_addr,
1300 out_plen,
1301 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001302 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001303
1304 :param is_add - 1 if add, 0 if delete
1305 :param in_addr - inside IP address
1306 :param in_plen - inside IP address prefix length
1307 :param out_addr - outside IP address
1308 :param out_plen - outside IP address prefix length
1309 """
1310 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001311 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001312 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001313 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001314 'in_addr': in_addr,
1315 'in_plen': in_plen,
1316 'out_addr': out_addr,
1317 'out_plen': out_plen})
1318
Matus Fabian2ba92e32017-08-21 07:05:03 -07001319 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001320 self,
1321 in_addr):
1322 """Get outside address and port range from inside address
1323
1324 :param in_addr - inside IP address
1325 """
1326 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001327 self.papi.nat_det_forward,
1328 {'in_addr': in_addr,
1329 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001330
Matus Fabian2ba92e32017-08-21 07:05:03 -07001331 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001332 self,
1333 out_addr,
1334 out_port):
1335 """Get inside address from outside address and port
1336
1337 :param out_addr - outside IP address
1338 :param out_port - outside port
1339 """
1340 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001341 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001342 {'out_addr': out_addr,
1343 'out_port': out_port})
1344
Matus Fabian2ba92e32017-08-21 07:05:03 -07001345 def nat_det_map_dump(self):
1346 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001347
Matus Fabian2ba92e32017-08-21 07:05:03 -07001348 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001349 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001350 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001351
Matus Fabian2ba92e32017-08-21 07:05:03 -07001352 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001353 self,
1354 udp=300,
1355 tcp_established=7440,
1356 tcp_transitory=240,
1357 icmp=60):
1358 """Set values of timeouts for deterministic NAT (in seconds)
1359
1360 :param udp - UDP timeout (Default value = 300)
1361 :param tcp_established - TCP established timeout (Default value = 7440)
1362 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1363 :param icmp - ICMP timeout (Default value = 60)
1364 """
1365 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001366 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001367 {'udp': udp,
1368 'tcp_established': tcp_established,
1369 'tcp_transitory': tcp_transitory,
1370 'icmp': icmp})
1371
Matus Fabian2ba92e32017-08-21 07:05:03 -07001372 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001373 """Get values of timeouts for deterministic NAT
1374
1375 :return: Timeouts for deterministic NAT (in seconds)
1376 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001377 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001378
Matus Fabian2ba92e32017-08-21 07:05:03 -07001379 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001380 self,
1381 out_addr,
1382 out_port,
1383 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001384 ext_port):
1385 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001386
1387 :param out_addr - outside IP address
1388 :param out_port - outside port
1389 :param ext_addr - external host IP address
1390 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001391 """
1392 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001393 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001394 {'out_addr': out_addr,
1395 'out_port': out_port,
1396 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001397 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001398
Matus Fabian2ba92e32017-08-21 07:05:03 -07001399 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001400 self,
1401 in_addr,
1402 in_port,
1403 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001404 ext_port):
1405 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001406
1407 :param in_addr - inside IP address
1408 :param in_port - inside port
1409 :param ext_addr - external host IP address
1410 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001411 """
1412 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001413 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001414 {'in_addr': in_addr,
1415 'in_port': in_port,
1416 'ext_addr': ext_addr,
1417 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001418 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001419
Matus Fabian2ba92e32017-08-21 07:05:03 -07001420 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001421 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001422 user_addr):
1423 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001424
1425 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001426 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001427 """
1428 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001429 self.papi.nat_det_session_dump,
1430 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001431 'user_addr': user_addr})
1432
Matus Fabian06596c52017-06-06 04:53:28 -07001433 def nat64_add_del_pool_addr_range(
1434 self,
1435 start_addr,
1436 end_addr,
1437 vrf_id=0xFFFFFFFF,
1438 is_add=1):
1439 """Add/del address range to NAT64 pool
1440
1441 :param start_addr: First IP address
1442 :param end_addr: Last IP address
1443 :param vrf_id: VRF id for the address range
1444 :param is_add: 1 if add, 0 if delete (Default value = 1)
1445 """
1446 return self.api(
1447 self.papi.nat64_add_del_pool_addr_range,
1448 {'start_addr': start_addr,
1449 'end_addr': end_addr,
1450 'vrf_id': vrf_id,
1451 'is_add': is_add})
1452
1453 def nat64_pool_addr_dump(self):
1454 """Dump NAT64 pool addresses
1455 :return: Dictionary of NAT64 pool addresses
1456 """
1457 return self.api(self.papi.nat64_pool_addr_dump, {})
1458
1459 def nat64_add_del_interface(
1460 self,
1461 sw_if_index,
1462 is_inside=1,
1463 is_add=1):
1464 """Enable/disable NAT64 feature on the interface
1465 :param sw_if_index: Index of the interface
1466 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1467 :param is_add: 1 if add, 0 if delete (Default value = 1)
1468 """
1469 return self.api(
1470 self.papi.nat64_add_del_interface,
1471 {'sw_if_index': sw_if_index,
1472 'is_inside': is_inside,
1473 'is_add': is_add})
1474
1475 def nat64_interface_dump(self):
1476 """Dump interfaces with NAT64 feature
1477 :return: Dictionary of interfaces with NAT64 feature
1478 """
1479 return self.api(self.papi.nat64_interface_dump, {})
1480
1481 def nat64_add_del_static_bib(
1482 self,
1483 in_ip,
1484 out_ip,
1485 in_port,
1486 out_port,
1487 protocol,
1488 vrf_id=0,
1489 is_add=1):
1490 """Add/delete S-NAT static BIB entry
1491
1492 :param in_ip: Inside IPv6 address
1493 :param out_ip: Outside IPv4 address
1494 :param in_port: Inside port number
1495 :param out_port: Outside port number
1496 :param protocol: IP protocol
1497 :param vrf_id: VRF ID (Default value = 0)
1498 :param is_add: 1 if add, 0 if delete (Default value = 1)
1499 """
1500 return self.api(
1501 self.papi.nat64_add_del_static_bib,
1502 {'i_addr': in_ip,
1503 'o_addr': out_ip,
1504 'i_port': in_port,
1505 'o_port': out_port,
1506 'vrf_id': vrf_id,
1507 'proto': protocol,
1508 'is_add': is_add})
1509
Matus Fabianab9a59c2017-08-16 05:37:36 -07001510 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001511 """Dump NAT64 BIB
1512
Matus Fabianab9a59c2017-08-16 05:37:36 -07001513 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001514 :returns: Dictionary of NAT64 BIB entries
1515 """
1516 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1517
1518 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1519 tcp_incoming_syn=6):
1520 """Set values of timeouts for NAT64 (in seconds)
1521
Matus Fabian428dc912017-06-21 06:15:18 -07001522 :param udpi: UDP timeout (Default value = 300)
1523 :param icmp: ICMP timeout (Default value = 60)
1524 :param tcp_trans: TCP transitory timeout (Default value = 240)
1525 :param tcp_est: TCP established timeout (Default value = 7440)
1526 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001527 """
1528 return self.api(
1529 self.papi.nat64_set_timeouts,
1530 {'udp': udp,
1531 'icmp': icmp,
1532 'tcp_trans': tcp_trans,
1533 'tcp_est': tcp_est,
1534 'tcp_incoming_syn': tcp_incoming_syn})
1535
1536 def nat64_get_timeouts(self):
1537 """Get values of timeouts for NAT64
1538
1539 :return: Timeouts for NAT64 (in seconds)
1540 """
1541 return self.api(self.papi.nat64_get_timeouts, {})
1542
Matus Fabianab9a59c2017-08-16 05:37:36 -07001543 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001544 """Dump NAT64 session table
1545
Matus Fabianab9a59c2017-08-16 05:37:36 -07001546 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001547 :returns: Dictionary of NAT64 sesstion table entries
1548 """
1549 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1550
Matus Fabian428dc912017-06-21 06:15:18 -07001551 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1552 """Add/del NAT64 prefix
1553
1554 :param prefix: NAT64 prefix
1555 :param plen: NAT64 prefix length
1556 :param vrf_id: VRF id of tenant (Default 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_prefix,
1561 {'prefix': prefix,
1562 'prefix_len': plen,
1563 'vrf_id': vrf_id,
1564 'is_add': is_add})
1565
1566 def nat64_prefix_dump(self):
1567 """Dump NAT64 prefix
1568
1569 :returns: Dictionary of NAT64 prefixes
1570 """
1571 return self.api(self.papi.nat64_prefix_dump, {})
1572
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001573 def control_ping(self):
1574 self.api(self.papi.control_ping)
1575
1576 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001577 detect_mult, local_addr, peer_addr, is_ipv6=0,
1578 bfd_key_id=None, conf_key_id=None):
1579 if bfd_key_id is None:
1580 return self.api(self.papi.bfd_udp_add,
1581 {
1582 'sw_if_index': sw_if_index,
1583 'desired_min_tx': desired_min_tx,
1584 'required_min_rx': required_min_rx,
1585 'local_addr': local_addr,
1586 'peer_addr': peer_addr,
1587 'is_ipv6': is_ipv6,
1588 'detect_mult': detect_mult,
1589 })
1590 else:
1591 return self.api(self.papi.bfd_udp_add,
1592 {
1593 'sw_if_index': sw_if_index,
1594 'desired_min_tx': desired_min_tx,
1595 'required_min_rx': required_min_rx,
1596 'local_addr': local_addr,
1597 'peer_addr': peer_addr,
1598 'is_ipv6': is_ipv6,
1599 'detect_mult': detect_mult,
1600 'is_authenticated': 1,
1601 'bfd_key_id': bfd_key_id,
1602 'conf_key_id': conf_key_id,
1603 })
1604
Klement Sekeraa57a9702017-02-02 06:58:07 +01001605 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1606 detect_mult, local_addr, peer_addr, is_ipv6=0):
1607 return self.api(self.papi.bfd_udp_mod,
1608 {
1609 'sw_if_index': sw_if_index,
1610 'desired_min_tx': desired_min_tx,
1611 'required_min_rx': required_min_rx,
1612 'local_addr': local_addr,
1613 'peer_addr': peer_addr,
1614 'is_ipv6': is_ipv6,
1615 'detect_mult': detect_mult,
1616 })
1617
Klement Sekerab17dd962017-01-09 07:43:48 +01001618 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1619 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1620 is_delayed=False):
1621 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001622 {
1623 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001624 'local_addr': local_addr,
1625 'peer_addr': peer_addr,
1626 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001627 'is_delayed': 1 if is_delayed else 0,
1628 'bfd_key_id': bfd_key_id,
1629 'conf_key_id': conf_key_id,
1630 })
1631
1632 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1633 is_ipv6=0, is_delayed=False):
1634 return self.api(self.papi.bfd_udp_auth_deactivate,
1635 {
1636 'sw_if_index': sw_if_index,
1637 'local_addr': local_addr,
1638 'peer_addr': peer_addr,
1639 'is_ipv6': is_ipv6,
1640 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001641 })
1642
1643 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1644 return self.api(self.papi.bfd_udp_del,
1645 {
1646 'sw_if_index': sw_if_index,
1647 'local_addr': local_addr,
1648 'peer_addr': peer_addr,
1649 'is_ipv6': is_ipv6,
1650 })
1651
1652 def bfd_udp_session_dump(self):
1653 return self.api(self.papi.bfd_udp_session_dump, {})
1654
Klement Sekerab17dd962017-01-09 07:43:48 +01001655 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1656 peer_addr, is_ipv6=0):
1657 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001658 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001659 'sw_if_index': sw_if_index,
1660 'local_addr': local_addr,
1661 'peer_addr': peer_addr,
1662 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001663 })
1664
1665 def want_bfd_events(self, enable_disable=1):
1666 return self.api(self.papi.want_bfd_events, {
1667 'enable_disable': enable_disable,
1668 'pid': os.getpid(),
1669 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001670
Klement Sekerab17dd962017-01-09 07:43:48 +01001671 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1672 return self.api(self.papi.bfd_auth_set_key, {
1673 'conf_key_id': conf_key_id,
1674 'auth_type': auth_type,
1675 'key': key,
1676 'key_len': len(key),
1677 })
1678
1679 def bfd_auth_del_key(self, conf_key_id):
1680 return self.api(self.papi.bfd_auth_del_key, {
1681 'conf_key_id': conf_key_id,
1682 })
1683
1684 def bfd_auth_keys_dump(self):
1685 return self.api(self.papi.bfd_auth_keys_dump, {})
1686
Klement Sekera239790f2017-02-16 10:53:53 +01001687 def bfd_udp_set_echo_source(self, sw_if_index):
1688 return self.api(self.papi.bfd_udp_set_echo_source,
1689 {'sw_if_index': sw_if_index})
1690
Klement Sekera73884482017-02-23 09:26:30 +01001691 def bfd_udp_del_echo_source(self):
1692 return self.api(self.papi.bfd_udp_del_echo_source, {})
1693
Steve Shin7957d6e2016-12-19 09:24:50 -08001694 def classify_add_del_table(
1695 self,
1696 is_add,
1697 mask,
1698 match_n_vectors=1,
1699 table_index=0xFFFFFFFF,
1700 nbuckets=2,
1701 memory_size=2097152,
1702 skip_n_vectors=0,
1703 next_table_index=0xFFFFFFFF,
1704 miss_next_index=0xFFFFFFFF,
1705 current_data_flag=0,
1706 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001707 """
1708 :param is_add:
1709 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001710 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001711 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001712 :param nbuckets: (Default value = 2)
1713 :param memory_size: (Default value = 2097152)
1714 :param skip_n_vectors: (Default value = 0)
1715 :param next_table_index: (Default value = 0xFFFFFFFF)
1716 :param miss_next_index: (Default value = 0xFFFFFFFF)
1717 :param current_data_flag: (Default value = 0)
1718 :param current_data_offset: (Default value = 0)
1719 """
1720
1721 return self.api(
1722 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001723 {'is_add': is_add,
1724 'table_index': table_index,
1725 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001726 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001727 'skip_n_vectors': skip_n_vectors,
1728 'match_n_vectors': match_n_vectors,
1729 'next_table_index': next_table_index,
1730 'miss_next_index': miss_next_index,
1731 'current_data_flag': current_data_flag,
1732 'current_data_offset': current_data_offset,
1733 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001734
1735 def classify_add_del_session(
1736 self,
1737 is_add,
1738 table_index,
1739 match,
1740 opaque_index=0xFFFFFFFF,
1741 hit_next_index=0xFFFFFFFF,
1742 advance=0,
1743 action=0,
1744 metadata=0):
1745 """
1746 :param is_add:
1747 :param table_index:
1748 :param match:
1749 :param opaque_index: (Default value = 0xFFFFFFFF)
1750 :param hit_next_index: (Default value = 0xFFFFFFFF)
1751 :param advance: (Default value = 0)
1752 :param action: (Default value = 0)
1753 :param metadata: (Default value = 0)
1754 """
1755
1756 return self.api(
1757 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001758 {'is_add': is_add,
1759 'table_index': table_index,
1760 'hit_next_index': hit_next_index,
1761 'opaque_index': opaque_index,
1762 'advance': advance,
1763 'action': action,
1764 'metadata': metadata,
1765 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001766
1767 def input_acl_set_interface(
1768 self,
1769 is_add,
1770 sw_if_index,
1771 ip4_table_index=0xFFFFFFFF,
1772 ip6_table_index=0xFFFFFFFF,
1773 l2_table_index=0xFFFFFFFF):
1774 """
1775 :param is_add:
1776 :param sw_if_index:
1777 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1778 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1779 :param l2_table_index: (Default value = 0xFFFFFFFF)
1780 """
1781
1782 return self.api(
1783 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001784 {'sw_if_index': sw_if_index,
1785 'ip4_table_index': ip4_table_index,
1786 'ip6_table_index': ip6_table_index,
1787 'l2_table_index': l2_table_index,
1788 'is_add': is_add})
1789
1790 def set_ipfix_exporter(
1791 self,
1792 collector_address,
1793 src_address,
1794 path_mtu,
1795 template_interval,
1796 vrf_id=0,
1797 collector_port=4739,
1798 udp_checksum=0):
1799 return self.api(
1800 self.papi.set_ipfix_exporter,
1801 {
1802 'collector_address': collector_address,
1803 'collector_port': collector_port,
1804 'src_address': src_address,
1805 'vrf_id': vrf_id,
1806 'path_mtu': path_mtu,
1807 'template_interval': template_interval,
1808 'udp_checksum': udp_checksum,
1809 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001810
1811 def dhcp_proxy_config(self,
1812 dhcp_server,
1813 dhcp_src_address,
1814 rx_table_id=0,
1815 server_table_id=0,
1816 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001817 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001818 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001819 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001820 {
1821 'rx_vrf_id': rx_table_id,
1822 'server_vrf_id': server_table_id,
1823 'is_ipv6': is_ipv6,
1824 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001825 'dhcp_server': dhcp_server,
1826 'dhcp_src_address': dhcp_src_address,
1827 })
1828
1829 def dhcp_proxy_set_vss(self,
1830 table_id,
1831 fib_id,
1832 oui,
1833 is_add=1,
1834 is_ip6=0):
1835 return self.api(
1836 self.papi.dhcp_proxy_set_vss,
1837 {
1838 'tbl_id': table_id,
1839 'fib_id': fib_id,
1840 'is_ipv6': is_ip6,
1841 'is_add': is_add,
1842 'oui': oui,
1843 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001844
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001845 def dhcp_client(self,
1846 sw_if_index,
1847 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001848 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001849 is_add=1,
1850 want_dhcp_events=0):
1851 return self.api(
1852 self.papi.dhcp_client_config,
1853 {
1854 'sw_if_index': sw_if_index,
1855 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001856 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001857 'is_add': is_add,
1858 'want_dhcp_event': want_dhcp_events,
1859 'pid': os.getpid(),
1860 })
1861
Neale Ranns32e1c012016-11-22 17:07:28 +00001862 def ip_mroute_add_del(self,
1863 src_address,
1864 grp_address,
1865 grp_address_length,
1866 e_flags,
1867 next_hop_sw_if_index,
1868 i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001869 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001870 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001871 is_add=1,
1872 is_ipv6=0,
1873 is_local=0):
1874 """
1875 """
1876 return self.api(
1877 self.papi.ip_mroute_add_del,
1878 {'next_hop_sw_if_index': next_hop_sw_if_index,
1879 'entry_flags': e_flags,
1880 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001881 'table_id': table_id,
1882 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001883 'is_add': is_add,
1884 'is_ipv6': is_ipv6,
1885 'is_local': is_local,
1886 'grp_address_length': grp_address_length,
1887 'grp_address': grp_address,
1888 'src_address': src_address})
1889
1890 def mfib_signal_dump(self):
1891 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001892
1893 def ip_mfib_dump(self):
1894 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001895
1896 def lisp_enable_disable(self, is_enabled):
1897 return self.api(
1898 self.papi.lisp_enable_disable,
1899 {
1900 'is_en': is_enabled,
1901 })
1902
1903 def lisp_locator_set(self,
1904 ls_name,
1905 is_add=1):
1906 return self.api(
1907 self.papi.lisp_add_del_locator_set,
1908 {
1909 'is_add': is_add,
1910 'locator_set_name': ls_name
1911 })
1912
1913 def lisp_locator_set_dump(self):
1914 return self.api(self.papi.lisp_locator_set_dump, {})
1915
1916 def lisp_locator(self,
1917 ls_name,
1918 sw_if_index,
1919 priority=1,
1920 weight=1,
1921 is_add=1):
1922 return self.api(
1923 self.papi.lisp_add_del_locator,
1924 {
1925 'is_add': is_add,
1926 'locator_set_name': ls_name,
1927 'sw_if_index': sw_if_index,
1928 'priority': priority,
1929 'weight': weight
1930 })
1931
1932 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1933 return self.api(
1934 self.papi.lisp_locator_dump,
1935 {
1936 'is_index_set': is_index_set,
1937 'ls_name': ls_name,
1938 'ls_index': ls_index,
1939 })
1940
1941 def lisp_local_mapping(self,
1942 ls_name,
1943 eid_type,
1944 eid,
1945 prefix_len,
1946 vni=0,
1947 key_id=0,
1948 key="",
1949 is_add=1):
1950 return self.api(
1951 self.papi.lisp_add_del_local_eid,
1952 {
1953 'locator_set_name': ls_name,
1954 'is_add': is_add,
1955 'eid_type': eid_type,
1956 'eid': eid,
1957 'prefix_len': prefix_len,
1958 'vni': vni,
1959 'key_id': key_id,
1960 'key': key
1961 })
1962
1963 def lisp_eid_table_dump(self,
1964 eid_set=0,
1965 prefix_length=0,
1966 vni=0,
1967 eid_type=0,
1968 eid=None,
1969 filter_opt=0):
1970 return self.api(
1971 self.papi.lisp_eid_table_dump,
1972 {
1973 'eid_set': eid_set,
1974 'prefix_length': prefix_length,
1975 'vni': vni,
1976 'eid_type': eid_type,
1977 'eid': eid,
1978 'filter': filter_opt,
1979 })
1980
1981 def lisp_remote_mapping(self,
1982 eid_type,
1983 eid,
1984 eid_prefix_len=0,
1985 vni=0,
1986 rlocs=None,
1987 rlocs_num=0,
1988 is_src_dst=0,
1989 is_add=1):
1990 return self.api(
1991 self.papi.lisp_add_del_remote_mapping,
1992 {
1993 'is_add': is_add,
1994 'eid_type': eid_type,
1995 'eid': eid,
1996 'eid_len': eid_prefix_len,
1997 'rloc_num': rlocs_num,
1998 'rlocs': rlocs,
1999 'vni': vni,
2000 'is_src_dst': is_src_dst,
2001 })
2002
2003 def lisp_adjacency(self,
2004 leid,
2005 reid,
2006 leid_len,
2007 reid_len,
2008 eid_type,
2009 is_add=1,
2010 vni=0):
2011 return self.api(
2012 self.papi.lisp_add_del_adjacency,
2013 {
2014 'is_add': is_add,
2015 'vni': vni,
2016 'eid_type': eid_type,
2017 'leid': leid,
2018 'reid': reid,
2019 'leid_len': leid_len,
2020 'reid_len': reid_len,
2021 })
2022
2023 def lisp_adjacencies_get(self, vni=0):
2024 return self.api(
2025 self.papi.lisp_adjacencies_get,
2026 {
2027 'vni': vni
2028 })
Neale Ranns80823802017-02-20 18:23:41 -08002029
2030 def map_add_domain(self,
2031 ip6_prefix,
2032 ip6_prefix_len,
2033 ip6_src,
2034 ip6_src_prefix_len,
2035 ip4_prefix,
2036 ip4_prefix_len,
2037 ea_bits_len=0,
2038 psid_offset=0,
2039 psid_length=0,
2040 is_translation=0,
2041 mtu=1280):
2042 return self.api(
2043 self.papi.map_add_domain,
2044 {
2045 'ip6_prefix': ip6_prefix,
2046 'ip6_prefix_len': ip6_prefix_len,
2047 'ip4_prefix': ip4_prefix,
2048 'ip4_prefix_len': ip4_prefix_len,
2049 'ip6_src': ip6_src,
2050 'ip6_src_prefix_len': ip6_src_prefix_len,
2051 'ea_bits_len': ea_bits_len,
2052 'psid_offset': psid_offset,
2053 'psid_length': psid_length,
2054 'is_translation': is_translation,
2055 'mtu': mtu
2056 })
Hongjun Nief486b12017-04-12 19:21:16 +08002057
2058 def gtpu_add_del_tunnel(
2059 self,
2060 src_addr,
2061 dst_addr,
2062 is_add=1,
2063 is_ipv6=0,
2064 mcast_sw_if_index=0xFFFFFFFF,
2065 encap_vrf_id=0,
2066 decap_next_index=0xFFFFFFFF,
2067 teid=0):
2068 """
2069
2070 :param is_add: (Default value = 1)
2071 :param is_ipv6: (Default value = 0)
2072 :param src_addr:
2073 :param dst_addr:
2074 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2075 :param encap_vrf_id: (Default value = 0)
2076 :param decap_next_index: (Default value = 0xFFFFFFFF)
2077 :param teid: (Default value = 0)
2078
2079 """
2080 return self.api(self.papi.gtpu_add_del_tunnel,
2081 {'is_add': is_add,
2082 'is_ipv6': is_ipv6,
2083 'src_address': src_addr,
2084 'dst_address': dst_addr,
2085 'mcast_sw_if_index': mcast_sw_if_index,
2086 'encap_vrf_id': encap_vrf_id,
2087 'decap_next_index': decap_next_index,
2088 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002089
2090 def vxlan_gpe_add_del_tunnel(
2091 self,
2092 src_addr,
2093 dst_addr,
2094 mcast_sw_if_index=0xFFFFFFFF,
2095 is_add=1,
2096 is_ipv6=0,
2097 encap_vrf_id=0,
2098 decap_vrf_id=0,
2099 protocol=3,
2100 vni=0):
2101 """
2102
2103 :param local:
2104 :param remote:
2105 :param is_add: (Default value = 1)
2106 :param is_ipv6: (Default value = 0)
2107 :param encap_vrf_id: (Default value = 0)
2108 :param decap_vrf_id: (Default value = 0)
2109 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2110 :param protocol: (Default value = 3)
2111 :param vni: (Default value = 0)
2112
2113 """
2114 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2115 {'is_add': is_add,
2116 'is_ipv6': is_ipv6,
2117 'local': src_addr,
2118 'remote': dst_addr,
2119 'mcast_sw_if_index': mcast_sw_if_index,
2120 'encap_vrf_id': encap_vrf_id,
2121 'decap_vrf_id': decap_vrf_id,
2122 'protocol': protocol,
2123 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002124
2125 def pppoe_add_del_session(
2126 self,
2127 client_ip,
2128 client_mac,
2129 session_id=0,
2130 is_add=1,
2131 is_ipv6=0,
2132 decap_vrf_id=0):
2133 """
2134
2135 :param is_add: (Default value = 1)
2136 :param is_ipv6: (Default value = 0)
2137 :param client_ip:
2138 :param session_id: (Default value = 0)
2139 :param client_mac:
2140 :param decap_vrf_id: (Default value = 0)
2141
2142 """
2143 return self.api(self.papi.pppoe_add_del_session,
2144 {'is_add': is_add,
2145 'is_ipv6': is_ipv6,
2146 'session_id': session_id,
2147 'client_ip': client_ip,
2148 'decap_vrf_id': decap_vrf_id,
2149 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002150
2151 def sr_localsid_add_del(self,
2152 localsid_addr,
2153 behavior,
2154 nh_addr,
2155 is_del=0,
2156 end_psp=0,
2157 sw_if_index=0xFFFFFFFF,
2158 vlan_index=0,
2159 fib_table=0,
2160 ):
2161 """ Add/del IPv6 SR local-SID.
2162
2163 :param localsid_addr:
2164 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2165 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2166 :param nh_addr:
2167 :param is_del: (Default value = 0)
2168 :param end_psp: (Default value = 0)
2169 :param sw_if_index: (Default value = 0xFFFFFFFF)
2170 :param vlan_index: (Default value = 0)
2171 :param fib_table: (Default value = 0)
2172 """
2173 return self.api(
2174 self.papi.sr_localsid_add_del,
2175 {'is_del': is_del,
2176 'localsid_addr': localsid_addr,
2177 'end_psp': end_psp,
2178 'behavior': behavior,
2179 'sw_if_index': sw_if_index,
2180 'vlan_index': vlan_index,
2181 'fib_table': fib_table,
2182 'nh_addr': nh_addr
2183 }
2184 )
2185
2186 def sr_policy_add(
2187 self,
2188 bsid_addr,
2189 weight=1,
2190 is_encap=1,
2191 type=0,
2192 fib_table=0,
2193 n_segments=0,
2194 segments=[]):
2195 """
2196 :param bsid_addr: bindingSID of the SR Policy
2197 :param weight: weight of the sid list. optional. (default: 1)
2198 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2199 (default: Encap)
2200 :param type: type/behavior of the SR policy. (default or spray) \
2201 (default: default)
2202 :param fib_table: VRF where to install the FIB entry for the BSID \
2203 (default: 0)
2204 :param n_segments: number of segments \
2205 (default: 0)
2206 :param segments: a vector of IPv6 address composing the segment list \
2207 (default: [])
2208 """
2209 return self.api(
2210 self.papi.sr_policy_add,
2211 {'bsid_addr': bsid_addr,
2212 'weight': weight,
2213 'is_encap': is_encap,
2214 'type': type,
2215 'fib_table': fib_table,
2216 'n_segments': n_segments,
2217 'segments': segments
2218 }
2219 )
2220
2221 def sr_policy_del(
2222 self,
2223 bsid_addr,
2224 sr_policy_index=0):
2225 """
2226 :param bsid: bindingSID of the SR Policy
2227 :param sr_policy_index: index of the sr policy (default: 0)
2228 """
2229 return self.api(
2230 self.papi.sr_policy_del,
2231 {'bsid_addr': bsid_addr,
2232 'sr_policy_index': sr_policy_index
2233 })
2234
2235 def sr_steering_add_del(
2236 self,
2237 is_del,
2238 bsid_addr,
2239 sr_policy_index,
2240 table_id,
2241 prefix_addr,
2242 mask_width,
2243 sw_if_index,
2244 traffic_type):
2245 """
2246 Steer traffic L2 and L3 traffic through a given SR policy
2247
2248 :param is_del: delete or add
2249 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2250 :param sr_policy: is the index of the SR Policy (alt to bsid)
2251 :param table_id: is the VRF where to install the FIB entry for the BSID
2252 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2253 :param mask_width: is the mask for L3 traffic type
2254 :param sw_if_index: is the incoming interface for L2 traffic
2255 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2256 """
2257 return self.api(
2258 self.papi.sr_steering_add_del,
2259 {'is_del': is_del,
2260 'bsid_addr': bsid_addr,
2261 'sr_policy_index': sr_policy_index,
2262 'table_id': table_id,
2263 'prefix_addr': prefix_addr,
2264 'mask_width': mask_width,
2265 'sw_if_index': sw_if_index,
2266 'traffic_type': traffic_type
2267 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002268
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002269 def macip_acl_add(self, rules, tag=""):
2270 """ Add MACIP acl
2271
2272 :param rules: list of rules for given acl
2273 :param tag: acl tag
2274 """
2275
2276 return self.api(self.papi.macip_acl_add,
2277 {'r': rules,
2278 'count': len(rules),
2279 'tag': tag})
2280
Pavel Kotucek932f7412017-09-07 14:44:52 +02002281 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2282 """ Add MACIP acl
2283
2284 :param rules: list of rules for given acl
2285 :param tag: acl tag
2286 """
2287
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002288 return self.api(self.papi.macip_acl_add_replace,
2289 {'acl_index': acl_index,
2290 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002291 'count': len(rules),
2292 'tag': tag})
2293
2294 def macip_acl_del(self, acl_index):
2295 """
2296
2297 :param acl_index:
2298 :return:
2299 """
2300 return self.api(self.papi.macip_acl_del,
2301 {'acl_index': acl_index})
2302
2303 def macip_acl_interface_add_del(self,
2304 sw_if_index,
2305 acl_index,
2306 is_add=1):
2307 """ Add MACIP acl to interface
2308
2309 :param sw_if_index:
2310 :param acl_index:
2311 :param is_add: (Default value = 1)
2312 """
2313
2314 return self.api(self.papi.macip_acl_interface_add_del,
2315 {'is_add': is_add,
2316 'sw_if_index': sw_if_index,
2317 'acl_index': acl_index})
2318
2319 def macip_acl_interface_get(self):
2320 """ Return interface acls dump
2321 """
2322 return self.api(
2323 self.papi.macip_acl_interface_get, {})
2324
2325 def macip_acl_dump(self, acl_index=4294967295):
2326 """ Return MACIP acl dump
2327 """
2328
2329 return self.api(
2330 self.papi.macip_acl_dump, {'acl_index': acl_index})