blob: e3d8459b0b10b6aab4cca952db89032667afb1a3 [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
Neale Ranns039cbfe2018-02-27 03:45:38 -080039class QOS_SOURCE:
40 EXT = 0
41 VLAN = 1
42 MPLS = 2
43 IP = 3
44
45
Klement Sekera73884482017-02-23 09:26:30 +010046class UnexpectedApiReturnValueError(Exception):
47 """ exception raised when the API return value is unexpected """
48 pass
49
50
Klement Sekeraf62ae122016-10-11 11:47:09 +020051class VppPapiProvider(object):
52 """VPP-api provider using vpp-papi
53
54 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020055 """
56
Klement Sekerae0545ef2017-01-25 08:00:40 +010057 _zero, _negative = range(2)
58
Klement Sekera7bb873a2016-11-18 07:38:42 +010059 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020060 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020061 self.name = name
62 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010063 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010064 self._expect_api_retval = self._zero
65 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010066 jsonfiles = []
67
Klement Sekera0e3c0de2016-09-29 14:43:44 +020068 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010069 for root, dirnames, filenames in os.walk(install_dir):
70 for filename in fnmatch.filter(filenames, '*.api.json'):
71 jsonfiles.append(os.path.join(root, filename))
72
Ole Troana7564e82018-06-12 21:06:44 +020073 self.vpp = VPP(jsonfiles, logger=test_class.logger, read_timeout=5)
Klement Sekerae4504c62016-12-08 10:16:41 +010074 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020075
Klement Sekerae0545ef2017-01-25 08:00:40 +010076 def __enter__(self):
77 return self
78
79 def expect_negative_api_retval(self):
80 """ Expect API failure """
81 self._expect_stack.append(self._expect_api_retval)
82 self._expect_api_retval = self._negative
83 return self
84
85 def expect_zero_api_retval(self):
86 """ Expect API success """
87 self._expect_stack.append(self._expect_api_retval)
88 self._expect_api_retval = self._zero
89 return self
90
91 def __exit__(self, exc_type, exc_value, traceback):
92 self._expect_api_retval = self._expect_stack.pop()
93
Klement Sekeraf62ae122016-10-11 11:47:09 +020094 def register_hook(self, hook):
95 """Replace hook registration with new hook
96
97 :param hook:
98
99 """
100 self.hook = hook
101
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200102 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100103 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200104 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100105 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200106 return e
107
108 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100109 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100110 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100111 self.test_class.logger.debug("Expecting event '%s' within %ss",
112 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300113 else:
114 self.test_class.logger.debug("Expecting event within %ss",
115 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100116 if self._events:
117 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200118 limit = time.time() + timeout
119 while time.time() < limit:
120 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100121 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200122 if name and type(e).__name__ != name:
123 raise Exception(
124 "Unexpected event received: %s, expected: %s" %
125 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 self.test_class.logger.debug("Returning event %s:%s" %
127 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200128 return e
129 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200130 raise Exception("Event did not occur within timeout")
131
132 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100133 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200134 # FIXME use the name instead of relying on type(e).__name__ ?
135 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100136 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200137 self._events.append(event)
138
Klement Sekeraf62ae122016-10-11 11:47:09 +0200139 def connect(self):
140 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100141 self.vpp.connect(self.name, self.shm_prefix)
142 self.papi = self.vpp.api
143 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200144
145 def disconnect(self):
146 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100147 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200148
149 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100150 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200151 Call the appropriate hooks before and after the API call
152
153 :param api_fn: API function to call
154 :param api_args: tuple of API function arguments
155 :param expected_retval: Expected return value (Default value = 0)
156 :returns: reply from the API
157
158 """
159 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100160 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100161 if self._expect_api_retval == self._negative:
162 if hasattr(reply, 'retval') and reply.retval >= 0:
163 msg = "API call passed unexpectedly: expected negative "\
164 "return value instead of %d in %s" % \
165 (reply.retval, repr(reply))
166 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 elif self._expect_api_retval == self._zero:
169 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700170 msg = "API call failed, expected %d return value instead "\
171 "of %d in %s" % (expected_retval, reply.retval,
172 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100173 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100174 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100175 else:
176 raise Exception("Internal error, unexpected value for "
177 "self._expect_api_retval %s" %
178 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200179 self.hook.after_api(api_fn.__name__, api_args)
180 return reply
181
182 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100183 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200184
185 :param cli: CLI to execute
186 :returns: CLI output
187
188 """
189 self.hook.before_cli(cli)
190 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100191 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200192 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200193 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100194 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195
Jan49c0fca2016-10-26 15:44:27 +0200196 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100197 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200198
199 :param cli: CLI to execute
200 :returns: CLI output
201 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600202 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200203
Jan4af521d2016-11-15 17:05:00 +0100204 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200205 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207 def show_version(self):
208 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100209 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210
211 def pg_create_interface(self, pg_index):
212 """
213
214 :param pg_index:
215
216 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100217 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200218 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200219
220 def sw_interface_dump(self, filter=None):
221 """
222
223 :param filter: (Default value = None)
224
225 """
226 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200227 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200228 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100229 args = {}
230 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200231
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000232 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100233 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000234
235 :param sw_if_index:
236 :param is_ipv6:
237 :param table_id:
238
239 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100240 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200241 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
242 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000243
Klement Sekeraf62ae122016-10-11 11:47:09 +0200244 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
245 is_ipv6=0, is_add=1, del_all=0):
246 """
247
248 :param addr: param is_ipv6: (Default value = 0)
249 :param sw_if_index:
250 :param addr_len:
251 :param is_ipv6: (Default value = 0)
252 :param is_add: (Default value = 1)
253 :param del_all: (Default value = 0)
254
255 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100256 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200257 {'sw_if_index': sw_if_index,
258 'is_add': is_add,
259 'is_ipv6': is_ipv6,
260 'del_all': del_all,
261 'address_length': addr_len,
262 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200263
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800264 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
265 is_add=1):
266 """ Set the Interface to be unnumbered
267
268 :param is_add: (Default value = 1)
269 :param sw_if_index - interface That will be unnumbered
270 :param ip_sw_if_index - interface with an IP addres
271
272 """
273 return self.api(self.papi.sw_interface_set_unnumbered,
274 {'sw_if_index': ip_sw_if_index,
275 'unnumbered_sw_if_index': sw_if_index,
276 'is_add': is_add})
277
Neale Ranns404d88e2018-08-08 06:37:33 -0700278 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
279 return self.api(self.papi.ip_unnumbered_dump,
280 {'sw_if_index': sw_if_index})
281
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000282 def sw_interface_enable_disable_mpls(self, sw_if_index,
283 is_enable=1):
284 """
285 Enable/Disable MPLS on the interface
286 :param sw_if_index:
287 :param is_enable: (Default value = 1)
288
289 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100290 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200291 {'sw_if_index': sw_if_index,
292 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000293
Jan Gelety057bb8c2016-12-20 17:32:45 +0100294 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100295 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100296 {'sw_if_index': sw_if_index,
297 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200298
Neale Ranns227038a2017-04-21 01:07:59 -0700299 def set_ip_flow_hash(self,
300 table_id,
301 src=1,
302 dst=1,
303 sport=1,
304 dport=1,
305 proto=1,
306 reverse=0,
307 is_ip6=0):
308 return self.api(self.papi.set_ip_flow_hash,
309 {'vrf_id': table_id,
310 'src': src,
311 'dst': dst,
312 'dport': dport,
313 'sport': sport,
314 'proto': proto,
315 'reverse': reverse,
316 'is_ipv6': is_ip6})
317
Neale Ranns3f844d02017-02-18 00:03:54 -0800318 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
319 return self.api(self.papi.ip6nd_proxy_add_del,
320 {'address': address,
321 'sw_if_index': sw_if_index,
322 'is_del': is_del})
323
Neale Ranns75152282017-01-09 01:00:45 -0800324 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000325 no,
Neale Ranns75152282017-01-09 01:00:45 -0800326 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000327 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800328 return self.api(self.papi.sw_interface_ip6nd_ra_config,
329 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000330 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100331 'suppress': suppress,
332 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800333
Neale Ranns87df12d2017-02-18 08:16:41 -0800334 def ip6_sw_interface_ra_prefix(self,
335 sw_if_index,
336 address,
337 address_length,
338 use_default=0,
339 no_advertise=0,
340 off_link=0,
341 no_autoconfig=0,
342 no_onlink=0,
343 is_no=0,
344 val_lifetime=0xffffffff,
345 pref_lifetime=0xffffffff):
346 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
347 {'sw_if_index': sw_if_index,
348 'address': address,
349 'address_length': address_length,
350 'use_default': use_default,
351 'no_advertise': no_advertise,
352 'off_link': off_link,
353 'no_autoconfig': no_autoconfig,
354 'no_onlink': no_onlink,
355 'is_no': is_no,
356 'val_lifetime': val_lifetime,
357 'pref_lifetime': pref_lifetime})
358
Neale Ranns75152282017-01-09 01:00:45 -0800359 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
360 """
361 Enable/Disable An interface for IPv6
362 """
363 return self.api(self.papi.sw_interface_ip6_enable_disable,
364 {'sw_if_index': sw_if_index,
365 'enable': enable})
366
Klement Sekeraf62ae122016-10-11 11:47:09 +0200367 def vxlan_add_del_tunnel(
368 self,
369 src_addr,
370 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200371 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200372 is_add=1,
373 is_ipv6=0,
374 encap_vrf_id=0,
375 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600376 vni=0,
377 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200378 """
379
380 :param dst_addr:
381 :param src_addr:
382 :param is_add: (Default value = 1)
383 :param is_ipv6: (Default value = 0)
384 :param encap_vrf_id: (Default value = 0)
385 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200386 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600388 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200389
390 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100391 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200392 {'is_add': is_add,
393 'is_ipv6': is_ipv6,
394 'src_address': src_addr,
395 'dst_address': dst_addr,
396 'mcast_sw_if_index': mcast_sw_if_index,
397 'encap_vrf_id': encap_vrf_id,
398 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600399 'vni': vni,
400 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200401
Marco Varleseb598f1d2017-09-19 14:25:28 +0200402 def geneve_add_del_tunnel(
403 self,
404 local_addr,
405 remote_addr,
406 mcast_sw_if_index=0xFFFFFFFF,
407 is_add=1,
408 is_ipv6=0,
409 encap_vrf_id=0,
410 decap_next_index=0xFFFFFFFF,
411 vni=0):
412 """
413
414 :param remote_addr:
415 :param local_addr:
416 :param is_add: (Default value = 1)
417 :param is_ipv6: (Default value = 0)
418 :param encap_vrf_id: (Default value = 0)
419 :param decap_next_index: (Default value = 0xFFFFFFFF)
420 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
421 :param vni: (Default value = 0)
422
423 """
424 return self.api(self.papi.geneve_add_del_tunnel,
425 {'is_add': is_add,
426 'is_ipv6': is_ipv6,
427 'local_address': local_addr,
428 'remote_address': remote_addr,
429 'mcast_sw_if_index': mcast_sw_if_index,
430 'encap_vrf_id': encap_vrf_id,
431 'decap_next_index': decap_next_index,
432 'vni': vni})
433
Jan4af521d2016-11-15 17:05:00 +0100434 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
435 learn=1, arp_term=0, is_add=1):
436 """Create/delete bridge domain.
437
438 :param int bd_id: Bridge domain index.
439 :param int flood: Enable/disable bcast/mcast flooding in the BD.
440 (Default value = 1)
441 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
442 (Default value = 1)
443 :param int forward: Enable/disable forwarding on all interfaces in
444 the BD. (Default value = 1)
445 :param int learn: Enable/disable learning on all interfaces in the BD.
446 (Default value = 1)
447 :param int arp_term: Enable/disable arp termination in the BD.
448 (Default value = 1)
449 :param int is_add: Add or delete flag. (Default value = 1)
450 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100451 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200452 {'bd_id': bd_id,
453 'flood': flood,
454 'uu_flood': uu_flood,
455 'forward': forward,
456 'learn': learn,
457 'arp_term': arp_term,
458 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100459
Eyal Baric86e5922017-07-02 18:33:16 +0300460 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
461 return self.api(self.papi.bd_ip_mac_add_del,
462 {'bd_id': bd_id,
463 'is_add': is_add,
464 'is_ipv6': is_ipv6,
465 'ip_address': ip,
466 'mac_address': mac})
467
Eyal Bari20197482017-09-13 12:29:08 +0300468 def want_ip4_arp_events(self, enable_disable=1, address=0):
469 return self.api(self.papi.want_ip4_arp_events,
470 {'enable_disable': enable_disable,
471 'address': address,
472 'pid': os.getpid(), })
473
Eyal Baric125ecc2017-09-20 11:29:17 +0300474 def want_ip6_nd_events(self, enable_disable=1, address=0):
475 return self.api(self.papi.want_ip6_nd_events,
476 {'enable_disable': enable_disable,
477 'address': address,
478 'pid': os.getpid(), })
479
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100480 def want_ip6_ra_events(self, enable_disable=1):
481 return self.api(self.papi.want_ip6_ra_events,
482 {'enable_disable': enable_disable,
483 'pid': os.getpid(), })
484
485 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
486 mrc=0, mrd=0):
487 return self.api(self.papi.ip6nd_send_router_solicitation,
488 {'irt': irt,
489 'mrt': mrt,
490 'mrc': mrc,
491 'mrd': mrd,
492 'sw_if_index': sw_if_index})
493
Juraj Slobodac0374232018-02-01 15:18:49 +0100494 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
495 install_default_routes):
496 return self.api(self.papi.ip6_nd_address_autoconfig,
497 {'sw_if_index': sw_if_index,
498 'enable': enable,
499 'install_default_routes': install_default_routes})
500
Eyal Bari24db0ec2017-09-27 21:43:51 +0300501 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
502 max_macs_in_event=0, learn_limit=0):
503 return self.api(self.papi.want_l2_macs_events,
504 {'enable_disable': enable_disable,
505 'scan_delay': scan_delay,
506 'max_macs_in_event': max_macs_in_event,
507 'learn_limit': learn_limit,
508 'pid': os.getpid(), })
509
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200510 def want_dhcp6_reply_events(self, enable_disable=1):
511 return self.api(self.papi.want_dhcp6_reply_events,
512 {'enable_disable': enable_disable,
513 'pid': os.getpid()})
514
Juraj Sloboda81119e82018-05-25 14:02:20 +0200515 def want_dhcp6_pd_reply_events(self, enable_disable=1):
516 return self.api(self.papi.want_dhcp6_pd_reply_events,
517 {'enable_disable': enable_disable,
518 'pid': os.getpid()})
519
520 def dhcp6_clients_enable_disable(self, enable=1):
521 return self.api(self.papi.dhcp6_clients_enable_disable,
522 {'enable': enable})
523
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200524 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
525 addresses, server_index=0xFFFFFFFF,
526 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
527 ):
528 return self.api(self.papi.dhcp6_send_client_message,
529 {'sw_if_index': sw_if_index,
530 'server_index': server_index,
531 'irt': irt,
532 'mrt': mrt,
533 'mrc': mrc,
534 'mrd': mrd,
535 'stop': stop,
536 'msg_type': msg_type,
537 'T1': T1,
538 'T2': T2,
539 'n_addresses': len(addresses),
540 'addresses': addresses})
541
Juraj Sloboda81119e82018-05-25 14:02:20 +0200542 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
543 prefixes, server_index=0xFFFFFFFF,
544 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
545 ):
546 return self.api(self.papi.dhcp6_pd_send_client_message,
547 {'sw_if_index': sw_if_index,
548 'server_index': server_index,
549 'irt': irt,
550 'mrt': mrt,
551 'mrc': mrc,
552 'mrd': mrd,
553 'stop': stop,
554 'msg_type': msg_type,
555 'T1': T1,
556 'T2': T2,
557 'n_prefixes': len(prefixes),
558 'prefixes': prefixes})
559
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200560 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
561 enable=1):
562 return self.api(self.papi.dhcp6_client_enable_disable,
563 {'sw_if_index': sw_if_index,
564 'enable': enable})
565
Juraj Sloboda81119e82018-05-25 14:02:20 +0200566 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
567 enable=1):
568 return self.api(self.papi.dhcp6_pd_client_enable_disable,
569 {'sw_if_index': sw_if_index,
570 'prefix_group': prefix_group,
571 'enable': enable})
572
573 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
574 prefix_length, prefix_group,
575 is_add=1):
576 return self.api(self.papi.ip6_add_del_address_using_prefix,
577 {'sw_if_index': sw_if_index,
578 'prefix_group': prefix_group,
579 'address': address,
580 'prefix_length': prefix_length,
581 'is_add': is_add})
582
Jan4af521d2016-11-15 17:05:00 +0100583 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
584 filter_mac=0, bvi_mac=0):
585 """Create/delete L2 FIB entry.
586
587 :param str mac: MAC address to create FIB entry for.
588 :param int bd_id: Bridge domain index.
589 :param int sw_if_index: Software interface index of the interface.
590 :param int is_add: Add or delete flag. (Default value = 1)
591 :param int static_mac: Set to 1 to create static MAC entry.
592 (Default value = 0)
593 :param int filter_mac: Set to 1 to drop packet that's source or
594 destination MAC address contains defined MAC address.
595 (Default value = 0)
596 :param int bvi_mac: Set to 1 to create entry that points to BVI
597 interface. (Default value = 0)
598 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100599 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200600 {'mac': self._convert_mac(mac),
601 'bd_id': bd_id,
602 'sw_if_index': sw_if_index,
603 'is_add': is_add,
604 'static_mac': static_mac,
605 'filter_mac': filter_mac,
606 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100607
Eyal Bari93b503e2017-05-15 10:13:15 +0300608 def l2fib_flush_int(self, sw_if_index):
609 """Flush L2 FIB entries for sw_if_index.
610
611 :param int sw_if_index: Software interface index of the interface.
612 """
613 return self.api(self.papi.l2fib_flush_int,
614 {'sw_if_index': sw_if_index})
615
616 def l2fib_flush_bd(self, bd_id):
617 """Flush L2 FIB entries for bd_id.
618
619 :param int sw_if_index: Bridge Domain id.
620 """
621 return self.api(self.papi.l2fib_flush_bd,
622 {'bd_id': bd_id})
623
624 def l2fib_flush_all(self):
625 """Flush all L2 FIB.
626 """
627 return self.api(self.papi.l2fib_flush_all, {})
628
Klement Sekeraf62ae122016-10-11 11:47:09 +0200629 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
630 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100631 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200632
Jan4af521d2016-11-15 17:05:00 +0100633 :param int sw_if_index: Software interface index of the interface.
634 :param int bd_id: Bridge domain index.
635 :param int shg: Split-horizon group index. (Default value = 0)
636 :param int bvi: Set interface as a bridge group virtual interface.
637 (Default value = 0)
638 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200639 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100640 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200641 {'rx_sw_if_index': sw_if_index,
642 'bd_id': bd_id,
643 'shg': shg,
644 'bvi': bvi,
645 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200646
Jan00dad122016-11-29 10:04:53 +0100647 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400648 """Enable/disable required feature of the bridge domain with defined
649 ID.
Jan00dad122016-11-29 10:04:53 +0100650
651 :param int bd_id: Bridge domain ID.
652 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
653 :param int feature_bitmap: Bitmap value of the feature to be set:
654 - learn (1 << 0),
655 - forward (1 << 1),
656 - flood (1 << 2),
657 - uu-flood (1 << 3) or
658 - arp-term (1 << 4).
659 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100660 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200661 {'bd_id': bd_id,
662 'is_set': is_set,
663 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100664
665 def bridge_domain_dump(self, bd_id=0):
666 """
667
668 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
669 existing bridge domains returned)
670 :return: Dictionary of bridge domain(s) data.
671 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100672 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200673 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100674
Klement Sekeraf62ae122016-10-11 11:47:09 +0200675 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
676 enable):
677 """Create or delete unidirectional cross-connect from Tx interface to
678 Rx interface.
679
Jan4af521d2016-11-15 17:05:00 +0100680 :param int rx_sw_if_index: Software interface index of Rx interface.
681 :param int tx_sw_if_index: Software interface index of Tx interface.
682 :param int enable: Create cross-connect if equal to 1, delete
683 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200684
685 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100686 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200687 {'rx_sw_if_index': rx_sw_if_index,
688 'tx_sw_if_index': tx_sw_if_index,
689 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200690
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200691 def sw_interface_set_l2_tag_rewrite(
692 self,
693 sw_if_index,
694 vtr_oper,
695 push=0,
696 tag1=0,
697 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000698 """L2 interface vlan tag rewrite configure request
699 :param client_index - opaque cookie to identify the sender
700 :param context - sender context, to match reply w/ request
701 :param sw_if_index - interface the operation is applied to
702 :param vtr_op - Choose from l2_vtr_op_t enum values
703 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
704 :param tag1 - Needed for any push or translate vtr op
705 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
706
707 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100708 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200709 {'sw_if_index': sw_if_index,
710 'vtr_op': vtr_oper,
711 'push_dot1q': push,
712 'tag1': tag1,
713 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000714
Neale Ranns55d03782017-10-21 06:34:22 -0700715 def sw_interface_set_l2_emulation(
716 self,
717 sw_if_index,
718 enable=1):
719 """L2 Emulation
720 :param sw_if_index - interface the operation is applied to
721
722 """
723 return self.api(self.papi.l2_emulation,
724 {'sw_if_index': sw_if_index,
725 'enable': enable})
726
Neale Ranns1855b8e2018-07-11 10:31:26 -0700727 def sw_interface_set_ip_directed_broadcast(
728 self,
729 sw_if_index,
730 enable=1):
731 """IP Directed broadcast
732 :param sw_if_index - interface the operation is applied to
733
734 """
735 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
736 {'sw_if_index': sw_if_index,
737 'enable': enable})
738
Neale Rannsa07bd702017-08-07 07:53:49 -0700739 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200740 """
741
742 :param admin_up_down:
743 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200744
745 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100746 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200747 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700748 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200749
Ole Troand7231612018-06-07 10:17:57 +0200750 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800751 """
752 :param sw_if_index:
753 :param mtu:
754
755 """
756 return self.api(self.papi.sw_interface_set_mtu,
757 {'sw_if_index': sw_if_index,
758 'mtu': mtu})
759
Neale Ranns25b04942018-04-04 09:34:50 -0700760 def sw_interface_set_promiscuous(self, sw_if_index, enable):
761 """
762 :param sw_if_index:
763 :param enable:
764
765 """
766 return self.api(self.papi.sw_interface_set_promiscuous,
767 {'sw_if_index': sw_if_index,
768 'enable': enable})
769
Neale Rannsc819fc62018-02-16 02:44:05 -0800770 def sw_interface_set_mac_address(self, sw_if_index, mac):
771 return self.api(self.papi.sw_interface_set_mac_address,
772 {'sw_if_index': sw_if_index,
773 'mac_address': mac})
774
Klement Sekeraf62ae122016-10-11 11:47:09 +0200775 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
776 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
777 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
778 """Create subinterface
779 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
780
781 :param sub_id: param inner_vlan:
782 :param sw_if_index:
783 :param outer_vlan:
784 :param inner_vlan:
785 :param no_tags: (Default value = 0)
786 :param one_tag: (Default value = 0)
787 :param two_tags: (Default value = 0)
788 :param dot1ad: (Default value = 0)
789 :param exact_match: (Default value = 0)
790 :param default_sub: (Default value = 0)
791 :param outer_vlan_id_any: (Default value = 0)
792 :param inner_vlan_id_any: (Default value = 0)
793
794 """
795 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100796 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200797 {'sw_if_index': sw_if_index,
798 'sub_id': sub_id,
799 'no_tags': no_tags,
800 'one_tag': one_tag,
801 'two_tags': two_tags,
802 'dot1ad': dot1ad,
803 'exact_match': exact_match,
804 'default_sub': default_sub,
805 'outer_vlan_id_any': outer_vlan_id_any,
806 'inner_vlan_id_any': inner_vlan_id_any,
807 'outer_vlan_id': outer_vlan,
808 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200809
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200810 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
811 """Create p2p ethernet subinterface
812
813 :param sw_if_index: main (parent) interface
814 :param remote_mac: client (remote) mac address
815
816 """
817 return self.api(
818 self.papi.p2p_ethernet_add,
819 {'parent_if_index': sw_if_index,
820 'remote_mac': remote_mac,
821 'subif_id': subif_id})
822
Neale Ranns177bbdc2016-11-15 09:46:51 +0000823 def delete_subif(self, sw_if_index):
824 """Delete subinterface
825
826 :param sw_if_index:
827 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100828 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200829 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000830
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200831 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
832 """Delete p2p ethernet subinterface
833
834 :param sw_if_index: main (parent) interface
835 :param remote_mac: client (remote) mac address
836
837 """
838 return self.api(
839 self.papi.p2p_ethernet_del,
840 {'parent_if_index': sw_if_index,
841 'remote_mac': remote_mac})
842
Klement Sekeraf62ae122016-10-11 11:47:09 +0200843 def create_vlan_subif(self, sw_if_index, vlan):
844 """
845
846 :param vlan:
847 :param sw_if_index:
848
849 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100850 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200851 {'sw_if_index': sw_if_index,
852 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200853
Matej Klotton0178d522016-11-04 11:11:44 +0100854 def create_loopback(self, mac=''):
855 """
856
857 :param mac: (Optional)
858 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100859 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200860 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100861
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100862 def delete_loopback(self, sw_if_index):
863 return self.api(self.papi.delete_loopback,
864 {'sw_if_index': sw_if_index, })
865
Neale Ranns15002542017-09-10 04:39:11 -0700866 def ip_table_add_del(self,
867 table_id,
868 is_add=1,
869 is_ipv6=0):
870 """
871
872 :param table_id
873 :param is_add: (Default value = 1)
874 :param is_ipv6: (Default value = 0)
875
876 """
877
878 return self.api(
879 self.papi.ip_table_add_del,
880 {'table_id': table_id,
881 'is_add': is_add,
882 'is_ipv6': is_ipv6})
883
Klement Sekeraf62ae122016-10-11 11:47:09 +0200884 def ip_add_del_route(
885 self,
886 dst_address,
887 dst_address_length,
888 next_hop_address,
889 next_hop_sw_if_index=0xFFFFFFFF,
890 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200891 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000892 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200893 next_hop_n_out_labels=0,
894 next_hop_out_label_stack=[],
895 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800896 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000897 is_resolve_host=0,
898 is_resolve_attached=0,
899 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200900 is_add=1,
901 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200902 is_unreach=0,
903 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200904 is_ipv6=0,
905 is_local=0,
906 is_classify=0,
907 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800908 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800909 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200910 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200911 """
912
913 :param dst_address_length:
914 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
915 :param dst_address:
916 :param next_hop_address:
917 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
918 :param vrf_id: (Default value = 0)
919 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200920 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200921 :param is_add: (Default value = 1)
922 :param is_drop: (Default value = 0)
923 :param is_ipv6: (Default value = 0)
924 :param is_local: (Default value = 0)
925 :param is_classify: (Default value = 0)
926 :param is_multipath: (Default value = 0)
927 :param is_resolve_host: (Default value = 0)
928 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800929 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700930 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200931 :param next_hop_weight: (Default value = 1)
932
933 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000934
Klement Sekeraf62ae122016-10-11 11:47:09 +0200935 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100936 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200937 {'next_hop_sw_if_index': next_hop_sw_if_index,
938 'table_id': table_id,
939 'classify_table_index': classify_table_index,
940 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200941 'is_add': is_add,
942 'is_drop': is_drop,
943 'is_unreach': is_unreach,
944 'is_prohibit': is_prohibit,
945 'is_ipv6': is_ipv6,
946 'is_local': is_local,
947 'is_classify': is_classify,
948 'is_multipath': is_multipath,
949 'is_resolve_host': is_resolve_host,
950 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800951 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700952 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800953 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200954 'next_hop_weight': next_hop_weight,
955 'dst_address_length': dst_address_length,
956 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800957 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200958 'next_hop_address': next_hop_address,
959 'next_hop_n_out_labels': next_hop_n_out_labels,
960 'next_hop_via_label': next_hop_via_label,
961 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100962
Matej Klotton16a14cd2016-12-07 15:09:13 +0100963 def ip_fib_dump(self):
964 return self.api(self.papi.ip_fib_dump, {})
965
Jan Gelety057bb8c2016-12-20 17:32:45 +0100966 def ip6_fib_dump(self):
967 return self.api(self.papi.ip6_fib_dump, {})
968
Matej Klotton0178d522016-11-04 11:11:44 +0100969 def ip_neighbor_add_del(self,
970 sw_if_index,
971 mac_address,
972 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100973 is_add=1,
974 is_ipv6=0,
975 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800976 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100977 ):
978 """ Add neighbor MAC to IPv4 or IPv6 address.
979
980 :param sw_if_index:
981 :param mac_address:
982 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100983 :param is_add: (Default value = 1)
984 :param is_ipv6: (Default value = 0)
985 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800986 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100987 """
988
989 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100990 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800991 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200992 'is_add': is_add,
993 'is_ipv6': is_ipv6,
994 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800995 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200996 'mac_address': mac_address,
997 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100998 }
Matej Klotton0178d522016-11-04 11:11:44 +0100999 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001000
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001001 def ip_neighbor_dump(self,
1002 sw_if_index,
1003 is_ipv6=0):
1004 """ Return IP neighbor dump.
1005
1006 :param sw_if_index:
1007 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1008 """
1009
1010 return self.api(
1011 self.papi.ip_neighbor_dump,
1012 {'is_ipv6': is_ipv6,
1013 'sw_if_index': sw_if_index
1014 }
1015 )
1016
1017 def proxy_arp_add_del(self,
1018 low_address,
1019 hi_address,
1020 vrf_id=0,
1021 is_add=1):
1022 """ Config Proxy Arp Range.
1023
1024 :param low_address: Start address in the rnage to Proxy for
1025 :param hi_address: End address in the rnage to Proxy for
1026 :param vrf_id: The VRF/table in which to proxy
1027 """
1028
1029 return self.api(
1030 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001031 {'proxy':
1032 {
1033 'vrf_id': vrf_id,
1034 'low_address': low_address,
1035 'hi_address': hi_address,
1036 },
1037 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001038
1039 def proxy_arp_intfc_enable_disable(self,
1040 sw_if_index,
1041 is_enable=1):
1042 """ Enable/Disable an interface for proxy ARP requests
1043
1044 :param sw_if_index: Interface
1045 :param enable_disable: Enable/Disable
1046 """
1047
1048 return self.api(
1049 self.papi.proxy_arp_intfc_enable_disable,
1050 {'sw_if_index': sw_if_index,
1051 'enable_disable': is_enable
1052 }
1053 )
1054
Jane546d3b2016-12-08 13:10:03 +01001055 def reset_vrf(self,
1056 vrf_id,
1057 is_ipv6=0,
1058 ):
1059 """ Reset VRF (remove all routes etc.) request.
1060
1061 :param int vrf_id: ID of the FIB table / VRF to reset.
1062 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1063 """
1064
1065 return self.api(
1066 self.papi.reset_vrf,
1067 {'vrf_id': vrf_id,
1068 'is_ipv6': is_ipv6,
1069 }
1070 )
1071
1072 def reset_fib(self,
1073 vrf_id,
1074 is_ipv6=0,
1075 ):
1076 """ Reset VRF (remove all routes etc.) request.
1077
1078 :param int vrf_id: ID of the FIB table / VRF to reset.
1079 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1080 """
1081
1082 return self.api(
1083 self.papi.reset_fib,
1084 {'vrf_id': vrf_id,
1085 'is_ipv6': is_ipv6,
1086 }
1087 )
1088
1089 def ip_dump(self,
1090 is_ipv6=0,
1091 ):
1092 """ Return IP dump.
1093
1094 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1095 """
1096
1097 return self.api(
1098 self.papi.ip_dump,
1099 {'is_ipv6': is_ipv6,
1100 }
1101 )
1102
Klement Sekera7bb873a2016-11-18 07:38:42 +01001103 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001104 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001105 """
1106
1107 :param sw_if_index_from:
1108 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001109 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001110 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001111 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001112 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001113 {'sw_if_index_from': sw_if_index_from,
1114 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001115 'state': state,
1116 'is_l2': is_l2,
1117 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001118
1119 def gre_tunnel_add_del(self,
1120 src_address,
1121 dst_address,
1122 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001123 tunnel_type=0,
1124 instance=0xFFFFFFFF,
1125 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001126 is_add=1,
1127 is_ip6=0):
1128 """ Add a GRE tunnel
1129
1130 :param src_address:
1131 :param dst_address:
1132 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001133 :param tunnel_type: (Default value = 0)
1134 :param instance: (Default value = 0xFFFFFFFF)
1135 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001136 :param is_add: (Default value = 1)
1137 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001138 """
1139
1140 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001141 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001142 {'is_add': is_add,
1143 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001144 'tunnel_type': tunnel_type,
1145 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001146 'src_address': src_address,
1147 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001148 'outer_fib_id': outer_fib_id,
1149 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001150 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001151
Neale Rannsd0df49f2018-08-08 01:06:40 -07001152 def udp_encap_add(self,
1153 id,
1154 src_ip,
1155 dst_ip,
1156 src_port,
1157 dst_port,
1158 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001159 """ Add a GRE tunnel
1160 :param id: user provided ID
1161 :param src_ip:
1162 :param dst_ip:
1163 :param src_port:
1164 :param dst_port:
1165 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001166 """
1167
1168 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001169 self.papi.udp_encap_add,
1170 {
1171 'udp_encap': {
1172 'id': id,
1173 'src_ip': src_ip,
1174 'dst_ip': dst_ip,
1175 'src_port': src_port,
1176 'dst_port': dst_port,
1177 'table_id': table_id
1178 }
1179 })
1180
1181 def udp_encap_del(self, id):
1182 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001183
1184 def udp_encap_dump(self):
1185 return self.api(self.papi.udp_encap_dump, {})
1186
Neale Ranns43b1f442018-03-20 01:47:35 -07001187 def want_udp_encap_stats(self, enable=1):
1188 return self.api(self.papi.want_udp_encap_stats,
1189 {'enable': enable,
1190 'pid': os.getpid()})
1191
Neale Ranns5a8123b2017-01-26 01:18:23 -08001192 def mpls_fib_dump(self):
1193 return self.api(self.papi.mpls_fib_dump, {})
1194
Neale Ranns15002542017-09-10 04:39:11 -07001195 def mpls_table_add_del(
1196 self,
1197 table_id,
1198 is_add=1):
1199 """
1200
1201 :param table_id
1202 :param is_add: (Default value = 1)
1203
1204 """
1205
1206 return self.api(
1207 self.papi.mpls_table_add_del,
1208 {'mt_table_id': table_id,
1209 'mt_is_add': is_add})
1210
Neale Rannsad422ed2016-11-02 14:20:04 +00001211 def mpls_route_add_del(
1212 self,
1213 label,
1214 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001215 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001216 next_hop_address,
1217 next_hop_sw_if_index=0xFFFFFFFF,
1218 table_id=0,
1219 next_hop_table_id=0,
1220 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001221 next_hop_n_out_labels=0,
1222 next_hop_out_label_stack=[],
1223 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001224 is_resolve_host=0,
1225 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001226 is_interface_rx=0,
1227 is_rpf_id=0,
1228 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001229 is_add=1,
1230 is_drop=0,
1231 is_multipath=0,
1232 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001233 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001234 """
1235
1236 :param dst_address_length:
1237 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1238 :param dst_address:
1239 :param next_hop_address:
1240 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1241 :param vrf_id: (Default value = 0)
1242 :param lookup_in_vrf: (Default value = 0)
1243 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001244 :param is_add: (Default value = 1)
1245 :param is_drop: (Default value = 0)
1246 :param is_ipv6: (Default value = 0)
1247 :param is_local: (Default value = 0)
1248 :param is_classify: (Default value = 0)
1249 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001250 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001251 :param is_resolve_host: (Default value = 0)
1252 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001253 :param next_hop_weight: (Default value = 1)
1254
1255 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001256 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001257 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001258 {'mr_label': label,
1259 'mr_eos': eos,
1260 'mr_table_id': table_id,
1261 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001262 'mr_is_add': is_add,
1263 'mr_is_classify': is_classify,
1264 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001265 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001266 'mr_is_resolve_host': is_resolve_host,
1267 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001268 'mr_is_interface_rx': is_interface_rx,
1269 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001270 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001271 'mr_next_hop_weight': next_hop_weight,
1272 'mr_next_hop': next_hop_address,
1273 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1274 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1275 'mr_next_hop_table_id': next_hop_table_id,
1276 'mr_next_hop_via_label': next_hop_via_label,
1277 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001278
1279 def mpls_ip_bind_unbind(
1280 self,
1281 label,
1282 dst_address,
1283 dst_address_length,
1284 table_id=0,
1285 ip_table_id=0,
1286 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001287 is_bind=1):
1288 """
1289 """
1290 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001291 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001292 {'mb_mpls_table_id': table_id,
1293 'mb_label': label,
1294 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001295 'mb_is_bind': is_bind,
1296 'mb_is_ip4': is_ip4,
1297 'mb_address_length': dst_address_length,
1298 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001299
1300 def mpls_tunnel_add_del(
1301 self,
1302 tun_sw_if_index,
1303 next_hop_proto_is_ip4,
1304 next_hop_address,
1305 next_hop_sw_if_index=0xFFFFFFFF,
1306 next_hop_table_id=0,
1307 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001308 next_hop_n_out_labels=0,
1309 next_hop_out_label_stack=[],
1310 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001311 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001312 l2_only=0,
1313 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001314 """
1315
1316 :param dst_address_length:
1317 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1318 :param dst_address:
1319 :param next_hop_address:
1320 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1321 :param vrf_id: (Default value = 0)
1322 :param lookup_in_vrf: (Default value = 0)
1323 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001324 :param is_add: (Default value = 1)
1325 :param is_drop: (Default value = 0)
1326 :param is_ipv6: (Default value = 0)
1327 :param is_local: (Default value = 0)
1328 :param is_classify: (Default value = 0)
1329 :param is_multipath: (Default value = 0)
1330 :param is_resolve_host: (Default value = 0)
1331 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001332 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001333 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001334
1335 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001336 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001337 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001338 {'mt_sw_if_index': tun_sw_if_index,
1339 'mt_is_add': is_add,
1340 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001341 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001342 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1343 'mt_next_hop_weight': next_hop_weight,
1344 'mt_next_hop': next_hop_address,
1345 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1346 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1347 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001348 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001349 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001350
Matus Fabian2ba92e32017-08-21 07:05:03 -07001351 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001352 self,
1353 sw_if_index,
1354 is_inside=1,
1355 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001356 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001357
1358 :param sw_if_index: Software index of the interface
1359 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1360 :param is_add: 1 if add, 0 if delete (Default value = 1)
1361 """
1362 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001363 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001364 {'is_add': is_add,
1365 'is_inside': is_inside,
1366 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001367
Matus Fabian2ba92e32017-08-21 07:05:03 -07001368 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001369 self,
1370 sw_if_index,
1371 is_inside=1,
1372 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001373 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001374
1375 :param sw_if_index: Software index of the interface
1376 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1377 :param is_add: 1 if add, 0 if delete (Default value = 1)
1378 """
1379 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001380 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001381 {'is_add': is_add,
1382 'is_inside': is_inside,
1383 'sw_if_index': sw_if_index})
1384
Matus Fabian2ba92e32017-08-21 07:05:03 -07001385 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001386 self,
1387 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001388 external_ip=0,
1389 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001390 local_port=0,
1391 external_port=0,
1392 addr_only=1,
1393 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001394 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001395 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001396 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001397 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001398 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001399 is_add=1):
1400 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001401
1402 :param local_ip: Local IP address
1403 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001404 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001405 :param local_port: Local port number (Default value = 0)
1406 :param external_port: External port number (Default value = 0)
1407 :param addr_only: 1 if address only mapping, 0 if address and port
1408 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001409 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001410 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001411 :param self_twice_nat: 1 if translate external host address and port
1412 whenever external host address equals
1413 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001414 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001415 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001416 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001417 """
1418 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001419 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001420 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001421 'addr_only': addr_only,
1422 'local_ip_address': local_ip,
1423 'external_ip_address': external_ip,
1424 'local_port': local_port,
1425 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001426 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001427 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001428 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001429 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001430 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001431 'out2in_only': out2in_only,
1432 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001433
Matus Fabianab7a8052017-11-28 04:29:41 -08001434 def nat44_add_del_identity_mapping(
1435 self,
1436 ip='0',
1437 sw_if_index=0xFFFFFFFF,
1438 port=0,
1439 addr_only=1,
1440 vrf_id=0,
1441 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001442 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001443 is_add=1):
1444 """Add/delete NAT44 identity mapping
1445
1446 :param ip: IP address (Default value = 0)
1447 :param sw_if_index: Interface instead of IP address
1448 :param port: Port number (Default value = 0)
1449 :param addr_only: 1 if address only mapping, 0 if address and port
1450 :param vrf_id: VRF ID
1451 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001452 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001453 :param is_add: 1 if add, 0 if delete (Default value = 1)
1454 """
1455 return self.api(
1456 self.papi.nat44_add_del_identity_mapping,
1457 {'is_add': is_add,
1458 'addr_only': addr_only,
1459 'ip_address': ip,
1460 'port': port,
1461 'sw_if_index': sw_if_index,
1462 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001463 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001464 'protocol': protocol})
1465
Matus Fabian2ba92e32017-08-21 07:05:03 -07001466 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001467 self,
1468 first_ip_address,
1469 last_ip_address,
1470 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001471 vrf_id=0xFFFFFFFF,
1472 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001473 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001474
1475 :param first_ip_address: First IP address
1476 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001477 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001478 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001479 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001480 """
1481 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001482 self.papi.nat44_add_del_address_range,
1483 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001484 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001485 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001486 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001487 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001488
Matus Fabian2ba92e32017-08-21 07:05:03 -07001489 def nat44_address_dump(self):
1490 """Dump NAT44 addresses
1491 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001492 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001493 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001494
Matus Fabian2ba92e32017-08-21 07:05:03 -07001495 def nat44_interface_dump(self):
1496 """Dump interfaces with NAT44 feature
1497 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001498 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001499 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001500
Matus Fabian2ba92e32017-08-21 07:05:03 -07001501 def nat44_interface_output_feature_dump(self):
1502 """Dump interfaces with NAT44 output feature
1503 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001504 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001505 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001506
Matus Fabian2ba92e32017-08-21 07:05:03 -07001507 def nat44_static_mapping_dump(self):
1508 """Dump NAT44 static mappings
1509 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001510 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001511 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001512
Matus Fabianab7a8052017-11-28 04:29:41 -08001513 def nat44_identity_mapping_dump(self):
1514 """Dump NAT44 identity mappings
1515 :return: Dictionary of NAT44 identity mappings
1516 """
1517 return self.api(self.papi.nat44_identity_mapping_dump, {})
1518
Matus Fabian2ba92e32017-08-21 07:05:03 -07001519 def nat_show_config(self):
1520 """Show NAT plugin config
1521 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001522 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001523 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001524
Matus Fabian2ba92e32017-08-21 07:05:03 -07001525 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001526 self,
1527 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001528 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001529 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001530 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001531
1532 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001533 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001534 :param is_add: 1 if add, 0 if delete (Default value = 1)
1535 """
Matus Fabianb932d262017-12-18 05:38:24 -08001536 return self.api(
1537 self.papi.nat44_add_del_interface_addr,
1538 {'is_add': is_add,
1539 'sw_if_index': sw_if_index,
1540 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001541
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 def nat44_interface_addr_dump(self):
1543 """Dump NAT44 addresses interfaces
1544 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001545 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001546 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001547
Matus Fabian2ba92e32017-08-21 07:05:03 -07001548 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001549 self,
1550 domain_id=1,
1551 src_port=4739,
1552 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001553 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001554
1555 :param domain_id: Observation domain ID (Default value = 1)
1556 :param src_port: Source port number (Default value = 4739)
1557 :param enable: 1 if enable, 0 if disable (Default value = 1)
1558 """
1559 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001561 {'domain_id': domain_id,
1562 'src_port': src_port,
1563 'enable': enable})
1564
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001566 self,
1567 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001568 vrf_id):
1569 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001570
1571 :param ip_address: ip adress of the user to be dumped
1572 :param cpu_index: cpu_index on which the user is
1573 :param vrf_id: VRF ID
1574 :return: Dictionary of S-NAT sessions
1575 """
1576 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001577 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001578 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001580
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 def nat44_user_dump(self):
1582 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001583
Matus Fabian2ba92e32017-08-21 07:05:03 -07001584 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001585 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001586 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001587
Matus Fabian704018c2017-09-04 02:17:18 -07001588 def nat44_add_del_lb_static_mapping(
1589 self,
1590 external_addr,
1591 external_port,
1592 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001593 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001594 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001595 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001596 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001597 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001598 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001599 is_add=1):
1600 """Add/delete NAT44 load balancing static mapping
1601
Matus Fabianb932d262017-12-18 05:38:24 -08001602 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001603 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001604 :param is_add - 1 if add, 0 if delete
1605 """
1606 return self.api(
1607 self.papi.nat44_add_del_lb_static_mapping,
1608 {'is_add': is_add,
1609 'external_addr': external_addr,
1610 'external_port': external_port,
1611 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001612 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001613 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001614 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001615 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001616 'local_num': local_num,
1617 'locals': locals})
1618
1619 def nat44_lb_static_mapping_dump(self):
1620 """Dump NAT44 load balancing static mappings
1621
1622 :return: Dictionary of NAT44 load balancing static mapping
1623 """
1624 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1625
Matus Fabian5ba86f72017-10-26 03:37:38 -07001626 def nat44_del_session(
1627 self,
1628 addr,
1629 port,
1630 protocol,
1631 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001632 is_in=1,
1633 ext_host_address=None,
1634 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001635 """Delete NAT44 session
1636
1637 :param addr: IPv4 address
1638 :param por: port number
1639 :param protocol: IP protocol number
1640 :param vrf_id: VRF ID
1641 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001642 :param ext_host_address: external host IPv4 address
1643 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001644 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001645 if ext_host_address is None:
1646 return self.api(
1647 self.papi.nat44_del_session,
1648 {'address': addr,
1649 'port': port,
1650 'protocol': protocol,
1651 'vrf_id': vrf_id,
1652 'is_in': is_in})
1653 else:
1654 return self.api(
1655 self.papi.nat44_del_session,
1656 {'address': addr,
1657 'port': port,
1658 'protocol': protocol,
1659 'vrf_id': vrf_id,
1660 'is_in': is_in,
1661 'ext_host_valid': 1,
1662 'ext_host_address': ext_host_address,
1663 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001664
Juraj Sloboda7b929792017-11-23 13:20:48 +01001665 def nat44_forwarding_enable_disable(
1666 self,
1667 enable):
1668 """Enable/disable forwarding for NAT44
1669
1670 :param enable: 1 for enable, 0 for disable
1671 """
1672 return self.api(
1673 self.papi.nat44_forwarding_enable_disable,
1674 {'enable': enable})
1675
Matus Fabianefcd1e92017-08-15 06:59:19 -07001676 def nat_set_reass(
1677 self,
1678 timeout=2,
1679 max_reass=1024,
1680 max_frag=5,
1681 drop_frag=0,
1682 is_ip6=0):
1683 """Set NAT virtual fragmentation reassembly
1684
1685 :param timeout: reassembly timeout (Default 2sec)
1686 :param max_reass: maximum concurrent reassemblies (Default 1024)
1687 :param max_frag: maximum fragmets per reassembly (Default 5)
1688 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1689 :param is_ip6: 1 if IPv6, 0 if IPv4
1690 """
1691 return self.api(
1692 self.papi.nat_set_reass,
1693 {'timeout': timeout,
1694 'max_reass': max_reass,
1695 'max_frag': max_frag,
1696 'drop_frag': drop_frag,
1697 'is_ip6': is_ip6})
1698
1699 def nat_get_reass(self):
1700 """Get NAT virtual fragmentation reassembly configuration
1701
1702 :return: NAT virtual fragmentation reassembly configuration
1703 """
1704 return self.api(self.papi.nat_get_reass, {})
1705
1706 def nat_reass_dump(self):
1707 """Dump NAT virtual fragmentation reassemblies
1708
1709 :return: Dictionary of NAT virtual fragmentation reassemblies
1710 """
1711 return self.api(self.papi.nat_reass_dump, {})
1712
Matus Fabian2ba92e32017-08-21 07:05:03 -07001713 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001714 self,
1715 in_addr,
1716 in_plen,
1717 out_addr,
1718 out_plen,
1719 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001720 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001721
1722 :param is_add - 1 if add, 0 if delete
1723 :param in_addr - inside IP address
1724 :param in_plen - inside IP address prefix length
1725 :param out_addr - outside IP address
1726 :param out_plen - outside IP address prefix length
1727 """
1728 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001729 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001730 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001731 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001732 'in_addr': in_addr,
1733 'in_plen': in_plen,
1734 'out_addr': out_addr,
1735 'out_plen': out_plen})
1736
Matus Fabian2ba92e32017-08-21 07:05:03 -07001737 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001738 self,
1739 in_addr):
1740 """Get outside address and port range from inside address
1741
1742 :param in_addr - inside IP address
1743 """
1744 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001745 self.papi.nat_det_forward,
1746 {'in_addr': in_addr,
1747 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001748
Matus Fabian2ba92e32017-08-21 07:05:03 -07001749 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001750 self,
1751 out_addr,
1752 out_port):
1753 """Get inside address from outside address and port
1754
1755 :param out_addr - outside IP address
1756 :param out_port - outside port
1757 """
1758 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001759 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001760 {'out_addr': out_addr,
1761 'out_port': out_port})
1762
Matus Fabian2ba92e32017-08-21 07:05:03 -07001763 def nat_det_map_dump(self):
1764 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001765
Matus Fabian2ba92e32017-08-21 07:05:03 -07001766 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001767 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001768 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001769
Matus Fabian878c6462018-08-23 00:33:35 -07001770 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001771 self,
1772 udp=300,
1773 tcp_established=7440,
1774 tcp_transitory=240,
1775 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001776 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001777
1778 :param udp - UDP timeout (Default value = 300)
1779 :param tcp_established - TCP established timeout (Default value = 7440)
1780 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1781 :param icmp - ICMP timeout (Default value = 60)
1782 """
1783 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001784 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001785 {'udp': udp,
1786 'tcp_established': tcp_established,
1787 'tcp_transitory': tcp_transitory,
1788 'icmp': icmp})
1789
Matus Fabian878c6462018-08-23 00:33:35 -07001790 def nat_get_timeouts(self):
1791 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001792
Matus Fabian878c6462018-08-23 00:33:35 -07001793 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001794 """
Matus Fabian878c6462018-08-23 00:33:35 -07001795 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001796
Matus Fabian2ba92e32017-08-21 07:05:03 -07001797 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001798 self,
1799 out_addr,
1800 out_port,
1801 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001802 ext_port):
1803 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001804
1805 :param out_addr - outside IP address
1806 :param out_port - outside port
1807 :param ext_addr - external host IP address
1808 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001809 """
1810 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001811 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001812 {'out_addr': out_addr,
1813 'out_port': out_port,
1814 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001815 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001816
Matus Fabian2ba92e32017-08-21 07:05:03 -07001817 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001818 self,
1819 in_addr,
1820 in_port,
1821 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001822 ext_port):
1823 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001824
1825 :param in_addr - inside IP address
1826 :param in_port - inside port
1827 :param ext_addr - external host IP address
1828 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001829 """
1830 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001831 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001832 {'in_addr': in_addr,
1833 'in_port': in_port,
1834 'ext_addr': ext_addr,
1835 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001836 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001837
Matus Fabian2ba92e32017-08-21 07:05:03 -07001838 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001839 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001840 user_addr):
1841 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001842
1843 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001844 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001845 """
1846 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001847 self.papi.nat_det_session_dump,
1848 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001849 'user_addr': user_addr})
1850
Matus Fabian06596c52017-06-06 04:53:28 -07001851 def nat64_add_del_pool_addr_range(
1852 self,
1853 start_addr,
1854 end_addr,
1855 vrf_id=0xFFFFFFFF,
1856 is_add=1):
1857 """Add/del address range to NAT64 pool
1858
1859 :param start_addr: First IP address
1860 :param end_addr: Last IP address
1861 :param vrf_id: VRF id for the address range
1862 :param is_add: 1 if add, 0 if delete (Default value = 1)
1863 """
1864 return self.api(
1865 self.papi.nat64_add_del_pool_addr_range,
1866 {'start_addr': start_addr,
1867 'end_addr': end_addr,
1868 'vrf_id': vrf_id,
1869 'is_add': is_add})
1870
1871 def nat64_pool_addr_dump(self):
1872 """Dump NAT64 pool addresses
1873 :return: Dictionary of NAT64 pool addresses
1874 """
1875 return self.api(self.papi.nat64_pool_addr_dump, {})
1876
1877 def nat64_add_del_interface(
1878 self,
1879 sw_if_index,
1880 is_inside=1,
1881 is_add=1):
1882 """Enable/disable NAT64 feature on the interface
1883 :param sw_if_index: Index of the interface
1884 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1885 :param is_add: 1 if add, 0 if delete (Default value = 1)
1886 """
1887 return self.api(
1888 self.papi.nat64_add_del_interface,
1889 {'sw_if_index': sw_if_index,
1890 'is_inside': is_inside,
1891 'is_add': is_add})
1892
1893 def nat64_interface_dump(self):
1894 """Dump interfaces with NAT64 feature
1895 :return: Dictionary of interfaces with NAT64 feature
1896 """
1897 return self.api(self.papi.nat64_interface_dump, {})
1898
1899 def nat64_add_del_static_bib(
1900 self,
1901 in_ip,
1902 out_ip,
1903 in_port,
1904 out_port,
1905 protocol,
1906 vrf_id=0,
1907 is_add=1):
1908 """Add/delete S-NAT static BIB entry
1909
1910 :param in_ip: Inside IPv6 address
1911 :param out_ip: Outside IPv4 address
1912 :param in_port: Inside port number
1913 :param out_port: Outside port number
1914 :param protocol: IP protocol
1915 :param vrf_id: VRF ID (Default value = 0)
1916 :param is_add: 1 if add, 0 if delete (Default value = 1)
1917 """
1918 return self.api(
1919 self.papi.nat64_add_del_static_bib,
1920 {'i_addr': in_ip,
1921 'o_addr': out_ip,
1922 'i_port': in_port,
1923 'o_port': out_port,
1924 'vrf_id': vrf_id,
1925 'proto': protocol,
1926 'is_add': is_add})
1927
Matus Fabianab9a59c2017-08-16 05:37:36 -07001928 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001929 """Dump NAT64 BIB
1930
Matus Fabianab9a59c2017-08-16 05:37:36 -07001931 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001932 :returns: Dictionary of NAT64 BIB entries
1933 """
1934 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1935
1936 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1937 tcp_incoming_syn=6):
1938 """Set values of timeouts for NAT64 (in seconds)
1939
Matus Fabian428dc912017-06-21 06:15:18 -07001940 :param udpi: UDP timeout (Default value = 300)
1941 :param icmp: ICMP timeout (Default value = 60)
1942 :param tcp_trans: TCP transitory timeout (Default value = 240)
1943 :param tcp_est: TCP established timeout (Default value = 7440)
1944 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001945 """
1946 return self.api(
1947 self.papi.nat64_set_timeouts,
1948 {'udp': udp,
1949 'icmp': icmp,
1950 'tcp_trans': tcp_trans,
1951 'tcp_est': tcp_est,
1952 'tcp_incoming_syn': tcp_incoming_syn})
1953
1954 def nat64_get_timeouts(self):
1955 """Get values of timeouts for NAT64
1956
1957 :return: Timeouts for NAT64 (in seconds)
1958 """
1959 return self.api(self.papi.nat64_get_timeouts, {})
1960
Matus Fabianab9a59c2017-08-16 05:37:36 -07001961 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001962 """Dump NAT64 session table
1963
Matus Fabianab9a59c2017-08-16 05:37:36 -07001964 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001965 :returns: Dictionary of NAT64 sesstion table entries
1966 """
1967 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1968
Matus Fabian428dc912017-06-21 06:15:18 -07001969 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1970 """Add/del NAT64 prefix
1971
1972 :param prefix: NAT64 prefix
1973 :param plen: NAT64 prefix length
1974 :param vrf_id: VRF id of tenant (Default 0)
1975 :param is_add: 1 if add, 0 if delete (Default value = 1)
1976 """
1977 return self.api(
1978 self.papi.nat64_add_del_prefix,
1979 {'prefix': prefix,
1980 'prefix_len': plen,
1981 'vrf_id': vrf_id,
1982 'is_add': is_add})
1983
1984 def nat64_prefix_dump(self):
1985 """Dump NAT64 prefix
1986
1987 :returns: Dictionary of NAT64 prefixes
1988 """
1989 return self.api(self.papi.nat64_prefix_dump, {})
1990
Matus Fabian0938dcf2017-11-08 01:59:38 -08001991 def nat64_add_interface_addr(
1992 self,
1993 sw_if_index,
1994 is_add=1):
1995 """Add/del NAT64 address from interface
1996
1997 :param sw_if_index: Software index of the interface
1998 :param is_add: 1 if add, 0 if delete (Default value = 1)
1999 """
2000 return self.api(self.papi.nat64_add_del_interface_addr,
2001 {'is_add': is_add, 'sw_if_index': sw_if_index})
2002
Matus Fabian8ebe6252017-11-06 05:04:53 -08002003 def dslite_set_aftr_addr(self, ip6, ip4):
2004 """Set DS-Lite AFTR addresses
2005
2006 :param ip4: IPv4 address
2007 :param ip6: IPv6 address
2008 """
2009 return self.api(
2010 self.papi.dslite_set_aftr_addr,
2011 {'ip4_addr': ip4,
2012 'ip6_addr': ip6})
2013
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002014 def dslite_set_b4_addr(self, ip6, ip4):
2015 """Set DS-Lite B4 IPv6 address
2016
2017 :param ip4: IPv4 address
2018 :param ip6: IPv6 address
2019 """
2020 return self.api(
2021 self.papi.dslite_set_b4_addr,
2022 {'ip4_addr': ip4,
2023 'ip6_addr': ip6})
2024
Matus Fabian8ebe6252017-11-06 05:04:53 -08002025 def dslite_add_del_pool_addr_range(
2026 self,
2027 start_addr,
2028 end_addr,
2029 is_add=1):
2030 """Add/del address range to DS-Lite pool
2031
2032 :param start_addr: First IP address
2033 :param end_addr: Last IP address
2034 :param is_add: 1 if add, 0 if delete (Default value = 1)
2035 """
2036 return self.api(
2037 self.papi.dslite_add_del_pool_addr_range,
2038 {'start_addr': start_addr,
2039 'end_addr': end_addr,
2040 'is_add': is_add})
2041
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002042 def nat66_add_del_interface(
2043 self,
2044 sw_if_index,
2045 is_inside=1,
2046 is_add=1):
2047 """Enable/disable NAT66 feature on the interface
2048 :param sw_if_index: Index of the interface
2049 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2050 :param is_add: 1 if add, 0 if delete (Default value = 1)
2051 """
2052 return self.api(
2053 self.papi.nat66_add_del_interface,
2054 {'sw_if_index': sw_if_index,
2055 'is_inside': is_inside,
2056 'is_add': is_add})
2057
2058 def nat66_add_del_static_mapping(
2059 self,
2060 in_ip,
2061 out_ip,
2062 vrf_id=0,
2063 is_add=1):
2064 """Add/delete NAT66 static mapping
2065
2066 :param in_ip: Inside IPv6 address
2067 :param out_ip: Outside IPv6 address
2068 :param vrf_id: VRF ID (Default value = 0)
2069 :param is_add: 1 if add, 0 if delete (Default value = 1)
2070 """
2071 return self.api(
2072 self.papi.nat66_add_del_static_mapping,
2073 {'local_ip_address': in_ip,
2074 'external_ip_address': out_ip,
2075 'vrf_id': vrf_id,
2076 'is_add': is_add})
2077
2078 def nat66_interface_dump(self):
2079 """Dump interfaces with NAT66 feature
2080 :return: Dictionary of interfaces with NAT66 feature
2081 """
2082 return self.api(self.papi.nat66_interface_dump, {})
2083
2084 def nat66_static_mapping_dump(self):
2085 """Dump NAT66 static mappings
2086 :return: Dictionary of NAT66 static mappings
2087 """
2088 return self.api(self.papi.nat66_static_mapping_dump, {})
2089
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002090 def control_ping(self):
2091 self.api(self.papi.control_ping)
2092
2093 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002094 detect_mult, local_addr, peer_addr, is_ipv6=0,
2095 bfd_key_id=None, conf_key_id=None):
2096 if bfd_key_id is None:
2097 return self.api(self.papi.bfd_udp_add,
2098 {
2099 'sw_if_index': sw_if_index,
2100 'desired_min_tx': desired_min_tx,
2101 'required_min_rx': required_min_rx,
2102 'local_addr': local_addr,
2103 'peer_addr': peer_addr,
2104 'is_ipv6': is_ipv6,
2105 'detect_mult': detect_mult,
2106 })
2107 else:
2108 return self.api(self.papi.bfd_udp_add,
2109 {
2110 'sw_if_index': sw_if_index,
2111 'desired_min_tx': desired_min_tx,
2112 'required_min_rx': required_min_rx,
2113 'local_addr': local_addr,
2114 'peer_addr': peer_addr,
2115 'is_ipv6': is_ipv6,
2116 'detect_mult': detect_mult,
2117 'is_authenticated': 1,
2118 'bfd_key_id': bfd_key_id,
2119 'conf_key_id': conf_key_id,
2120 })
2121
Klement Sekeraa57a9702017-02-02 06:58:07 +01002122 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2123 detect_mult, local_addr, peer_addr, is_ipv6=0):
2124 return self.api(self.papi.bfd_udp_mod,
2125 {
2126 'sw_if_index': sw_if_index,
2127 'desired_min_tx': desired_min_tx,
2128 'required_min_rx': required_min_rx,
2129 'local_addr': local_addr,
2130 'peer_addr': peer_addr,
2131 'is_ipv6': is_ipv6,
2132 'detect_mult': detect_mult,
2133 })
2134
Klement Sekerab17dd962017-01-09 07:43:48 +01002135 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2136 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2137 is_delayed=False):
2138 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002139 {
2140 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002141 'local_addr': local_addr,
2142 'peer_addr': peer_addr,
2143 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002144 'is_delayed': 1 if is_delayed else 0,
2145 'bfd_key_id': bfd_key_id,
2146 'conf_key_id': conf_key_id,
2147 })
2148
2149 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2150 is_ipv6=0, is_delayed=False):
2151 return self.api(self.papi.bfd_udp_auth_deactivate,
2152 {
2153 'sw_if_index': sw_if_index,
2154 'local_addr': local_addr,
2155 'peer_addr': peer_addr,
2156 'is_ipv6': is_ipv6,
2157 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002158 })
2159
2160 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2161 return self.api(self.papi.bfd_udp_del,
2162 {
2163 'sw_if_index': sw_if_index,
2164 'local_addr': local_addr,
2165 'peer_addr': peer_addr,
2166 'is_ipv6': is_ipv6,
2167 })
2168
2169 def bfd_udp_session_dump(self):
2170 return self.api(self.papi.bfd_udp_session_dump, {})
2171
Klement Sekerab17dd962017-01-09 07:43:48 +01002172 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2173 peer_addr, is_ipv6=0):
2174 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002175 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002176 'sw_if_index': sw_if_index,
2177 'local_addr': local_addr,
2178 'peer_addr': peer_addr,
2179 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002180 })
2181
2182 def want_bfd_events(self, enable_disable=1):
2183 return self.api(self.papi.want_bfd_events, {
2184 'enable_disable': enable_disable,
2185 'pid': os.getpid(),
2186 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002187
Klement Sekerab17dd962017-01-09 07:43:48 +01002188 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2189 return self.api(self.papi.bfd_auth_set_key, {
2190 'conf_key_id': conf_key_id,
2191 'auth_type': auth_type,
2192 'key': key,
2193 'key_len': len(key),
2194 })
2195
2196 def bfd_auth_del_key(self, conf_key_id):
2197 return self.api(self.papi.bfd_auth_del_key, {
2198 'conf_key_id': conf_key_id,
2199 })
2200
2201 def bfd_auth_keys_dump(self):
2202 return self.api(self.papi.bfd_auth_keys_dump, {})
2203
Klement Sekera239790f2017-02-16 10:53:53 +01002204 def bfd_udp_set_echo_source(self, sw_if_index):
2205 return self.api(self.papi.bfd_udp_set_echo_source,
2206 {'sw_if_index': sw_if_index})
2207
Klement Sekera73884482017-02-23 09:26:30 +01002208 def bfd_udp_del_echo_source(self):
2209 return self.api(self.papi.bfd_udp_del_echo_source, {})
2210
Steve Shin7957d6e2016-12-19 09:24:50 -08002211 def classify_add_del_table(
2212 self,
2213 is_add,
2214 mask,
2215 match_n_vectors=1,
2216 table_index=0xFFFFFFFF,
2217 nbuckets=2,
2218 memory_size=2097152,
2219 skip_n_vectors=0,
2220 next_table_index=0xFFFFFFFF,
2221 miss_next_index=0xFFFFFFFF,
2222 current_data_flag=0,
2223 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002224 """
2225 :param is_add:
2226 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002227 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002228 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002229 :param nbuckets: (Default value = 2)
2230 :param memory_size: (Default value = 2097152)
2231 :param skip_n_vectors: (Default value = 0)
2232 :param next_table_index: (Default value = 0xFFFFFFFF)
2233 :param miss_next_index: (Default value = 0xFFFFFFFF)
2234 :param current_data_flag: (Default value = 0)
2235 :param current_data_offset: (Default value = 0)
2236 """
2237
Juraj Sloboda75282452018-06-12 14:20:49 +02002238 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2239 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002240 return self.api(
2241 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002242 {'is_add': is_add,
2243 'table_index': table_index,
2244 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002245 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002246 'skip_n_vectors': skip_n_vectors,
2247 'match_n_vectors': match_n_vectors,
2248 'next_table_index': next_table_index,
2249 'miss_next_index': miss_next_index,
2250 'current_data_flag': current_data_flag,
2251 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002252 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002253 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002254
2255 def classify_add_del_session(
2256 self,
2257 is_add,
2258 table_index,
2259 match,
2260 opaque_index=0xFFFFFFFF,
2261 hit_next_index=0xFFFFFFFF,
2262 advance=0,
2263 action=0,
2264 metadata=0):
2265 """
2266 :param is_add:
2267 :param table_index:
2268 :param match:
2269 :param opaque_index: (Default value = 0xFFFFFFFF)
2270 :param hit_next_index: (Default value = 0xFFFFFFFF)
2271 :param advance: (Default value = 0)
2272 :param action: (Default value = 0)
2273 :param metadata: (Default value = 0)
2274 """
2275
Juraj Sloboda75282452018-06-12 14:20:49 +02002276 match_len = ((len(match) - 1) / 16 + 1) * 16
2277 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002278 return self.api(
2279 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002280 {'is_add': is_add,
2281 'table_index': table_index,
2282 'hit_next_index': hit_next_index,
2283 'opaque_index': opaque_index,
2284 'advance': advance,
2285 'action': action,
2286 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002287 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002288 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002289
2290 def input_acl_set_interface(
2291 self,
2292 is_add,
2293 sw_if_index,
2294 ip4_table_index=0xFFFFFFFF,
2295 ip6_table_index=0xFFFFFFFF,
2296 l2_table_index=0xFFFFFFFF):
2297 """
2298 :param is_add:
2299 :param sw_if_index:
2300 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2301 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2302 :param l2_table_index: (Default value = 0xFFFFFFFF)
2303 """
2304
2305 return self.api(
2306 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002307 {'sw_if_index': sw_if_index,
2308 'ip4_table_index': ip4_table_index,
2309 'ip6_table_index': ip6_table_index,
2310 'l2_table_index': l2_table_index,
2311 'is_add': is_add})
2312
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002313 def output_acl_set_interface(
2314 self,
2315 is_add,
2316 sw_if_index,
2317 ip4_table_index=0xFFFFFFFF,
2318 ip6_table_index=0xFFFFFFFF,
2319 l2_table_index=0xFFFFFFFF):
2320 """
2321 :param is_add:
2322 :param sw_if_index:
2323 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2324 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2325 :param l2_table_index: (Default value = 0xFFFFFFFF)
2326 """
2327
2328 return self.api(
2329 self.papi.output_acl_set_interface,
2330 {'sw_if_index': sw_if_index,
2331 'ip4_table_index': ip4_table_index,
2332 'ip6_table_index': ip6_table_index,
2333 'l2_table_index': l2_table_index,
2334 'is_add': is_add})
2335
Klement Sekera77fabdb2017-01-02 07:46:14 +01002336 def set_ipfix_exporter(
2337 self,
2338 collector_address,
2339 src_address,
2340 path_mtu,
2341 template_interval,
2342 vrf_id=0,
2343 collector_port=4739,
2344 udp_checksum=0):
2345 return self.api(
2346 self.papi.set_ipfix_exporter,
2347 {
2348 'collector_address': collector_address,
2349 'collector_port': collector_port,
2350 'src_address': src_address,
2351 'vrf_id': vrf_id,
2352 'path_mtu': path_mtu,
2353 'template_interval': template_interval,
2354 'udp_checksum': udp_checksum,
2355 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002356
2357 def dhcp_proxy_config(self,
2358 dhcp_server,
2359 dhcp_src_address,
2360 rx_table_id=0,
2361 server_table_id=0,
2362 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002363 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002364 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002365 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002366 {
2367 'rx_vrf_id': rx_table_id,
2368 'server_vrf_id': server_table_id,
2369 'is_ipv6': is_ipv6,
2370 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002371 'dhcp_server': dhcp_server,
2372 'dhcp_src_address': dhcp_src_address,
2373 })
2374
2375 def dhcp_proxy_set_vss(self,
2376 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002377 vss_type=255,
2378 vpn_ascii_id="",
2379 oui=0,
2380 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002381 is_add=1,
2382 is_ip6=0):
2383 return self.api(
2384 self.papi.dhcp_proxy_set_vss,
2385 {
2386 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002387 'vss_type': vss_type,
2388 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002389 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002390 'vpn_index': vpn_index,
2391 'is_add': is_add,
2392 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002393 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002394
Neale Rannsdaff1782018-05-16 04:12:18 -07002395 def dhcp_client_dump(self):
2396 return self.api(self.papi.dhcp_client_dump, {})
2397
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002398 def dhcp_client(self,
2399 sw_if_index,
2400 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002401 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002402 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002403 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002404 want_dhcp_events=0):
2405 return self.api(
2406 self.papi.dhcp_client_config,
2407 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002408 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002409 'client': {
2410 'sw_if_index': sw_if_index,
2411 'hostname': hostname,
2412 'id': client_id,
2413 'want_dhcp_event': want_dhcp_events,
2414 'set_broadcast_flag': set_broadcast_flag,
2415 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002416 })
2417
Neale Ranns32e1c012016-11-22 17:07:28 +00002418 def ip_mroute_add_del(self,
2419 src_address,
2420 grp_address,
2421 grp_address_length,
2422 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002423 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002424 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002425 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002426 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002427 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002428 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002429 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002430 is_add=1,
2431 is_ipv6=0,
2432 is_local=0):
2433 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002434 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002435 """
2436 return self.api(
2437 self.papi.ip_mroute_add_del,
2438 {'next_hop_sw_if_index': next_hop_sw_if_index,
2439 'entry_flags': e_flags,
2440 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002441 'table_id': table_id,
2442 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002443 'is_add': is_add,
2444 'is_ipv6': is_ipv6,
2445 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002446 'bier_imp': bier_imp,
2447 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002448 'grp_address_length': grp_address_length,
2449 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002450 'src_address': src_address,
2451 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002452
2453 def mfib_signal_dump(self):
2454 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002455
2456 def ip_mfib_dump(self):
2457 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002458
Neale Rannsd792d9c2017-10-21 10:53:20 -07002459 def ip6_mfib_dump(self):
2460 return self.api(self.papi.ip6_mfib_dump, {})
2461
Filip Tehlar770e89e2017-01-31 10:39:16 +01002462 def lisp_enable_disable(self, is_enabled):
2463 return self.api(
2464 self.papi.lisp_enable_disable,
2465 {
2466 'is_en': is_enabled,
2467 })
2468
2469 def lisp_locator_set(self,
2470 ls_name,
2471 is_add=1):
2472 return self.api(
2473 self.papi.lisp_add_del_locator_set,
2474 {
2475 'is_add': is_add,
2476 'locator_set_name': ls_name
2477 })
2478
2479 def lisp_locator_set_dump(self):
2480 return self.api(self.papi.lisp_locator_set_dump, {})
2481
2482 def lisp_locator(self,
2483 ls_name,
2484 sw_if_index,
2485 priority=1,
2486 weight=1,
2487 is_add=1):
2488 return self.api(
2489 self.papi.lisp_add_del_locator,
2490 {
2491 'is_add': is_add,
2492 'locator_set_name': ls_name,
2493 'sw_if_index': sw_if_index,
2494 'priority': priority,
2495 'weight': weight
2496 })
2497
2498 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2499 return self.api(
2500 self.papi.lisp_locator_dump,
2501 {
2502 'is_index_set': is_index_set,
2503 'ls_name': ls_name,
2504 'ls_index': ls_index,
2505 })
2506
2507 def lisp_local_mapping(self,
2508 ls_name,
2509 eid_type,
2510 eid,
2511 prefix_len,
2512 vni=0,
2513 key_id=0,
2514 key="",
2515 is_add=1):
2516 return self.api(
2517 self.papi.lisp_add_del_local_eid,
2518 {
2519 'locator_set_name': ls_name,
2520 'is_add': is_add,
2521 'eid_type': eid_type,
2522 'eid': eid,
2523 'prefix_len': prefix_len,
2524 'vni': vni,
2525 'key_id': key_id,
2526 'key': key
2527 })
2528
2529 def lisp_eid_table_dump(self,
2530 eid_set=0,
2531 prefix_length=0,
2532 vni=0,
2533 eid_type=0,
2534 eid=None,
2535 filter_opt=0):
2536 return self.api(
2537 self.papi.lisp_eid_table_dump,
2538 {
2539 'eid_set': eid_set,
2540 'prefix_length': prefix_length,
2541 'vni': vni,
2542 'eid_type': eid_type,
2543 'eid': eid,
2544 'filter': filter_opt,
2545 })
2546
2547 def lisp_remote_mapping(self,
2548 eid_type,
2549 eid,
2550 eid_prefix_len=0,
2551 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002552 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002553 rlocs_num=0,
2554 is_src_dst=0,
2555 is_add=1):
2556 return self.api(
2557 self.papi.lisp_add_del_remote_mapping,
2558 {
2559 'is_add': is_add,
2560 'eid_type': eid_type,
2561 'eid': eid,
2562 'eid_len': eid_prefix_len,
2563 'rloc_num': rlocs_num,
2564 'rlocs': rlocs,
2565 'vni': vni,
2566 'is_src_dst': is_src_dst,
2567 })
2568
2569 def lisp_adjacency(self,
2570 leid,
2571 reid,
2572 leid_len,
2573 reid_len,
2574 eid_type,
2575 is_add=1,
2576 vni=0):
2577 return self.api(
2578 self.papi.lisp_add_del_adjacency,
2579 {
2580 'is_add': is_add,
2581 'vni': vni,
2582 'eid_type': eid_type,
2583 'leid': leid,
2584 'reid': reid,
2585 'leid_len': leid_len,
2586 'reid_len': reid_len,
2587 })
2588
2589 def lisp_adjacencies_get(self, vni=0):
2590 return self.api(
2591 self.papi.lisp_adjacencies_get,
2592 {
2593 'vni': vni
2594 })
Neale Ranns80823802017-02-20 18:23:41 -08002595
2596 def map_add_domain(self,
2597 ip6_prefix,
2598 ip6_prefix_len,
2599 ip6_src,
2600 ip6_src_prefix_len,
2601 ip4_prefix,
2602 ip4_prefix_len,
2603 ea_bits_len=0,
2604 psid_offset=0,
2605 psid_length=0,
2606 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002607 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002608 mtu=1280):
2609 return self.api(
2610 self.papi.map_add_domain,
2611 {
2612 'ip6_prefix': ip6_prefix,
2613 'ip6_prefix_len': ip6_prefix_len,
2614 'ip4_prefix': ip4_prefix,
2615 'ip4_prefix_len': ip4_prefix_len,
2616 'ip6_src': ip6_src,
2617 'ip6_src_prefix_len': ip6_src_prefix_len,
2618 'ea_bits_len': ea_bits_len,
2619 'psid_offset': psid_offset,
2620 'psid_length': psid_length,
2621 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002622 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002623 'mtu': mtu
2624 })
Hongjun Nief486b12017-04-12 19:21:16 +08002625
2626 def gtpu_add_del_tunnel(
2627 self,
2628 src_addr,
2629 dst_addr,
2630 is_add=1,
2631 is_ipv6=0,
2632 mcast_sw_if_index=0xFFFFFFFF,
2633 encap_vrf_id=0,
2634 decap_next_index=0xFFFFFFFF,
2635 teid=0):
2636 """
2637
2638 :param is_add: (Default value = 1)
2639 :param is_ipv6: (Default value = 0)
2640 :param src_addr:
2641 :param dst_addr:
2642 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2643 :param encap_vrf_id: (Default value = 0)
2644 :param decap_next_index: (Default value = 0xFFFFFFFF)
2645 :param teid: (Default value = 0)
2646
2647 """
2648 return self.api(self.papi.gtpu_add_del_tunnel,
2649 {'is_add': is_add,
2650 'is_ipv6': is_ipv6,
2651 'src_address': src_addr,
2652 'dst_address': dst_addr,
2653 'mcast_sw_if_index': mcast_sw_if_index,
2654 'encap_vrf_id': encap_vrf_id,
2655 'decap_next_index': decap_next_index,
2656 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002657
2658 def vxlan_gpe_add_del_tunnel(
2659 self,
2660 src_addr,
2661 dst_addr,
2662 mcast_sw_if_index=0xFFFFFFFF,
2663 is_add=1,
2664 is_ipv6=0,
2665 encap_vrf_id=0,
2666 decap_vrf_id=0,
2667 protocol=3,
2668 vni=0):
2669 """
2670
2671 :param local:
2672 :param remote:
2673 :param is_add: (Default value = 1)
2674 :param is_ipv6: (Default value = 0)
2675 :param encap_vrf_id: (Default value = 0)
2676 :param decap_vrf_id: (Default value = 0)
2677 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2678 :param protocol: (Default value = 3)
2679 :param vni: (Default value = 0)
2680
2681 """
2682 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2683 {'is_add': is_add,
2684 'is_ipv6': is_ipv6,
2685 'local': src_addr,
2686 'remote': dst_addr,
2687 'mcast_sw_if_index': mcast_sw_if_index,
2688 'encap_vrf_id': encap_vrf_id,
2689 'decap_vrf_id': decap_vrf_id,
2690 'protocol': protocol,
2691 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002692
2693 def pppoe_add_del_session(
2694 self,
2695 client_ip,
2696 client_mac,
2697 session_id=0,
2698 is_add=1,
2699 is_ipv6=0,
2700 decap_vrf_id=0):
2701 """
2702
2703 :param is_add: (Default value = 1)
2704 :param is_ipv6: (Default value = 0)
2705 :param client_ip:
2706 :param session_id: (Default value = 0)
2707 :param client_mac:
2708 :param decap_vrf_id: (Default value = 0)
2709
2710 """
2711 return self.api(self.papi.pppoe_add_del_session,
2712 {'is_add': is_add,
2713 'is_ipv6': is_ipv6,
2714 'session_id': session_id,
2715 'client_ip': client_ip,
2716 'decap_vrf_id': decap_vrf_id,
2717 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002718
Neale Ranns7c922dc2018-08-30 06:12:27 -07002719 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2720 return self.api(self.papi.sr_mpls_policy_add,
2721 {'bsid': bsid,
2722 'weight': weight,
2723 'type': type,
2724 'n_segments': len(segments),
2725 'segments': segments})
2726
2727 def sr_mpls_policy_del(self, bsid):
2728 return self.api(self.papi.sr_mpls_policy_del,
2729 {'bsid': bsid})
2730
Kris Michielsen91074432017-06-22 13:00:20 +02002731 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002732 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002733 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002734 nh_addr4,
2735 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002736 is_del=0,
2737 end_psp=0,
2738 sw_if_index=0xFFFFFFFF,
2739 vlan_index=0,
2740 fib_table=0,
2741 ):
2742 """ Add/del IPv6 SR local-SID.
2743
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002744 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002745 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2746 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002747 :param nh_addr4:
2748 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002749 :param is_del: (Default value = 0)
2750 :param end_psp: (Default value = 0)
2751 :param sw_if_index: (Default value = 0xFFFFFFFF)
2752 :param vlan_index: (Default value = 0)
2753 :param fib_table: (Default value = 0)
2754 """
2755 return self.api(
2756 self.papi.sr_localsid_add_del,
2757 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002758 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002759 'end_psp': end_psp,
2760 'behavior': behavior,
2761 'sw_if_index': sw_if_index,
2762 'vlan_index': vlan_index,
2763 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002764 'nh_addr4': nh_addr4,
2765 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002766 }
2767 )
2768
2769 def sr_policy_add(
2770 self,
2771 bsid_addr,
2772 weight=1,
2773 is_encap=1,
2774 type=0,
2775 fib_table=0,
2776 n_segments=0,
2777 segments=[]):
2778 """
2779 :param bsid_addr: bindingSID of the SR Policy
2780 :param weight: weight of the sid list. optional. (default: 1)
2781 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2782 (default: Encap)
2783 :param type: type/behavior of the SR policy. (default or spray) \
2784 (default: default)
2785 :param fib_table: VRF where to install the FIB entry for the BSID \
2786 (default: 0)
2787 :param n_segments: number of segments \
2788 (default: 0)
2789 :param segments: a vector of IPv6 address composing the segment list \
2790 (default: [])
2791 """
2792 return self.api(
2793 self.papi.sr_policy_add,
2794 {'bsid_addr': bsid_addr,
2795 'weight': weight,
2796 'is_encap': is_encap,
2797 'type': type,
2798 'fib_table': fib_table,
2799 'n_segments': n_segments,
2800 'segments': segments
2801 }
2802 )
2803
2804 def sr_policy_del(
2805 self,
2806 bsid_addr,
2807 sr_policy_index=0):
2808 """
2809 :param bsid: bindingSID of the SR Policy
2810 :param sr_policy_index: index of the sr policy (default: 0)
2811 """
2812 return self.api(
2813 self.papi.sr_policy_del,
2814 {'bsid_addr': bsid_addr,
2815 'sr_policy_index': sr_policy_index
2816 })
2817
2818 def sr_steering_add_del(
2819 self,
2820 is_del,
2821 bsid_addr,
2822 sr_policy_index,
2823 table_id,
2824 prefix_addr,
2825 mask_width,
2826 sw_if_index,
2827 traffic_type):
2828 """
2829 Steer traffic L2 and L3 traffic through a given SR policy
2830
2831 :param is_del: delete or add
2832 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2833 :param sr_policy: is the index of the SR Policy (alt to bsid)
2834 :param table_id: is the VRF where to install the FIB entry for the BSID
2835 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2836 :param mask_width: is the mask for L3 traffic type
2837 :param sw_if_index: is the incoming interface for L2 traffic
2838 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2839 """
2840 return self.api(
2841 self.papi.sr_steering_add_del,
2842 {'is_del': is_del,
2843 'bsid_addr': bsid_addr,
2844 'sr_policy_index': sr_policy_index,
2845 'table_id': table_id,
2846 'prefix_addr': prefix_addr,
2847 'mask_width': mask_width,
2848 'sw_if_index': sw_if_index,
2849 'traffic_type': traffic_type
2850 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002851
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002852 def acl_add_replace(self, acl_index, r, tag='',
2853 expected_retval=0):
2854 """Add/replace an ACL
2855 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2856 :param acl_rule r: ACL rules array.
2857 :param str tag: symbolic tag (description) for this ACL.
2858 :param int count: number of rules.
2859 """
2860 return self.api(self.papi.acl_add_replace,
2861 {'acl_index': acl_index,
2862 'r': r,
2863 'count': len(r),
2864 'tag': tag},
2865 expected_retval=expected_retval)
2866
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002867 def acl_del(self, acl_index, expected_retval=0):
2868 """
2869
2870 :param acl_index:
2871 :return:
2872 """
2873 return self.api(self.papi.acl_del,
2874 {'acl_index': acl_index},
2875 expected_retval=expected_retval)
2876
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002877 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2878 expected_retval=0):
2879 return self.api(self.papi.acl_interface_set_acl_list,
2880 {'sw_if_index': sw_if_index,
2881 'count': len(acls),
2882 'n_input': n_input,
2883 'acls': acls},
2884 expected_retval=expected_retval)
2885
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002886 def acl_interface_set_etype_whitelist(self, sw_if_index,
2887 n_input, whitelist,
2888 expected_retval=0):
2889 return self.api(self.papi.acl_interface_set_etype_whitelist,
2890 {'sw_if_index': sw_if_index,
2891 'count': len(whitelist),
2892 'n_input': n_input,
2893 'whitelist': whitelist},
2894 expected_retval=expected_retval)
2895
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002896 def acl_interface_add_del(self,
2897 sw_if_index,
2898 acl_index,
2899 is_add=1):
2900 """ Add/Delete ACL to/from interface
2901
2902 :param sw_if_index:
2903 :param acl_index:
2904 :param is_add: (Default value = 1)
2905 """
2906
2907 return self.api(self.papi.acl_interface_add_del,
2908 {'is_add': is_add,
2909 'is_input': 1,
2910 'sw_if_index': sw_if_index,
2911 'acl_index': acl_index})
2912
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002913 def acl_dump(self, acl_index, expected_retval=0):
2914 return self.api(self.papi.acl_dump,
2915 {'acl_index': acl_index},
2916 expected_retval=expected_retval)
2917
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002918 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2919 expected_retval=0):
2920 return self.api(self.papi.acl_interface_list_dump,
2921 {'sw_if_index': sw_if_index},
2922 expected_retval=expected_retval)
2923
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002924 def macip_acl_add(self, rules, tag=""):
2925 """ Add MACIP acl
2926
2927 :param rules: list of rules for given acl
2928 :param tag: acl tag
2929 """
2930
2931 return self.api(self.papi.macip_acl_add,
2932 {'r': rules,
2933 'count': len(rules),
2934 'tag': tag})
2935
Pavel Kotucek932f7412017-09-07 14:44:52 +02002936 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2937 """ Add MACIP acl
2938
2939 :param rules: list of rules for given acl
2940 :param tag: acl tag
2941 """
2942
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002943 return self.api(self.papi.macip_acl_add_replace,
2944 {'acl_index': acl_index,
2945 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002946 'count': len(rules),
2947 'tag': tag})
2948
2949 def macip_acl_del(self, acl_index):
2950 """
2951
2952 :param acl_index:
2953 :return:
2954 """
2955 return self.api(self.papi.macip_acl_del,
2956 {'acl_index': acl_index})
2957
2958 def macip_acl_interface_add_del(self,
2959 sw_if_index,
2960 acl_index,
2961 is_add=1):
2962 """ Add MACIP acl to interface
2963
2964 :param sw_if_index:
2965 :param acl_index:
2966 :param is_add: (Default value = 1)
2967 """
2968
2969 return self.api(self.papi.macip_acl_interface_add_del,
2970 {'is_add': is_add,
2971 'sw_if_index': sw_if_index,
2972 'acl_index': acl_index})
2973
2974 def macip_acl_interface_get(self):
2975 """ Return interface acls dump
2976 """
2977 return self.api(
2978 self.papi.macip_acl_interface_get, {})
2979
2980 def macip_acl_dump(self, acl_index=4294967295):
2981 """ Return MACIP acl dump
2982 """
2983
2984 return self.api(
2985 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002986
2987 def policer_add_del(self,
2988 name,
2989 cir,
2990 eir,
2991 cb,
2992 eb,
2993 is_add=1,
2994 rate_type=0,
2995 round_type=0,
2996 ptype=0,
2997 color_aware=0,
2998 conform_action_type=1,
2999 conform_dscp=0,
3000 exceed_action_type=0,
3001 exceed_dscp=0,
3002 violate_action_type=0,
3003 violate_dscp=0):
3004 return self.api(self.papi.policer_add_del,
3005 {'name': name,
3006 'cir': cir,
3007 'eir': eir,
3008 'cb': cb,
3009 'eb': eb,
3010 'is_add': is_add,
3011 'rate_type': rate_type,
3012 'round_type': round_type,
3013 'type': ptype,
3014 'color_aware': color_aware,
3015 'conform_action_type': conform_action_type,
3016 'conform_dscp': conform_dscp,
3017 'exceed_action_type': exceed_action_type,
3018 'exceed_dscp': exceed_dscp,
3019 'violate_action_type': violate_action_type,
3020 'violate_dscp': violate_dscp})
3021
3022 def ip_punt_police(self,
3023 policer_index,
3024 is_ip6=0,
3025 is_add=1):
3026 return self.api(self.papi.ip_punt_police,
3027 {'policer_index': policer_index,
3028 'is_add': is_add,
3029 'is_ip6': is_ip6})
3030
3031 def ip_punt_redirect(self,
3032 rx_sw_if_index,
3033 tx_sw_if_index,
3034 nh,
3035 is_ip6=0,
3036 is_add=1):
3037 return self.api(self.papi.ip_punt_redirect,
3038 {'rx_sw_if_index': rx_sw_if_index,
3039 'tx_sw_if_index': tx_sw_if_index,
3040 'nh': nh,
3041 'is_add': is_add,
3042 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003043
3044 def bier_table_add_del(self,
3045 bti,
3046 mpls_label,
3047 is_add=1):
3048 """ BIER Table add/del """
3049 return self.api(
3050 self.papi.bier_table_add_del,
3051 {'bt_tbl_id': {"bt_set": bti.set_id,
3052 "bt_sub_domain": bti.sub_domain_id,
3053 "bt_hdr_len_id": bti.hdr_len_id},
3054 'bt_label': mpls_label,
3055 'bt_is_add': is_add})
3056
3057 def bier_table_dump(self):
3058 return self.api(self.papi.bier_table_dump, {})
3059
3060 def bier_route_add_del(self,
3061 bti,
3062 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003063 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003064 is_add=1):
3065 """ BIER Route add/del """
3066 return self.api(
3067 self.papi.bier_route_add_del,
3068 {'br_tbl_id': {"bt_set": bti.set_id,
3069 "bt_sub_domain": bti.sub_domain_id,
3070 "bt_hdr_len_id": bti.hdr_len_id},
3071 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003072 'br_n_paths': len(paths),
3073 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003074 'br_is_add': is_add})
3075
3076 def bier_route_dump(self, bti):
3077 return self.api(
3078 self.papi.bier_route_dump,
3079 {'br_tbl_id': {"bt_set": bti.set_id,
3080 "bt_sub_domain": bti.sub_domain_id,
3081 "bt_hdr_len_id": bti.hdr_len_id}})
3082
3083 def bier_imp_add(self,
3084 bti,
3085 src,
3086 ibytes,
3087 is_add=1):
3088 """ BIER Imposition Add """
3089 return self.api(
3090 self.papi.bier_imp_add,
3091 {'bi_tbl_id': {"bt_set": bti.set_id,
3092 "bt_sub_domain": bti.sub_domain_id,
3093 "bt_hdr_len_id": bti.hdr_len_id},
3094 'bi_src': src,
3095 'bi_n_bytes': len(ibytes),
3096 'bi_bytes': ibytes})
3097
3098 def bier_imp_del(self, bi_index):
3099 """ BIER Imposition del """
3100 return self.api(
3101 self.papi.bier_imp_del,
3102 {'bi_index': bi_index})
3103
3104 def bier_imp_dump(self):
3105 return self.api(self.papi.bier_imp_dump, {})
3106
3107 def bier_disp_table_add_del(self,
3108 bdti,
3109 is_add=1):
3110 """ BIER Disposition Table add/del """
3111 return self.api(
3112 self.papi.bier_disp_table_add_del,
3113 {'bdt_tbl_id': bdti,
3114 'bdt_is_add': is_add})
3115
3116 def bier_disp_table_dump(self):
3117 return self.api(self.papi.bier_disp_table_dump, {})
3118
3119 def bier_disp_entry_add_del(self,
3120 bdti,
3121 bp,
3122 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003123 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003124 next_hop,
3125 next_hop_tbl_id=0,
3126 next_hop_rpf_id=~0,
3127 next_hop_is_ip4=1,
3128 is_add=1):
3129 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003130 lstack = []
3131 while (len(lstack) < 16):
3132 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003133 return self.api(
3134 self.papi.bier_disp_entry_add_del,
3135 {'bde_tbl_id': bdti,
3136 'bde_bp': bp,
3137 'bde_payload_proto': payload_proto,
3138 'bde_n_paths': 1,
3139 'bde_paths': [{'next_hop': next_hop,
3140 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003141 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003142 'rpf_id': next_hop_rpf_id,
3143 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003144 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003145 'bde_is_add': is_add})
3146
3147 def bier_disp_entry_dump(self, bdti):
3148 return self.api(
3149 self.papi.bier_disp_entry_dump,
3150 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003151
3152 def add_node_next(self, node_name, next_name):
3153 """ Set the next node for a given node request
3154
3155 :param node_name:
3156 :param next_name:
3157 """
3158 return self.api(self.papi.add_node_next,
3159 {'node_name': node_name,
3160 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003161
3162 def session_enable_disable(self, is_enabled):
3163 return self.api(
3164 self.papi.session_enable_disable,
3165 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003166
3167 def ipsec_spd_add_del(self, spd_id, is_add=1):
3168 """ SPD add/del - Wrapper to add or del ipsec SPD
3169 Sample CLI : 'ipsec spd add 1'
3170
3171 :param spd_id - SPD ID to be created in the vpp . mandatory
3172 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3173 optional
3174 :returns: reply from the API
3175 """
3176 return self.api(
3177 self.papi.ipsec_spd_add_del, {
3178 'spd_id': spd_id, 'is_add': is_add})
3179
3180 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3181 """ IPSEC interface SPD add/del - \
3182 Wrapper to associate/disassociate SPD to interface in VPP
3183 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3184
3185 :param spd_id - SPD ID to associate with the interface . mandatory
3186 :param sw_if_index - Interface Index which needs to ipsec \
3187 association mandatory
3188 :param is_add - add(1) or del(0) association with interface \
3189 (Default 1 - add) . optional
3190 :returns: reply from the API
3191 """
3192 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003193 self.papi.ipsec_interface_add_del_spd,
3194 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003195
3196 def ipsec_sad_add_del_entry(self,
3197 sad_id,
3198 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003199 integrity_algorithm,
3200 integrity_key,
3201 crypto_algorithm,
3202 crypto_key,
3203 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003204 tunnel_src_address='',
3205 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003206 is_tunnel=1,
Klement Sekera31da2e32018-06-24 22:49:55 +02003207 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003208 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003209 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003210 :param sad_id: security association ID
3211 :param spi: security param index of the SA in decimal
3212 :param integrity_algorithm:
3213 :param integrity_key:
3214 :param crypto_algorithm:
3215 :param crypto_key:
3216 :param protocol: AH(0) or ESP(1) protocol
3217 :param tunnel_src_address: tunnel mode outer src address
3218 :param tunnel_dst_address: tunnel mode outer dst address
3219 :param is_add:
3220 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003221 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3222 crypto and ipsec algorithms
3223 """
3224 return self.api(
3225 self.papi.ipsec_sad_add_del_entry,
3226 {'sad_id': sad_id,
3227 'spi': spi,
3228 'tunnel_src_address': tunnel_src_address,
3229 'tunnel_dst_address': tunnel_dst_address,
3230 'protocol': protocol,
3231 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003232 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003233 'integrity_key': integrity_key,
3234 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003235 'crypto_key_length': len(crypto_key) if crypto_key is not None
3236 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003237 'crypto_key': crypto_key,
3238 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003239 'is_tunnel': is_tunnel,
3240 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003241
3242 def ipsec_spd_add_del_entry(self,
3243 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003244 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003245 local_address_start,
3246 local_address_stop,
3247 remote_address_start,
3248 remote_address_stop,
3249 local_port_start=0,
3250 local_port_stop=65535,
3251 remote_port_start=0,
3252 remote_port_stop=65535,
3253 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003254 policy=0,
3255 priority=100,
3256 is_outbound=1,
3257 is_add=1,
3258 is_ip_any=0):
3259 """ IPSEC policy SPD add/del -
3260 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003261 :param spd_id: SPD ID for the policy
3262 :param local_address_start: local-ip-range start address
3263 :param local_address_stop : local-ip-range stop address
3264 :param remote_address_start: remote-ip-range start address
3265 :param remote_address_stop : remote-ip-range stop address
3266 :param local_port_start: (Default value = 0)
3267 :param local_port_stop: (Default value = 65535)
3268 :param remote_port_start: (Default value = 0)
3269 :param remote_port_stop: (Default value = 65535)
3270 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3271 :param sa_id: Security Association ID for mapping it to SPD
3272 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3273 (Default value = 0)
3274 :param priority: value for the spd action (Default value = 100)
3275 :param is_outbound: flag for inbound(0) or outbound(1)
3276 (Default value = 1)
3277 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003278 """
3279 return self.api(
3280 self.papi.ipsec_spd_add_del_entry,
3281 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003282 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003283 'local_address_start': local_address_start,
3284 'local_address_stop': local_address_stop,
3285 'remote_address_start': remote_address_start,
3286 'remote_address_stop': remote_address_stop,
3287 'local_port_start': local_port_start,
3288 'local_port_stop': local_port_stop,
3289 'remote_port_start': remote_port_start,
3290 'remote_port_stop': remote_port_stop,
3291 'is_add': is_add,
3292 'protocol': protocol,
3293 'policy': policy,
3294 'priority': priority,
3295 'is_outbound': is_outbound,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003296 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003297
Klement Sekera31da2e32018-06-24 22:49:55 +02003298 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3299 remote_spi, crypto_alg, local_crypto_key,
3300 remote_crypto_key, integ_alg, local_integ_key,
3301 remote_integ_key, is_add=1, esn=0,
3302 anti_replay=1, renumber=0, show_instance=0):
3303 return self.api(
3304 self.papi.ipsec_tunnel_if_add_del,
3305 {'local_ip': local_ip, 'remote_ip': remote_ip,
3306 'local_spi': local_spi, 'remote_spi': remote_spi,
3307 'crypto_alg': crypto_alg,
3308 'local_crypto_key_len': len(local_crypto_key),
3309 'local_crypto_key': local_crypto_key,
3310 'remote_crypto_key_len': len(remote_crypto_key),
3311 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3312 'local_integ_key_len': len(local_integ_key),
3313 'local_integ_key': local_integ_key,
3314 'remote_integ_key_len': len(remote_integ_key),
3315 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3316 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3317 'show_instance': show_instance
3318 })
3319
Florin Corasb795bd02017-12-14 11:30:48 -08003320 def app_namespace_add(self,
3321 namespace_id,
3322 ip4_fib_id=0,
3323 ip6_fib_id=0,
3324 sw_if_index=0xFFFFFFFF,
3325 secret=0):
3326 return self.api(
3327 self.papi.app_namespace_add_del,
3328 {'secret': secret,
3329 'sw_if_index': sw_if_index,
3330 'ip4_fib_id': ip4_fib_id,
3331 'ip6_fib_id': ip6_fib_id,
3332 'namespace_id': namespace_id,
3333 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003334
3335 def punt_socket_register(self, l4_port, pathname, header_version=1,
3336 is_ip4=1, l4_protocol=0x11):
3337 """ Punt to socket """
3338 return self.api(self.papi.punt_socket_register,
3339 {'is_ip4': is_ip4,
3340 'l4_protocol': l4_protocol,
3341 'l4_port': l4_port,
3342 'pathname': pathname,
3343 'header_version': header_version})
3344
3345 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3346 expire_walk_interval_ms, is_ip6=0):
3347 """ Set IP reassembly parameters """
3348 return self.api(self.papi.ip_reassembly_set,
3349 {'is_ip6': is_ip6,
3350 'timeout_ms': timeout_ms,
3351 'expire_walk_interval_ms': expire_walk_interval_ms,
3352 'max_reassemblies': max_reassemblies})
3353
3354 def ip_reassembly_get(self, is_ip6=0):
3355 """ Get IP reassembly parameters """
3356 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003357
Klement Sekera4c533132018-02-22 11:41:12 +01003358 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3359 enable_ip6=False):
3360 """ Enable/disable IP reassembly """
3361 return self.api(self.papi.ip_reassembly_enable_disable,
3362 {'sw_if_index': sw_if_index,
3363 'enable_ip4': 1 if enable_ip4 else 0,
3364 'enable_ip6': 1 if enable_ip6 else 0,
3365 })
3366
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003367 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3368 """ GBP endpoint Add/Del """
3369 return self.api(self.papi.gbp_endpoint_add_del,
3370 {'is_add': is_add,
3371 'endpoint': {
3372 'is_ip6': is_ip6,
3373 'sw_if_index': sw_if_index,
3374 'address': addr,
3375 'epg_id': epg}})
3376
3377 def gbp_endpoint_dump(self):
3378 """ GBP endpoint Dump """
3379 return self.api(self.papi.gbp_endpoint_dump, {})
3380
Neale Ranns25b04942018-04-04 09:34:50 -07003381 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3382 ip4_rd,
3383 ip6_rd,
3384 uplink_sw_if_index):
3385 """ GBP endpoint group Add/Del """
3386 return self.api(self.papi.gbp_endpoint_group_add_del,
3387 {'is_add': is_add,
3388 'epg': {
3389 'uplink_sw_if_index': uplink_sw_if_index,
3390 'bd_id': bd,
3391 'ip4_table_id': ip4_rd,
3392 'ip6_table_id': ip6_rd,
3393 'epg_id': epg}})
3394
3395 def gbp_endpoint_group_dump(self):
3396 """ GBP endpoint group Dump """
3397 return self.api(self.papi.gbp_endpoint_group_dump, {})
3398
3399 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3400 """ GBP recirc Add/Del """
3401 return self.api(self.papi.gbp_recirc_add_del,
3402 {'is_add': is_add,
3403 'recirc': {
3404 'is_ext': is_ext,
3405 'sw_if_index': sw_if_index,
3406 'epg_id': epg}})
3407
3408 def gbp_recirc_dump(self):
3409 """ GBP recirc Dump """
3410 return self.api(self.papi.gbp_recirc_dump, {})
3411
3412 def gbp_subnet_add_del(self, is_add, table_id,
3413 is_internal,
3414 addr, addr_len,
3415 sw_if_index=0xffffffff,
3416 epg_id=0xffffffff,
3417 is_ip6=False):
3418 """ GBP Subnet Add/Del """
3419 return self.api(self.papi.gbp_subnet_add_del,
3420 {'is_add': is_add,
3421 'subnet': {
3422 'is_internal': is_internal,
3423 'is_ip6': is_ip6,
3424 'sw_if_index': sw_if_index,
3425 'epg_id': epg_id,
3426 'address': addr,
3427 'address_length': addr_len,
3428 'table_id': table_id}})
3429
3430 def gbp_subnet_dump(self):
3431 """ GBP Subnet Dump """
3432 return self.api(self.papi.gbp_subnet_dump, {})
3433
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003434 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3435 """ GBP contract Add/Del """
3436 return self.api(self.papi.gbp_contract_add_del,
3437 {'is_add': is_add,
3438 'contract': {
3439 'acl_index': acl_index,
3440 'src_epg': src_epg,
3441 'dst_epg': dst_epg}})
3442
3443 def gbp_contract_dump(self):
3444 """ GBP contract Dump """
3445 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003446
Neale Ranns61502112018-08-22 00:21:14 -07003447 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3448 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003449 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003450 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003451 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003452 {'ip4_table_id': ip4_table_id,
3453 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003454 'ip6_prefix': ip6_prefix,
3455 'ip6_prefix_len': ip6_prefix_len,
3456 'ip4_prefix': ip4_prefix,
3457 'ip4_prefix_len': ip4_prefix_len,
3458 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003459 'security_check': security_check})
3460
Ole Troan298c6952018-03-08 12:30:43 +01003461 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003462 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003463 return self.api(self.papi.ipip_6rd_del_tunnel,
3464 {'sw_if_index': sw_if_index})
3465
3466 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003467 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003468 """ IPIP tunnel Add/Del """
3469 return self.api(self.papi.ipip_add_tunnel,
3470 {'is_ipv6': is_ipv6,
3471 'instance': instance,
3472 'src_address': src_address,
3473 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003474 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003475 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003476
3477 def ipip_del_tunnel(self, sw_if_index):
3478 """ IPIP tunnel Delete """
3479 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003480 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003481
3482 def qos_egress_map_update(self, id, outputs):
3483 """ QOS egress map update """
3484 return self.api(self.papi.qos_egress_map_update,
3485 {'map_id': id,
3486 'rows': outputs})
3487
3488 def qos_egress_map_delete(self, id):
3489 """ QOS egress map delete """
3490 return self.api(self.papi.qos_egress_map_delete,
3491 {'map_id': id})
3492
3493 def qos_mark_enable_disable(self, sw_if_index,
3494 output_source,
3495 map_id,
3496 enable):
3497 """ QOS Mark Enable/Disable """
3498 return self.api(self.papi.qos_mark_enable_disable,
3499 {'map_id': map_id,
3500 'sw_if_index': sw_if_index,
3501 'output_source': output_source,
3502 'enable': enable})
3503
3504 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3505 """ IP QoS recording Enble/Disable """
3506 return self.api(self.papi.qos_record_enable_disable,
3507 {'sw_if_index': sw_if_index,
3508 'input_source': input_source,
3509 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003510
Neale Ranns947ea622018-06-07 23:48:20 -07003511 def igmp_enable_disable(self, sw_if_index, enable, host):
3512 """ Enable/disable IGMP on a given interface """
3513 return self.api(self.papi.igmp_enable_disable,
3514 {'enable': enable,
3515 'mode': host,
3516 'sw_if_index': sw_if_index})
3517
3518 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003519 """ Listen for new (S,G) on specified interface
3520
3521 :param enable: add/del
3522 :param sw_if_index: interface sw index
3523 :param saddr: source ip4 addr
3524 :param gaddr: group ip4 addr
3525 """
3526 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003527 {
3528 'group':
3529 {
3530 'filter': filter,
3531 'sw_if_index': sw_if_index,
3532 'n_srcs': len(saddrs),
3533 'saddrs': saddrs,
3534 'gaddr':
3535 {
3536 'address': gaddr
3537 }
3538 }
3539 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003540
3541 def igmp_dump(self, sw_if_index=None):
3542 """ Dump all (S,G) interface configurations """
3543 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003544 sw_if_index = 0xffffffff
3545 return self.api(self.papi.igmp_dump,
3546 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003547
3548 def igmp_clear_interface(self, sw_if_index):
3549 """ Remove all (S,G)s from specified interface
3550 doesn't send IGMP report!
3551 """
3552 return self.api(
3553 self.papi.igmp_clear_interface, {
3554 'sw_if_index': sw_if_index})
3555
3556 def want_igmp_events(self, enable=1):
3557 return self.api(self.papi.want_igmp_events, {'enable': enable,
3558 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003559
3560 def bond_create(
3561 self,
3562 mode,
3563 lb,
3564 use_custom_mac,
3565 mac_address=''):
3566 """
3567 :param mode: mode
3568 :param lb: load balance
3569 :param use_custom_mac: use custom mac
3570 :param mac_address: mac address
3571 """
3572 return self.api(
3573 self.papi.bond_create,
3574 {'mode': mode,
3575 'lb': lb,
3576 'use_custom_mac': use_custom_mac,
3577 'mac_address': mac_address
3578 })
3579
3580 def bond_delete(
3581 self,
3582 sw_if_index):
3583 """
3584 :param sw_if_index: interface the operation is applied to
3585 """
3586 return self.api(self.papi.bond_delete,
3587 {'sw_if_index': sw_if_index})
3588
3589 def bond_enslave(
3590 self,
3591 sw_if_index,
3592 bond_sw_if_index,
3593 is_passive,
3594 is_long_timeout):
3595 """
3596 :param sw_if_index: slave sw_if_index
3597 :param bond_sw_if_index: bond sw_if_index
3598 :param is_passive: is passive lacp speaker
3599 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3600 """
3601 return self.api(
3602 self.papi.bond_enslave,
3603 {'sw_if_index': sw_if_index,
3604 'bond_sw_if_index': bond_sw_if_index,
3605 'is_passive': is_passive,
3606 'is_long_timeout': is_long_timeout
3607 })
3608
3609 def bond_detach_slave(
3610 self,
3611 sw_if_index):
3612 """
3613 :param sw_if_index: slave interface the operation is applied to
3614 """
3615 return self.api(self.papi.bond_detach_slave,
3616 {'sw_if_index': sw_if_index})
3617
3618 def sw_interface_slave_dump(
3619 self,
3620 sw_if_index):
3621 """
3622 :param sw_if_index: bond sw_if_index
3623 """
3624 return self.api(self.papi.sw_interface_slave_dump,
3625 {'sw_if_index': sw_if_index})
3626
3627 def sw_interface_bond_dump(
3628 self):
3629 """
3630
3631 """
3632 return self.api(self.papi.sw_interface_bond_dump,
3633 {})
Stevene8fa6202017-08-30 14:36:45 -07003634
3635 def create_vhost_user_if(
3636 self,
3637 is_server,
3638 sock_filename,
3639 renumber,
3640 custom_dev_instance,
3641 use_custom_mac,
3642 mac_address,
3643 tag=''):
3644 """
3645 :param is_server: is server
3646 :param sock_filename: socket name
3647 :param renumber: renumber
3648 :param custom_dev_instance: custom dev instance
3649 :param use_custom_mac: use custom mac
3650 :param mac_address: mac address
3651 :param tag: tag (default ''
3652 """
3653 return self.api(
3654 self.papi.create_vhost_user_if,
3655 {'is_server': is_server,
3656 'sock_filename': sock_filename,
3657 'renumber': renumber,
3658 'custom_dev_instance': custom_dev_instance,
3659 'use_custom_mac': use_custom_mac,
3660 'mac_address': mac_address,
3661 'tag': tag
3662 })
3663
3664 def delete_vhost_user_if(
3665 self,
3666 sw_if_index):
3667 """
3668 :param sw_if_index: interface the operation is applied to
3669 """
3670 return self.api(self.papi.delete_vhost_user_if,
3671 {'sw_if_index': sw_if_index, })
3672
3673 def sw_interface_vhost_user_dump(
3674 self):
3675 """
3676
3677 """
3678 return self.api(self.papi.sw_interface_vhost_user_dump,
3679 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003680
3681 def abf_policy_add_del(self, is_add, policy):
3682 return self.api(
3683 self.papi.abf_policy_add_del,
3684 {'is_add': is_add,
3685 'policy': policy})
3686
3687 def abf_itf_attach_add_del(self, is_add, attach):
3688 return self.api(
3689 self.papi.abf_itf_attach_add_del,
3690 {'is_add': is_add,
3691 'attach': attach})
3692
3693 def abf_policy_dump(self):
3694 return self.api(
3695 self.papi.abf_policy_dump, {})
3696
3697 def abf_itf_attach_dump(self):
3698 return self.api(
3699 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003700
3701 def pipe_create(self, is_specified, user_instance):
3702 return self.api(self.papi.pipe_create,
3703 {'is_specified': is_specified,
3704 'user_instance': user_instance})
3705
3706 def pipe_delete(self, parent_sw_if_index):
3707 return self.api(self.papi.pipe_delete,
3708 {'parent_sw_if_index': parent_sw_if_index})
3709
3710 def pipe_dump(self):
3711 return self.api(self.papi.pipe_dump, {})