blob: efe1454c93492c00537d110104d37800b84524ee [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import fnmatch
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08002import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02003import time
Klement Sekerae4504c62016-12-08 10:16:41 +01004from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02005
Paul Vinciguerra6c746172018-11-26 09:57:21 -08006from six import moves
Paul Vinciguerra84679192019-01-13 11:33:52 -08007from vpp_papi import VPP, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008from hook import Hook
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -08009from vpp_l2 import L2_PORT_TYPE
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080010
Klement Sekeraf62ae122016-10-11 11:47:09 +020011# from vnet/vnet/mpls/mpls_types.h
12MPLS_IETF_MAX_LABEL = 0xfffff
13MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
14
Klement Sekera0e3c0de2016-09-29 14:43:44 +020015
Neale Ranns177bbdc2016-11-15 09:46:51 +000016class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030017 L2_DISABLED = 0
18 L2_PUSH_1 = 1
19 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000020 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030021 L2_POP_2 = 4
22 L2_TRANSLATE_1_1 = 5
23 L2_TRANSLATE_1_2 = 6
24 L2_TRANSLATE_2_1 = 7
25 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000026
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns039cbfe2018-02-27 03:45:38 -080028class QOS_SOURCE:
29 EXT = 0
30 VLAN = 1
31 MPLS = 2
32 IP = 3
33
34
Matus Fabianb4515b42018-11-19 04:25:32 -080035class SYSLOG_SEVERITY:
36 EMERG = 0
37 ALERT = 1
38 CRIT = 2
39 ERR = 3
40 WARN = 4
41 NOTICE = 5
42 INFO = 6
43 DBG = 7
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 Sekera611864f2018-09-26 11:19:00 +020059 def __init__(self, name, shm_prefix, test_class, read_timeout):
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
Klement Sekerab8c72a42018-11-08 11:21:39 +010067 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010068
Paul Vinciguerra04575c52019-01-13 10:26:05 -080069 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
70 if 'VPP_API_DIR' not in os.environ:
71 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
72
73 self.vpp = VPP(logger=test_class.logger,
Klement Sekera611864f2018-09-26 11:19:00 +020074 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010075 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020076
Klement Sekerae0545ef2017-01-25 08:00:40 +010077 def __enter__(self):
78 return self
79
Klement Sekera7d6afb32018-11-08 11:52:04 +010080 def assert_negative_api_retval(self):
81 """ Expect API failure - used with with, e.g.:
82 with self.vapi.assert_negative_api_retval():
83 self.vapi.<api call expected to fail>
84 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010085 self._expect_stack.append(self._expect_api_retval)
86 self._expect_api_retval = self._negative
87 return self
88
Klement Sekera7d6afb32018-11-08 11:52:04 +010089 def assert_zero_api_retval(self):
90 """ Expect API success - used with with, e.g.:
91 with self.vapi.assert_negative_api_retval():
92 self.vapi.<api call expected to succeed>
93
94 note: this is useful only inside another with block
95 as success is the default expected value
96 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010097 self._expect_stack.append(self._expect_api_retval)
98 self._expect_api_retval = self._zero
99 return self
100
101 def __exit__(self, exc_type, exc_value, traceback):
102 self._expect_api_retval = self._expect_stack.pop()
103
Klement Sekeraf62ae122016-10-11 11:47:09 +0200104 def register_hook(self, hook):
105 """Replace hook registration with new hook
106
107 :param hook:
108
109 """
110 self.hook = hook
111
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200112 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100113 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200114 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100115 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200116 return e
117
118 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100119 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100120 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100121 self.test_class.logger.debug("Expecting event '%s' within %ss",
122 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300123 else:
124 self.test_class.logger.debug("Expecting event within %ss",
125 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 if self._events:
127 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200128 limit = time.time() + timeout
129 while time.time() < limit:
130 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100131 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200132 if name and type(e).__name__ != name:
133 raise Exception(
134 "Unexpected event received: %s, expected: %s" %
135 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100136 self.test_class.logger.debug("Returning event %s:%s" %
137 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200138 return e
139 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200140 raise Exception("Event did not occur within timeout")
141
142 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200144 # FIXME use the name instead of relying on type(e).__name__ ?
145 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100146 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200147 self._events.append(event)
148
Klement Sekeraf62ae122016-10-11 11:47:09 +0200149 def connect(self):
150 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100151 self.vpp.connect(self.name, self.shm_prefix)
152 self.papi = self.vpp.api
153 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200154
155 def disconnect(self):
156 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100157 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200158
159 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100160 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200161 Call the appropriate hooks before and after the API call
162
163 :param api_fn: API function to call
164 :param api_args: tuple of API function arguments
165 :param expected_retval: Expected return value (Default value = 0)
166 :returns: reply from the API
167
168 """
169 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100170 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100171 if self._expect_api_retval == self._negative:
172 if hasattr(reply, 'retval') and reply.retval >= 0:
173 msg = "API call passed unexpectedly: expected negative "\
174 "return value instead of %d in %s" % \
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800175 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100176 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100177 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100178 elif self._expect_api_retval == self._zero:
179 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700180 msg = "API call failed, expected %d return value instead "\
181 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800182 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100183 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100184 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100185 else:
186 raise Exception("Internal error, unexpected value for "
187 "self._expect_api_retval %s" %
188 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200189 self.hook.after_api(api_fn.__name__, api_args)
190 return reply
191
192 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100193 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194
195 :param cli: CLI to execute
196 :returns: CLI output
197
198 """
199 self.hook.before_cli(cli)
200 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100201 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200202 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200203 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100204 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200205
Jan49c0fca2016-10-26 15:44:27 +0200206 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100207 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200208
209 :param cli: CLI to execute
210 :returns: CLI output
211 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600212 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200213
Klement Sekeraf62ae122016-10-11 11:47:09 +0200214 def show_version(self):
215 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100216 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217
218 def pg_create_interface(self, pg_index):
219 """
220
221 :param pg_index:
222
223 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100224 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200225 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200226
227 def sw_interface_dump(self, filter=None):
228 """
229
230 :param filter: (Default value = None)
231
232 """
233 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200235 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100236 args = {}
237 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000239 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100240 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000241
242 :param sw_if_index:
243 :param is_ipv6:
244 :param table_id:
245
246 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100247 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200248 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
249 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000250
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700251 def sw_interface_get_table(self, sw_if_index, is_ipv6):
252 """ Get the IPvX Table-id for the Interface
253
254 :param sw_if_index:
255 :param is_ipv6:
256 :return table_id
257
258 """
259 return self.api(self.papi.sw_interface_get_table,
260 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
261
Klement Sekeraf62ae122016-10-11 11:47:09 +0200262 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
263 is_ipv6=0, is_add=1, del_all=0):
264 """
265
266 :param addr: param is_ipv6: (Default value = 0)
267 :param sw_if_index:
268 :param addr_len:
269 :param is_ipv6: (Default value = 0)
270 :param is_add: (Default value = 1)
271 :param del_all: (Default value = 0)
272
273 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100274 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200275 {'sw_if_index': sw_if_index,
276 'is_add': is_add,
277 'is_ipv6': is_ipv6,
278 'del_all': del_all,
279 'address_length': addr_len,
280 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200281
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700282 def ip_address_dump(self, sw_if_index, is_ipv6=0):
283 return self.api(self.papi.ip_address_dump,
284 {'sw_if_index': sw_if_index,
285 'is_ipv6': is_ipv6})
286
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800287 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
288 is_add=1):
289 """ Set the Interface to be unnumbered
290
291 :param is_add: (Default value = 1)
292 :param sw_if_index - interface That will be unnumbered
293 :param ip_sw_if_index - interface with an IP addres
294
295 """
296 return self.api(self.papi.sw_interface_set_unnumbered,
297 {'sw_if_index': ip_sw_if_index,
298 'unnumbered_sw_if_index': sw_if_index,
299 'is_add': is_add})
300
Neale Ranns404d88e2018-08-08 06:37:33 -0700301 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
302 return self.api(self.papi.ip_unnumbered_dump,
303 {'sw_if_index': sw_if_index})
304
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000305 def sw_interface_enable_disable_mpls(self, sw_if_index,
306 is_enable=1):
307 """
308 Enable/Disable MPLS on the interface
309 :param sw_if_index:
310 :param is_enable: (Default value = 1)
311
312 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100313 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200314 {'sw_if_index': sw_if_index,
315 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000316
Jan Gelety057bb8c2016-12-20 17:32:45 +0100317 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100318 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100319 {'sw_if_index': sw_if_index,
320 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200321
Neale Ranns227038a2017-04-21 01:07:59 -0700322 def set_ip_flow_hash(self,
323 table_id,
324 src=1,
325 dst=1,
326 sport=1,
327 dport=1,
328 proto=1,
329 reverse=0,
330 is_ip6=0):
331 return self.api(self.papi.set_ip_flow_hash,
332 {'vrf_id': table_id,
333 'src': src,
334 'dst': dst,
335 'dport': dport,
336 'sport': sport,
337 'proto': proto,
338 'reverse': reverse,
339 'is_ipv6': is_ip6})
340
Neale Ranns37029302018-08-10 05:30:06 -0700341 def ip6_nd_proxy(self, ip, sw_if_index, is_del=0):
Neale Ranns3f844d02017-02-18 00:03:54 -0800342 return self.api(self.papi.ip6nd_proxy_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700343 {'ip': ip,
Neale Ranns3f844d02017-02-18 00:03:54 -0800344 'sw_if_index': sw_if_index,
345 'is_del': is_del})
346
Neale Ranns75152282017-01-09 01:00:45 -0800347 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000348 no,
Neale Ranns75152282017-01-09 01:00:45 -0800349 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000350 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800351 return self.api(self.papi.sw_interface_ip6nd_ra_config,
352 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000353 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100354 'suppress': suppress,
355 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800356
Neale Ranns87df12d2017-02-18 08:16:41 -0800357 def ip6_sw_interface_ra_prefix(self,
358 sw_if_index,
359 address,
360 address_length,
361 use_default=0,
362 no_advertise=0,
363 off_link=0,
364 no_autoconfig=0,
365 no_onlink=0,
366 is_no=0,
367 val_lifetime=0xffffffff,
368 pref_lifetime=0xffffffff):
369 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
370 {'sw_if_index': sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700371 'prefix': {
372 'address': address,
373 'address_length': address_length,
374 },
Neale Ranns87df12d2017-02-18 08:16:41 -0800375 'use_default': use_default,
376 'no_advertise': no_advertise,
377 'off_link': off_link,
378 'no_autoconfig': no_autoconfig,
379 'no_onlink': no_onlink,
380 'is_no': is_no,
381 'val_lifetime': val_lifetime,
382 'pref_lifetime': pref_lifetime})
383
Neale Ranns75152282017-01-09 01:00:45 -0800384 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
385 """
386 Enable/Disable An interface for IPv6
387 """
388 return self.api(self.papi.sw_interface_ip6_enable_disable,
389 {'sw_if_index': sw_if_index,
390 'enable': enable})
391
Klement Sekeraf62ae122016-10-11 11:47:09 +0200392 def vxlan_add_del_tunnel(
393 self,
394 src_addr,
395 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200396 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200397 is_add=1,
398 is_ipv6=0,
399 encap_vrf_id=0,
400 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600401 vni=0,
402 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200403 """
404
405 :param dst_addr:
406 :param src_addr:
407 :param is_add: (Default value = 1)
408 :param is_ipv6: (Default value = 0)
409 :param encap_vrf_id: (Default value = 0)
410 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200411 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200412 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600413 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200414
415 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100416 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200417 {'is_add': is_add,
418 'is_ipv6': is_ipv6,
419 'src_address': src_addr,
420 'dst_address': dst_addr,
421 'mcast_sw_if_index': mcast_sw_if_index,
422 'encap_vrf_id': encap_vrf_id,
423 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600424 'vni': vni,
425 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200426
Marco Varleseb598f1d2017-09-19 14:25:28 +0200427 def geneve_add_del_tunnel(
428 self,
429 local_addr,
430 remote_addr,
431 mcast_sw_if_index=0xFFFFFFFF,
432 is_add=1,
433 is_ipv6=0,
434 encap_vrf_id=0,
435 decap_next_index=0xFFFFFFFF,
436 vni=0):
437 """
438
439 :param remote_addr:
440 :param local_addr:
441 :param is_add: (Default value = 1)
442 :param is_ipv6: (Default value = 0)
443 :param encap_vrf_id: (Default value = 0)
444 :param decap_next_index: (Default value = 0xFFFFFFFF)
445 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
446 :param vni: (Default value = 0)
447
448 """
449 return self.api(self.papi.geneve_add_del_tunnel,
450 {'is_add': is_add,
451 'is_ipv6': is_ipv6,
452 'local_address': local_addr,
453 'remote_address': remote_addr,
454 'mcast_sw_if_index': mcast_sw_if_index,
455 'encap_vrf_id': encap_vrf_id,
456 'decap_next_index': decap_next_index,
457 'vni': vni})
458
Jan4af521d2016-11-15 17:05:00 +0100459 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
460 learn=1, arp_term=0, is_add=1):
461 """Create/delete bridge domain.
462
463 :param int bd_id: Bridge domain index.
464 :param int flood: Enable/disable bcast/mcast flooding in the BD.
465 (Default value = 1)
466 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
467 (Default value = 1)
468 :param int forward: Enable/disable forwarding on all interfaces in
469 the BD. (Default value = 1)
470 :param int learn: Enable/disable learning on all interfaces in the BD.
471 (Default value = 1)
472 :param int arp_term: Enable/disable arp termination in the BD.
473 (Default value = 1)
474 :param int is_add: Add or delete flag. (Default value = 1)
475 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100476 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200477 {'bd_id': bd_id,
478 'flood': flood,
479 'uu_flood': uu_flood,
480 'forward': forward,
481 'learn': learn,
482 'arp_term': arp_term,
483 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100484
Eyal Baric86e5922017-07-02 18:33:16 +0300485 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
486 return self.api(self.papi.bd_ip_mac_add_del,
487 {'bd_id': bd_id,
488 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700489 'ip': ip,
490 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300491
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700492 def bd_ip_mac_dump(self, bd_id):
493 return self.api(self.papi.bd_ip_mac_dump,
494 {'bd_id': bd_id})
495
Neale Ranns37029302018-08-10 05:30:06 -0700496 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300497 return self.api(self.papi.want_ip4_arp_events,
498 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700499 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300500 'pid': os.getpid(), })
501
Neale Ranns37029302018-08-10 05:30:06 -0700502 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300503 return self.api(self.papi.want_ip6_nd_events,
504 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700505 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300506 'pid': os.getpid(), })
507
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100508 def want_ip6_ra_events(self, enable_disable=1):
509 return self.api(self.papi.want_ip6_ra_events,
510 {'enable_disable': enable_disable,
511 'pid': os.getpid(), })
512
513 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
514 mrc=0, mrd=0):
515 return self.api(self.papi.ip6nd_send_router_solicitation,
516 {'irt': irt,
517 'mrt': mrt,
518 'mrc': mrc,
519 'mrd': mrd,
520 'sw_if_index': sw_if_index})
521
Juraj Slobodac0374232018-02-01 15:18:49 +0100522 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
523 install_default_routes):
524 return self.api(self.papi.ip6_nd_address_autoconfig,
525 {'sw_if_index': sw_if_index,
526 'enable': enable,
527 'install_default_routes': install_default_routes})
528
Juraj Slobodab3f90502018-10-04 15:15:16 +0200529 def want_interface_events(self, enable_disable=1):
530 return self.api(self.papi.want_interface_events,
531 {'enable_disable': enable_disable,
532 'pid': os.getpid(), })
533
Eyal Bari24db0ec2017-09-27 21:43:51 +0300534 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
535 max_macs_in_event=0, learn_limit=0):
536 return self.api(self.papi.want_l2_macs_events,
537 {'enable_disable': enable_disable,
538 'scan_delay': scan_delay,
539 'max_macs_in_event': max_macs_in_event,
540 'learn_limit': learn_limit,
541 'pid': os.getpid(), })
542
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200543 def want_dhcp6_reply_events(self, enable_disable=1):
544 return self.api(self.papi.want_dhcp6_reply_events,
545 {'enable_disable': enable_disable,
546 'pid': os.getpid()})
547
Juraj Sloboda81119e82018-05-25 14:02:20 +0200548 def want_dhcp6_pd_reply_events(self, enable_disable=1):
549 return self.api(self.papi.want_dhcp6_pd_reply_events,
550 {'enable_disable': enable_disable,
551 'pid': os.getpid()})
552
553 def dhcp6_clients_enable_disable(self, enable=1):
554 return self.api(self.papi.dhcp6_clients_enable_disable,
555 {'enable': enable})
556
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200557 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
558 addresses, server_index=0xFFFFFFFF,
559 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
560 ):
561 return self.api(self.papi.dhcp6_send_client_message,
562 {'sw_if_index': sw_if_index,
563 'server_index': server_index,
564 'irt': irt,
565 'mrt': mrt,
566 'mrc': mrc,
567 'mrd': mrd,
568 'stop': stop,
569 'msg_type': msg_type,
570 'T1': T1,
571 'T2': T2,
572 'n_addresses': len(addresses),
573 'addresses': addresses})
574
Juraj Sloboda81119e82018-05-25 14:02:20 +0200575 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
576 prefixes, server_index=0xFFFFFFFF,
577 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
578 ):
579 return self.api(self.papi.dhcp6_pd_send_client_message,
580 {'sw_if_index': sw_if_index,
581 'server_index': server_index,
582 'irt': irt,
583 'mrt': mrt,
584 'mrc': mrc,
585 'mrd': mrd,
586 'stop': stop,
587 'msg_type': msg_type,
588 'T1': T1,
589 'T2': T2,
590 'n_prefixes': len(prefixes),
591 'prefixes': prefixes})
592
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200593 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
594 enable=1):
595 return self.api(self.papi.dhcp6_client_enable_disable,
596 {'sw_if_index': sw_if_index,
597 'enable': enable})
598
Juraj Sloboda81119e82018-05-25 14:02:20 +0200599 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
600 enable=1):
601 return self.api(self.papi.dhcp6_pd_client_enable_disable,
602 {'sw_if_index': sw_if_index,
603 'prefix_group': prefix_group,
604 'enable': enable})
605
606 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
607 prefix_length, prefix_group,
608 is_add=1):
609 return self.api(self.papi.ip6_add_del_address_using_prefix,
610 {'sw_if_index': sw_if_index,
611 'prefix_group': prefix_group,
612 'address': address,
613 'prefix_length': prefix_length,
614 'is_add': is_add})
615
Jan4af521d2016-11-15 17:05:00 +0100616 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
617 filter_mac=0, bvi_mac=0):
618 """Create/delete L2 FIB entry.
619
620 :param str mac: MAC address to create FIB entry for.
621 :param int bd_id: Bridge domain index.
622 :param int sw_if_index: Software interface index of the interface.
623 :param int is_add: Add or delete flag. (Default value = 1)
624 :param int static_mac: Set to 1 to create static MAC entry.
625 (Default value = 0)
626 :param int filter_mac: Set to 1 to drop packet that's source or
627 destination MAC address contains defined MAC address.
628 (Default value = 0)
629 :param int bvi_mac: Set to 1 to create entry that points to BVI
630 interface. (Default value = 0)
631 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100632 return self.api(self.papi.l2fib_add_del,
Ole Troan8006c6a2018-12-17 12:02:26 +0100633 {'mac': mac,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200634 'bd_id': bd_id,
635 'sw_if_index': sw_if_index,
636 'is_add': is_add,
637 'static_mac': static_mac,
638 'filter_mac': filter_mac,
639 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100640
Eyal Bari93b503e2017-05-15 10:13:15 +0300641 def l2fib_flush_int(self, sw_if_index):
642 """Flush L2 FIB entries for sw_if_index.
643
644 :param int sw_if_index: Software interface index of the interface.
645 """
646 return self.api(self.papi.l2fib_flush_int,
647 {'sw_if_index': sw_if_index})
648
649 def l2fib_flush_bd(self, bd_id):
650 """Flush L2 FIB entries for bd_id.
651
652 :param int sw_if_index: Bridge Domain id.
653 """
654 return self.api(self.papi.l2fib_flush_bd,
655 {'bd_id': bd_id})
656
657 def l2fib_flush_all(self):
658 """Flush all L2 FIB.
659 """
660 return self.api(self.papi.l2fib_flush_all, {})
661
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700662 def l2_fib_table_dump(self, bd_id):
663 """ Dump the L2 FIB """
664 return self.api(self.papi.l2_fib_table_dump,
665 {'bd_id': bd_id})
666
Klement Sekeraf62ae122016-10-11 11:47:09 +0200667 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700668 shg=0, port_type=L2_PORT_TYPE.NORMAL,
669 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100670 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200671
Jan4af521d2016-11-15 17:05:00 +0100672 :param int sw_if_index: Software interface index of the interface.
673 :param int bd_id: Bridge domain index.
674 :param int shg: Split-horizon group index. (Default value = 0)
675 :param int bvi: Set interface as a bridge group virtual interface.
676 (Default value = 0)
677 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200678 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100679 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200680 {'rx_sw_if_index': sw_if_index,
681 'bd_id': bd_id,
682 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700683 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200684 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200685
Jan00dad122016-11-29 10:04:53 +0100686 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400687 """Enable/disable required feature of the bridge domain with defined
688 ID.
Jan00dad122016-11-29 10:04:53 +0100689
690 :param int bd_id: Bridge domain ID.
691 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700692 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100693 - learn (1 << 0),
694 - forward (1 << 1),
695 - flood (1 << 2),
696 - uu-flood (1 << 3) or
697 - arp-term (1 << 4).
698 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100699 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200700 {'bd_id': bd_id,
701 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700702 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100703
704 def bridge_domain_dump(self, bd_id=0):
705 """
706
707 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
708 existing bridge domains returned)
709 :return: Dictionary of bridge domain(s) data.
710 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100711 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200712 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100713
Klement Sekeraf62ae122016-10-11 11:47:09 +0200714 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
715 enable):
716 """Create or delete unidirectional cross-connect from Tx interface to
717 Rx interface.
718
Jan4af521d2016-11-15 17:05:00 +0100719 :param int rx_sw_if_index: Software interface index of Rx interface.
720 :param int tx_sw_if_index: Software interface index of Tx interface.
721 :param int enable: Create cross-connect if equal to 1, delete
722 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200723
724 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100725 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200726 {'rx_sw_if_index': rx_sw_if_index,
727 'tx_sw_if_index': tx_sw_if_index,
728 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200729
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200730 def sw_interface_set_l2_tag_rewrite(
731 self,
732 sw_if_index,
733 vtr_oper,
734 push=0,
735 tag1=0,
736 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000737 """L2 interface vlan tag rewrite configure request
738 :param client_index - opaque cookie to identify the sender
739 :param context - sender context, to match reply w/ request
740 :param sw_if_index - interface the operation is applied to
741 :param vtr_op - Choose from l2_vtr_op_t enum values
742 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
743 :param tag1 - Needed for any push or translate vtr op
744 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
745
746 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100747 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200748 {'sw_if_index': sw_if_index,
749 'vtr_op': vtr_oper,
750 'push_dot1q': push,
751 'tag1': tag1,
752 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000753
Neale Ranns55d03782017-10-21 06:34:22 -0700754 def sw_interface_set_l2_emulation(
755 self,
756 sw_if_index,
757 enable=1):
758 """L2 Emulation
759 :param sw_if_index - interface the operation is applied to
760
761 """
762 return self.api(self.papi.l2_emulation,
763 {'sw_if_index': sw_if_index,
764 'enable': enable})
765
Neale Ranns1855b8e2018-07-11 10:31:26 -0700766 def sw_interface_set_ip_directed_broadcast(
767 self,
768 sw_if_index,
769 enable=1):
770 """IP Directed broadcast
771 :param sw_if_index - interface the operation is applied to
772
773 """
774 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
775 {'sw_if_index': sw_if_index,
776 'enable': enable})
777
Neale Rannsa07bd702017-08-07 07:53:49 -0700778 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200779 """
780
781 :param admin_up_down:
782 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200783
784 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100785 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200786 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700787 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200788
Ole Troand7231612018-06-07 10:17:57 +0200789 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800790 """
791 :param sw_if_index:
792 :param mtu:
793
794 """
795 return self.api(self.papi.sw_interface_set_mtu,
796 {'sw_if_index': sw_if_index,
797 'mtu': mtu})
798
Neale Ranns25b04942018-04-04 09:34:50 -0700799 def sw_interface_set_promiscuous(self, sw_if_index, enable):
800 """
801 :param sw_if_index:
802 :param enable:
803
804 """
805 return self.api(self.papi.sw_interface_set_promiscuous,
806 {'sw_if_index': sw_if_index,
807 'enable': enable})
808
Neale Rannsc819fc62018-02-16 02:44:05 -0800809 def sw_interface_set_mac_address(self, sw_if_index, mac):
810 return self.api(self.papi.sw_interface_set_mac_address,
811 {'sw_if_index': sw_if_index,
812 'mac_address': mac})
813
Klement Sekeraf62ae122016-10-11 11:47:09 +0200814 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
815 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
816 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
817 """Create subinterface
818 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
819
820 :param sub_id: param inner_vlan:
821 :param sw_if_index:
822 :param outer_vlan:
823 :param inner_vlan:
824 :param no_tags: (Default value = 0)
825 :param one_tag: (Default value = 0)
826 :param two_tags: (Default value = 0)
827 :param dot1ad: (Default value = 0)
828 :param exact_match: (Default value = 0)
829 :param default_sub: (Default value = 0)
830 :param outer_vlan_id_any: (Default value = 0)
831 :param inner_vlan_id_any: (Default value = 0)
832
833 """
834 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100835 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200836 {'sw_if_index': sw_if_index,
837 'sub_id': sub_id,
838 'no_tags': no_tags,
839 'one_tag': one_tag,
840 'two_tags': two_tags,
841 'dot1ad': dot1ad,
842 'exact_match': exact_match,
843 'default_sub': default_sub,
844 'outer_vlan_id_any': outer_vlan_id_any,
845 'inner_vlan_id_any': inner_vlan_id_any,
846 'outer_vlan_id': outer_vlan,
847 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200848
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200849 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
850 """Create p2p ethernet subinterface
851
852 :param sw_if_index: main (parent) interface
853 :param remote_mac: client (remote) mac address
854
855 """
856 return self.api(
857 self.papi.p2p_ethernet_add,
858 {'parent_if_index': sw_if_index,
859 'remote_mac': remote_mac,
860 'subif_id': subif_id})
861
Neale Ranns177bbdc2016-11-15 09:46:51 +0000862 def delete_subif(self, sw_if_index):
863 """Delete subinterface
864
865 :param sw_if_index:
866 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100867 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200868 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000869
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200870 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
871 """Delete p2p ethernet subinterface
872
873 :param sw_if_index: main (parent) interface
874 :param remote_mac: client (remote) mac address
875
876 """
877 return self.api(
878 self.papi.p2p_ethernet_del,
879 {'parent_if_index': sw_if_index,
880 'remote_mac': remote_mac})
881
Klement Sekeraf62ae122016-10-11 11:47:09 +0200882 def create_vlan_subif(self, sw_if_index, vlan):
883 """
884
885 :param vlan:
886 :param sw_if_index:
887
888 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100889 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200890 {'sw_if_index': sw_if_index,
891 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200892
Matej Klotton0178d522016-11-04 11:11:44 +0100893 def create_loopback(self, mac=''):
894 """
895
896 :param mac: (Optional)
897 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100898 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200899 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100900
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100901 def delete_loopback(self, sw_if_index):
902 return self.api(self.papi.delete_loopback,
903 {'sw_if_index': sw_if_index, })
904
Neale Ranns15002542017-09-10 04:39:11 -0700905 def ip_table_add_del(self,
906 table_id,
907 is_add=1,
908 is_ipv6=0):
909 """
910
911 :param table_id
912 :param is_add: (Default value = 1)
913 :param is_ipv6: (Default value = 0)
914
915 """
916
917 return self.api(
918 self.papi.ip_table_add_del,
919 {'table_id': table_id,
920 'is_add': is_add,
921 'is_ipv6': is_ipv6})
922
Klement Sekeraf62ae122016-10-11 11:47:09 +0200923 def ip_add_del_route(
924 self,
925 dst_address,
926 dst_address_length,
927 next_hop_address,
928 next_hop_sw_if_index=0xFFFFFFFF,
929 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200930 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000931 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200932 next_hop_n_out_labels=0,
933 next_hop_out_label_stack=[],
934 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800935 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000936 is_resolve_host=0,
937 is_resolve_attached=0,
938 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200939 is_add=1,
940 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200941 is_unreach=0,
942 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200943 is_ipv6=0,
944 is_local=0,
945 is_classify=0,
946 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800947 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800948 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200949 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200950 """
951
952 :param dst_address_length:
953 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
954 :param dst_address:
955 :param next_hop_address:
956 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
957 :param vrf_id: (Default value = 0)
958 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200959 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200960 :param is_add: (Default value = 1)
961 :param is_drop: (Default value = 0)
962 :param is_ipv6: (Default value = 0)
963 :param is_local: (Default value = 0)
964 :param is_classify: (Default value = 0)
965 :param is_multipath: (Default value = 0)
966 :param is_resolve_host: (Default value = 0)
967 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800968 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700969 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200970 :param next_hop_weight: (Default value = 1)
971
972 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000973
Klement Sekeraf62ae122016-10-11 11:47:09 +0200974 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100975 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200976 {'next_hop_sw_if_index': next_hop_sw_if_index,
977 'table_id': table_id,
978 'classify_table_index': classify_table_index,
979 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200980 'is_add': is_add,
981 'is_drop': is_drop,
982 'is_unreach': is_unreach,
983 'is_prohibit': is_prohibit,
984 'is_ipv6': is_ipv6,
985 'is_local': is_local,
986 'is_classify': is_classify,
987 'is_multipath': is_multipath,
988 'is_resolve_host': is_resolve_host,
989 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800990 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700991 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800992 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200993 'next_hop_weight': next_hop_weight,
994 'dst_address_length': dst_address_length,
995 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800996 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200997 'next_hop_address': next_hop_address,
998 'next_hop_n_out_labels': next_hop_n_out_labels,
999 'next_hop_via_label': next_hop_via_label,
1000 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001001
Matej Klotton16a14cd2016-12-07 15:09:13 +01001002 def ip_fib_dump(self):
1003 return self.api(self.papi.ip_fib_dump, {})
1004
Jan Gelety057bb8c2016-12-20 17:32:45 +01001005 def ip6_fib_dump(self):
1006 return self.api(self.papi.ip6_fib_dump, {})
1007
Matej Klotton0178d522016-11-04 11:11:44 +01001008 def ip_neighbor_add_del(self,
1009 sw_if_index,
1010 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -07001011 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001012 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -07001013 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +01001014 """ Add neighbor MAC to IPv4 or IPv6 address.
1015
1016 :param sw_if_index:
1017 :param mac_address:
1018 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001019 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -07001020 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +01001021 """
Matej Klotton0178d522016-11-04 11:11:44 +01001022 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001023 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -07001024 {
1025 'is_add': is_add,
1026 'neighbor': {
1027 'sw_if_index': sw_if_index,
1028 'flags': flags,
1029 'mac_address': mac_address,
1030 'ip_address': ip_address
1031 }
1032 }
Matej Klotton0178d522016-11-04 11:11:44 +01001033 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001034
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001035 def ip_neighbor_dump(self,
1036 sw_if_index,
1037 is_ipv6=0):
1038 """ Return IP neighbor dump.
1039
1040 :param sw_if_index:
1041 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1042 """
1043
1044 return self.api(
1045 self.papi.ip_neighbor_dump,
1046 {'is_ipv6': is_ipv6,
1047 'sw_if_index': sw_if_index
1048 }
1049 )
1050
1051 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -07001052 low,
1053 hi,
1054 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001055 is_add=1):
1056 """ Config Proxy Arp Range.
1057
1058 :param low_address: Start address in the rnage to Proxy for
1059 :param hi_address: End address in the rnage to Proxy for
1060 :param vrf_id: The VRF/table in which to proxy
1061 """
1062
1063 return self.api(
1064 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001065 {'proxy':
1066 {
Neale Ranns37029302018-08-10 05:30:06 -07001067 'table_id': table_id,
1068 'low': low,
1069 'hi': hi,
Neale Ranns0053de62018-05-22 08:40:52 -07001070 },
1071 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001072
1073 def proxy_arp_intfc_enable_disable(self,
1074 sw_if_index,
1075 is_enable=1):
1076 """ Enable/Disable an interface for proxy ARP requests
1077
1078 :param sw_if_index: Interface
1079 :param enable_disable: Enable/Disable
1080 """
1081
1082 return self.api(
1083 self.papi.proxy_arp_intfc_enable_disable,
1084 {'sw_if_index': sw_if_index,
1085 'enable_disable': is_enable
1086 }
1087 )
1088
Jane546d3b2016-12-08 13:10:03 +01001089 def reset_vrf(self,
1090 vrf_id,
1091 is_ipv6=0,
1092 ):
1093 """ Reset VRF (remove all routes etc.) request.
1094
1095 :param int vrf_id: ID of the FIB table / VRF to reset.
1096 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1097 """
1098
1099 return self.api(
1100 self.papi.reset_vrf,
1101 {'vrf_id': vrf_id,
1102 'is_ipv6': is_ipv6,
1103 }
1104 )
1105
1106 def reset_fib(self,
1107 vrf_id,
1108 is_ipv6=0,
1109 ):
1110 """ Reset VRF (remove all routes etc.) request.
1111
1112 :param int vrf_id: ID of the FIB table / VRF to reset.
1113 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1114 """
1115
1116 return self.api(
1117 self.papi.reset_fib,
1118 {'vrf_id': vrf_id,
1119 'is_ipv6': is_ipv6,
1120 }
1121 )
1122
1123 def ip_dump(self,
1124 is_ipv6=0,
1125 ):
1126 """ Return IP dump.
1127
1128 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1129 """
1130
1131 return self.api(
1132 self.papi.ip_dump,
1133 {'is_ipv6': is_ipv6,
1134 }
1135 )
1136
Klement Sekera7bb873a2016-11-18 07:38:42 +01001137 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001138 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001139 """
1140
1141 :param sw_if_index_from:
1142 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001143 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001144 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001145 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001146 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001147 {'sw_if_index_from': sw_if_index_from,
1148 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001149 'state': state,
1150 'is_l2': is_l2,
1151 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001152
1153 def gre_tunnel_add_del(self,
1154 src_address,
1155 dst_address,
1156 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001157 tunnel_type=0,
1158 instance=0xFFFFFFFF,
1159 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001160 is_add=1,
1161 is_ip6=0):
1162 """ Add a GRE tunnel
1163
1164 :param src_address:
1165 :param dst_address:
1166 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001167 :param tunnel_type: (Default value = 0)
1168 :param instance: (Default value = 0xFFFFFFFF)
1169 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001170 :param is_add: (Default value = 1)
1171 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001172 """
1173
1174 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001175 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001176 {'is_add': is_add,
1177 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001178 'tunnel_type': tunnel_type,
1179 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001180 'src_address': src_address,
1181 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001182 'outer_fib_id': outer_fib_id,
1183 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001184 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001185
Neale Rannsd0df49f2018-08-08 01:06:40 -07001186 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001187 src_ip,
1188 dst_ip,
1189 src_port,
1190 dst_port,
1191 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001192 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001193 :param src_ip:
1194 :param dst_ip:
1195 :param src_port:
1196 :param dst_port:
1197 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001198 """
1199
1200 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001201 self.papi.udp_encap_add,
1202 {
1203 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001204 'src_ip': src_ip,
1205 'dst_ip': dst_ip,
1206 'src_port': src_port,
1207 'dst_port': dst_port,
1208 'table_id': table_id
1209 }
1210 })
1211
1212 def udp_encap_del(self, id):
1213 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001214
1215 def udp_encap_dump(self):
1216 return self.api(self.papi.udp_encap_dump, {})
1217
Neale Ranns43b1f442018-03-20 01:47:35 -07001218 def want_udp_encap_stats(self, enable=1):
1219 return self.api(self.papi.want_udp_encap_stats,
1220 {'enable': enable,
1221 'pid': os.getpid()})
1222
Neale Ranns5a8123b2017-01-26 01:18:23 -08001223 def mpls_fib_dump(self):
1224 return self.api(self.papi.mpls_fib_dump, {})
1225
Neale Ranns15002542017-09-10 04:39:11 -07001226 def mpls_table_add_del(
1227 self,
1228 table_id,
1229 is_add=1):
1230 """
1231
1232 :param table_id
1233 :param is_add: (Default value = 1)
1234
1235 """
1236
1237 return self.api(
1238 self.papi.mpls_table_add_del,
1239 {'mt_table_id': table_id,
1240 'mt_is_add': is_add})
1241
Neale Rannsad422ed2016-11-02 14:20:04 +00001242 def mpls_route_add_del(
1243 self,
1244 label,
1245 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001246 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001247 next_hop_address,
1248 next_hop_sw_if_index=0xFFFFFFFF,
1249 table_id=0,
1250 next_hop_table_id=0,
1251 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001252 next_hop_n_out_labels=0,
1253 next_hop_out_label_stack=[],
1254 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001255 is_resolve_host=0,
1256 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001257 is_interface_rx=0,
1258 is_rpf_id=0,
1259 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001260 is_add=1,
1261 is_drop=0,
1262 is_multipath=0,
1263 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001264 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001265 """
1266
1267 :param dst_address_length:
1268 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1269 :param dst_address:
1270 :param next_hop_address:
1271 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1272 :param vrf_id: (Default value = 0)
1273 :param lookup_in_vrf: (Default value = 0)
1274 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001275 :param is_add: (Default value = 1)
1276 :param is_drop: (Default value = 0)
1277 :param is_ipv6: (Default value = 0)
1278 :param is_local: (Default value = 0)
1279 :param is_classify: (Default value = 0)
1280 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001281 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001282 :param is_resolve_host: (Default value = 0)
1283 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001284 :param next_hop_weight: (Default value = 1)
1285
1286 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001287 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001288 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001289 {'mr_label': label,
1290 'mr_eos': eos,
1291 'mr_table_id': table_id,
1292 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001293 'mr_is_add': is_add,
1294 'mr_is_classify': is_classify,
1295 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001296 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001297 'mr_is_resolve_host': is_resolve_host,
1298 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001299 'mr_is_interface_rx': is_interface_rx,
1300 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001301 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001302 'mr_next_hop_weight': next_hop_weight,
1303 'mr_next_hop': next_hop_address,
1304 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1305 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1306 'mr_next_hop_table_id': next_hop_table_id,
1307 'mr_next_hop_via_label': next_hop_via_label,
1308 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001309
1310 def mpls_ip_bind_unbind(
1311 self,
1312 label,
1313 dst_address,
1314 dst_address_length,
1315 table_id=0,
1316 ip_table_id=0,
1317 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001318 is_bind=1):
1319 """
1320 """
1321 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001322 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001323 {'mb_mpls_table_id': table_id,
1324 'mb_label': label,
1325 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001326 'mb_is_bind': is_bind,
1327 'mb_is_ip4': is_ip4,
1328 'mb_address_length': dst_address_length,
1329 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001330
1331 def mpls_tunnel_add_del(
1332 self,
1333 tun_sw_if_index,
1334 next_hop_proto_is_ip4,
1335 next_hop_address,
1336 next_hop_sw_if_index=0xFFFFFFFF,
1337 next_hop_table_id=0,
1338 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001339 next_hop_n_out_labels=0,
1340 next_hop_out_label_stack=[],
1341 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001342 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001343 l2_only=0,
1344 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001345 """
1346
1347 :param dst_address_length:
1348 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1349 :param dst_address:
1350 :param next_hop_address:
1351 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1352 :param vrf_id: (Default value = 0)
1353 :param lookup_in_vrf: (Default value = 0)
1354 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001355 :param is_add: (Default value = 1)
1356 :param is_drop: (Default value = 0)
1357 :param is_ipv6: (Default value = 0)
1358 :param is_local: (Default value = 0)
1359 :param is_classify: (Default value = 0)
1360 :param is_multipath: (Default value = 0)
1361 :param is_resolve_host: (Default value = 0)
1362 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001363 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001364 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001365
1366 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001367 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001368 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001369 {'mt_sw_if_index': tun_sw_if_index,
1370 'mt_is_add': is_add,
1371 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001372 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001373 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1374 'mt_next_hop_weight': next_hop_weight,
1375 'mt_next_hop': next_hop_address,
1376 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1377 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1378 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001379 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001380 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001381
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001382 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1383 return self.api(self.papi.mpls_tunnel_dump,
1384 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001385
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001387 self,
1388 sw_if_index,
1389 is_inside=1,
1390 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001391 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001392
1393 :param sw_if_index: Software index of the interface
1394 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1395 :param is_add: 1 if add, 0 if delete (Default value = 1)
1396 """
1397 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001398 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001399 {'is_add': is_add,
1400 'is_inside': is_inside,
1401 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001402
Matus Fabian2ba92e32017-08-21 07:05:03 -07001403 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001404 self,
1405 sw_if_index,
1406 is_inside=1,
1407 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001408 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001409
1410 :param sw_if_index: Software index of the interface
1411 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1412 :param is_add: 1 if add, 0 if delete (Default value = 1)
1413 """
1414 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001415 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001416 {'is_add': is_add,
1417 'is_inside': is_inside,
1418 'sw_if_index': sw_if_index})
1419
Matus Fabian2ba92e32017-08-21 07:05:03 -07001420 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001421 self,
1422 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001423 external_ip=0,
1424 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001425 local_port=0,
1426 external_port=0,
1427 addr_only=1,
1428 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001429 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001430 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001431 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001432 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001433 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001434 is_add=1):
1435 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001436
1437 :param local_ip: Local IP address
1438 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001439 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001440 :param local_port: Local port number (Default value = 0)
1441 :param external_port: External port number (Default value = 0)
1442 :param addr_only: 1 if address only mapping, 0 if address and port
1443 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001444 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001445 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001446 :param self_twice_nat: 1 if translate external host address and port
1447 whenever external host address equals
1448 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001449 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001450 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001451 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001452 """
1453 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001454 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001455 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001456 'addr_only': addr_only,
1457 'local_ip_address': local_ip,
1458 'external_ip_address': external_ip,
1459 'local_port': local_port,
1460 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001461 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001462 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001463 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001464 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001465 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001466 'out2in_only': out2in_only,
1467 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001468
Matus Fabianab7a8052017-11-28 04:29:41 -08001469 def nat44_add_del_identity_mapping(
1470 self,
1471 ip='0',
1472 sw_if_index=0xFFFFFFFF,
1473 port=0,
1474 addr_only=1,
1475 vrf_id=0,
1476 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001477 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001478 is_add=1):
1479 """Add/delete NAT44 identity mapping
1480
1481 :param ip: IP address (Default value = 0)
1482 :param sw_if_index: Interface instead of IP address
1483 :param port: Port number (Default value = 0)
1484 :param addr_only: 1 if address only mapping, 0 if address and port
1485 :param vrf_id: VRF ID
1486 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001487 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001488 :param is_add: 1 if add, 0 if delete (Default value = 1)
1489 """
1490 return self.api(
1491 self.papi.nat44_add_del_identity_mapping,
1492 {'is_add': is_add,
1493 'addr_only': addr_only,
1494 'ip_address': ip,
1495 'port': port,
1496 'sw_if_index': sw_if_index,
1497 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001498 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001499 'protocol': protocol})
1500
Matus Fabian2ba92e32017-08-21 07:05:03 -07001501 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001502 self,
1503 first_ip_address,
1504 last_ip_address,
1505 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001506 vrf_id=0xFFFFFFFF,
1507 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001508 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001509
1510 :param first_ip_address: First IP address
1511 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001512 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001513 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001514 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001515 """
1516 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001517 self.papi.nat44_add_del_address_range,
1518 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001519 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001520 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001521 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001522 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001523
Matus Fabian2ba92e32017-08-21 07:05:03 -07001524 def nat44_address_dump(self):
1525 """Dump NAT44 addresses
1526 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001527 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001528 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001529
Matus Fabian2ba92e32017-08-21 07:05:03 -07001530 def nat44_interface_dump(self):
1531 """Dump interfaces with NAT44 feature
1532 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001533 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001534 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001535
Matus Fabian2ba92e32017-08-21 07:05:03 -07001536 def nat44_interface_output_feature_dump(self):
1537 """Dump interfaces with NAT44 output feature
1538 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001539 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001540 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001541
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 def nat44_static_mapping_dump(self):
1543 """Dump NAT44 static mappings
1544 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001545 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001546 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001547
Matus Fabianab7a8052017-11-28 04:29:41 -08001548 def nat44_identity_mapping_dump(self):
1549 """Dump NAT44 identity mappings
1550 :return: Dictionary of NAT44 identity mappings
1551 """
1552 return self.api(self.papi.nat44_identity_mapping_dump, {})
1553
Matus Fabian2ba92e32017-08-21 07:05:03 -07001554 def nat_show_config(self):
1555 """Show NAT plugin config
1556 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001557 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001558 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001559
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001561 self,
1562 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001563 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001564 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001566
1567 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001568 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001569 :param is_add: 1 if add, 0 if delete (Default value = 1)
1570 """
Matus Fabianb932d262017-12-18 05:38:24 -08001571 return self.api(
1572 self.papi.nat44_add_del_interface_addr,
1573 {'is_add': is_add,
1574 'sw_if_index': sw_if_index,
1575 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001576
Matus Fabian2ba92e32017-08-21 07:05:03 -07001577 def nat44_interface_addr_dump(self):
1578 """Dump NAT44 addresses interfaces
1579 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001580 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001582
Matus Fabian2ba92e32017-08-21 07:05:03 -07001583 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001584 self,
1585 domain_id=1,
1586 src_port=4739,
1587 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001588 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001589
1590 :param domain_id: Observation domain ID (Default value = 1)
1591 :param src_port: Source port number (Default value = 4739)
1592 :param enable: 1 if enable, 0 if disable (Default value = 1)
1593 """
1594 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001595 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001596 {'domain_id': domain_id,
1597 'src_port': src_port,
1598 'enable': enable})
1599
Matus Fabian2ba92e32017-08-21 07:05:03 -07001600 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001601 self,
1602 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001603 vrf_id):
1604 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001605
1606 :param ip_address: ip adress of the user to be dumped
1607 :param cpu_index: cpu_index on which the user is
1608 :param vrf_id: VRF ID
1609 :return: Dictionary of S-NAT sessions
1610 """
1611 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001612 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001613 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001614 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001615
Matus Fabian2ba92e32017-08-21 07:05:03 -07001616 def nat44_user_dump(self):
1617 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001618
Matus Fabian2ba92e32017-08-21 07:05:03 -07001619 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001620 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001621 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001622
Matus Fabian704018c2017-09-04 02:17:18 -07001623 def nat44_add_del_lb_static_mapping(
1624 self,
1625 external_addr,
1626 external_port,
1627 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001628 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001629 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001630 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001631 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001632 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001633 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001634 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001635 is_add=1):
1636 """Add/delete NAT44 load balancing static mapping
1637
Matus Fabianb932d262017-12-18 05:38:24 -08001638 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001639 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001640 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001641 :param is_add - 1 if add, 0 if delete
1642 """
1643 return self.api(
1644 self.papi.nat44_add_del_lb_static_mapping,
1645 {'is_add': is_add,
1646 'external_addr': external_addr,
1647 'external_port': external_port,
1648 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001649 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001650 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001651 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001652 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001653 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001654 'local_num': local_num,
1655 'locals': locals})
1656
Matus Fabianb6865082018-12-06 03:11:09 -08001657 def nat44_lb_static_mapping_add_del_local(
1658 self,
1659 external_addr,
1660 external_port,
1661 local_addr,
1662 local_port,
1663 protocol,
1664 probability,
1665 vrf_id=0,
1666 is_add=1):
1667 """Add/delete NAT44 load-balancing static mapping rule backend
1668
1669 :param external_addr: external IPv4 address of the servic
1670 :param external_port: external L4 port number of the service
1671 :param local_addr: IPv4 address of the internal node
1672 :param local_port: L4 port number of the internal node
1673 :param protocol: IP protocol number
1674 :param probability: probability of the internal node
1675 :param vrf_id: VRF id of the internal node
1676 :param is_add: 1 if add, 0 if delete
1677 """
1678 return self.api(
1679 self.papi.nat44_lb_static_mapping_add_del_local,
1680 {'is_add': is_add,
1681 'external_addr': external_addr,
1682 'external_port': external_port,
1683 'local': {
1684 'addr': local_addr,
1685 'port': local_port,
1686 'probability': probability,
1687 'vrf_id': vrf_id},
1688 'protocol': protocol})
1689
Matus Fabian704018c2017-09-04 02:17:18 -07001690 def nat44_lb_static_mapping_dump(self):
1691 """Dump NAT44 load balancing static mappings
1692
1693 :return: Dictionary of NAT44 load balancing static mapping
1694 """
1695 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1696
Matus Fabian5ba86f72017-10-26 03:37:38 -07001697 def nat44_del_session(
1698 self,
1699 addr,
1700 port,
1701 protocol,
1702 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001703 is_in=1,
1704 ext_host_address=None,
1705 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001706 """Delete NAT44 session
1707
1708 :param addr: IPv4 address
1709 :param por: port number
1710 :param protocol: IP protocol number
1711 :param vrf_id: VRF ID
1712 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001713 :param ext_host_address: external host IPv4 address
1714 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001715 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001716 if ext_host_address is None:
1717 return self.api(
1718 self.papi.nat44_del_session,
1719 {'address': addr,
1720 'port': port,
1721 'protocol': protocol,
1722 'vrf_id': vrf_id,
1723 'is_in': is_in})
1724 else:
1725 return self.api(
1726 self.papi.nat44_del_session,
1727 {'address': addr,
1728 'port': port,
1729 'protocol': protocol,
1730 'vrf_id': vrf_id,
1731 'is_in': is_in,
1732 'ext_host_valid': 1,
1733 'ext_host_address': ext_host_address,
1734 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001735
Juraj Sloboda7b929792017-11-23 13:20:48 +01001736 def nat44_forwarding_enable_disable(
1737 self,
1738 enable):
1739 """Enable/disable forwarding for NAT44
1740
1741 :param enable: 1 for enable, 0 for disable
1742 """
1743 return self.api(
1744 self.papi.nat44_forwarding_enable_disable,
1745 {'enable': enable})
1746
Matus Fabianefcd1e92017-08-15 06:59:19 -07001747 def nat_set_reass(
1748 self,
1749 timeout=2,
1750 max_reass=1024,
1751 max_frag=5,
1752 drop_frag=0,
1753 is_ip6=0):
1754 """Set NAT virtual fragmentation reassembly
1755
1756 :param timeout: reassembly timeout (Default 2sec)
1757 :param max_reass: maximum concurrent reassemblies (Default 1024)
1758 :param max_frag: maximum fragmets per reassembly (Default 5)
1759 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1760 :param is_ip6: 1 if IPv6, 0 if IPv4
1761 """
1762 return self.api(
1763 self.papi.nat_set_reass,
1764 {'timeout': timeout,
1765 'max_reass': max_reass,
1766 'max_frag': max_frag,
1767 'drop_frag': drop_frag,
1768 'is_ip6': is_ip6})
1769
1770 def nat_get_reass(self):
1771 """Get NAT virtual fragmentation reassembly configuration
1772
1773 :return: NAT virtual fragmentation reassembly configuration
1774 """
1775 return self.api(self.papi.nat_get_reass, {})
1776
1777 def nat_reass_dump(self):
1778 """Dump NAT virtual fragmentation reassemblies
1779
1780 :return: Dictionary of NAT virtual fragmentation reassemblies
1781 """
1782 return self.api(self.papi.nat_reass_dump, {})
1783
Matus Fabian2ba92e32017-08-21 07:05:03 -07001784 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001785 self,
1786 in_addr,
1787 in_plen,
1788 out_addr,
1789 out_plen,
1790 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001791 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001792
1793 :param is_add - 1 if add, 0 if delete
1794 :param in_addr - inside IP address
1795 :param in_plen - inside IP address prefix length
1796 :param out_addr - outside IP address
1797 :param out_plen - outside IP address prefix length
1798 """
1799 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001800 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001801 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001802 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001803 'in_addr': in_addr,
1804 'in_plen': in_plen,
1805 'out_addr': out_addr,
1806 'out_plen': out_plen})
1807
Matus Fabian2ba92e32017-08-21 07:05:03 -07001808 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001809 self,
1810 in_addr):
1811 """Get outside address and port range from inside address
1812
1813 :param in_addr - inside IP address
1814 """
1815 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001816 self.papi.nat_det_forward,
1817 {'in_addr': in_addr,
1818 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001819
Matus Fabian2ba92e32017-08-21 07:05:03 -07001820 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001821 self,
1822 out_addr,
1823 out_port):
1824 """Get inside address from outside address and port
1825
1826 :param out_addr - outside IP address
1827 :param out_port - outside port
1828 """
1829 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001830 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001831 {'out_addr': out_addr,
1832 'out_port': out_port})
1833
Matus Fabian2ba92e32017-08-21 07:05:03 -07001834 def nat_det_map_dump(self):
1835 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001836
Matus Fabian2ba92e32017-08-21 07:05:03 -07001837 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001838 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001839 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001840
Matus Fabian878c6462018-08-23 00:33:35 -07001841 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001842 self,
1843 udp=300,
1844 tcp_established=7440,
1845 tcp_transitory=240,
1846 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001847 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001848
1849 :param udp - UDP timeout (Default value = 300)
1850 :param tcp_established - TCP established timeout (Default value = 7440)
1851 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1852 :param icmp - ICMP timeout (Default value = 60)
1853 """
1854 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001855 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001856 {'udp': udp,
1857 'tcp_established': tcp_established,
1858 'tcp_transitory': tcp_transitory,
1859 'icmp': icmp})
1860
Matus Fabian878c6462018-08-23 00:33:35 -07001861 def nat_get_timeouts(self):
1862 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001863
Matus Fabian878c6462018-08-23 00:33:35 -07001864 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001865 """
Matus Fabian878c6462018-08-23 00:33:35 -07001866 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001867
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001868 def nat_set_addr_and_port_alloc_alg(
1869 self,
1870 alg=0,
1871 psid_offset=0,
1872 psid_length=0,
1873 psid=0,
1874 start_port=0,
1875 end_port=0):
1876 """Set address and port assignment algorithm
1877
1878 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1879 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1880 :param psid_length: length of PSID (valid only for MAP-E alg)
1881 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1882 :param start_port: beginning of the port range
1883 :param end_port: end of the port range
1884 """
1885 return self.api(
1886 self.papi.nat_set_addr_and_port_alloc_alg,
1887 {'alg': alg,
1888 'psid_offset': psid_offset,
1889 'psid_length': psid_length,
1890 'psid': psid,
1891 'start_port': start_port,
1892 'end_port': end_port})
1893
1894 def nat_get_addr_and_port_alloc_alg(self):
1895 """Get address and port assignment algorithm"""
1896 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1897
Matus Fabianbb4e0222018-09-13 02:36:25 -07001898 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1899 """Set TCP MSS rewriting configuration
1900
1901 :param enable: disable(0)/enable(1) MSS rewriting feature
1902 :param mss_value: MSS value to be used for MSS rewriting
1903 """
1904 return self.api(
1905 self.papi.nat_set_mss_clamping,
1906 {'enable': enable, 'mss_value': mss_value})
1907
1908 def nat_get_mss_clamping(self):
1909 """Get TCP MSS rewriting configuration"""
1910 return self.api(self.papi.nat_get_mss_clamping, {})
1911
Matus Fabian2ba92e32017-08-21 07:05:03 -07001912 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001913 self,
1914 out_addr,
1915 out_port,
1916 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001917 ext_port):
1918 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001919
1920 :param out_addr - outside IP address
1921 :param out_port - outside port
1922 :param ext_addr - external host IP address
1923 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001924 """
1925 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001926 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001927 {'out_addr': out_addr,
1928 'out_port': out_port,
1929 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001930 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001931
Matus Fabian2ba92e32017-08-21 07:05:03 -07001932 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001933 self,
1934 in_addr,
1935 in_port,
1936 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001937 ext_port):
1938 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001939
1940 :param in_addr - inside IP address
1941 :param in_port - inside port
1942 :param ext_addr - external host IP address
1943 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001944 """
1945 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001946 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001947 {'in_addr': in_addr,
1948 'in_port': in_port,
1949 'ext_addr': ext_addr,
1950 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001951 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001952
Matus Fabian2ba92e32017-08-21 07:05:03 -07001953 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001954 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001955 user_addr):
1956 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001957
1958 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001959 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001960 """
1961 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001962 self.papi.nat_det_session_dump,
1963 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001964 'user_addr': user_addr})
1965
Matus Fabian06596c52017-06-06 04:53:28 -07001966 def nat64_add_del_pool_addr_range(
1967 self,
1968 start_addr,
1969 end_addr,
1970 vrf_id=0xFFFFFFFF,
1971 is_add=1):
1972 """Add/del address range to NAT64 pool
1973
1974 :param start_addr: First IP address
1975 :param end_addr: Last IP address
1976 :param vrf_id: VRF id for the address range
1977 :param is_add: 1 if add, 0 if delete (Default value = 1)
1978 """
1979 return self.api(
1980 self.papi.nat64_add_del_pool_addr_range,
1981 {'start_addr': start_addr,
1982 'end_addr': end_addr,
1983 'vrf_id': vrf_id,
1984 'is_add': is_add})
1985
1986 def nat64_pool_addr_dump(self):
1987 """Dump NAT64 pool addresses
1988 :return: Dictionary of NAT64 pool addresses
1989 """
1990 return self.api(self.papi.nat64_pool_addr_dump, {})
1991
1992 def nat64_add_del_interface(
1993 self,
1994 sw_if_index,
1995 is_inside=1,
1996 is_add=1):
1997 """Enable/disable NAT64 feature on the interface
1998 :param sw_if_index: Index of the interface
1999 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2000 :param is_add: 1 if add, 0 if delete (Default value = 1)
2001 """
2002 return self.api(
2003 self.papi.nat64_add_del_interface,
2004 {'sw_if_index': sw_if_index,
2005 'is_inside': is_inside,
2006 'is_add': is_add})
2007
2008 def nat64_interface_dump(self):
2009 """Dump interfaces with NAT64 feature
2010 :return: Dictionary of interfaces with NAT64 feature
2011 """
2012 return self.api(self.papi.nat64_interface_dump, {})
2013
2014 def nat64_add_del_static_bib(
2015 self,
2016 in_ip,
2017 out_ip,
2018 in_port,
2019 out_port,
2020 protocol,
2021 vrf_id=0,
2022 is_add=1):
2023 """Add/delete S-NAT static BIB entry
2024
2025 :param in_ip: Inside IPv6 address
2026 :param out_ip: Outside IPv4 address
2027 :param in_port: Inside port number
2028 :param out_port: Outside port number
2029 :param protocol: IP protocol
2030 :param vrf_id: VRF ID (Default value = 0)
2031 :param is_add: 1 if add, 0 if delete (Default value = 1)
2032 """
2033 return self.api(
2034 self.papi.nat64_add_del_static_bib,
2035 {'i_addr': in_ip,
2036 'o_addr': out_ip,
2037 'i_port': in_port,
2038 'o_port': out_port,
2039 'vrf_id': vrf_id,
2040 'proto': protocol,
2041 'is_add': is_add})
2042
Matus Fabianab9a59c2017-08-16 05:37:36 -07002043 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002044 """Dump NAT64 BIB
2045
Matus Fabianab9a59c2017-08-16 05:37:36 -07002046 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002047 :returns: Dictionary of NAT64 BIB entries
2048 """
2049 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2050
2051 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2052 tcp_incoming_syn=6):
2053 """Set values of timeouts for NAT64 (in seconds)
2054
Matus Fabian428dc912017-06-21 06:15:18 -07002055 :param udpi: UDP timeout (Default value = 300)
2056 :param icmp: ICMP timeout (Default value = 60)
2057 :param tcp_trans: TCP transitory timeout (Default value = 240)
2058 :param tcp_est: TCP established timeout (Default value = 7440)
2059 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002060 """
2061 return self.api(
2062 self.papi.nat64_set_timeouts,
2063 {'udp': udp,
2064 'icmp': icmp,
2065 'tcp_trans': tcp_trans,
2066 'tcp_est': tcp_est,
2067 'tcp_incoming_syn': tcp_incoming_syn})
2068
2069 def nat64_get_timeouts(self):
2070 """Get values of timeouts for NAT64
2071
2072 :return: Timeouts for NAT64 (in seconds)
2073 """
2074 return self.api(self.papi.nat64_get_timeouts, {})
2075
Matus Fabianab9a59c2017-08-16 05:37:36 -07002076 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002077 """Dump NAT64 session table
2078
Matus Fabianab9a59c2017-08-16 05:37:36 -07002079 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002080 :returns: Dictionary of NAT64 sesstion table entries
2081 """
2082 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2083
Matus Fabian428dc912017-06-21 06:15:18 -07002084 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2085 """Add/del NAT64 prefix
2086
2087 :param prefix: NAT64 prefix
2088 :param plen: NAT64 prefix length
2089 :param vrf_id: VRF id of tenant (Default 0)
2090 :param is_add: 1 if add, 0 if delete (Default value = 1)
2091 """
2092 return self.api(
2093 self.papi.nat64_add_del_prefix,
2094 {'prefix': prefix,
2095 'prefix_len': plen,
2096 'vrf_id': vrf_id,
2097 'is_add': is_add})
2098
2099 def nat64_prefix_dump(self):
2100 """Dump NAT64 prefix
2101
2102 :returns: Dictionary of NAT64 prefixes
2103 """
2104 return self.api(self.papi.nat64_prefix_dump, {})
2105
Matus Fabian0938dcf2017-11-08 01:59:38 -08002106 def nat64_add_interface_addr(
2107 self,
2108 sw_if_index,
2109 is_add=1):
2110 """Add/del NAT64 address from interface
2111
2112 :param sw_if_index: Software index of the interface
2113 :param is_add: 1 if add, 0 if delete (Default value = 1)
2114 """
2115 return self.api(self.papi.nat64_add_del_interface_addr,
2116 {'is_add': is_add, 'sw_if_index': sw_if_index})
2117
Matus Fabian8ebe6252017-11-06 05:04:53 -08002118 def dslite_set_aftr_addr(self, ip6, ip4):
2119 """Set DS-Lite AFTR addresses
2120
2121 :param ip4: IPv4 address
2122 :param ip6: IPv6 address
2123 """
2124 return self.api(
2125 self.papi.dslite_set_aftr_addr,
2126 {'ip4_addr': ip4,
2127 'ip6_addr': ip6})
2128
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002129 def dslite_set_b4_addr(self, ip6, ip4):
2130 """Set DS-Lite B4 IPv6 address
2131
2132 :param ip4: IPv4 address
2133 :param ip6: IPv6 address
2134 """
2135 return self.api(
2136 self.papi.dslite_set_b4_addr,
2137 {'ip4_addr': ip4,
2138 'ip6_addr': ip6})
2139
Matus Fabian8ebe6252017-11-06 05:04:53 -08002140 def dslite_add_del_pool_addr_range(
2141 self,
2142 start_addr,
2143 end_addr,
2144 is_add=1):
2145 """Add/del address range to DS-Lite pool
2146
2147 :param start_addr: First IP address
2148 :param end_addr: Last IP address
2149 :param is_add: 1 if add, 0 if delete (Default value = 1)
2150 """
2151 return self.api(
2152 self.papi.dslite_add_del_pool_addr_range,
2153 {'start_addr': start_addr,
2154 'end_addr': end_addr,
2155 'is_add': is_add})
2156
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002157 def nat66_add_del_interface(
2158 self,
2159 sw_if_index,
2160 is_inside=1,
2161 is_add=1):
2162 """Enable/disable NAT66 feature on the interface
2163 :param sw_if_index: Index of the interface
2164 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2165 :param is_add: 1 if add, 0 if delete (Default value = 1)
2166 """
2167 return self.api(
2168 self.papi.nat66_add_del_interface,
2169 {'sw_if_index': sw_if_index,
2170 'is_inside': is_inside,
2171 'is_add': is_add})
2172
2173 def nat66_add_del_static_mapping(
2174 self,
2175 in_ip,
2176 out_ip,
2177 vrf_id=0,
2178 is_add=1):
2179 """Add/delete NAT66 static mapping
2180
2181 :param in_ip: Inside IPv6 address
2182 :param out_ip: Outside IPv6 address
2183 :param vrf_id: VRF ID (Default value = 0)
2184 :param is_add: 1 if add, 0 if delete (Default value = 1)
2185 """
2186 return self.api(
2187 self.papi.nat66_add_del_static_mapping,
2188 {'local_ip_address': in_ip,
2189 'external_ip_address': out_ip,
2190 'vrf_id': vrf_id,
2191 'is_add': is_add})
2192
2193 def nat66_interface_dump(self):
2194 """Dump interfaces with NAT66 feature
2195 :return: Dictionary of interfaces with NAT66 feature
2196 """
2197 return self.api(self.papi.nat66_interface_dump, {})
2198
2199 def nat66_static_mapping_dump(self):
2200 """Dump NAT66 static mappings
2201 :return: Dictionary of NAT66 static mappings
2202 """
2203 return self.api(self.papi.nat66_static_mapping_dump, {})
2204
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002205 def control_ping(self):
2206 self.api(self.papi.control_ping)
2207
2208 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002209 detect_mult, local_addr, peer_addr, is_ipv6=0,
2210 bfd_key_id=None, conf_key_id=None):
2211 if bfd_key_id is None:
2212 return self.api(self.papi.bfd_udp_add,
2213 {
2214 'sw_if_index': sw_if_index,
2215 'desired_min_tx': desired_min_tx,
2216 'required_min_rx': required_min_rx,
2217 'local_addr': local_addr,
2218 'peer_addr': peer_addr,
2219 'is_ipv6': is_ipv6,
2220 'detect_mult': detect_mult,
2221 })
2222 else:
2223 return self.api(self.papi.bfd_udp_add,
2224 {
2225 'sw_if_index': sw_if_index,
2226 'desired_min_tx': desired_min_tx,
2227 'required_min_rx': required_min_rx,
2228 'local_addr': local_addr,
2229 'peer_addr': peer_addr,
2230 'is_ipv6': is_ipv6,
2231 'detect_mult': detect_mult,
2232 'is_authenticated': 1,
2233 'bfd_key_id': bfd_key_id,
2234 'conf_key_id': conf_key_id,
2235 })
2236
Klement Sekeraa57a9702017-02-02 06:58:07 +01002237 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2238 detect_mult, local_addr, peer_addr, is_ipv6=0):
2239 return self.api(self.papi.bfd_udp_mod,
2240 {
2241 'sw_if_index': sw_if_index,
2242 'desired_min_tx': desired_min_tx,
2243 'required_min_rx': required_min_rx,
2244 'local_addr': local_addr,
2245 'peer_addr': peer_addr,
2246 'is_ipv6': is_ipv6,
2247 'detect_mult': detect_mult,
2248 })
2249
Klement Sekerab17dd962017-01-09 07:43:48 +01002250 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2251 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2252 is_delayed=False):
2253 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002254 {
2255 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002256 'local_addr': local_addr,
2257 'peer_addr': peer_addr,
2258 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002259 'is_delayed': 1 if is_delayed else 0,
2260 'bfd_key_id': bfd_key_id,
2261 'conf_key_id': conf_key_id,
2262 })
2263
2264 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2265 is_ipv6=0, is_delayed=False):
2266 return self.api(self.papi.bfd_udp_auth_deactivate,
2267 {
2268 'sw_if_index': sw_if_index,
2269 'local_addr': local_addr,
2270 'peer_addr': peer_addr,
2271 'is_ipv6': is_ipv6,
2272 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002273 })
2274
2275 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2276 return self.api(self.papi.bfd_udp_del,
2277 {
2278 'sw_if_index': sw_if_index,
2279 'local_addr': local_addr,
2280 'peer_addr': peer_addr,
2281 'is_ipv6': is_ipv6,
2282 })
2283
2284 def bfd_udp_session_dump(self):
2285 return self.api(self.papi.bfd_udp_session_dump, {})
2286
Klement Sekerab17dd962017-01-09 07:43:48 +01002287 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2288 peer_addr, is_ipv6=0):
2289 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002290 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002291 'sw_if_index': sw_if_index,
2292 'local_addr': local_addr,
2293 'peer_addr': peer_addr,
2294 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002295 })
2296
2297 def want_bfd_events(self, enable_disable=1):
2298 return self.api(self.papi.want_bfd_events, {
2299 'enable_disable': enable_disable,
2300 'pid': os.getpid(),
2301 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002302
Klement Sekerab17dd962017-01-09 07:43:48 +01002303 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2304 return self.api(self.papi.bfd_auth_set_key, {
2305 'conf_key_id': conf_key_id,
2306 'auth_type': auth_type,
2307 'key': key,
2308 'key_len': len(key),
2309 })
2310
2311 def bfd_auth_del_key(self, conf_key_id):
2312 return self.api(self.papi.bfd_auth_del_key, {
2313 'conf_key_id': conf_key_id,
2314 })
2315
2316 def bfd_auth_keys_dump(self):
2317 return self.api(self.papi.bfd_auth_keys_dump, {})
2318
Klement Sekera239790f2017-02-16 10:53:53 +01002319 def bfd_udp_set_echo_source(self, sw_if_index):
2320 return self.api(self.papi.bfd_udp_set_echo_source,
2321 {'sw_if_index': sw_if_index})
2322
Klement Sekera73884482017-02-23 09:26:30 +01002323 def bfd_udp_del_echo_source(self):
2324 return self.api(self.papi.bfd_udp_del_echo_source, {})
2325
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002326 def bfd_udp_get_echo_source(self):
2327 return self.api(self.papi.bfd_udp_get_echo_source, {})
2328
Steve Shin7957d6e2016-12-19 09:24:50 -08002329 def classify_add_del_table(
2330 self,
2331 is_add,
2332 mask,
2333 match_n_vectors=1,
2334 table_index=0xFFFFFFFF,
2335 nbuckets=2,
2336 memory_size=2097152,
2337 skip_n_vectors=0,
2338 next_table_index=0xFFFFFFFF,
2339 miss_next_index=0xFFFFFFFF,
2340 current_data_flag=0,
2341 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002342 """
2343 :param is_add:
2344 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002345 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002346 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002347 :param nbuckets: (Default value = 2)
2348 :param memory_size: (Default value = 2097152)
2349 :param skip_n_vectors: (Default value = 0)
2350 :param next_table_index: (Default value = 0xFFFFFFFF)
2351 :param miss_next_index: (Default value = 0xFFFFFFFF)
2352 :param current_data_flag: (Default value = 0)
2353 :param current_data_offset: (Default value = 0)
2354 """
2355
Juraj Sloboda75282452018-06-12 14:20:49 +02002356 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2357 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002358 return self.api(
2359 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002360 {'is_add': is_add,
2361 'table_index': table_index,
2362 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002363 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002364 'skip_n_vectors': skip_n_vectors,
2365 'match_n_vectors': match_n_vectors,
2366 'next_table_index': next_table_index,
2367 'miss_next_index': miss_next_index,
2368 'current_data_flag': current_data_flag,
2369 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002370 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002371 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002372
2373 def classify_add_del_session(
2374 self,
2375 is_add,
2376 table_index,
2377 match,
2378 opaque_index=0xFFFFFFFF,
2379 hit_next_index=0xFFFFFFFF,
2380 advance=0,
2381 action=0,
2382 metadata=0):
2383 """
2384 :param is_add:
2385 :param table_index:
2386 :param match:
2387 :param opaque_index: (Default value = 0xFFFFFFFF)
2388 :param hit_next_index: (Default value = 0xFFFFFFFF)
2389 :param advance: (Default value = 0)
2390 :param action: (Default value = 0)
2391 :param metadata: (Default value = 0)
2392 """
2393
Juraj Sloboda75282452018-06-12 14:20:49 +02002394 match_len = ((len(match) - 1) / 16 + 1) * 16
2395 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002396 return self.api(
2397 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002398 {'is_add': is_add,
2399 'table_index': table_index,
2400 'hit_next_index': hit_next_index,
2401 'opaque_index': opaque_index,
2402 'advance': advance,
2403 'action': action,
2404 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002405 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002406 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002407
2408 def input_acl_set_interface(
2409 self,
2410 is_add,
2411 sw_if_index,
2412 ip4_table_index=0xFFFFFFFF,
2413 ip6_table_index=0xFFFFFFFF,
2414 l2_table_index=0xFFFFFFFF):
2415 """
2416 :param is_add:
2417 :param sw_if_index:
2418 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2419 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2420 :param l2_table_index: (Default value = 0xFFFFFFFF)
2421 """
2422
2423 return self.api(
2424 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002425 {'sw_if_index': sw_if_index,
2426 'ip4_table_index': ip4_table_index,
2427 'ip6_table_index': ip6_table_index,
2428 'l2_table_index': l2_table_index,
2429 'is_add': is_add})
2430
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002431 def output_acl_set_interface(
2432 self,
2433 is_add,
2434 sw_if_index,
2435 ip4_table_index=0xFFFFFFFF,
2436 ip6_table_index=0xFFFFFFFF,
2437 l2_table_index=0xFFFFFFFF):
2438 """
2439 :param is_add:
2440 :param sw_if_index:
2441 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2442 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2443 :param l2_table_index: (Default value = 0xFFFFFFFF)
2444 """
2445
2446 return self.api(
2447 self.papi.output_acl_set_interface,
2448 {'sw_if_index': sw_if_index,
2449 'ip4_table_index': ip4_table_index,
2450 'ip6_table_index': ip6_table_index,
2451 'l2_table_index': l2_table_index,
2452 'is_add': is_add})
2453
Klement Sekera77fabdb2017-01-02 07:46:14 +01002454 def set_ipfix_exporter(
2455 self,
2456 collector_address,
2457 src_address,
2458 path_mtu,
2459 template_interval,
2460 vrf_id=0,
2461 collector_port=4739,
2462 udp_checksum=0):
2463 return self.api(
2464 self.papi.set_ipfix_exporter,
2465 {
2466 'collector_address': collector_address,
2467 'collector_port': collector_port,
2468 'src_address': src_address,
2469 'vrf_id': vrf_id,
2470 'path_mtu': path_mtu,
2471 'template_interval': template_interval,
2472 'udp_checksum': udp_checksum,
2473 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002474
2475 def dhcp_proxy_config(self,
2476 dhcp_server,
2477 dhcp_src_address,
2478 rx_table_id=0,
2479 server_table_id=0,
2480 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002481 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002482 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002483 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002484 {
2485 'rx_vrf_id': rx_table_id,
2486 'server_vrf_id': server_table_id,
2487 'is_ipv6': is_ipv6,
2488 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002489 'dhcp_server': dhcp_server,
2490 'dhcp_src_address': dhcp_src_address,
2491 })
2492
2493 def dhcp_proxy_set_vss(self,
2494 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002495 vss_type=255,
2496 vpn_ascii_id="",
2497 oui=0,
2498 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002499 is_add=1,
2500 is_ip6=0):
2501 return self.api(
2502 self.papi.dhcp_proxy_set_vss,
2503 {
2504 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002505 'vss_type': vss_type,
2506 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002507 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002508 'vpn_index': vpn_index,
2509 'is_add': is_add,
2510 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002511 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002512
Neale Rannsdaff1782018-05-16 04:12:18 -07002513 def dhcp_client_dump(self):
2514 return self.api(self.papi.dhcp_client_dump, {})
2515
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002516 def dhcp_client(self,
2517 sw_if_index,
2518 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002519 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002520 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002521 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002522 want_dhcp_events=0):
2523 return self.api(
2524 self.papi.dhcp_client_config,
2525 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002526 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002527 'client': {
2528 'sw_if_index': sw_if_index,
2529 'hostname': hostname,
2530 'id': client_id,
2531 'want_dhcp_event': want_dhcp_events,
2532 'set_broadcast_flag': set_broadcast_flag,
2533 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002534 })
2535
Neale Ranns32e1c012016-11-22 17:07:28 +00002536 def ip_mroute_add_del(self,
2537 src_address,
2538 grp_address,
2539 grp_address_length,
2540 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002541 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002542 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002543 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002544 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002545 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002546 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002547 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002548 is_add=1,
2549 is_ipv6=0,
2550 is_local=0):
2551 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002552 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002553 """
2554 return self.api(
2555 self.papi.ip_mroute_add_del,
2556 {'next_hop_sw_if_index': next_hop_sw_if_index,
2557 'entry_flags': e_flags,
2558 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002559 'table_id': table_id,
2560 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002561 'is_add': is_add,
2562 'is_ipv6': is_ipv6,
2563 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002564 'bier_imp': bier_imp,
2565 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002566 'grp_address_length': grp_address_length,
2567 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002568 'src_address': src_address,
2569 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002570
2571 def mfib_signal_dump(self):
2572 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002573
2574 def ip_mfib_dump(self):
2575 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002576
Neale Rannsd792d9c2017-10-21 10:53:20 -07002577 def ip6_mfib_dump(self):
2578 return self.api(self.papi.ip6_mfib_dump, {})
2579
Filip Tehlar770e89e2017-01-31 10:39:16 +01002580 def lisp_enable_disable(self, is_enabled):
2581 return self.api(
2582 self.papi.lisp_enable_disable,
2583 {
2584 'is_en': is_enabled,
2585 })
2586
2587 def lisp_locator_set(self,
2588 ls_name,
2589 is_add=1):
2590 return self.api(
2591 self.papi.lisp_add_del_locator_set,
2592 {
2593 'is_add': is_add,
2594 'locator_set_name': ls_name
2595 })
2596
2597 def lisp_locator_set_dump(self):
2598 return self.api(self.papi.lisp_locator_set_dump, {})
2599
2600 def lisp_locator(self,
2601 ls_name,
2602 sw_if_index,
2603 priority=1,
2604 weight=1,
2605 is_add=1):
2606 return self.api(
2607 self.papi.lisp_add_del_locator,
2608 {
2609 'is_add': is_add,
2610 'locator_set_name': ls_name,
2611 'sw_if_index': sw_if_index,
2612 'priority': priority,
2613 'weight': weight
2614 })
2615
2616 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2617 return self.api(
2618 self.papi.lisp_locator_dump,
2619 {
2620 'is_index_set': is_index_set,
2621 'ls_name': ls_name,
2622 'ls_index': ls_index,
2623 })
2624
2625 def lisp_local_mapping(self,
2626 ls_name,
2627 eid_type,
2628 eid,
2629 prefix_len,
2630 vni=0,
2631 key_id=0,
2632 key="",
2633 is_add=1):
2634 return self.api(
2635 self.papi.lisp_add_del_local_eid,
2636 {
2637 'locator_set_name': ls_name,
2638 'is_add': is_add,
2639 'eid_type': eid_type,
2640 'eid': eid,
2641 'prefix_len': prefix_len,
2642 'vni': vni,
2643 'key_id': key_id,
2644 'key': key
2645 })
2646
2647 def lisp_eid_table_dump(self,
2648 eid_set=0,
2649 prefix_length=0,
2650 vni=0,
2651 eid_type=0,
2652 eid=None,
2653 filter_opt=0):
2654 return self.api(
2655 self.papi.lisp_eid_table_dump,
2656 {
2657 'eid_set': eid_set,
2658 'prefix_length': prefix_length,
2659 'vni': vni,
2660 'eid_type': eid_type,
2661 'eid': eid,
2662 'filter': filter_opt,
2663 })
2664
2665 def lisp_remote_mapping(self,
2666 eid_type,
2667 eid,
2668 eid_prefix_len=0,
2669 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002670 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002671 rlocs_num=0,
2672 is_src_dst=0,
2673 is_add=1):
2674 return self.api(
2675 self.papi.lisp_add_del_remote_mapping,
2676 {
2677 'is_add': is_add,
2678 'eid_type': eid_type,
2679 'eid': eid,
2680 'eid_len': eid_prefix_len,
2681 'rloc_num': rlocs_num,
2682 'rlocs': rlocs,
2683 'vni': vni,
2684 'is_src_dst': is_src_dst,
2685 })
2686
2687 def lisp_adjacency(self,
2688 leid,
2689 reid,
2690 leid_len,
2691 reid_len,
2692 eid_type,
2693 is_add=1,
2694 vni=0):
2695 return self.api(
2696 self.papi.lisp_add_del_adjacency,
2697 {
2698 'is_add': is_add,
2699 'vni': vni,
2700 'eid_type': eid_type,
2701 'leid': leid,
2702 'reid': reid,
2703 'leid_len': leid_len,
2704 'reid_len': reid_len,
2705 })
2706
2707 def lisp_adjacencies_get(self, vni=0):
2708 return self.api(
2709 self.papi.lisp_adjacencies_get,
2710 {
2711 'vni': vni
2712 })
Neale Ranns80823802017-02-20 18:23:41 -08002713
2714 def map_add_domain(self,
2715 ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002716 ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002717 ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002718 ea_bits_len=0,
2719 psid_offset=0,
2720 psid_length=0,
Neale Ranns80823802017-02-20 18:23:41 -08002721 mtu=1280):
Jon Loeligerfc7344f2018-12-20 11:47:30 -06002722
Neale Ranns80823802017-02-20 18:23:41 -08002723 return self.api(
2724 self.papi.map_add_domain,
2725 {
2726 'ip6_prefix': ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002727 'ip4_prefix': ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002728 'ip6_src': ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002729 'ea_bits_len': ea_bits_len,
2730 'psid_offset': psid_offset,
2731 'psid_length': psid_length,
Neale Ranns80823802017-02-20 18:23:41 -08002732 'mtu': mtu
2733 })
Hongjun Nief486b12017-04-12 19:21:16 +08002734
Jon Loeligerfc7344f2018-12-20 11:47:30 -06002735 def map_if_enable_disable(self, is_enable, sw_if_index, is_translation):
2736 return self.api(
2737 self.papi.map_if_enable_disable,
2738 {
2739 'is_enable': is_enable,
2740 'sw_if_index': sw_if_index,
2741 'is_translation': is_translation,
2742 })
2743
2744 def map_param_set_tcp(self, tcp_mss):
2745 return self.api(
2746 self.papi.map_param_set_tcp,
2747 {
2748 'tcp_mss': tcp_mss,
2749 })
2750
Hongjun Nief486b12017-04-12 19:21:16 +08002751 def gtpu_add_del_tunnel(
2752 self,
2753 src_addr,
2754 dst_addr,
2755 is_add=1,
2756 is_ipv6=0,
2757 mcast_sw_if_index=0xFFFFFFFF,
2758 encap_vrf_id=0,
2759 decap_next_index=0xFFFFFFFF,
2760 teid=0):
2761 """
2762
2763 :param is_add: (Default value = 1)
2764 :param is_ipv6: (Default value = 0)
2765 :param src_addr:
2766 :param dst_addr:
2767 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2768 :param encap_vrf_id: (Default value = 0)
2769 :param decap_next_index: (Default value = 0xFFFFFFFF)
2770 :param teid: (Default value = 0)
2771
2772 """
2773 return self.api(self.papi.gtpu_add_del_tunnel,
2774 {'is_add': is_add,
2775 'is_ipv6': is_ipv6,
2776 'src_address': src_addr,
2777 'dst_address': dst_addr,
2778 'mcast_sw_if_index': mcast_sw_if_index,
2779 'encap_vrf_id': encap_vrf_id,
2780 'decap_next_index': decap_next_index,
2781 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002782
2783 def vxlan_gpe_add_del_tunnel(
2784 self,
2785 src_addr,
2786 dst_addr,
2787 mcast_sw_if_index=0xFFFFFFFF,
2788 is_add=1,
2789 is_ipv6=0,
2790 encap_vrf_id=0,
2791 decap_vrf_id=0,
2792 protocol=3,
2793 vni=0):
2794 """
2795
2796 :param local:
2797 :param remote:
2798 :param is_add: (Default value = 1)
2799 :param is_ipv6: (Default value = 0)
2800 :param encap_vrf_id: (Default value = 0)
2801 :param decap_vrf_id: (Default value = 0)
2802 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2803 :param protocol: (Default value = 3)
2804 :param vni: (Default value = 0)
2805
2806 """
2807 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2808 {'is_add': is_add,
2809 'is_ipv6': is_ipv6,
2810 'local': src_addr,
2811 'remote': dst_addr,
2812 'mcast_sw_if_index': mcast_sw_if_index,
2813 'encap_vrf_id': encap_vrf_id,
2814 'decap_vrf_id': decap_vrf_id,
2815 'protocol': protocol,
2816 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002817
Neale Ranns79a05f52018-09-11 07:39:43 -07002818 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002819 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002820 src,
2821 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002822 mcast_sw_if_index=0xFFFFFFFF,
2823 is_add=1,
2824 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002825 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002826 vni=0,
2827 instance=0xFFFFFFFF):
2828 """
2829
2830 :param dst_addr:
2831 :param src_addr:
2832 :param is_add: (Default value = 1)
2833 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002834 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002835 :param decap_next_index: (Default value = 0xFFFFFFFF)
2836 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2837 :param vni: (Default value = 0)
2838 :param instance: (Default value = 0xFFFFFFFF)
2839
2840 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002841 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002842 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002843 'tunnel': {
2844 'src': src,
2845 'dst': dst,
2846 'mcast_sw_if_index': mcast_sw_if_index,
2847 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002848 'vni': vni,
2849 'instance': instance}})
2850
2851 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2852 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01002853 {'sw_if_index': sw_if_index,
2854 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002855
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002856 def pppoe_add_del_session(
2857 self,
2858 client_ip,
2859 client_mac,
2860 session_id=0,
2861 is_add=1,
2862 is_ipv6=0,
2863 decap_vrf_id=0):
2864 """
2865
2866 :param is_add: (Default value = 1)
2867 :param is_ipv6: (Default value = 0)
2868 :param client_ip:
2869 :param session_id: (Default value = 0)
2870 :param client_mac:
2871 :param decap_vrf_id: (Default value = 0)
2872
2873 """
2874 return self.api(self.papi.pppoe_add_del_session,
2875 {'is_add': is_add,
2876 'is_ipv6': is_ipv6,
2877 'session_id': session_id,
2878 'client_ip': client_ip,
2879 'decap_vrf_id': decap_vrf_id,
2880 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002881
Neale Ranns7c922dc2018-08-30 06:12:27 -07002882 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2883 return self.api(self.papi.sr_mpls_policy_add,
2884 {'bsid': bsid,
2885 'weight': weight,
2886 'type': type,
2887 'n_segments': len(segments),
2888 'segments': segments})
2889
2890 def sr_mpls_policy_del(self, bsid):
2891 return self.api(self.papi.sr_mpls_policy_del,
2892 {'bsid': bsid})
2893
Kris Michielsen91074432017-06-22 13:00:20 +02002894 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002895 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002896 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002897 nh_addr4,
2898 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002899 is_del=0,
2900 end_psp=0,
2901 sw_if_index=0xFFFFFFFF,
2902 vlan_index=0,
2903 fib_table=0,
2904 ):
2905 """ Add/del IPv6 SR local-SID.
2906
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002907 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002908 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2909 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002910 :param nh_addr4:
2911 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002912 :param is_del: (Default value = 0)
2913 :param end_psp: (Default value = 0)
2914 :param sw_if_index: (Default value = 0xFFFFFFFF)
2915 :param vlan_index: (Default value = 0)
2916 :param fib_table: (Default value = 0)
2917 """
2918 return self.api(
2919 self.papi.sr_localsid_add_del,
2920 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002921 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002922 'end_psp': end_psp,
2923 'behavior': behavior,
2924 'sw_if_index': sw_if_index,
2925 'vlan_index': vlan_index,
2926 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002927 'nh_addr4': nh_addr4,
2928 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002929 }
2930 )
2931
2932 def sr_policy_add(
2933 self,
2934 bsid_addr,
2935 weight=1,
2936 is_encap=1,
2937 type=0,
2938 fib_table=0,
2939 n_segments=0,
2940 segments=[]):
2941 """
2942 :param bsid_addr: bindingSID of the SR Policy
2943 :param weight: weight of the sid list. optional. (default: 1)
2944 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2945 (default: Encap)
2946 :param type: type/behavior of the SR policy. (default or spray) \
2947 (default: default)
2948 :param fib_table: VRF where to install the FIB entry for the BSID \
2949 (default: 0)
2950 :param n_segments: number of segments \
2951 (default: 0)
2952 :param segments: a vector of IPv6 address composing the segment list \
2953 (default: [])
2954 """
2955 return self.api(
2956 self.papi.sr_policy_add,
2957 {'bsid_addr': bsid_addr,
2958 'weight': weight,
2959 'is_encap': is_encap,
2960 'type': type,
2961 'fib_table': fib_table,
2962 'n_segments': n_segments,
2963 'segments': segments
2964 }
2965 )
2966
2967 def sr_policy_del(
2968 self,
2969 bsid_addr,
2970 sr_policy_index=0):
2971 """
2972 :param bsid: bindingSID of the SR Policy
2973 :param sr_policy_index: index of the sr policy (default: 0)
2974 """
2975 return self.api(
2976 self.papi.sr_policy_del,
2977 {'bsid_addr': bsid_addr,
2978 'sr_policy_index': sr_policy_index
2979 })
2980
2981 def sr_steering_add_del(
2982 self,
2983 is_del,
2984 bsid_addr,
2985 sr_policy_index,
2986 table_id,
2987 prefix_addr,
2988 mask_width,
2989 sw_if_index,
2990 traffic_type):
2991 """
2992 Steer traffic L2 and L3 traffic through a given SR policy
2993
2994 :param is_del: delete or add
2995 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2996 :param sr_policy: is the index of the SR Policy (alt to bsid)
2997 :param table_id: is the VRF where to install the FIB entry for the BSID
2998 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2999 :param mask_width: is the mask for L3 traffic type
3000 :param sw_if_index: is the incoming interface for L2 traffic
3001 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
3002 """
3003 return self.api(
3004 self.papi.sr_steering_add_del,
3005 {'is_del': is_del,
3006 'bsid_addr': bsid_addr,
3007 'sr_policy_index': sr_policy_index,
3008 'table_id': table_id,
3009 'prefix_addr': prefix_addr,
3010 'mask_width': mask_width,
3011 'sw_if_index': sw_if_index,
3012 'traffic_type': traffic_type
3013 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02003014
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003015 def acl_add_replace(self, acl_index, r, tag='',
3016 expected_retval=0):
3017 """Add/replace an ACL
3018 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
3019 :param acl_rule r: ACL rules array.
3020 :param str tag: symbolic tag (description) for this ACL.
3021 :param int count: number of rules.
3022 """
3023 return self.api(self.papi.acl_add_replace,
3024 {'acl_index': acl_index,
3025 'r': r,
3026 'count': len(r),
3027 'tag': tag},
3028 expected_retval=expected_retval)
3029
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003030 def acl_del(self, acl_index, expected_retval=0):
3031 """
3032
3033 :param acl_index:
3034 :return:
3035 """
3036 return self.api(self.papi.acl_del,
3037 {'acl_index': acl_index},
3038 expected_retval=expected_retval)
3039
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003040 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3041 expected_retval=0):
3042 return self.api(self.papi.acl_interface_set_acl_list,
3043 {'sw_if_index': sw_if_index,
3044 'count': len(acls),
3045 'n_input': n_input,
3046 'acls': acls},
3047 expected_retval=expected_retval)
3048
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003049 def acl_interface_set_etype_whitelist(self, sw_if_index,
3050 n_input, whitelist,
3051 expected_retval=0):
3052 return self.api(self.papi.acl_interface_set_etype_whitelist,
3053 {'sw_if_index': sw_if_index,
3054 'count': len(whitelist),
3055 'n_input': n_input,
3056 'whitelist': whitelist},
3057 expected_retval=expected_retval)
3058
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003059 def acl_interface_add_del(self,
3060 sw_if_index,
3061 acl_index,
3062 is_add=1):
3063 """ Add/Delete ACL to/from interface
3064
3065 :param sw_if_index:
3066 :param acl_index:
3067 :param is_add: (Default value = 1)
3068 """
3069
3070 return self.api(self.papi.acl_interface_add_del,
3071 {'is_add': is_add,
3072 'is_input': 1,
3073 'sw_if_index': sw_if_index,
3074 'acl_index': acl_index})
3075
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003076 def acl_dump(self, acl_index, expected_retval=0):
3077 return self.api(self.papi.acl_dump,
3078 {'acl_index': acl_index},
3079 expected_retval=expected_retval)
3080
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003081 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3082 expected_retval=0):
3083 return self.api(self.papi.acl_interface_list_dump,
3084 {'sw_if_index': sw_if_index},
3085 expected_retval=expected_retval)
3086
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003087 def macip_acl_add(self, rules, tag=""):
3088 """ Add MACIP acl
3089
3090 :param rules: list of rules for given acl
3091 :param tag: acl tag
3092 """
3093
3094 return self.api(self.papi.macip_acl_add,
3095 {'r': rules,
3096 'count': len(rules),
3097 'tag': tag})
3098
Pavel Kotucek932f7412017-09-07 14:44:52 +02003099 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3100 """ Add MACIP acl
3101
3102 :param rules: list of rules for given acl
3103 :param tag: acl tag
3104 """
3105
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003106 return self.api(self.papi.macip_acl_add_replace,
3107 {'acl_index': acl_index,
3108 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003109 'count': len(rules),
3110 'tag': tag})
3111
3112 def macip_acl_del(self, acl_index):
3113 """
3114
3115 :param acl_index:
3116 :return:
3117 """
3118 return self.api(self.papi.macip_acl_del,
3119 {'acl_index': acl_index})
3120
3121 def macip_acl_interface_add_del(self,
3122 sw_if_index,
3123 acl_index,
3124 is_add=1):
3125 """ Add MACIP acl to interface
3126
3127 :param sw_if_index:
3128 :param acl_index:
3129 :param is_add: (Default value = 1)
3130 """
3131
3132 return self.api(self.papi.macip_acl_interface_add_del,
3133 {'is_add': is_add,
3134 'sw_if_index': sw_if_index,
3135 'acl_index': acl_index})
3136
3137 def macip_acl_interface_get(self):
3138 """ Return interface acls dump
3139 """
3140 return self.api(
3141 self.papi.macip_acl_interface_get, {})
3142
3143 def macip_acl_dump(self, acl_index=4294967295):
3144 """ Return MACIP acl dump
3145 """
3146
3147 return self.api(
3148 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003149
3150 def policer_add_del(self,
3151 name,
3152 cir,
3153 eir,
3154 cb,
3155 eb,
3156 is_add=1,
3157 rate_type=0,
3158 round_type=0,
3159 ptype=0,
3160 color_aware=0,
3161 conform_action_type=1,
3162 conform_dscp=0,
3163 exceed_action_type=0,
3164 exceed_dscp=0,
3165 violate_action_type=0,
3166 violate_dscp=0):
3167 return self.api(self.papi.policer_add_del,
3168 {'name': name,
3169 'cir': cir,
3170 'eir': eir,
3171 'cb': cb,
3172 'eb': eb,
3173 'is_add': is_add,
3174 'rate_type': rate_type,
3175 'round_type': round_type,
3176 'type': ptype,
3177 'color_aware': color_aware,
3178 'conform_action_type': conform_action_type,
3179 'conform_dscp': conform_dscp,
3180 'exceed_action_type': exceed_action_type,
3181 'exceed_dscp': exceed_dscp,
3182 'violate_action_type': violate_action_type,
3183 'violate_dscp': violate_dscp})
3184
3185 def ip_punt_police(self,
3186 policer_index,
3187 is_ip6=0,
3188 is_add=1):
3189 return self.api(self.papi.ip_punt_police,
3190 {'policer_index': policer_index,
3191 'is_add': is_add,
3192 'is_ip6': is_ip6})
3193
3194 def ip_punt_redirect(self,
3195 rx_sw_if_index,
3196 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003197 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07003198 is_add=1):
3199 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003200 {'punt': {'rx_sw_if_index': rx_sw_if_index,
3201 'tx_sw_if_index': tx_sw_if_index,
3202 'nh': address},
3203 'is_add': is_add})
3204
3205 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
3206 return self.api(self.papi.ip_punt_redirect_dump,
3207 {'sw_if_index': sw_if_index,
3208 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003209
3210 def bier_table_add_del(self,
3211 bti,
3212 mpls_label,
3213 is_add=1):
3214 """ BIER Table add/del """
3215 return self.api(
3216 self.papi.bier_table_add_del,
3217 {'bt_tbl_id': {"bt_set": bti.set_id,
3218 "bt_sub_domain": bti.sub_domain_id,
3219 "bt_hdr_len_id": bti.hdr_len_id},
3220 'bt_label': mpls_label,
3221 'bt_is_add': is_add})
3222
3223 def bier_table_dump(self):
3224 return self.api(self.papi.bier_table_dump, {})
3225
3226 def bier_route_add_del(self,
3227 bti,
3228 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003229 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003230 is_add=1,
3231 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003232 """ BIER Route add/del """
3233 return self.api(
3234 self.papi.bier_route_add_del,
3235 {'br_tbl_id': {"bt_set": bti.set_id,
3236 "bt_sub_domain": bti.sub_domain_id,
3237 "bt_hdr_len_id": bti.hdr_len_id},
3238 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003239 'br_n_paths': len(paths),
3240 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003241 'br_is_add': is_add,
3242 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003243
3244 def bier_route_dump(self, bti):
3245 return self.api(
3246 self.papi.bier_route_dump,
3247 {'br_tbl_id': {"bt_set": bti.set_id,
3248 "bt_sub_domain": bti.sub_domain_id,
3249 "bt_hdr_len_id": bti.hdr_len_id}})
3250
3251 def bier_imp_add(self,
3252 bti,
3253 src,
3254 ibytes,
3255 is_add=1):
3256 """ BIER Imposition Add """
3257 return self.api(
3258 self.papi.bier_imp_add,
3259 {'bi_tbl_id': {"bt_set": bti.set_id,
3260 "bt_sub_domain": bti.sub_domain_id,
3261 "bt_hdr_len_id": bti.hdr_len_id},
3262 'bi_src': src,
3263 'bi_n_bytes': len(ibytes),
3264 'bi_bytes': ibytes})
3265
3266 def bier_imp_del(self, bi_index):
3267 """ BIER Imposition del """
3268 return self.api(
3269 self.papi.bier_imp_del,
3270 {'bi_index': bi_index})
3271
3272 def bier_imp_dump(self):
3273 return self.api(self.papi.bier_imp_dump, {})
3274
3275 def bier_disp_table_add_del(self,
3276 bdti,
3277 is_add=1):
3278 """ BIER Disposition Table add/del """
3279 return self.api(
3280 self.papi.bier_disp_table_add_del,
3281 {'bdt_tbl_id': bdti,
3282 'bdt_is_add': is_add})
3283
3284 def bier_disp_table_dump(self):
3285 return self.api(self.papi.bier_disp_table_dump, {})
3286
3287 def bier_disp_entry_add_del(self,
3288 bdti,
3289 bp,
3290 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003291 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003292 next_hop,
3293 next_hop_tbl_id=0,
3294 next_hop_rpf_id=~0,
3295 next_hop_is_ip4=1,
3296 is_add=1):
3297 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003298 lstack = []
3299 while (len(lstack) < 16):
3300 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003301 return self.api(
3302 self.papi.bier_disp_entry_add_del,
3303 {'bde_tbl_id': bdti,
3304 'bde_bp': bp,
3305 'bde_payload_proto': payload_proto,
3306 'bde_n_paths': 1,
3307 'bde_paths': [{'next_hop': next_hop,
3308 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003309 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003310 'rpf_id': next_hop_rpf_id,
3311 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003312 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003313 'bde_is_add': is_add})
3314
3315 def bier_disp_entry_dump(self, bdti):
3316 return self.api(
3317 self.papi.bier_disp_entry_dump,
3318 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003319
3320 def add_node_next(self, node_name, next_name):
3321 """ Set the next node for a given node request
3322
3323 :param node_name:
3324 :param next_name:
3325 """
3326 return self.api(self.papi.add_node_next,
3327 {'node_name': node_name,
3328 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003329
3330 def session_enable_disable(self, is_enabled):
3331 return self.api(
3332 self.papi.session_enable_disable,
3333 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003334
3335 def ipsec_spd_add_del(self, spd_id, is_add=1):
3336 """ SPD add/del - Wrapper to add or del ipsec SPD
3337 Sample CLI : 'ipsec spd add 1'
3338
3339 :param spd_id - SPD ID to be created in the vpp . mandatory
3340 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3341 optional
3342 :returns: reply from the API
3343 """
3344 return self.api(
3345 self.papi.ipsec_spd_add_del, {
3346 'spd_id': spd_id, 'is_add': is_add})
3347
Neale Ranns311124e2019-01-24 04:52:25 -08003348 def ipsec_spds_dump(self):
3349 return self.api(self.papi.ipsec_spds_dump, {})
3350
“mystarrocks”23f0c452017-12-11 07:11:51 -08003351 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3352 """ IPSEC interface SPD add/del - \
3353 Wrapper to associate/disassociate SPD to interface in VPP
3354 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3355
3356 :param spd_id - SPD ID to associate with the interface . mandatory
3357 :param sw_if_index - Interface Index which needs to ipsec \
3358 association mandatory
3359 :param is_add - add(1) or del(0) association with interface \
3360 (Default 1 - add) . optional
3361 :returns: reply from the API
3362 """
3363 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003364 self.papi.ipsec_interface_add_del_spd,
3365 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003366
Neale Ranns311124e2019-01-24 04:52:25 -08003367 def ipsec_spd_interface_dump(self, spd_index=None):
3368 return self.api(self.papi.ipsec_spd_interface_dump,
3369 {'spd_index': spd_index if spd_index else 0,
3370 'spd_index_valid': 1 if spd_index else 0})
3371
“mystarrocks”23f0c452017-12-11 07:11:51 -08003372 def ipsec_sad_add_del_entry(self,
3373 sad_id,
3374 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003375 integrity_algorithm,
3376 integrity_key,
3377 crypto_algorithm,
3378 crypto_key,
3379 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003380 tunnel_src_address='',
3381 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003382 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003383 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003384 is_add=1,
Neale Rannsde847272018-11-28 01:38:34 -08003385 udp_encap=0,
3386 use_anti_replay=0,
3387 use_extended_sequence_number=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003388 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003389 :param sad_id: security association ID
3390 :param spi: security param index of the SA in decimal
3391 :param integrity_algorithm:
3392 :param integrity_key:
3393 :param crypto_algorithm:
3394 :param crypto_key:
3395 :param protocol: AH(0) or ESP(1) protocol
3396 :param tunnel_src_address: tunnel mode outer src address
3397 :param tunnel_dst_address: tunnel mode outer dst address
3398 :param is_add:
3399 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003400 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3401 crypto and ipsec algorithms
3402 """
3403 return self.api(
3404 self.papi.ipsec_sad_add_del_entry,
3405 {'sad_id': sad_id,
3406 'spi': spi,
3407 'tunnel_src_address': tunnel_src_address,
3408 'tunnel_dst_address': tunnel_dst_address,
3409 'protocol': protocol,
3410 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003411 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003412 'integrity_key': integrity_key,
3413 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003414 'crypto_key_length': len(crypto_key) if crypto_key is not None
3415 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003416 'crypto_key': crypto_key,
3417 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003418 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003419 'is_tunnel_ipv6': is_tunnel_ipv6,
Neale Rannsde847272018-11-28 01:38:34 -08003420 'udp_encap': udp_encap,
3421 'use_extended_sequence_number': use_extended_sequence_number,
3422 'use_anti_replay': use_anti_replay})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003423
Neale Ranns311124e2019-01-24 04:52:25 -08003424 def ipsec_sa_dump(self, sa_id=None):
3425 return self.api(self.papi.ipsec_sa_dump,
3426 {'sa_id': sa_id if sa_id else 0xffffffff})
3427
“mystarrocks”23f0c452017-12-11 07:11:51 -08003428 def ipsec_spd_add_del_entry(self,
3429 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003430 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003431 local_address_start,
3432 local_address_stop,
3433 remote_address_start,
3434 remote_address_stop,
3435 local_port_start=0,
3436 local_port_stop=65535,
3437 remote_port_start=0,
3438 remote_port_stop=65535,
3439 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003440 policy=0,
3441 priority=100,
3442 is_outbound=1,
3443 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003444 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003445 is_ip_any=0):
3446 """ IPSEC policy SPD add/del -
3447 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003448 :param spd_id: SPD ID for the policy
3449 :param local_address_start: local-ip-range start address
3450 :param local_address_stop : local-ip-range stop address
3451 :param remote_address_start: remote-ip-range start address
3452 :param remote_address_stop : remote-ip-range stop address
3453 :param local_port_start: (Default value = 0)
3454 :param local_port_stop: (Default value = 65535)
3455 :param remote_port_start: (Default value = 0)
3456 :param remote_port_stop: (Default value = 65535)
3457 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3458 :param sa_id: Security Association ID for mapping it to SPD
3459 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3460 (Default value = 0)
3461 :param priority: value for the spd action (Default value = 100)
3462 :param is_outbound: flag for inbound(0) or outbound(1)
3463 (Default value = 1)
3464 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003465 """
3466 return self.api(
3467 self.papi.ipsec_spd_add_del_entry,
3468 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003469 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003470 'local_address_start': local_address_start,
3471 'local_address_stop': local_address_stop,
3472 'remote_address_start': remote_address_start,
3473 'remote_address_stop': remote_address_stop,
3474 'local_port_start': local_port_start,
3475 'local_port_stop': local_port_stop,
3476 'remote_port_start': remote_port_start,
3477 'remote_port_stop': remote_port_stop,
3478 'is_add': is_add,
3479 'protocol': protocol,
3480 'policy': policy,
3481 'priority': priority,
3482 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003483 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003484 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003485
Neale Ranns311124e2019-01-24 04:52:25 -08003486 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
3487 return self.api(self.papi.ipsec_spd_dump,
3488 {'spd_id': spd_id,
3489 'sa_id': sa_id})
3490
Klement Sekera31da2e32018-06-24 22:49:55 +02003491 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3492 remote_spi, crypto_alg, local_crypto_key,
3493 remote_crypto_key, integ_alg, local_integ_key,
3494 remote_integ_key, is_add=1, esn=0,
3495 anti_replay=1, renumber=0, show_instance=0):
3496 return self.api(
3497 self.papi.ipsec_tunnel_if_add_del,
3498 {'local_ip': local_ip, 'remote_ip': remote_ip,
3499 'local_spi': local_spi, 'remote_spi': remote_spi,
3500 'crypto_alg': crypto_alg,
3501 'local_crypto_key_len': len(local_crypto_key),
3502 'local_crypto_key': local_crypto_key,
3503 'remote_crypto_key_len': len(remote_crypto_key),
3504 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3505 'local_integ_key_len': len(local_integ_key),
3506 'local_integ_key': local_integ_key,
3507 'remote_integ_key_len': len(remote_integ_key),
3508 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3509 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3510 'show_instance': show_instance
3511 })
3512
Klement Sekerab4d30532018-11-08 13:00:02 +01003513 def ipsec_select_backend(self, protocol, index):
3514 return self.api(self.papi.ipsec_select_backend,
3515 {'protocol': protocol, 'index': index})
3516
3517 def ipsec_backend_dump(self):
3518 return self.api(self.papi.ipsec_backend_dump, {})
3519
Florin Corasb795bd02017-12-14 11:30:48 -08003520 def app_namespace_add(self,
3521 namespace_id,
3522 ip4_fib_id=0,
3523 ip6_fib_id=0,
3524 sw_if_index=0xFFFFFFFF,
3525 secret=0):
3526 return self.api(
3527 self.papi.app_namespace_add_del,
3528 {'secret': secret,
3529 'sw_if_index': sw_if_index,
3530 'ip4_fib_id': ip4_fib_id,
3531 'ip6_fib_id': ip6_fib_id,
3532 'namespace_id': namespace_id,
3533 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003534
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003535 def punt_socket_register(self, port, pathname, protocol=0x11,
3536 header_version=1, is_ip4=1):
3537 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02003538 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003539 {'header_version': header_version,
3540 'punt': {'ipv': is_ip4,
3541 'l4_protocol': protocol,
3542 'l4_port': port},
3543 'pathname': pathname})
3544
3545 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
3546 """ Unregister punt socket """
3547 return self.api(self.papi.punt_socket_deregister,
3548 {'punt': {'ipv': is_ip4,
3549 'l4_protocol': protocol,
3550 'l4_port': port}})
3551
3552 def punt_socket_dump(self, is_ip6=1):
3553 """ Dump punt socket"""
3554 return self.api(self.papi.punt_socket_dump,
3555 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02003556
3557 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3558 expire_walk_interval_ms, is_ip6=0):
3559 """ Set IP reassembly parameters """
3560 return self.api(self.papi.ip_reassembly_set,
3561 {'is_ip6': is_ip6,
3562 'timeout_ms': timeout_ms,
3563 'expire_walk_interval_ms': expire_walk_interval_ms,
3564 'max_reassemblies': max_reassemblies})
3565
3566 def ip_reassembly_get(self, is_ip6=0):
3567 """ Get IP reassembly parameters """
3568 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003569
Klement Sekera4c533132018-02-22 11:41:12 +01003570 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3571 enable_ip6=False):
3572 """ Enable/disable IP reassembly """
3573 return self.api(self.papi.ip_reassembly_enable_disable,
3574 {'sw_if_index': sw_if_index,
3575 'enable_ip4': 1 if enable_ip4 else 0,
3576 'enable_ip6': 1 if enable_ip6 else 0,
3577 })
3578
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003579 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3580 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003581 """ GBP endpoint Add """
3582 return self.api(self.papi.gbp_endpoint_add,
3583 {'endpoint': {
3584 'sw_if_index': sw_if_index,
3585 'ips': ips,
3586 'n_ips': len(ips),
3587 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003588 'epg_id': epg,
3589 'flags': flags,
3590 'tun': {
3591 'src': tun_src,
3592 'dst': tun_dst,
3593 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003594
3595 def gbp_endpoint_del(self, handle):
3596 """ GBP endpoint Del """
3597 return self.api(self.papi.gbp_endpoint_del,
3598 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003599
3600 def gbp_endpoint_dump(self):
3601 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003602 return self.api(self.papi.gbp_endpoint_dump,
3603 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003604
Neale Ranns879d11c2019-01-21 23:34:18 -08003605 def gbp_endpoint_group_add(self, epg, sclass, bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003606 rd, uplink_sw_if_index):
3607 """ GBP endpoint group Add """
3608 return self.api(self.papi.gbp_endpoint_group_add,
3609 {'epg':
3610 {
Neale Ranns25b04942018-04-04 09:34:50 -07003611 'uplink_sw_if_index': uplink_sw_if_index,
3612 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003613 'rd_id': rd,
Neale Ranns879d11c2019-01-21 23:34:18 -08003614 'epg_id': epg,
3615 'sclass': sclass
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003616 }})
3617
3618 def gbp_endpoint_group_del(self, epg):
3619 """ GBP endpoint group Del """
3620 return self.api(self.papi.gbp_endpoint_group_del,
3621 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003622
3623 def gbp_endpoint_group_dump(self):
3624 """ GBP endpoint group Dump """
3625 return self.api(self.papi.gbp_endpoint_group_dump, {})
3626
Neale Rannsc29c0af2018-11-07 04:21:12 -08003627 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003628 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08003629 uu_fwd_sw_if_index,
3630 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003631 """ GBP bridge-domain Add """
3632 return self.api(self.papi.gbp_bridge_domain_add,
3633 {'bd':
3634 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003635 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003636 'bvi_sw_if_index': bvi_sw_if_index,
3637 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08003638 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003639 'bd_id': bd_id
3640 }})
3641
3642 def gbp_bridge_domain_del(self, bd_id):
3643 """ GBP bridge-domain Del """
3644 return self.api(self.papi.gbp_bridge_domain_del,
3645 {'bd_id': bd_id})
3646
3647 def gbp_bridge_domain_dump(self):
3648 """ GBP Bridge Domain Dump """
3649 return self.api(self.papi.gbp_bridge_domain_dump, {})
3650
3651 def gbp_route_domain_add(self, rd_id,
3652 ip4_table_id,
3653 ip6_table_id,
3654 ip4_uu_sw_if_index,
3655 ip6_uu_sw_if_index):
3656 """ GBP route-domain Add """
3657 return self.api(self.papi.gbp_route_domain_add,
3658 {'rd':
3659 {
3660 'ip4_table_id': ip4_table_id,
3661 'ip6_table_id': ip6_table_id,
3662 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3663 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3664 'rd_id': rd_id
3665 }})
3666
3667 def gbp_route_domain_del(self, rd_id):
3668 """ GBP route-domain Del """
3669 return self.api(self.papi.gbp_route_domain_del,
3670 {'rd_id': rd_id})
3671
3672 def gbp_route_domain_dump(self):
3673 """ GBP Route Domain Dump """
3674 return self.api(self.papi.gbp_route_domain_dump, {})
3675
Neale Ranns25b04942018-04-04 09:34:50 -07003676 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3677 """ GBP recirc Add/Del """
3678 return self.api(self.papi.gbp_recirc_add_del,
3679 {'is_add': is_add,
3680 'recirc': {
3681 'is_ext': is_ext,
3682 'sw_if_index': sw_if_index,
3683 'epg_id': epg}})
3684
3685 def gbp_recirc_dump(self):
3686 """ GBP recirc Dump """
3687 return self.api(self.papi.gbp_recirc_dump, {})
3688
Neale Rannsb6a47952018-11-21 05:44:35 -08003689 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
3690 """ GBP recirc Add/Del """
3691 return self.api(self.papi.gbp_ext_itf_add_del,
3692 {'is_add': is_add,
3693 'ext_itf': {
3694 'sw_if_index': sw_if_index,
3695 'bd_id': bd_id,
3696 'rd_id': rd_id}})
3697
3698 def gbp_ext_itf_dump(self):
3699 """ GBP recirc Dump """
3700 return self.api(self.papi.gbp_ext_itf_dump, {})
3701
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003702 def gbp_subnet_add_del(self, is_add, rd_id,
3703 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003704 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003705 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003706 """ GBP Subnet Add/Del """
3707 return self.api(self.papi.gbp_subnet_add_del,
3708 {'is_add': is_add,
3709 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003710 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003711 'sw_if_index': sw_if_index,
3712 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003713 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003714 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003715
3716 def gbp_subnet_dump(self):
3717 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003718 return self.api(self.papi.gbp_subnet_dump,
3719 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07003720
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003721 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index,
3722 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003723 """ GBP contract Add/Del """
3724 return self.api(self.papi.gbp_contract_add_del,
3725 {'is_add': is_add,
3726 'contract': {
3727 'acl_index': acl_index,
3728 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003729 'dst_epg': dst_epg,
3730 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003731 'rules': rules,
3732 'n_ether_types': len(allowed_ethertypes),
3733 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003734
3735 def gbp_contract_dump(self):
3736 """ GBP contract Dump """
3737 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003738
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003739 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3740 """ GBP set inactive threshold """
3741 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3742 {'threshold': threshold})
3743
3744 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3745 """ GBP VXLAN tunnel add """
3746 return self.api(self.papi.gbp_vxlan_tunnel_add,
3747 {
3748 'tunnel': {
3749 'vni': vni,
3750 'mode': mode,
3751 'bd_rd_id': bd_rd_id
3752 }
3753 })
3754
3755 def gbp_vxlan_tunnel_del(self, vni):
3756 """ GBP VXLAN tunnel del """
3757 return self.api(self.papi.gbp_vxlan_tunnel_del,
3758 {
3759 'vni': vni,
3760 })
3761
3762 def gbp_vxlan_tunnel_dump(self):
3763 """ GBP VXLAN tunnel add/del """
3764 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3765
Neale Ranns61502112018-08-22 00:21:14 -07003766 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3767 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003768 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003769 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003770 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003771 {'ip4_table_id': ip4_table_id,
3772 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003773 'ip6_prefix': ip6_prefix,
3774 'ip6_prefix_len': ip6_prefix_len,
3775 'ip4_prefix': ip4_prefix,
3776 'ip4_prefix_len': ip4_prefix_len,
3777 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003778 'security_check': security_check})
3779
Ole Troan298c6952018-03-08 12:30:43 +01003780 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003781 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003782 return self.api(self.papi.ipip_6rd_del_tunnel,
3783 {'sw_if_index': sw_if_index})
3784
3785 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003786 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003787 """ IPIP tunnel Add/Del """
3788 return self.api(self.papi.ipip_add_tunnel,
3789 {'is_ipv6': is_ipv6,
3790 'instance': instance,
3791 'src_address': src_address,
3792 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003793 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003794 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003795
3796 def ipip_del_tunnel(self, sw_if_index):
3797 """ IPIP tunnel Delete """
3798 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003799 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003800
3801 def qos_egress_map_update(self, id, outputs):
3802 """ QOS egress map update """
3803 return self.api(self.papi.qos_egress_map_update,
3804 {'map_id': id,
3805 'rows': outputs})
3806
3807 def qos_egress_map_delete(self, id):
3808 """ QOS egress map delete """
3809 return self.api(self.papi.qos_egress_map_delete,
3810 {'map_id': id})
3811
3812 def qos_mark_enable_disable(self, sw_if_index,
3813 output_source,
3814 map_id,
3815 enable):
3816 """ QOS Mark Enable/Disable """
3817 return self.api(self.papi.qos_mark_enable_disable,
3818 {'map_id': map_id,
3819 'sw_if_index': sw_if_index,
3820 'output_source': output_source,
3821 'enable': enable})
3822
3823 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3824 """ IP QoS recording Enble/Disable """
3825 return self.api(self.papi.qos_record_enable_disable,
3826 {'sw_if_index': sw_if_index,
3827 'input_source': input_source,
3828 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003829
Neale Ranns947ea622018-06-07 23:48:20 -07003830 def igmp_enable_disable(self, sw_if_index, enable, host):
3831 """ Enable/disable IGMP on a given interface """
3832 return self.api(self.papi.igmp_enable_disable,
3833 {'enable': enable,
3834 'mode': host,
3835 'sw_if_index': sw_if_index})
3836
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003837 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3838 """ Add/del IGMP proxy device """
3839 return self.api(self.papi.igmp_proxy_device_add_del,
3840 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3841 'add': add})
3842
3843 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3844 """ Add/del interface to/from IGMP proxy device """
3845 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3846 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3847 'add': add})
3848
Neale Ranns947ea622018-06-07 23:48:20 -07003849 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003850 """ Listen for new (S,G) on specified interface
3851
3852 :param enable: add/del
3853 :param sw_if_index: interface sw index
3854 :param saddr: source ip4 addr
3855 :param gaddr: group ip4 addr
3856 """
3857 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003858 {
3859 'group':
3860 {
3861 'filter': filter,
3862 'sw_if_index': sw_if_index,
3863 'n_srcs': len(saddrs),
3864 'saddrs': saddrs,
Ole Troan8c8acc02018-11-27 10:05:23 +01003865 'gaddr': gaddr
Neale Ranns947ea622018-06-07 23:48:20 -07003866 }
3867 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003868
3869 def igmp_dump(self, sw_if_index=None):
3870 """ Dump all (S,G) interface configurations """
3871 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003872 sw_if_index = 0xffffffff
3873 return self.api(self.papi.igmp_dump,
3874 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003875
3876 def igmp_clear_interface(self, sw_if_index):
3877 """ Remove all (S,G)s from specified interface
3878 doesn't send IGMP report!
3879 """
3880 return self.api(
3881 self.papi.igmp_clear_interface, {
3882 'sw_if_index': sw_if_index})
3883
3884 def want_igmp_events(self, enable=1):
3885 return self.api(self.papi.want_igmp_events, {'enable': enable,
3886 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003887
3888 def bond_create(
3889 self,
3890 mode,
3891 lb,
3892 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003893 mac_address='',
3894 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08003895 """
3896 :param mode: mode
3897 :param lb: load balance
3898 :param use_custom_mac: use custom mac
3899 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003900 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08003901 """
3902 return self.api(
3903 self.papi.bond_create,
3904 {'mode': mode,
3905 'lb': lb,
3906 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003907 'mac_address': mac_address,
3908 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08003909 })
3910
3911 def bond_delete(
3912 self,
3913 sw_if_index):
3914 """
3915 :param sw_if_index: interface the operation is applied to
3916 """
3917 return self.api(self.papi.bond_delete,
3918 {'sw_if_index': sw_if_index})
3919
3920 def bond_enslave(
3921 self,
3922 sw_if_index,
3923 bond_sw_if_index,
3924 is_passive,
3925 is_long_timeout):
3926 """
3927 :param sw_if_index: slave sw_if_index
3928 :param bond_sw_if_index: bond sw_if_index
3929 :param is_passive: is passive lacp speaker
3930 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3931 """
3932 return self.api(
3933 self.papi.bond_enslave,
3934 {'sw_if_index': sw_if_index,
3935 'bond_sw_if_index': bond_sw_if_index,
3936 'is_passive': is_passive,
3937 'is_long_timeout': is_long_timeout
3938 })
3939
3940 def bond_detach_slave(
3941 self,
3942 sw_if_index):
3943 """
3944 :param sw_if_index: slave interface the operation is applied to
3945 """
3946 return self.api(self.papi.bond_detach_slave,
3947 {'sw_if_index': sw_if_index})
3948
3949 def sw_interface_slave_dump(
3950 self,
3951 sw_if_index):
3952 """
3953 :param sw_if_index: bond sw_if_index
3954 """
3955 return self.api(self.papi.sw_interface_slave_dump,
3956 {'sw_if_index': sw_if_index})
3957
3958 def sw_interface_bond_dump(
3959 self):
3960 """
3961
3962 """
3963 return self.api(self.papi.sw_interface_bond_dump,
3964 {})
Stevene8fa6202017-08-30 14:36:45 -07003965
3966 def create_vhost_user_if(
3967 self,
3968 is_server,
3969 sock_filename,
3970 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003971 disable_mrg_rxbuf,
3972 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003973 custom_dev_instance,
3974 use_custom_mac,
3975 mac_address,
3976 tag=''):
3977 """
3978 :param is_server: is server
3979 :param sock_filename: socket name
3980 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003981 :param disable_mrg_rxbuf: disable mergable rx buffers
3982 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003983 :param custom_dev_instance: custom dev instance
3984 :param use_custom_mac: use custom mac
3985 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003986 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003987 """
3988 return self.api(
3989 self.papi.create_vhost_user_if,
3990 {'is_server': is_server,
3991 'sock_filename': sock_filename,
3992 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003993 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3994 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003995 'custom_dev_instance': custom_dev_instance,
3996 'use_custom_mac': use_custom_mac,
3997 'mac_address': mac_address,
3998 'tag': tag
3999 })
4000
4001 def delete_vhost_user_if(
4002 self,
4003 sw_if_index):
4004 """
4005 :param sw_if_index: interface the operation is applied to
4006 """
4007 return self.api(self.papi.delete_vhost_user_if,
4008 {'sw_if_index': sw_if_index, })
4009
4010 def sw_interface_vhost_user_dump(
4011 self):
4012 """
4013
4014 """
4015 return self.api(self.papi.sw_interface_vhost_user_dump,
4016 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01004017
4018 def abf_policy_add_del(self, is_add, policy):
4019 return self.api(
4020 self.papi.abf_policy_add_del,
4021 {'is_add': is_add,
4022 'policy': policy})
4023
4024 def abf_itf_attach_add_del(self, is_add, attach):
4025 return self.api(
4026 self.papi.abf_itf_attach_add_del,
4027 {'is_add': is_add,
4028 'attach': attach})
4029
4030 def abf_policy_dump(self):
4031 return self.api(
4032 self.papi.abf_policy_dump, {})
4033
4034 def abf_itf_attach_dump(self):
4035 return self.api(
4036 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07004037
4038 def pipe_create(self, is_specified, user_instance):
4039 return self.api(self.papi.pipe_create,
4040 {'is_specified': is_specified,
4041 'user_instance': user_instance})
4042
4043 def pipe_delete(self, parent_sw_if_index):
4044 return self.api(self.papi.pipe_delete,
4045 {'parent_sw_if_index': parent_sw_if_index})
4046
4047 def pipe_dump(self):
4048 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02004049
4050 def memif_create(
4051 self,
4052 role,
4053 mode,
4054 rx_queues=None,
4055 tx_queues=None,
4056 _id=None,
4057 socket_id=None,
4058 secret=None,
4059 ring_size=None,
4060 buffer_size=None,
4061 hw_addr=None):
4062 return self.api(self.papi.memif_create,
4063 {'role': role,
4064 'mode': mode,
4065 'rx_queues': rx_queues,
4066 'tx_queues': tx_queues,
4067 'id': _id,
4068 'socket_id': socket_id,
4069 'secret': secret,
4070 'ring_size': ring_size,
4071 'buffer_size': buffer_size,
4072 'hw_addr': hw_addr})
4073
4074 def memif_delete(self, sw_if_index):
4075 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
4076
4077 def memif_dump(self):
4078 return self.api(self.papi.memif_dump, {})
4079
4080 def memif_socket_filename_add_del(
4081 self, is_add, socket_id, socket_filename):
4082 return self.api(
4083 self.papi.memif_socket_filename_add_del,
4084 {'is_add': is_add,
4085 'socket_id': socket_id,
4086 'socket_filename': socket_filename})
4087
4088 def memif_socket_filename_dump(self):
4089 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004090
4091 def svs_table_add_del(self, af, table_id, is_add=1):
4092 return self.api(self.papi.svs_table_add_del,
4093 {
4094 'table_id': table_id,
4095 'is_add': is_add,
4096 'af': af,
4097 })
4098
4099 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4100 return self.api(self.papi.svs_route_add_del,
4101 {
4102 'table_id': table_id,
4103 'source_table_id': src_table_id,
4104 'prefix': prefix,
4105 'is_add': is_add,
4106 })
4107
4108 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4109 return self.api(self.papi.svs_enable_disable,
4110 {
4111 'af': af,
4112 'table_id': table_id,
4113 'sw_if_index': sw_if_index,
4114 'is_enable': is_enable,
4115 })
4116
4117 def svs_dump(self):
4118 return self.api(self.papi.svs_dump, {})
Matus Fabianb4515b42018-11-19 04:25:32 -08004119
4120 def syslog_set_sender(
4121 self,
4122 collector,
4123 src,
4124 collector_port=514,
4125 vrf_id=0,
4126 max_msg_size=480):
4127 """Set syslog sender configuration
4128
4129 :param collector: colector IP address
4130 :param src: source IP address
4131 :param collector_port: collector UDP port (Default value = 514)
4132 :param vrf_id: VRF id (Default value = 0)
4133 :param max_msg_size: maximum message length (Default value = 480)
4134 """
4135 return self.api(self.papi.syslog_set_sender,
Ole Troan8c8acc02018-11-27 10:05:23 +01004136 {'collector_address': collector,
4137 'src_address': src,
Matus Fabianb4515b42018-11-19 04:25:32 -08004138 'collector_port': collector_port,
4139 'vrf_id': vrf_id,
4140 'max_msg_size': max_msg_size})
4141
4142 def syslog_get_sender(self):
4143 """Return syslog sender configuration"""
4144 return self.api(self.papi.syslog_get_sender, {})
4145
4146 def syslog_set_filter(self, severity):
4147 """Set syslog filter parameters
4148
4149 :param severity: severity filter (specified severity and greater match)
4150 """
4151 return self.api(self.papi.syslog_set_filter, {'severity': severity})
4152
4153 def syslog_get_filter(self):
4154 """Return syslog filter parameters"""
4155 return self.api(self.papi.syslog_get_filter, {})