blob: 249288b4f7f141ce8164b523bda86127e12e9c85 [file] [log] [blame]
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08001import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002import time
Klement Sekerae4504c62016-12-08 10:16:41 +01003from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02004
Paul Vinciguerra6c746172018-11-26 09:57:21 -08005from six import moves
Paul Vinciguerra84679192019-01-13 11:33:52 -08006from vpp_papi import VPP, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08007from hook import Hook
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -08008from vpp_l2 import L2_PORT_TYPE
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08009
Klement Sekeraf62ae122016-10-11 11:47:09 +020010# from vnet/vnet/mpls/mpls_types.h
11MPLS_IETF_MAX_LABEL = 0xfffff
12MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
13
Klement Sekera0e3c0de2016-09-29 14:43:44 +020014
Neale Ranns177bbdc2016-11-15 09:46:51 +000015class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030016 L2_DISABLED = 0
17 L2_PUSH_1 = 1
18 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000019 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030020 L2_POP_2 = 4
21 L2_TRANSLATE_1_1 = 5
22 L2_TRANSLATE_1_2 = 6
23 L2_TRANSLATE_2_1 = 7
24 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000025
Klement Sekera0e3c0de2016-09-29 14:43:44 +020026
Neale Ranns039cbfe2018-02-27 03:45:38 -080027class QOS_SOURCE:
28 EXT = 0
29 VLAN = 1
30 MPLS = 2
31 IP = 3
32
33
Matus Fabianb4515b42018-11-19 04:25:32 -080034class SYSLOG_SEVERITY:
35 EMERG = 0
36 ALERT = 1
37 CRIT = 2
38 ERR = 3
39 WARN = 4
40 NOTICE = 5
41 INFO = 6
42 DBG = 7
43
44
Klement Sekera73884482017-02-23 09:26:30 +010045class UnexpectedApiReturnValueError(Exception):
46 """ exception raised when the API return value is unexpected """
47 pass
48
49
Klement Sekeraf62ae122016-10-11 11:47:09 +020050class VppPapiProvider(object):
51 """VPP-api provider using vpp-papi
52
53 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020054 """
55
Klement Sekerae0545ef2017-01-25 08:00:40 +010056 _zero, _negative = range(2)
57
Klement Sekera611864f2018-09-26 11:19:00 +020058 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -080059 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +020060 self.name = name
61 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010062 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010063 self._expect_api_retval = self._zero
64 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010065
Klement Sekerab8c72a42018-11-08 11:21:39 +010066 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010067
Paul Vinciguerra04575c52019-01-13 10:26:05 -080068 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
69 if 'VPP_API_DIR' not in os.environ:
70 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
71
72 self.vpp = VPP(logger=test_class.logger,
Klement Sekera611864f2018-09-26 11:19:00 +020073 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010074 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020075
Klement Sekerae0545ef2017-01-25 08:00:40 +010076 def __enter__(self):
77 return self
78
Klement Sekera7d6afb32018-11-08 11:52:04 +010079 def assert_negative_api_retval(self):
80 """ Expect API failure - used with with, e.g.:
81 with self.vapi.assert_negative_api_retval():
82 self.vapi.<api call expected to fail>
83 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010084 self._expect_stack.append(self._expect_api_retval)
85 self._expect_api_retval = self._negative
86 return self
87
Klement Sekera7d6afb32018-11-08 11:52:04 +010088 def assert_zero_api_retval(self):
89 """ Expect API success - used with with, e.g.:
90 with self.vapi.assert_negative_api_retval():
91 self.vapi.<api call expected to succeed>
92
93 note: this is useful only inside another with block
94 as success is the default expected value
95 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010096 self._expect_stack.append(self._expect_api_retval)
97 self._expect_api_retval = self._zero
98 return self
99
100 def __exit__(self, exc_type, exc_value, traceback):
101 self._expect_api_retval = self._expect_stack.pop()
102
Klement Sekeraf62ae122016-10-11 11:47:09 +0200103 def register_hook(self, hook):
104 """Replace hook registration with new hook
105
106 :param hook:
107
108 """
109 self.hook = hook
110
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200111 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100112 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200113 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100114 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200115 return e
116
117 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100118 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100119 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100120 self.test_class.logger.debug("Expecting event '%s' within %ss",
121 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300122 else:
123 self.test_class.logger.debug("Expecting event within %ss",
124 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100125 if self._events:
126 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200127 limit = time.time() + timeout
128 while time.time() < limit:
129 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100130 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200131 if name and type(e).__name__ != name:
132 raise Exception(
133 "Unexpected event received: %s, expected: %s" %
134 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100135 self.test_class.logger.debug("Returning event %s:%s" %
136 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200137 return e
138 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200139 raise Exception("Event did not occur within timeout")
140
141 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100142 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200143 # FIXME use the name instead of relying on type(e).__name__ ?
144 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100145 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200146 self._events.append(event)
147
Klement Sekeraf62ae122016-10-11 11:47:09 +0200148 def connect(self):
149 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100150 self.vpp.connect(self.name, self.shm_prefix)
151 self.papi = self.vpp.api
152 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200153
154 def disconnect(self):
155 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100156 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200157
158 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100159 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200160 Call the appropriate hooks before and after the API call
161
162 :param api_fn: API function to call
163 :param api_args: tuple of API function arguments
164 :param expected_retval: Expected return value (Default value = 0)
165 :returns: reply from the API
166
167 """
168 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100169 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100170 if self._expect_api_retval == self._negative:
171 if hasattr(reply, 'retval') and reply.retval >= 0:
172 msg = "API call passed unexpectedly: expected negative "\
173 "return value instead of %d in %s" % \
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800174 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100175 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100176 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100177 elif self._expect_api_retval == self._zero:
178 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700179 msg = "API call failed, expected %d return value instead "\
180 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800181 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100182 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100183 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100184 else:
185 raise Exception("Internal error, unexpected value for "
186 "self._expect_api_retval %s" %
187 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188 self.hook.after_api(api_fn.__name__, api_args)
189 return reply
190
191 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100192 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200193
194 :param cli: CLI to execute
195 :returns: CLI output
196
197 """
198 self.hook.before_cli(cli)
199 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100200 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200201 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200202 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100203 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200204
Jan49c0fca2016-10-26 15:44:27 +0200205 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100206 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200207
208 :param cli: CLI to execute
209 :returns: CLI output
210 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600211 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200212
Klement Sekeraf62ae122016-10-11 11:47:09 +0200213 def show_version(self):
214 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100215 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200216
217 def pg_create_interface(self, pg_index):
218 """
219
220 :param pg_index:
221
222 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100223 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200224 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200225
226 def sw_interface_dump(self, filter=None):
227 """
228
229 :param filter: (Default value = None)
230
231 """
232 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200233 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200234 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100235 args = {}
236 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200237
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000238 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100239 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000240
241 :param sw_if_index:
242 :param is_ipv6:
243 :param table_id:
244
245 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100246 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200247 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
248 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000249
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700250 def sw_interface_get_table(self, sw_if_index, is_ipv6):
251 """ Get the IPvX Table-id for the Interface
252
253 :param sw_if_index:
254 :param is_ipv6:
255 :return table_id
256
257 """
258 return self.api(self.papi.sw_interface_get_table,
259 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
260
Klement Sekeraf62ae122016-10-11 11:47:09 +0200261 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
262 is_ipv6=0, is_add=1, del_all=0):
263 """
264
265 :param addr: param is_ipv6: (Default value = 0)
266 :param sw_if_index:
267 :param addr_len:
268 :param is_ipv6: (Default value = 0)
269 :param is_add: (Default value = 1)
270 :param del_all: (Default value = 0)
271
272 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100273 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200274 {'sw_if_index': sw_if_index,
275 'is_add': is_add,
276 'is_ipv6': is_ipv6,
277 'del_all': del_all,
278 'address_length': addr_len,
279 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200280
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700281 def ip_address_dump(self, sw_if_index, is_ipv6=0):
282 return self.api(self.papi.ip_address_dump,
283 {'sw_if_index': sw_if_index,
284 'is_ipv6': is_ipv6})
285
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800286 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
287 is_add=1):
288 """ Set the Interface to be unnumbered
289
290 :param is_add: (Default value = 1)
291 :param sw_if_index - interface That will be unnumbered
292 :param ip_sw_if_index - interface with an IP addres
293
294 """
295 return self.api(self.papi.sw_interface_set_unnumbered,
296 {'sw_if_index': ip_sw_if_index,
297 'unnumbered_sw_if_index': sw_if_index,
298 'is_add': is_add})
299
Neale Ranns404d88e2018-08-08 06:37:33 -0700300 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
301 return self.api(self.papi.ip_unnumbered_dump,
302 {'sw_if_index': sw_if_index})
303
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000304 def sw_interface_enable_disable_mpls(self, sw_if_index,
305 is_enable=1):
306 """
307 Enable/Disable MPLS on the interface
308 :param sw_if_index:
309 :param is_enable: (Default value = 1)
310
311 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100312 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200313 {'sw_if_index': sw_if_index,
314 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000315
Jan Gelety057bb8c2016-12-20 17:32:45 +0100316 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100317 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100318 {'sw_if_index': sw_if_index,
319 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200320
Neale Ranns227038a2017-04-21 01:07:59 -0700321 def set_ip_flow_hash(self,
322 table_id,
323 src=1,
324 dst=1,
325 sport=1,
326 dport=1,
327 proto=1,
328 reverse=0,
329 is_ip6=0):
330 return self.api(self.papi.set_ip_flow_hash,
331 {'vrf_id': table_id,
332 'src': src,
333 'dst': dst,
334 'dport': dport,
335 'sport': sport,
336 'proto': proto,
337 'reverse': reverse,
338 'is_ipv6': is_ip6})
339
Neale Ranns37029302018-08-10 05:30:06 -0700340 def ip6_nd_proxy(self, ip, sw_if_index, is_del=0):
Neale Ranns3f844d02017-02-18 00:03:54 -0800341 return self.api(self.papi.ip6nd_proxy_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700342 {'ip': ip,
Neale Ranns3f844d02017-02-18 00:03:54 -0800343 'sw_if_index': sw_if_index,
344 'is_del': is_del})
345
Neale Ranns75152282017-01-09 01:00:45 -0800346 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000347 no,
Neale Ranns75152282017-01-09 01:00:45 -0800348 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000349 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800350 return self.api(self.papi.sw_interface_ip6nd_ra_config,
351 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000352 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100353 'suppress': suppress,
354 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800355
Neale Ranns87df12d2017-02-18 08:16:41 -0800356 def ip6_sw_interface_ra_prefix(self,
357 sw_if_index,
358 address,
359 address_length,
360 use_default=0,
361 no_advertise=0,
362 off_link=0,
363 no_autoconfig=0,
364 no_onlink=0,
365 is_no=0,
366 val_lifetime=0xffffffff,
367 pref_lifetime=0xffffffff):
368 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
369 {'sw_if_index': sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700370 'prefix': {
371 'address': address,
372 'address_length': address_length,
373 },
Neale Ranns87df12d2017-02-18 08:16:41 -0800374 'use_default': use_default,
375 'no_advertise': no_advertise,
376 'off_link': off_link,
377 'no_autoconfig': no_autoconfig,
378 'no_onlink': no_onlink,
379 'is_no': is_no,
380 'val_lifetime': val_lifetime,
381 'pref_lifetime': pref_lifetime})
382
Neale Ranns75152282017-01-09 01:00:45 -0800383 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
384 """
385 Enable/Disable An interface for IPv6
386 """
387 return self.api(self.papi.sw_interface_ip6_enable_disable,
388 {'sw_if_index': sw_if_index,
389 'enable': enable})
390
Klement Sekeraf62ae122016-10-11 11:47:09 +0200391 def vxlan_add_del_tunnel(
392 self,
393 src_addr,
394 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200395 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200396 is_add=1,
397 is_ipv6=0,
398 encap_vrf_id=0,
399 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600400 vni=0,
401 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200402 """
403
404 :param dst_addr:
405 :param src_addr:
406 :param is_add: (Default value = 1)
407 :param is_ipv6: (Default value = 0)
408 :param encap_vrf_id: (Default value = 0)
409 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200410 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200411 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600412 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200413
414 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100415 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200416 {'is_add': is_add,
417 'is_ipv6': is_ipv6,
418 'src_address': src_addr,
419 'dst_address': dst_addr,
420 'mcast_sw_if_index': mcast_sw_if_index,
421 'encap_vrf_id': encap_vrf_id,
422 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600423 'vni': vni,
424 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200425
Marco Varleseb598f1d2017-09-19 14:25:28 +0200426 def geneve_add_del_tunnel(
427 self,
428 local_addr,
429 remote_addr,
430 mcast_sw_if_index=0xFFFFFFFF,
431 is_add=1,
432 is_ipv6=0,
433 encap_vrf_id=0,
434 decap_next_index=0xFFFFFFFF,
435 vni=0):
436 """
437
438 :param remote_addr:
439 :param local_addr:
440 :param is_add: (Default value = 1)
441 :param is_ipv6: (Default value = 0)
442 :param encap_vrf_id: (Default value = 0)
443 :param decap_next_index: (Default value = 0xFFFFFFFF)
444 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
445 :param vni: (Default value = 0)
446
447 """
448 return self.api(self.papi.geneve_add_del_tunnel,
449 {'is_add': is_add,
450 'is_ipv6': is_ipv6,
451 'local_address': local_addr,
452 'remote_address': remote_addr,
453 'mcast_sw_if_index': mcast_sw_if_index,
454 'encap_vrf_id': encap_vrf_id,
455 'decap_next_index': decap_next_index,
456 'vni': vni})
457
Jan4af521d2016-11-15 17:05:00 +0100458 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
459 learn=1, arp_term=0, is_add=1):
460 """Create/delete bridge domain.
461
462 :param int bd_id: Bridge domain index.
463 :param int flood: Enable/disable bcast/mcast flooding in the BD.
464 (Default value = 1)
465 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
466 (Default value = 1)
467 :param int forward: Enable/disable forwarding on all interfaces in
468 the BD. (Default value = 1)
469 :param int learn: Enable/disable learning on all interfaces in the BD.
470 (Default value = 1)
471 :param int arp_term: Enable/disable arp termination in the BD.
472 (Default value = 1)
473 :param int is_add: Add or delete flag. (Default value = 1)
474 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100475 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200476 {'bd_id': bd_id,
477 'flood': flood,
478 'uu_flood': uu_flood,
479 'forward': forward,
480 'learn': learn,
481 'arp_term': arp_term,
482 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100483
Eyal Baric86e5922017-07-02 18:33:16 +0300484 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
485 return self.api(self.papi.bd_ip_mac_add_del,
486 {'bd_id': bd_id,
487 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700488 'ip': ip,
489 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300490
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700491 def bd_ip_mac_dump(self, bd_id):
492 return self.api(self.papi.bd_ip_mac_dump,
493 {'bd_id': bd_id})
494
Neale Ranns37029302018-08-10 05:30:06 -0700495 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300496 return self.api(self.papi.want_ip4_arp_events,
497 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700498 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300499 'pid': os.getpid(), })
500
Neale Ranns37029302018-08-10 05:30:06 -0700501 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300502 return self.api(self.papi.want_ip6_nd_events,
503 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700504 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300505 'pid': os.getpid(), })
506
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100507 def want_ip6_ra_events(self, enable_disable=1):
508 return self.api(self.papi.want_ip6_ra_events,
509 {'enable_disable': enable_disable,
510 'pid': os.getpid(), })
511
512 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
513 mrc=0, mrd=0):
514 return self.api(self.papi.ip6nd_send_router_solicitation,
515 {'irt': irt,
516 'mrt': mrt,
517 'mrc': mrc,
518 'mrd': mrd,
519 'sw_if_index': sw_if_index})
520
Juraj Slobodac0374232018-02-01 15:18:49 +0100521 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
522 install_default_routes):
523 return self.api(self.papi.ip6_nd_address_autoconfig,
524 {'sw_if_index': sw_if_index,
525 'enable': enable,
526 'install_default_routes': install_default_routes})
527
Juraj Slobodab3f90502018-10-04 15:15:16 +0200528 def want_interface_events(self, enable_disable=1):
529 return self.api(self.papi.want_interface_events,
530 {'enable_disable': enable_disable,
531 'pid': os.getpid(), })
532
Eyal Bari24db0ec2017-09-27 21:43:51 +0300533 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
534 max_macs_in_event=0, learn_limit=0):
535 return self.api(self.papi.want_l2_macs_events,
536 {'enable_disable': enable_disable,
537 'scan_delay': scan_delay,
538 'max_macs_in_event': max_macs_in_event,
539 'learn_limit': learn_limit,
540 'pid': os.getpid(), })
541
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200542 def want_dhcp6_reply_events(self, enable_disable=1):
543 return self.api(self.papi.want_dhcp6_reply_events,
544 {'enable_disable': enable_disable,
545 'pid': os.getpid()})
546
Juraj Sloboda81119e82018-05-25 14:02:20 +0200547 def want_dhcp6_pd_reply_events(self, enable_disable=1):
548 return self.api(self.papi.want_dhcp6_pd_reply_events,
549 {'enable_disable': enable_disable,
550 'pid': os.getpid()})
551
552 def dhcp6_clients_enable_disable(self, enable=1):
553 return self.api(self.papi.dhcp6_clients_enable_disable,
554 {'enable': enable})
555
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200556 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
557 addresses, server_index=0xFFFFFFFF,
558 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
559 ):
560 return self.api(self.papi.dhcp6_send_client_message,
561 {'sw_if_index': sw_if_index,
562 'server_index': server_index,
563 'irt': irt,
564 'mrt': mrt,
565 'mrc': mrc,
566 'mrd': mrd,
567 'stop': stop,
568 'msg_type': msg_type,
569 'T1': T1,
570 'T2': T2,
571 'n_addresses': len(addresses),
572 'addresses': addresses})
573
Juraj Sloboda81119e82018-05-25 14:02:20 +0200574 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
575 prefixes, server_index=0xFFFFFFFF,
576 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
577 ):
578 return self.api(self.papi.dhcp6_pd_send_client_message,
579 {'sw_if_index': sw_if_index,
580 'server_index': server_index,
581 'irt': irt,
582 'mrt': mrt,
583 'mrc': mrc,
584 'mrd': mrd,
585 'stop': stop,
586 'msg_type': msg_type,
587 'T1': T1,
588 'T2': T2,
589 'n_prefixes': len(prefixes),
590 'prefixes': prefixes})
591
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200592 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
593 enable=1):
594 return self.api(self.papi.dhcp6_client_enable_disable,
595 {'sw_if_index': sw_if_index,
596 'enable': enable})
597
Juraj Sloboda81119e82018-05-25 14:02:20 +0200598 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
599 enable=1):
600 return self.api(self.papi.dhcp6_pd_client_enable_disable,
601 {'sw_if_index': sw_if_index,
602 'prefix_group': prefix_group,
603 'enable': enable})
604
605 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
606 prefix_length, prefix_group,
607 is_add=1):
608 return self.api(self.papi.ip6_add_del_address_using_prefix,
609 {'sw_if_index': sw_if_index,
610 'prefix_group': prefix_group,
611 'address': address,
612 'prefix_length': prefix_length,
613 'is_add': is_add})
614
Jan4af521d2016-11-15 17:05:00 +0100615 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
616 filter_mac=0, bvi_mac=0):
617 """Create/delete L2 FIB entry.
618
619 :param str mac: MAC address to create FIB entry for.
620 :param int bd_id: Bridge domain index.
621 :param int sw_if_index: Software interface index of the interface.
622 :param int is_add: Add or delete flag. (Default value = 1)
623 :param int static_mac: Set to 1 to create static MAC entry.
624 (Default value = 0)
625 :param int filter_mac: Set to 1 to drop packet that's source or
626 destination MAC address contains defined MAC address.
627 (Default value = 0)
628 :param int bvi_mac: Set to 1 to create entry that points to BVI
629 interface. (Default value = 0)
630 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100631 return self.api(self.papi.l2fib_add_del,
Ole Troan8006c6a2018-12-17 12:02:26 +0100632 {'mac': mac,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200633 'bd_id': bd_id,
634 'sw_if_index': sw_if_index,
635 'is_add': is_add,
636 'static_mac': static_mac,
637 'filter_mac': filter_mac,
638 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100639
Eyal Bari93b503e2017-05-15 10:13:15 +0300640 def l2fib_flush_int(self, sw_if_index):
641 """Flush L2 FIB entries for sw_if_index.
642
643 :param int sw_if_index: Software interface index of the interface.
644 """
645 return self.api(self.papi.l2fib_flush_int,
646 {'sw_if_index': sw_if_index})
647
648 def l2fib_flush_bd(self, bd_id):
649 """Flush L2 FIB entries for bd_id.
650
651 :param int sw_if_index: Bridge Domain id.
652 """
653 return self.api(self.papi.l2fib_flush_bd,
654 {'bd_id': bd_id})
655
656 def l2fib_flush_all(self):
657 """Flush all L2 FIB.
658 """
659 return self.api(self.papi.l2fib_flush_all, {})
660
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700661 def l2_fib_table_dump(self, bd_id):
662 """ Dump the L2 FIB """
663 return self.api(self.papi.l2_fib_table_dump,
664 {'bd_id': bd_id})
665
Klement Sekeraf62ae122016-10-11 11:47:09 +0200666 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700667 shg=0, port_type=L2_PORT_TYPE.NORMAL,
668 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100669 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200670
Jan4af521d2016-11-15 17:05:00 +0100671 :param int sw_if_index: Software interface index of the interface.
672 :param int bd_id: Bridge domain index.
673 :param int shg: Split-horizon group index. (Default value = 0)
674 :param int bvi: Set interface as a bridge group virtual interface.
675 (Default value = 0)
676 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200677 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100678 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200679 {'rx_sw_if_index': sw_if_index,
680 'bd_id': bd_id,
681 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700682 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200683 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200684
Jan00dad122016-11-29 10:04:53 +0100685 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400686 """Enable/disable required feature of the bridge domain with defined
687 ID.
Jan00dad122016-11-29 10:04:53 +0100688
689 :param int bd_id: Bridge domain ID.
690 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700691 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100692 - learn (1 << 0),
693 - forward (1 << 1),
694 - flood (1 << 2),
695 - uu-flood (1 << 3) or
696 - arp-term (1 << 4).
697 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100698 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200699 {'bd_id': bd_id,
700 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700701 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100702
703 def bridge_domain_dump(self, bd_id=0):
704 """
705
706 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
707 existing bridge domains returned)
708 :return: Dictionary of bridge domain(s) data.
709 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100710 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200711 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100712
Klement Sekeraf62ae122016-10-11 11:47:09 +0200713 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
714 enable):
715 """Create or delete unidirectional cross-connect from Tx interface to
716 Rx interface.
717
Jan4af521d2016-11-15 17:05:00 +0100718 :param int rx_sw_if_index: Software interface index of Rx interface.
719 :param int tx_sw_if_index: Software interface index of Tx interface.
720 :param int enable: Create cross-connect if equal to 1, delete
721 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200722
723 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100724 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200725 {'rx_sw_if_index': rx_sw_if_index,
726 'tx_sw_if_index': tx_sw_if_index,
727 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200728
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200729 def sw_interface_set_l2_tag_rewrite(
730 self,
731 sw_if_index,
732 vtr_oper,
733 push=0,
734 tag1=0,
735 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000736 """L2 interface vlan tag rewrite configure request
737 :param client_index - opaque cookie to identify the sender
738 :param context - sender context, to match reply w/ request
739 :param sw_if_index - interface the operation is applied to
740 :param vtr_op - Choose from l2_vtr_op_t enum values
741 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
742 :param tag1 - Needed for any push or translate vtr op
743 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
744
745 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100746 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200747 {'sw_if_index': sw_if_index,
748 'vtr_op': vtr_oper,
749 'push_dot1q': push,
750 'tag1': tag1,
751 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000752
Neale Ranns55d03782017-10-21 06:34:22 -0700753 def sw_interface_set_l2_emulation(
754 self,
755 sw_if_index,
756 enable=1):
757 """L2 Emulation
758 :param sw_if_index - interface the operation is applied to
759
760 """
761 return self.api(self.papi.l2_emulation,
762 {'sw_if_index': sw_if_index,
763 'enable': enable})
764
Neale Ranns1855b8e2018-07-11 10:31:26 -0700765 def sw_interface_set_ip_directed_broadcast(
766 self,
767 sw_if_index,
768 enable=1):
769 """IP Directed broadcast
770 :param sw_if_index - interface the operation is applied to
771
772 """
773 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
774 {'sw_if_index': sw_if_index,
775 'enable': enable})
776
Neale Rannsa07bd702017-08-07 07:53:49 -0700777 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200778 """
779
780 :param admin_up_down:
781 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200782
783 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100784 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200785 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700786 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200787
Ole Troand7231612018-06-07 10:17:57 +0200788 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800789 """
790 :param sw_if_index:
791 :param mtu:
792
793 """
794 return self.api(self.papi.sw_interface_set_mtu,
795 {'sw_if_index': sw_if_index,
796 'mtu': mtu})
797
Neale Ranns25b04942018-04-04 09:34:50 -0700798 def sw_interface_set_promiscuous(self, sw_if_index, enable):
799 """
800 :param sw_if_index:
801 :param enable:
802
803 """
804 return self.api(self.papi.sw_interface_set_promiscuous,
805 {'sw_if_index': sw_if_index,
806 'enable': enable})
807
Neale Rannsc819fc62018-02-16 02:44:05 -0800808 def sw_interface_set_mac_address(self, sw_if_index, mac):
809 return self.api(self.papi.sw_interface_set_mac_address,
810 {'sw_if_index': sw_if_index,
811 'mac_address': mac})
812
Klement Sekeraf62ae122016-10-11 11:47:09 +0200813 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
814 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
815 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
816 """Create subinterface
817 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
818
819 :param sub_id: param inner_vlan:
820 :param sw_if_index:
821 :param outer_vlan:
822 :param inner_vlan:
823 :param no_tags: (Default value = 0)
824 :param one_tag: (Default value = 0)
825 :param two_tags: (Default value = 0)
826 :param dot1ad: (Default value = 0)
827 :param exact_match: (Default value = 0)
828 :param default_sub: (Default value = 0)
829 :param outer_vlan_id_any: (Default value = 0)
830 :param inner_vlan_id_any: (Default value = 0)
831
832 """
833 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100834 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200835 {'sw_if_index': sw_if_index,
836 'sub_id': sub_id,
837 'no_tags': no_tags,
838 'one_tag': one_tag,
839 'two_tags': two_tags,
840 'dot1ad': dot1ad,
841 'exact_match': exact_match,
842 'default_sub': default_sub,
843 'outer_vlan_id_any': outer_vlan_id_any,
844 'inner_vlan_id_any': inner_vlan_id_any,
845 'outer_vlan_id': outer_vlan,
846 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200847
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200848 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
849 """Create p2p ethernet subinterface
850
851 :param sw_if_index: main (parent) interface
852 :param remote_mac: client (remote) mac address
853
854 """
855 return self.api(
856 self.papi.p2p_ethernet_add,
857 {'parent_if_index': sw_if_index,
858 'remote_mac': remote_mac,
859 'subif_id': subif_id})
860
Neale Ranns177bbdc2016-11-15 09:46:51 +0000861 def delete_subif(self, sw_if_index):
862 """Delete subinterface
863
864 :param sw_if_index:
865 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100866 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200867 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000868
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200869 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
870 """Delete p2p ethernet subinterface
871
872 :param sw_if_index: main (parent) interface
873 :param remote_mac: client (remote) mac address
874
875 """
876 return self.api(
877 self.papi.p2p_ethernet_del,
878 {'parent_if_index': sw_if_index,
879 'remote_mac': remote_mac})
880
Klement Sekeraf62ae122016-10-11 11:47:09 +0200881 def create_vlan_subif(self, sw_if_index, vlan):
882 """
883
884 :param vlan:
885 :param sw_if_index:
886
887 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100888 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200889 {'sw_if_index': sw_if_index,
890 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200891
Matej Klotton0178d522016-11-04 11:11:44 +0100892 def create_loopback(self, mac=''):
893 """
894
895 :param mac: (Optional)
896 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100897 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200898 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100899
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100900 def delete_loopback(self, sw_if_index):
901 return self.api(self.papi.delete_loopback,
902 {'sw_if_index': sw_if_index, })
903
Neale Ranns15002542017-09-10 04:39:11 -0700904 def ip_table_add_del(self,
905 table_id,
906 is_add=1,
907 is_ipv6=0):
908 """
909
910 :param table_id
911 :param is_add: (Default value = 1)
912 :param is_ipv6: (Default value = 0)
913
914 """
915
916 return self.api(
917 self.papi.ip_table_add_del,
918 {'table_id': table_id,
919 'is_add': is_add,
920 'is_ipv6': is_ipv6})
921
Klement Sekeraf62ae122016-10-11 11:47:09 +0200922 def ip_add_del_route(
923 self,
924 dst_address,
925 dst_address_length,
926 next_hop_address,
927 next_hop_sw_if_index=0xFFFFFFFF,
928 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200929 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000930 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200931 next_hop_n_out_labels=0,
932 next_hop_out_label_stack=[],
933 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800934 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000935 is_resolve_host=0,
936 is_resolve_attached=0,
937 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200938 is_add=1,
939 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200940 is_unreach=0,
941 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200942 is_ipv6=0,
943 is_local=0,
944 is_classify=0,
945 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800946 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800947 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200948 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200949 """
950
951 :param dst_address_length:
952 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
953 :param dst_address:
954 :param next_hop_address:
955 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
956 :param vrf_id: (Default value = 0)
957 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200958 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200959 :param is_add: (Default value = 1)
960 :param is_drop: (Default value = 0)
961 :param is_ipv6: (Default value = 0)
962 :param is_local: (Default value = 0)
963 :param is_classify: (Default value = 0)
964 :param is_multipath: (Default value = 0)
965 :param is_resolve_host: (Default value = 0)
966 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800967 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700968 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200969 :param next_hop_weight: (Default value = 1)
970
971 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000972
Klement Sekeraf62ae122016-10-11 11:47:09 +0200973 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100974 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200975 {'next_hop_sw_if_index': next_hop_sw_if_index,
976 'table_id': table_id,
977 'classify_table_index': classify_table_index,
978 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200979 'is_add': is_add,
980 'is_drop': is_drop,
981 'is_unreach': is_unreach,
982 'is_prohibit': is_prohibit,
983 'is_ipv6': is_ipv6,
984 'is_local': is_local,
985 'is_classify': is_classify,
986 'is_multipath': is_multipath,
987 'is_resolve_host': is_resolve_host,
988 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800989 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700990 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800991 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200992 'next_hop_weight': next_hop_weight,
993 'dst_address_length': dst_address_length,
994 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800995 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200996 'next_hop_address': next_hop_address,
997 'next_hop_n_out_labels': next_hop_n_out_labels,
998 'next_hop_via_label': next_hop_via_label,
999 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001000
Matej Klotton16a14cd2016-12-07 15:09:13 +01001001 def ip_fib_dump(self):
1002 return self.api(self.papi.ip_fib_dump, {})
1003
Jan Gelety057bb8c2016-12-20 17:32:45 +01001004 def ip6_fib_dump(self):
1005 return self.api(self.papi.ip6_fib_dump, {})
1006
Matej Klotton0178d522016-11-04 11:11:44 +01001007 def ip_neighbor_add_del(self,
1008 sw_if_index,
1009 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -07001010 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001011 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -07001012 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +01001013 """ Add neighbor MAC to IPv4 or IPv6 address.
1014
1015 :param sw_if_index:
1016 :param mac_address:
1017 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001018 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -07001019 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +01001020 """
Matej Klotton0178d522016-11-04 11:11:44 +01001021 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001022 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -07001023 {
1024 'is_add': is_add,
1025 'neighbor': {
1026 'sw_if_index': sw_if_index,
1027 'flags': flags,
1028 'mac_address': mac_address,
1029 'ip_address': ip_address
1030 }
1031 }
Matej Klotton0178d522016-11-04 11:11:44 +01001032 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001033
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001034 def ip_neighbor_dump(self,
1035 sw_if_index,
1036 is_ipv6=0):
1037 """ Return IP neighbor dump.
1038
1039 :param sw_if_index:
1040 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1041 """
1042
1043 return self.api(
1044 self.papi.ip_neighbor_dump,
1045 {'is_ipv6': is_ipv6,
1046 'sw_if_index': sw_if_index
1047 }
1048 )
1049
1050 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -07001051 low,
1052 hi,
1053 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001054 is_add=1):
1055 """ Config Proxy Arp Range.
1056
1057 :param low_address: Start address in the rnage to Proxy for
1058 :param hi_address: End address in the rnage to Proxy for
1059 :param vrf_id: The VRF/table in which to proxy
1060 """
1061
1062 return self.api(
1063 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001064 {'proxy':
1065 {
Neale Ranns37029302018-08-10 05:30:06 -07001066 'table_id': table_id,
1067 'low': low,
1068 'hi': hi,
Neale Ranns0053de62018-05-22 08:40:52 -07001069 },
1070 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001071
1072 def proxy_arp_intfc_enable_disable(self,
1073 sw_if_index,
1074 is_enable=1):
1075 """ Enable/Disable an interface for proxy ARP requests
1076
1077 :param sw_if_index: Interface
1078 :param enable_disable: Enable/Disable
1079 """
1080
1081 return self.api(
1082 self.papi.proxy_arp_intfc_enable_disable,
1083 {'sw_if_index': sw_if_index,
1084 'enable_disable': is_enable
1085 }
1086 )
1087
Jane546d3b2016-12-08 13:10:03 +01001088 def reset_vrf(self,
1089 vrf_id,
1090 is_ipv6=0,
1091 ):
1092 """ Reset VRF (remove all routes etc.) request.
1093
1094 :param int vrf_id: ID of the FIB table / VRF to reset.
1095 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1096 """
1097
1098 return self.api(
1099 self.papi.reset_vrf,
1100 {'vrf_id': vrf_id,
1101 'is_ipv6': is_ipv6,
1102 }
1103 )
1104
1105 def reset_fib(self,
1106 vrf_id,
1107 is_ipv6=0,
1108 ):
1109 """ Reset VRF (remove all routes etc.) request.
1110
1111 :param int vrf_id: ID of the FIB table / VRF to reset.
1112 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1113 """
1114
1115 return self.api(
1116 self.papi.reset_fib,
1117 {'vrf_id': vrf_id,
1118 'is_ipv6': is_ipv6,
1119 }
1120 )
1121
1122 def ip_dump(self,
1123 is_ipv6=0,
1124 ):
1125 """ Return IP dump.
1126
1127 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1128 """
1129
1130 return self.api(
1131 self.papi.ip_dump,
1132 {'is_ipv6': is_ipv6,
1133 }
1134 )
1135
Klement Sekera7bb873a2016-11-18 07:38:42 +01001136 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001137 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001138 """
1139
1140 :param sw_if_index_from:
1141 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001142 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001143 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001144 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001145 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001146 {'sw_if_index_from': sw_if_index_from,
1147 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001148 'state': state,
1149 'is_l2': is_l2,
1150 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001151
1152 def gre_tunnel_add_del(self,
1153 src_address,
1154 dst_address,
1155 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001156 tunnel_type=0,
1157 instance=0xFFFFFFFF,
1158 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001159 is_add=1,
1160 is_ip6=0):
1161 """ Add a GRE tunnel
1162
1163 :param src_address:
1164 :param dst_address:
1165 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001166 :param tunnel_type: (Default value = 0)
1167 :param instance: (Default value = 0xFFFFFFFF)
1168 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001169 :param is_add: (Default value = 1)
1170 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001171 """
1172
1173 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001174 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001175 {'is_add': is_add,
1176 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001177 'tunnel_type': tunnel_type,
1178 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001179 'src_address': src_address,
1180 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001181 'outer_fib_id': outer_fib_id,
1182 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001183 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001184
Neale Rannsd0df49f2018-08-08 01:06:40 -07001185 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001186 src_ip,
1187 dst_ip,
1188 src_port,
1189 dst_port,
1190 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001191 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001192 :param src_ip:
1193 :param dst_ip:
1194 :param src_port:
1195 :param dst_port:
1196 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001197 """
1198
1199 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001200 self.papi.udp_encap_add,
1201 {
1202 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001203 'src_ip': src_ip,
1204 'dst_ip': dst_ip,
1205 'src_port': src_port,
1206 'dst_port': dst_port,
1207 'table_id': table_id
1208 }
1209 })
1210
1211 def udp_encap_del(self, id):
1212 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001213
1214 def udp_encap_dump(self):
1215 return self.api(self.papi.udp_encap_dump, {})
1216
Neale Ranns43b1f442018-03-20 01:47:35 -07001217 def want_udp_encap_stats(self, enable=1):
1218 return self.api(self.papi.want_udp_encap_stats,
1219 {'enable': enable,
1220 'pid': os.getpid()})
1221
Neale Ranns5a8123b2017-01-26 01:18:23 -08001222 def mpls_fib_dump(self):
1223 return self.api(self.papi.mpls_fib_dump, {})
1224
Neale Ranns15002542017-09-10 04:39:11 -07001225 def mpls_table_add_del(
1226 self,
1227 table_id,
1228 is_add=1):
1229 """
1230
1231 :param table_id
1232 :param is_add: (Default value = 1)
1233
1234 """
1235
1236 return self.api(
1237 self.papi.mpls_table_add_del,
1238 {'mt_table_id': table_id,
1239 'mt_is_add': is_add})
1240
Neale Rannsad422ed2016-11-02 14:20:04 +00001241 def mpls_route_add_del(
1242 self,
1243 label,
1244 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001245 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001246 next_hop_address,
1247 next_hop_sw_if_index=0xFFFFFFFF,
1248 table_id=0,
1249 next_hop_table_id=0,
1250 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001251 next_hop_n_out_labels=0,
1252 next_hop_out_label_stack=[],
1253 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001254 is_resolve_host=0,
1255 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001256 is_interface_rx=0,
1257 is_rpf_id=0,
1258 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001259 is_add=1,
1260 is_drop=0,
1261 is_multipath=0,
1262 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001263 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001264 """
1265
1266 :param dst_address_length:
1267 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1268 :param dst_address:
1269 :param next_hop_address:
1270 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1271 :param vrf_id: (Default value = 0)
1272 :param lookup_in_vrf: (Default value = 0)
1273 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001274 :param is_add: (Default value = 1)
1275 :param is_drop: (Default value = 0)
1276 :param is_ipv6: (Default value = 0)
1277 :param is_local: (Default value = 0)
1278 :param is_classify: (Default value = 0)
1279 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001280 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001281 :param is_resolve_host: (Default value = 0)
1282 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001283 :param next_hop_weight: (Default value = 1)
1284
1285 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001286 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001287 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001288 {'mr_label': label,
1289 'mr_eos': eos,
1290 'mr_table_id': table_id,
1291 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001292 'mr_is_add': is_add,
1293 'mr_is_classify': is_classify,
1294 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001295 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001296 'mr_is_resolve_host': is_resolve_host,
1297 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001298 'mr_is_interface_rx': is_interface_rx,
1299 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001300 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001301 'mr_next_hop_weight': next_hop_weight,
1302 'mr_next_hop': next_hop_address,
1303 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1304 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1305 'mr_next_hop_table_id': next_hop_table_id,
1306 'mr_next_hop_via_label': next_hop_via_label,
1307 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001308
1309 def mpls_ip_bind_unbind(
1310 self,
1311 label,
1312 dst_address,
1313 dst_address_length,
1314 table_id=0,
1315 ip_table_id=0,
1316 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001317 is_bind=1):
1318 """
1319 """
1320 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001321 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001322 {'mb_mpls_table_id': table_id,
1323 'mb_label': label,
1324 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001325 'mb_is_bind': is_bind,
1326 'mb_is_ip4': is_ip4,
1327 'mb_address_length': dst_address_length,
1328 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001329
1330 def mpls_tunnel_add_del(
1331 self,
1332 tun_sw_if_index,
1333 next_hop_proto_is_ip4,
1334 next_hop_address,
1335 next_hop_sw_if_index=0xFFFFFFFF,
1336 next_hop_table_id=0,
1337 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001338 next_hop_n_out_labels=0,
1339 next_hop_out_label_stack=[],
1340 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001341 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001342 l2_only=0,
1343 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001344 """
1345
1346 :param dst_address_length:
1347 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1348 :param dst_address:
1349 :param next_hop_address:
1350 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1351 :param vrf_id: (Default value = 0)
1352 :param lookup_in_vrf: (Default value = 0)
1353 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001354 :param is_add: (Default value = 1)
1355 :param is_drop: (Default value = 0)
1356 :param is_ipv6: (Default value = 0)
1357 :param is_local: (Default value = 0)
1358 :param is_classify: (Default value = 0)
1359 :param is_multipath: (Default value = 0)
1360 :param is_resolve_host: (Default value = 0)
1361 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001362 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001363 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001364
1365 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001366 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001367 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001368 {'mt_sw_if_index': tun_sw_if_index,
1369 'mt_is_add': is_add,
1370 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001371 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001372 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1373 'mt_next_hop_weight': next_hop_weight,
1374 'mt_next_hop': next_hop_address,
1375 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1376 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1377 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001378 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001379 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001380
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001381 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1382 return self.api(self.papi.mpls_tunnel_dump,
1383 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001384
Matus Fabian2ba92e32017-08-21 07:05:03 -07001385 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001386 self,
1387 sw_if_index,
1388 is_inside=1,
1389 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001390 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001391
1392 :param sw_if_index: Software index of the interface
1393 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1394 :param is_add: 1 if add, 0 if delete (Default value = 1)
1395 """
1396 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001397 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001398 {'is_add': is_add,
1399 'is_inside': is_inside,
1400 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001401
Matus Fabian2ba92e32017-08-21 07:05:03 -07001402 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001403 self,
1404 sw_if_index,
1405 is_inside=1,
1406 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001407 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001408
1409 :param sw_if_index: Software index of the interface
1410 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1411 :param is_add: 1 if add, 0 if delete (Default value = 1)
1412 """
1413 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001414 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001415 {'is_add': is_add,
1416 'is_inside': is_inside,
1417 'sw_if_index': sw_if_index})
1418
Matus Fabian2ba92e32017-08-21 07:05:03 -07001419 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001420 self,
1421 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001422 external_ip=0,
1423 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001424 local_port=0,
1425 external_port=0,
1426 addr_only=1,
1427 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001428 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001429 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001430 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001431 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001432 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001433 is_add=1):
1434 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001435
1436 :param local_ip: Local IP address
1437 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001438 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001439 :param local_port: Local port number (Default value = 0)
1440 :param external_port: External port number (Default value = 0)
1441 :param addr_only: 1 if address only mapping, 0 if address and port
1442 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001443 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001444 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001445 :param self_twice_nat: 1 if translate external host address and port
1446 whenever external host address equals
1447 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001448 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001449 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001450 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001451 """
1452 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001453 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001454 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001455 'addr_only': addr_only,
1456 'local_ip_address': local_ip,
1457 'external_ip_address': external_ip,
1458 'local_port': local_port,
1459 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001460 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001461 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001462 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001463 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001464 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001465 'out2in_only': out2in_only,
1466 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001467
Matus Fabianab7a8052017-11-28 04:29:41 -08001468 def nat44_add_del_identity_mapping(
1469 self,
1470 ip='0',
1471 sw_if_index=0xFFFFFFFF,
1472 port=0,
1473 addr_only=1,
1474 vrf_id=0,
1475 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001476 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001477 is_add=1):
1478 """Add/delete NAT44 identity mapping
1479
1480 :param ip: IP address (Default value = 0)
1481 :param sw_if_index: Interface instead of IP address
1482 :param port: Port number (Default value = 0)
1483 :param addr_only: 1 if address only mapping, 0 if address and port
1484 :param vrf_id: VRF ID
1485 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001486 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001487 :param is_add: 1 if add, 0 if delete (Default value = 1)
1488 """
1489 return self.api(
1490 self.papi.nat44_add_del_identity_mapping,
1491 {'is_add': is_add,
1492 'addr_only': addr_only,
1493 'ip_address': ip,
1494 'port': port,
1495 'sw_if_index': sw_if_index,
1496 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001497 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001498 'protocol': protocol})
1499
Matus Fabian2ba92e32017-08-21 07:05:03 -07001500 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001501 self,
1502 first_ip_address,
1503 last_ip_address,
1504 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001505 vrf_id=0xFFFFFFFF,
1506 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001507 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001508
1509 :param first_ip_address: First IP address
1510 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001511 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001512 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001513 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001514 """
1515 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001516 self.papi.nat44_add_del_address_range,
1517 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001518 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001519 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001520 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001521 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001522
Matus Fabian2ba92e32017-08-21 07:05:03 -07001523 def nat44_address_dump(self):
1524 """Dump NAT44 addresses
1525 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001526 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001527 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001528
Matus Fabian2ba92e32017-08-21 07:05:03 -07001529 def nat44_interface_dump(self):
1530 """Dump interfaces with NAT44 feature
1531 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001532 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001533 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001534
Matus Fabian2ba92e32017-08-21 07:05:03 -07001535 def nat44_interface_output_feature_dump(self):
1536 """Dump interfaces with NAT44 output feature
1537 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001538 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001539 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001540
Matus Fabian2ba92e32017-08-21 07:05:03 -07001541 def nat44_static_mapping_dump(self):
1542 """Dump NAT44 static mappings
1543 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001544 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001545 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001546
Matus Fabianab7a8052017-11-28 04:29:41 -08001547 def nat44_identity_mapping_dump(self):
1548 """Dump NAT44 identity mappings
1549 :return: Dictionary of NAT44 identity mappings
1550 """
1551 return self.api(self.papi.nat44_identity_mapping_dump, {})
1552
Matus Fabian2ba92e32017-08-21 07:05:03 -07001553 def nat_show_config(self):
1554 """Show NAT plugin config
1555 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001556 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001557 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001558
Matus Fabian2ba92e32017-08-21 07:05:03 -07001559 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001560 self,
1561 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001562 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001563 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001564 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001565
1566 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001567 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001568 :param is_add: 1 if add, 0 if delete (Default value = 1)
1569 """
Matus Fabianb932d262017-12-18 05:38:24 -08001570 return self.api(
1571 self.papi.nat44_add_del_interface_addr,
1572 {'is_add': is_add,
1573 'sw_if_index': sw_if_index,
1574 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001575
Matus Fabian2ba92e32017-08-21 07:05:03 -07001576 def nat44_interface_addr_dump(self):
1577 """Dump NAT44 addresses interfaces
1578 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001579 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001580 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001581
Matus Fabian2ba92e32017-08-21 07:05:03 -07001582 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001583 self,
1584 domain_id=1,
1585 src_port=4739,
1586 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001587 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001588
1589 :param domain_id: Observation domain ID (Default value = 1)
1590 :param src_port: Source port number (Default value = 4739)
1591 :param enable: 1 if enable, 0 if disable (Default value = 1)
1592 """
1593 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001594 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001595 {'domain_id': domain_id,
1596 'src_port': src_port,
1597 'enable': enable})
1598
Matus Fabian2ba92e32017-08-21 07:05:03 -07001599 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001600 self,
1601 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001602 vrf_id):
1603 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001604
1605 :param ip_address: ip adress of the user to be dumped
1606 :param cpu_index: cpu_index on which the user is
1607 :param vrf_id: VRF ID
1608 :return: Dictionary of S-NAT sessions
1609 """
1610 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001611 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001612 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001613 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001614
Matus Fabian2ba92e32017-08-21 07:05:03 -07001615 def nat44_user_dump(self):
1616 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001617
Matus Fabian2ba92e32017-08-21 07:05:03 -07001618 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001619 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001620 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001621
Matus Fabian704018c2017-09-04 02:17:18 -07001622 def nat44_add_del_lb_static_mapping(
1623 self,
1624 external_addr,
1625 external_port,
1626 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001627 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001628 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001629 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001630 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001631 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001632 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001633 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001634 is_add=1):
1635 """Add/delete NAT44 load balancing static mapping
1636
Matus Fabianb932d262017-12-18 05:38:24 -08001637 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001638 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001639 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001640 :param is_add - 1 if add, 0 if delete
1641 """
1642 return self.api(
1643 self.papi.nat44_add_del_lb_static_mapping,
1644 {'is_add': is_add,
1645 'external_addr': external_addr,
1646 'external_port': external_port,
1647 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001648 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001649 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001650 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001651 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001652 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001653 'local_num': local_num,
1654 'locals': locals})
1655
Matus Fabianb6865082018-12-06 03:11:09 -08001656 def nat44_lb_static_mapping_add_del_local(
1657 self,
1658 external_addr,
1659 external_port,
1660 local_addr,
1661 local_port,
1662 protocol,
1663 probability,
1664 vrf_id=0,
1665 is_add=1):
1666 """Add/delete NAT44 load-balancing static mapping rule backend
1667
1668 :param external_addr: external IPv4 address of the servic
1669 :param external_port: external L4 port number of the service
1670 :param local_addr: IPv4 address of the internal node
1671 :param local_port: L4 port number of the internal node
1672 :param protocol: IP protocol number
1673 :param probability: probability of the internal node
1674 :param vrf_id: VRF id of the internal node
1675 :param is_add: 1 if add, 0 if delete
1676 """
1677 return self.api(
1678 self.papi.nat44_lb_static_mapping_add_del_local,
1679 {'is_add': is_add,
1680 'external_addr': external_addr,
1681 'external_port': external_port,
1682 'local': {
1683 'addr': local_addr,
1684 'port': local_port,
1685 'probability': probability,
1686 'vrf_id': vrf_id},
1687 'protocol': protocol})
1688
Matus Fabian704018c2017-09-04 02:17:18 -07001689 def nat44_lb_static_mapping_dump(self):
1690 """Dump NAT44 load balancing static mappings
1691
1692 :return: Dictionary of NAT44 load balancing static mapping
1693 """
1694 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1695
Matus Fabian5ba86f72017-10-26 03:37:38 -07001696 def nat44_del_session(
1697 self,
1698 addr,
1699 port,
1700 protocol,
1701 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001702 is_in=1,
1703 ext_host_address=None,
1704 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001705 """Delete NAT44 session
1706
1707 :param addr: IPv4 address
1708 :param por: port number
1709 :param protocol: IP protocol number
1710 :param vrf_id: VRF ID
1711 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001712 :param ext_host_address: external host IPv4 address
1713 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001714 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001715 if ext_host_address is None:
1716 return self.api(
1717 self.papi.nat44_del_session,
1718 {'address': addr,
1719 'port': port,
1720 'protocol': protocol,
1721 'vrf_id': vrf_id,
1722 'is_in': is_in})
1723 else:
1724 return self.api(
1725 self.papi.nat44_del_session,
1726 {'address': addr,
1727 'port': port,
1728 'protocol': protocol,
1729 'vrf_id': vrf_id,
1730 'is_in': is_in,
1731 'ext_host_valid': 1,
1732 'ext_host_address': ext_host_address,
1733 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001734
Juraj Sloboda7b929792017-11-23 13:20:48 +01001735 def nat44_forwarding_enable_disable(
1736 self,
1737 enable):
1738 """Enable/disable forwarding for NAT44
1739
1740 :param enable: 1 for enable, 0 for disable
1741 """
1742 return self.api(
1743 self.papi.nat44_forwarding_enable_disable,
1744 {'enable': enable})
1745
Matus Fabianefcd1e92017-08-15 06:59:19 -07001746 def nat_set_reass(
1747 self,
1748 timeout=2,
1749 max_reass=1024,
1750 max_frag=5,
1751 drop_frag=0,
1752 is_ip6=0):
1753 """Set NAT virtual fragmentation reassembly
1754
1755 :param timeout: reassembly timeout (Default 2sec)
1756 :param max_reass: maximum concurrent reassemblies (Default 1024)
1757 :param max_frag: maximum fragmets per reassembly (Default 5)
1758 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1759 :param is_ip6: 1 if IPv6, 0 if IPv4
1760 """
1761 return self.api(
1762 self.papi.nat_set_reass,
1763 {'timeout': timeout,
1764 'max_reass': max_reass,
1765 'max_frag': max_frag,
1766 'drop_frag': drop_frag,
1767 'is_ip6': is_ip6})
1768
1769 def nat_get_reass(self):
1770 """Get NAT virtual fragmentation reassembly configuration
1771
1772 :return: NAT virtual fragmentation reassembly configuration
1773 """
1774 return self.api(self.papi.nat_get_reass, {})
1775
1776 def nat_reass_dump(self):
1777 """Dump NAT virtual fragmentation reassemblies
1778
1779 :return: Dictionary of NAT virtual fragmentation reassemblies
1780 """
1781 return self.api(self.papi.nat_reass_dump, {})
1782
Matus Fabian2ba92e32017-08-21 07:05:03 -07001783 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001784 self,
1785 in_addr,
1786 in_plen,
1787 out_addr,
1788 out_plen,
1789 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001790 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001791
1792 :param is_add - 1 if add, 0 if delete
1793 :param in_addr - inside IP address
1794 :param in_plen - inside IP address prefix length
1795 :param out_addr - outside IP address
1796 :param out_plen - outside IP address prefix length
1797 """
1798 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001799 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001800 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001801 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001802 'in_addr': in_addr,
1803 'in_plen': in_plen,
1804 'out_addr': out_addr,
1805 'out_plen': out_plen})
1806
Matus Fabian2ba92e32017-08-21 07:05:03 -07001807 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001808 self,
1809 in_addr):
1810 """Get outside address and port range from inside address
1811
1812 :param in_addr - inside IP address
1813 """
1814 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001815 self.papi.nat_det_forward,
1816 {'in_addr': in_addr,
1817 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001818
Matus Fabian2ba92e32017-08-21 07:05:03 -07001819 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001820 self,
1821 out_addr,
1822 out_port):
1823 """Get inside address from outside address and port
1824
1825 :param out_addr - outside IP address
1826 :param out_port - outside port
1827 """
1828 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001829 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001830 {'out_addr': out_addr,
1831 'out_port': out_port})
1832
Matus Fabian2ba92e32017-08-21 07:05:03 -07001833 def nat_det_map_dump(self):
1834 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001835
Matus Fabian2ba92e32017-08-21 07:05:03 -07001836 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001837 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001838 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001839
Matus Fabian878c6462018-08-23 00:33:35 -07001840 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001841 self,
1842 udp=300,
1843 tcp_established=7440,
1844 tcp_transitory=240,
1845 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001846 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001847
1848 :param udp - UDP timeout (Default value = 300)
1849 :param tcp_established - TCP established timeout (Default value = 7440)
1850 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1851 :param icmp - ICMP timeout (Default value = 60)
1852 """
1853 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001854 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001855 {'udp': udp,
1856 'tcp_established': tcp_established,
1857 'tcp_transitory': tcp_transitory,
1858 'icmp': icmp})
1859
Matus Fabian878c6462018-08-23 00:33:35 -07001860 def nat_get_timeouts(self):
1861 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001862
Matus Fabian878c6462018-08-23 00:33:35 -07001863 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001864 """
Matus Fabian878c6462018-08-23 00:33:35 -07001865 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001866
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001867 def nat_set_addr_and_port_alloc_alg(
1868 self,
1869 alg=0,
1870 psid_offset=0,
1871 psid_length=0,
1872 psid=0,
1873 start_port=0,
1874 end_port=0):
1875 """Set address and port assignment algorithm
1876
1877 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1878 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1879 :param psid_length: length of PSID (valid only for MAP-E alg)
1880 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1881 :param start_port: beginning of the port range
1882 :param end_port: end of the port range
1883 """
1884 return self.api(
1885 self.papi.nat_set_addr_and_port_alloc_alg,
1886 {'alg': alg,
1887 'psid_offset': psid_offset,
1888 'psid_length': psid_length,
1889 'psid': psid,
1890 'start_port': start_port,
1891 'end_port': end_port})
1892
1893 def nat_get_addr_and_port_alloc_alg(self):
1894 """Get address and port assignment algorithm"""
1895 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1896
Matus Fabianbb4e0222018-09-13 02:36:25 -07001897 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1898 """Set TCP MSS rewriting configuration
1899
1900 :param enable: disable(0)/enable(1) MSS rewriting feature
1901 :param mss_value: MSS value to be used for MSS rewriting
1902 """
1903 return self.api(
1904 self.papi.nat_set_mss_clamping,
1905 {'enable': enable, 'mss_value': mss_value})
1906
1907 def nat_get_mss_clamping(self):
1908 """Get TCP MSS rewriting configuration"""
1909 return self.api(self.papi.nat_get_mss_clamping, {})
1910
Matus Fabian2ba92e32017-08-21 07:05:03 -07001911 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001912 self,
1913 out_addr,
1914 out_port,
1915 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001916 ext_port):
1917 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001918
1919 :param out_addr - outside IP address
1920 :param out_port - outside port
1921 :param ext_addr - external host IP address
1922 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001923 """
1924 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001925 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001926 {'out_addr': out_addr,
1927 'out_port': out_port,
1928 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001929 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001930
Matus Fabian2ba92e32017-08-21 07:05:03 -07001931 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001932 self,
1933 in_addr,
1934 in_port,
1935 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001936 ext_port):
1937 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001938
1939 :param in_addr - inside IP address
1940 :param in_port - inside port
1941 :param ext_addr - external host IP address
1942 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001943 """
1944 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001945 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001946 {'in_addr': in_addr,
1947 'in_port': in_port,
1948 'ext_addr': ext_addr,
1949 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001950 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001951
Matus Fabian2ba92e32017-08-21 07:05:03 -07001952 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001953 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001954 user_addr):
1955 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001956
1957 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001958 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001959 """
1960 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001961 self.papi.nat_det_session_dump,
1962 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001963 'user_addr': user_addr})
1964
Matus Fabian06596c52017-06-06 04:53:28 -07001965 def nat64_add_del_pool_addr_range(
1966 self,
1967 start_addr,
1968 end_addr,
1969 vrf_id=0xFFFFFFFF,
1970 is_add=1):
1971 """Add/del address range to NAT64 pool
1972
1973 :param start_addr: First IP address
1974 :param end_addr: Last IP address
1975 :param vrf_id: VRF id for the address range
1976 :param is_add: 1 if add, 0 if delete (Default value = 1)
1977 """
1978 return self.api(
1979 self.papi.nat64_add_del_pool_addr_range,
1980 {'start_addr': start_addr,
1981 'end_addr': end_addr,
1982 'vrf_id': vrf_id,
1983 'is_add': is_add})
1984
1985 def nat64_pool_addr_dump(self):
1986 """Dump NAT64 pool addresses
1987 :return: Dictionary of NAT64 pool addresses
1988 """
1989 return self.api(self.papi.nat64_pool_addr_dump, {})
1990
1991 def nat64_add_del_interface(
1992 self,
1993 sw_if_index,
1994 is_inside=1,
1995 is_add=1):
1996 """Enable/disable NAT64 feature on the interface
1997 :param sw_if_index: Index of the interface
1998 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1999 :param is_add: 1 if add, 0 if delete (Default value = 1)
2000 """
2001 return self.api(
2002 self.papi.nat64_add_del_interface,
2003 {'sw_if_index': sw_if_index,
2004 'is_inside': is_inside,
2005 'is_add': is_add})
2006
2007 def nat64_interface_dump(self):
2008 """Dump interfaces with NAT64 feature
2009 :return: Dictionary of interfaces with NAT64 feature
2010 """
2011 return self.api(self.papi.nat64_interface_dump, {})
2012
2013 def nat64_add_del_static_bib(
2014 self,
2015 in_ip,
2016 out_ip,
2017 in_port,
2018 out_port,
2019 protocol,
2020 vrf_id=0,
2021 is_add=1):
2022 """Add/delete S-NAT static BIB entry
2023
2024 :param in_ip: Inside IPv6 address
2025 :param out_ip: Outside IPv4 address
2026 :param in_port: Inside port number
2027 :param out_port: Outside port number
2028 :param protocol: IP protocol
2029 :param vrf_id: VRF ID (Default value = 0)
2030 :param is_add: 1 if add, 0 if delete (Default value = 1)
2031 """
2032 return self.api(
2033 self.papi.nat64_add_del_static_bib,
2034 {'i_addr': in_ip,
2035 'o_addr': out_ip,
2036 'i_port': in_port,
2037 'o_port': out_port,
2038 'vrf_id': vrf_id,
2039 'proto': protocol,
2040 'is_add': is_add})
2041
Matus Fabianab9a59c2017-08-16 05:37:36 -07002042 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002043 """Dump NAT64 BIB
2044
Matus Fabianab9a59c2017-08-16 05:37:36 -07002045 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002046 :returns: Dictionary of NAT64 BIB entries
2047 """
2048 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2049
2050 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2051 tcp_incoming_syn=6):
2052 """Set values of timeouts for NAT64 (in seconds)
2053
Matus Fabian428dc912017-06-21 06:15:18 -07002054 :param udpi: UDP timeout (Default value = 300)
2055 :param icmp: ICMP timeout (Default value = 60)
2056 :param tcp_trans: TCP transitory timeout (Default value = 240)
2057 :param tcp_est: TCP established timeout (Default value = 7440)
2058 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002059 """
2060 return self.api(
2061 self.papi.nat64_set_timeouts,
2062 {'udp': udp,
2063 'icmp': icmp,
2064 'tcp_trans': tcp_trans,
2065 'tcp_est': tcp_est,
2066 'tcp_incoming_syn': tcp_incoming_syn})
2067
2068 def nat64_get_timeouts(self):
2069 """Get values of timeouts for NAT64
2070
2071 :return: Timeouts for NAT64 (in seconds)
2072 """
2073 return self.api(self.papi.nat64_get_timeouts, {})
2074
Matus Fabianab9a59c2017-08-16 05:37:36 -07002075 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002076 """Dump NAT64 session table
2077
Matus Fabianab9a59c2017-08-16 05:37:36 -07002078 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002079 :returns: Dictionary of NAT64 sesstion table entries
2080 """
2081 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2082
Matus Fabian428dc912017-06-21 06:15:18 -07002083 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2084 """Add/del NAT64 prefix
2085
2086 :param prefix: NAT64 prefix
2087 :param plen: NAT64 prefix length
2088 :param vrf_id: VRF id of tenant (Default 0)
2089 :param is_add: 1 if add, 0 if delete (Default value = 1)
2090 """
2091 return self.api(
2092 self.papi.nat64_add_del_prefix,
2093 {'prefix': prefix,
2094 'prefix_len': plen,
2095 'vrf_id': vrf_id,
2096 'is_add': is_add})
2097
2098 def nat64_prefix_dump(self):
2099 """Dump NAT64 prefix
2100
2101 :returns: Dictionary of NAT64 prefixes
2102 """
2103 return self.api(self.papi.nat64_prefix_dump, {})
2104
Matus Fabian0938dcf2017-11-08 01:59:38 -08002105 def nat64_add_interface_addr(
2106 self,
2107 sw_if_index,
2108 is_add=1):
2109 """Add/del NAT64 address from interface
2110
2111 :param sw_if_index: Software index of the interface
2112 :param is_add: 1 if add, 0 if delete (Default value = 1)
2113 """
2114 return self.api(self.papi.nat64_add_del_interface_addr,
2115 {'is_add': is_add, 'sw_if_index': sw_if_index})
2116
Matus Fabian8ebe6252017-11-06 05:04:53 -08002117 def dslite_set_aftr_addr(self, ip6, ip4):
2118 """Set DS-Lite AFTR addresses
2119
2120 :param ip4: IPv4 address
2121 :param ip6: IPv6 address
2122 """
2123 return self.api(
2124 self.papi.dslite_set_aftr_addr,
2125 {'ip4_addr': ip4,
2126 'ip6_addr': ip6})
2127
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002128 def dslite_set_b4_addr(self, ip6, ip4):
2129 """Set DS-Lite B4 IPv6 address
2130
2131 :param ip4: IPv4 address
2132 :param ip6: IPv6 address
2133 """
2134 return self.api(
2135 self.papi.dslite_set_b4_addr,
2136 {'ip4_addr': ip4,
2137 'ip6_addr': ip6})
2138
Matus Fabian8ebe6252017-11-06 05:04:53 -08002139 def dslite_add_del_pool_addr_range(
2140 self,
2141 start_addr,
2142 end_addr,
2143 is_add=1):
2144 """Add/del address range to DS-Lite pool
2145
2146 :param start_addr: First IP address
2147 :param end_addr: Last IP address
2148 :param is_add: 1 if add, 0 if delete (Default value = 1)
2149 """
2150 return self.api(
2151 self.papi.dslite_add_del_pool_addr_range,
2152 {'start_addr': start_addr,
2153 'end_addr': end_addr,
2154 'is_add': is_add})
2155
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002156 def nat66_add_del_interface(
2157 self,
2158 sw_if_index,
2159 is_inside=1,
2160 is_add=1):
2161 """Enable/disable NAT66 feature on the interface
2162 :param sw_if_index: Index of the interface
2163 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2164 :param is_add: 1 if add, 0 if delete (Default value = 1)
2165 """
2166 return self.api(
2167 self.papi.nat66_add_del_interface,
2168 {'sw_if_index': sw_if_index,
2169 'is_inside': is_inside,
2170 'is_add': is_add})
2171
2172 def nat66_add_del_static_mapping(
2173 self,
2174 in_ip,
2175 out_ip,
2176 vrf_id=0,
2177 is_add=1):
2178 """Add/delete NAT66 static mapping
2179
2180 :param in_ip: Inside IPv6 address
2181 :param out_ip: Outside IPv6 address
2182 :param vrf_id: VRF ID (Default value = 0)
2183 :param is_add: 1 if add, 0 if delete (Default value = 1)
2184 """
2185 return self.api(
2186 self.papi.nat66_add_del_static_mapping,
2187 {'local_ip_address': in_ip,
2188 'external_ip_address': out_ip,
2189 'vrf_id': vrf_id,
2190 'is_add': is_add})
2191
2192 def nat66_interface_dump(self):
2193 """Dump interfaces with NAT66 feature
2194 :return: Dictionary of interfaces with NAT66 feature
2195 """
2196 return self.api(self.papi.nat66_interface_dump, {})
2197
2198 def nat66_static_mapping_dump(self):
2199 """Dump NAT66 static mappings
2200 :return: Dictionary of NAT66 static mappings
2201 """
2202 return self.api(self.papi.nat66_static_mapping_dump, {})
2203
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002204 def control_ping(self):
2205 self.api(self.papi.control_ping)
2206
2207 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002208 detect_mult, local_addr, peer_addr, is_ipv6=0,
2209 bfd_key_id=None, conf_key_id=None):
2210 if bfd_key_id is None:
2211 return self.api(self.papi.bfd_udp_add,
2212 {
2213 'sw_if_index': sw_if_index,
2214 'desired_min_tx': desired_min_tx,
2215 'required_min_rx': required_min_rx,
2216 'local_addr': local_addr,
2217 'peer_addr': peer_addr,
2218 'is_ipv6': is_ipv6,
2219 'detect_mult': detect_mult,
2220 })
2221 else:
2222 return self.api(self.papi.bfd_udp_add,
2223 {
2224 'sw_if_index': sw_if_index,
2225 'desired_min_tx': desired_min_tx,
2226 'required_min_rx': required_min_rx,
2227 'local_addr': local_addr,
2228 'peer_addr': peer_addr,
2229 'is_ipv6': is_ipv6,
2230 'detect_mult': detect_mult,
2231 'is_authenticated': 1,
2232 'bfd_key_id': bfd_key_id,
2233 'conf_key_id': conf_key_id,
2234 })
2235
Klement Sekeraa57a9702017-02-02 06:58:07 +01002236 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2237 detect_mult, local_addr, peer_addr, is_ipv6=0):
2238 return self.api(self.papi.bfd_udp_mod,
2239 {
2240 'sw_if_index': sw_if_index,
2241 'desired_min_tx': desired_min_tx,
2242 'required_min_rx': required_min_rx,
2243 'local_addr': local_addr,
2244 'peer_addr': peer_addr,
2245 'is_ipv6': is_ipv6,
2246 'detect_mult': detect_mult,
2247 })
2248
Klement Sekerab17dd962017-01-09 07:43:48 +01002249 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2250 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2251 is_delayed=False):
2252 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002253 {
2254 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002255 'local_addr': local_addr,
2256 'peer_addr': peer_addr,
2257 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002258 'is_delayed': 1 if is_delayed else 0,
2259 'bfd_key_id': bfd_key_id,
2260 'conf_key_id': conf_key_id,
2261 })
2262
2263 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2264 is_ipv6=0, is_delayed=False):
2265 return self.api(self.papi.bfd_udp_auth_deactivate,
2266 {
2267 'sw_if_index': sw_if_index,
2268 'local_addr': local_addr,
2269 'peer_addr': peer_addr,
2270 'is_ipv6': is_ipv6,
2271 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002272 })
2273
2274 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2275 return self.api(self.papi.bfd_udp_del,
2276 {
2277 'sw_if_index': sw_if_index,
2278 'local_addr': local_addr,
2279 'peer_addr': peer_addr,
2280 'is_ipv6': is_ipv6,
2281 })
2282
2283 def bfd_udp_session_dump(self):
2284 return self.api(self.papi.bfd_udp_session_dump, {})
2285
Klement Sekerab17dd962017-01-09 07:43:48 +01002286 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2287 peer_addr, is_ipv6=0):
2288 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002289 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002290 'sw_if_index': sw_if_index,
2291 'local_addr': local_addr,
2292 'peer_addr': peer_addr,
2293 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002294 })
2295
2296 def want_bfd_events(self, enable_disable=1):
2297 return self.api(self.papi.want_bfd_events, {
2298 'enable_disable': enable_disable,
2299 'pid': os.getpid(),
2300 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002301
Klement Sekerab17dd962017-01-09 07:43:48 +01002302 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2303 return self.api(self.papi.bfd_auth_set_key, {
2304 'conf_key_id': conf_key_id,
2305 'auth_type': auth_type,
2306 'key': key,
2307 'key_len': len(key),
2308 })
2309
2310 def bfd_auth_del_key(self, conf_key_id):
2311 return self.api(self.papi.bfd_auth_del_key, {
2312 'conf_key_id': conf_key_id,
2313 })
2314
2315 def bfd_auth_keys_dump(self):
2316 return self.api(self.papi.bfd_auth_keys_dump, {})
2317
Klement Sekera239790f2017-02-16 10:53:53 +01002318 def bfd_udp_set_echo_source(self, sw_if_index):
2319 return self.api(self.papi.bfd_udp_set_echo_source,
2320 {'sw_if_index': sw_if_index})
2321
Klement Sekera73884482017-02-23 09:26:30 +01002322 def bfd_udp_del_echo_source(self):
2323 return self.api(self.papi.bfd_udp_del_echo_source, {})
2324
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002325 def bfd_udp_get_echo_source(self):
2326 return self.api(self.papi.bfd_udp_get_echo_source, {})
2327
Steve Shin7957d6e2016-12-19 09:24:50 -08002328 def classify_add_del_table(
2329 self,
2330 is_add,
2331 mask,
2332 match_n_vectors=1,
2333 table_index=0xFFFFFFFF,
2334 nbuckets=2,
2335 memory_size=2097152,
2336 skip_n_vectors=0,
2337 next_table_index=0xFFFFFFFF,
2338 miss_next_index=0xFFFFFFFF,
2339 current_data_flag=0,
2340 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002341 """
2342 :param is_add:
2343 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002344 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002345 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002346 :param nbuckets: (Default value = 2)
2347 :param memory_size: (Default value = 2097152)
2348 :param skip_n_vectors: (Default value = 0)
2349 :param next_table_index: (Default value = 0xFFFFFFFF)
2350 :param miss_next_index: (Default value = 0xFFFFFFFF)
2351 :param current_data_flag: (Default value = 0)
2352 :param current_data_offset: (Default value = 0)
2353 """
2354
Juraj Sloboda75282452018-06-12 14:20:49 +02002355 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2356 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002357 return self.api(
2358 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002359 {'is_add': is_add,
2360 'table_index': table_index,
2361 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002362 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002363 'skip_n_vectors': skip_n_vectors,
2364 'match_n_vectors': match_n_vectors,
2365 'next_table_index': next_table_index,
2366 'miss_next_index': miss_next_index,
2367 'current_data_flag': current_data_flag,
2368 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002369 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002370 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002371
2372 def classify_add_del_session(
2373 self,
2374 is_add,
2375 table_index,
2376 match,
2377 opaque_index=0xFFFFFFFF,
2378 hit_next_index=0xFFFFFFFF,
2379 advance=0,
2380 action=0,
2381 metadata=0):
2382 """
2383 :param is_add:
2384 :param table_index:
2385 :param match:
2386 :param opaque_index: (Default value = 0xFFFFFFFF)
2387 :param hit_next_index: (Default value = 0xFFFFFFFF)
2388 :param advance: (Default value = 0)
2389 :param action: (Default value = 0)
2390 :param metadata: (Default value = 0)
2391 """
2392
Juraj Sloboda75282452018-06-12 14:20:49 +02002393 match_len = ((len(match) - 1) / 16 + 1) * 16
2394 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002395 return self.api(
2396 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002397 {'is_add': is_add,
2398 'table_index': table_index,
2399 'hit_next_index': hit_next_index,
2400 'opaque_index': opaque_index,
2401 'advance': advance,
2402 'action': action,
2403 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002404 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002405 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002406
2407 def input_acl_set_interface(
2408 self,
2409 is_add,
2410 sw_if_index,
2411 ip4_table_index=0xFFFFFFFF,
2412 ip6_table_index=0xFFFFFFFF,
2413 l2_table_index=0xFFFFFFFF):
2414 """
2415 :param is_add:
2416 :param sw_if_index:
2417 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2418 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2419 :param l2_table_index: (Default value = 0xFFFFFFFF)
2420 """
2421
2422 return self.api(
2423 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002424 {'sw_if_index': sw_if_index,
2425 'ip4_table_index': ip4_table_index,
2426 'ip6_table_index': ip6_table_index,
2427 'l2_table_index': l2_table_index,
2428 'is_add': is_add})
2429
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002430 def output_acl_set_interface(
2431 self,
2432 is_add,
2433 sw_if_index,
2434 ip4_table_index=0xFFFFFFFF,
2435 ip6_table_index=0xFFFFFFFF,
2436 l2_table_index=0xFFFFFFFF):
2437 """
2438 :param is_add:
2439 :param sw_if_index:
2440 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2441 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2442 :param l2_table_index: (Default value = 0xFFFFFFFF)
2443 """
2444
2445 return self.api(
2446 self.papi.output_acl_set_interface,
2447 {'sw_if_index': sw_if_index,
2448 'ip4_table_index': ip4_table_index,
2449 'ip6_table_index': ip6_table_index,
2450 'l2_table_index': l2_table_index,
2451 'is_add': is_add})
2452
Klement Sekera77fabdb2017-01-02 07:46:14 +01002453 def set_ipfix_exporter(
2454 self,
2455 collector_address,
2456 src_address,
2457 path_mtu,
2458 template_interval,
2459 vrf_id=0,
2460 collector_port=4739,
2461 udp_checksum=0):
2462 return self.api(
2463 self.papi.set_ipfix_exporter,
2464 {
2465 'collector_address': collector_address,
2466 'collector_port': collector_port,
2467 'src_address': src_address,
2468 'vrf_id': vrf_id,
2469 'path_mtu': path_mtu,
2470 'template_interval': template_interval,
2471 'udp_checksum': udp_checksum,
2472 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002473
2474 def dhcp_proxy_config(self,
2475 dhcp_server,
2476 dhcp_src_address,
2477 rx_table_id=0,
2478 server_table_id=0,
2479 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002480 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002481 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002482 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002483 {
2484 'rx_vrf_id': rx_table_id,
2485 'server_vrf_id': server_table_id,
2486 'is_ipv6': is_ipv6,
2487 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002488 'dhcp_server': dhcp_server,
2489 'dhcp_src_address': dhcp_src_address,
2490 })
2491
2492 def dhcp_proxy_set_vss(self,
2493 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002494 vss_type=255,
2495 vpn_ascii_id="",
2496 oui=0,
2497 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002498 is_add=1,
2499 is_ip6=0):
2500 return self.api(
2501 self.papi.dhcp_proxy_set_vss,
2502 {
2503 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002504 'vss_type': vss_type,
2505 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002506 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002507 'vpn_index': vpn_index,
2508 'is_add': is_add,
2509 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002510 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002511
Neale Rannsdaff1782018-05-16 04:12:18 -07002512 def dhcp_client_dump(self):
2513 return self.api(self.papi.dhcp_client_dump, {})
2514
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002515 def dhcp_client(self,
2516 sw_if_index,
2517 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002518 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002519 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002520 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002521 want_dhcp_events=0):
2522 return self.api(
2523 self.papi.dhcp_client_config,
2524 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002525 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002526 'client': {
2527 'sw_if_index': sw_if_index,
2528 'hostname': hostname,
2529 'id': client_id,
2530 'want_dhcp_event': want_dhcp_events,
2531 'set_broadcast_flag': set_broadcast_flag,
2532 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002533 })
2534
Neale Ranns32e1c012016-11-22 17:07:28 +00002535 def ip_mroute_add_del(self,
2536 src_address,
2537 grp_address,
2538 grp_address_length,
2539 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002540 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002541 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002542 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002543 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002544 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002545 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002546 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002547 is_add=1,
2548 is_ipv6=0,
2549 is_local=0):
2550 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002551 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002552 """
2553 return self.api(
2554 self.papi.ip_mroute_add_del,
2555 {'next_hop_sw_if_index': next_hop_sw_if_index,
2556 'entry_flags': e_flags,
2557 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002558 'table_id': table_id,
2559 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002560 'is_add': is_add,
2561 'is_ipv6': is_ipv6,
2562 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002563 'bier_imp': bier_imp,
2564 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002565 'grp_address_length': grp_address_length,
2566 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002567 'src_address': src_address,
2568 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002569
2570 def mfib_signal_dump(self):
2571 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002572
2573 def ip_mfib_dump(self):
2574 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002575
Neale Rannsd792d9c2017-10-21 10:53:20 -07002576 def ip6_mfib_dump(self):
2577 return self.api(self.papi.ip6_mfib_dump, {})
2578
Filip Tehlar770e89e2017-01-31 10:39:16 +01002579 def lisp_enable_disable(self, is_enabled):
2580 return self.api(
2581 self.papi.lisp_enable_disable,
2582 {
2583 'is_en': is_enabled,
2584 })
2585
2586 def lisp_locator_set(self,
2587 ls_name,
2588 is_add=1):
2589 return self.api(
2590 self.papi.lisp_add_del_locator_set,
2591 {
2592 'is_add': is_add,
2593 'locator_set_name': ls_name
2594 })
2595
2596 def lisp_locator_set_dump(self):
2597 return self.api(self.papi.lisp_locator_set_dump, {})
2598
2599 def lisp_locator(self,
2600 ls_name,
2601 sw_if_index,
2602 priority=1,
2603 weight=1,
2604 is_add=1):
2605 return self.api(
2606 self.papi.lisp_add_del_locator,
2607 {
2608 'is_add': is_add,
2609 'locator_set_name': ls_name,
2610 'sw_if_index': sw_if_index,
2611 'priority': priority,
2612 'weight': weight
2613 })
2614
2615 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2616 return self.api(
2617 self.papi.lisp_locator_dump,
2618 {
2619 'is_index_set': is_index_set,
2620 'ls_name': ls_name,
2621 'ls_index': ls_index,
2622 })
2623
2624 def lisp_local_mapping(self,
2625 ls_name,
2626 eid_type,
2627 eid,
2628 prefix_len,
2629 vni=0,
2630 key_id=0,
2631 key="",
2632 is_add=1):
2633 return self.api(
2634 self.papi.lisp_add_del_local_eid,
2635 {
2636 'locator_set_name': ls_name,
2637 'is_add': is_add,
2638 'eid_type': eid_type,
2639 'eid': eid,
2640 'prefix_len': prefix_len,
2641 'vni': vni,
2642 'key_id': key_id,
2643 'key': key
2644 })
2645
2646 def lisp_eid_table_dump(self,
2647 eid_set=0,
2648 prefix_length=0,
2649 vni=0,
2650 eid_type=0,
2651 eid=None,
2652 filter_opt=0):
2653 return self.api(
2654 self.papi.lisp_eid_table_dump,
2655 {
2656 'eid_set': eid_set,
2657 'prefix_length': prefix_length,
2658 'vni': vni,
2659 'eid_type': eid_type,
2660 'eid': eid,
2661 'filter': filter_opt,
2662 })
2663
2664 def lisp_remote_mapping(self,
2665 eid_type,
2666 eid,
2667 eid_prefix_len=0,
2668 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002669 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002670 rlocs_num=0,
2671 is_src_dst=0,
2672 is_add=1):
2673 return self.api(
2674 self.papi.lisp_add_del_remote_mapping,
2675 {
2676 'is_add': is_add,
2677 'eid_type': eid_type,
2678 'eid': eid,
2679 'eid_len': eid_prefix_len,
2680 'rloc_num': rlocs_num,
2681 'rlocs': rlocs,
2682 'vni': vni,
2683 'is_src_dst': is_src_dst,
2684 })
2685
2686 def lisp_adjacency(self,
2687 leid,
2688 reid,
2689 leid_len,
2690 reid_len,
2691 eid_type,
2692 is_add=1,
2693 vni=0):
2694 return self.api(
2695 self.papi.lisp_add_del_adjacency,
2696 {
2697 'is_add': is_add,
2698 'vni': vni,
2699 'eid_type': eid_type,
2700 'leid': leid,
2701 'reid': reid,
2702 'leid_len': leid_len,
2703 'reid_len': reid_len,
2704 })
2705
2706 def lisp_adjacencies_get(self, vni=0):
2707 return self.api(
2708 self.papi.lisp_adjacencies_get,
2709 {
2710 'vni': vni
2711 })
Neale Ranns80823802017-02-20 18:23:41 -08002712
2713 def map_add_domain(self,
2714 ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002715 ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002716 ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002717 ea_bits_len=0,
2718 psid_offset=0,
2719 psid_length=0,
Neale Ranns80823802017-02-20 18:23:41 -08002720 mtu=1280):
Jon Loeligerfc7344f2018-12-20 11:47:30 -06002721
Neale Ranns80823802017-02-20 18:23:41 -08002722 return self.api(
2723 self.papi.map_add_domain,
2724 {
2725 'ip6_prefix': ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002726 'ip4_prefix': ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002727 'ip6_src': ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002728 'ea_bits_len': ea_bits_len,
2729 'psid_offset': psid_offset,
2730 'psid_length': psid_length,
Neale Ranns80823802017-02-20 18:23:41 -08002731 'mtu': mtu
2732 })
Hongjun Nief486b12017-04-12 19:21:16 +08002733
Jon Loeligerfc7344f2018-12-20 11:47:30 -06002734 def map_if_enable_disable(self, is_enable, sw_if_index, is_translation):
2735 return self.api(
2736 self.papi.map_if_enable_disable,
2737 {
2738 'is_enable': is_enable,
2739 'sw_if_index': sw_if_index,
2740 'is_translation': is_translation,
2741 })
2742
2743 def map_param_set_tcp(self, tcp_mss):
2744 return self.api(
2745 self.papi.map_param_set_tcp,
2746 {
2747 'tcp_mss': tcp_mss,
2748 })
2749
Hongjun Nief486b12017-04-12 19:21:16 +08002750 def gtpu_add_del_tunnel(
2751 self,
2752 src_addr,
2753 dst_addr,
2754 is_add=1,
2755 is_ipv6=0,
2756 mcast_sw_if_index=0xFFFFFFFF,
2757 encap_vrf_id=0,
2758 decap_next_index=0xFFFFFFFF,
2759 teid=0):
2760 """
2761
2762 :param is_add: (Default value = 1)
2763 :param is_ipv6: (Default value = 0)
2764 :param src_addr:
2765 :param dst_addr:
2766 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2767 :param encap_vrf_id: (Default value = 0)
2768 :param decap_next_index: (Default value = 0xFFFFFFFF)
2769 :param teid: (Default value = 0)
2770
2771 """
2772 return self.api(self.papi.gtpu_add_del_tunnel,
2773 {'is_add': is_add,
2774 'is_ipv6': is_ipv6,
2775 'src_address': src_addr,
2776 'dst_address': dst_addr,
2777 'mcast_sw_if_index': mcast_sw_if_index,
2778 'encap_vrf_id': encap_vrf_id,
2779 'decap_next_index': decap_next_index,
2780 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002781
2782 def vxlan_gpe_add_del_tunnel(
2783 self,
2784 src_addr,
2785 dst_addr,
2786 mcast_sw_if_index=0xFFFFFFFF,
2787 is_add=1,
2788 is_ipv6=0,
2789 encap_vrf_id=0,
2790 decap_vrf_id=0,
2791 protocol=3,
2792 vni=0):
2793 """
2794
2795 :param local:
2796 :param remote:
2797 :param is_add: (Default value = 1)
2798 :param is_ipv6: (Default value = 0)
2799 :param encap_vrf_id: (Default value = 0)
2800 :param decap_vrf_id: (Default value = 0)
2801 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2802 :param protocol: (Default value = 3)
2803 :param vni: (Default value = 0)
2804
2805 """
2806 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2807 {'is_add': is_add,
2808 'is_ipv6': is_ipv6,
2809 'local': src_addr,
2810 'remote': dst_addr,
2811 'mcast_sw_if_index': mcast_sw_if_index,
2812 'encap_vrf_id': encap_vrf_id,
2813 'decap_vrf_id': decap_vrf_id,
2814 'protocol': protocol,
2815 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002816
Neale Ranns79a05f52018-09-11 07:39:43 -07002817 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002818 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002819 src,
2820 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002821 mcast_sw_if_index=0xFFFFFFFF,
2822 is_add=1,
2823 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002824 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002825 vni=0,
2826 instance=0xFFFFFFFF):
2827 """
2828
2829 :param dst_addr:
2830 :param src_addr:
2831 :param is_add: (Default value = 1)
2832 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002833 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002834 :param decap_next_index: (Default value = 0xFFFFFFFF)
2835 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2836 :param vni: (Default value = 0)
2837 :param instance: (Default value = 0xFFFFFFFF)
2838
2839 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002840 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002841 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002842 'tunnel': {
2843 'src': src,
2844 'dst': dst,
2845 'mcast_sw_if_index': mcast_sw_if_index,
2846 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002847 'vni': vni,
2848 'instance': instance}})
2849
2850 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2851 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01002852 {'sw_if_index': sw_if_index,
2853 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002854
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002855 def pppoe_add_del_session(
2856 self,
2857 client_ip,
2858 client_mac,
2859 session_id=0,
2860 is_add=1,
2861 is_ipv6=0,
2862 decap_vrf_id=0):
2863 """
2864
2865 :param is_add: (Default value = 1)
2866 :param is_ipv6: (Default value = 0)
2867 :param client_ip:
2868 :param session_id: (Default value = 0)
2869 :param client_mac:
2870 :param decap_vrf_id: (Default value = 0)
2871
2872 """
2873 return self.api(self.papi.pppoe_add_del_session,
2874 {'is_add': is_add,
2875 'is_ipv6': is_ipv6,
2876 'session_id': session_id,
2877 'client_ip': client_ip,
2878 'decap_vrf_id': decap_vrf_id,
2879 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002880
Neale Ranns7c922dc2018-08-30 06:12:27 -07002881 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2882 return self.api(self.papi.sr_mpls_policy_add,
2883 {'bsid': bsid,
2884 'weight': weight,
2885 'type': type,
2886 'n_segments': len(segments),
2887 'segments': segments})
2888
2889 def sr_mpls_policy_del(self, bsid):
2890 return self.api(self.papi.sr_mpls_policy_del,
2891 {'bsid': bsid})
2892
Kris Michielsen91074432017-06-22 13:00:20 +02002893 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002894 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002895 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002896 nh_addr4,
2897 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002898 is_del=0,
2899 end_psp=0,
2900 sw_if_index=0xFFFFFFFF,
2901 vlan_index=0,
2902 fib_table=0,
2903 ):
2904 """ Add/del IPv6 SR local-SID.
2905
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002906 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002907 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2908 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002909 :param nh_addr4:
2910 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002911 :param is_del: (Default value = 0)
2912 :param end_psp: (Default value = 0)
2913 :param sw_if_index: (Default value = 0xFFFFFFFF)
2914 :param vlan_index: (Default value = 0)
2915 :param fib_table: (Default value = 0)
2916 """
2917 return self.api(
2918 self.papi.sr_localsid_add_del,
2919 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002920 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002921 'end_psp': end_psp,
2922 'behavior': behavior,
2923 'sw_if_index': sw_if_index,
2924 'vlan_index': vlan_index,
2925 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002926 'nh_addr4': nh_addr4,
2927 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002928 }
2929 )
2930
2931 def sr_policy_add(
2932 self,
2933 bsid_addr,
2934 weight=1,
2935 is_encap=1,
2936 type=0,
2937 fib_table=0,
2938 n_segments=0,
2939 segments=[]):
2940 """
2941 :param bsid_addr: bindingSID of the SR Policy
2942 :param weight: weight of the sid list. optional. (default: 1)
2943 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2944 (default: Encap)
2945 :param type: type/behavior of the SR policy. (default or spray) \
2946 (default: default)
2947 :param fib_table: VRF where to install the FIB entry for the BSID \
2948 (default: 0)
2949 :param n_segments: number of segments \
2950 (default: 0)
2951 :param segments: a vector of IPv6 address composing the segment list \
2952 (default: [])
2953 """
2954 return self.api(
2955 self.papi.sr_policy_add,
2956 {'bsid_addr': bsid_addr,
2957 'weight': weight,
2958 'is_encap': is_encap,
2959 'type': type,
2960 'fib_table': fib_table,
2961 'n_segments': n_segments,
2962 'segments': segments
2963 }
2964 )
2965
2966 def sr_policy_del(
2967 self,
2968 bsid_addr,
2969 sr_policy_index=0):
2970 """
2971 :param bsid: bindingSID of the SR Policy
2972 :param sr_policy_index: index of the sr policy (default: 0)
2973 """
2974 return self.api(
2975 self.papi.sr_policy_del,
2976 {'bsid_addr': bsid_addr,
2977 'sr_policy_index': sr_policy_index
2978 })
2979
2980 def sr_steering_add_del(
2981 self,
2982 is_del,
2983 bsid_addr,
2984 sr_policy_index,
2985 table_id,
2986 prefix_addr,
2987 mask_width,
2988 sw_if_index,
2989 traffic_type):
2990 """
2991 Steer traffic L2 and L3 traffic through a given SR policy
2992
2993 :param is_del: delete or add
2994 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2995 :param sr_policy: is the index of the SR Policy (alt to bsid)
2996 :param table_id: is the VRF where to install the FIB entry for the BSID
2997 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2998 :param mask_width: is the mask for L3 traffic type
2999 :param sw_if_index: is the incoming interface for L2 traffic
3000 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
3001 """
3002 return self.api(
3003 self.papi.sr_steering_add_del,
3004 {'is_del': is_del,
3005 'bsid_addr': bsid_addr,
3006 'sr_policy_index': sr_policy_index,
3007 'table_id': table_id,
3008 'prefix_addr': prefix_addr,
3009 'mask_width': mask_width,
3010 'sw_if_index': sw_if_index,
3011 'traffic_type': traffic_type
3012 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02003013
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003014 def acl_add_replace(self, acl_index, r, tag='',
3015 expected_retval=0):
3016 """Add/replace an ACL
3017 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
3018 :param acl_rule r: ACL rules array.
3019 :param str tag: symbolic tag (description) for this ACL.
3020 :param int count: number of rules.
3021 """
3022 return self.api(self.papi.acl_add_replace,
3023 {'acl_index': acl_index,
3024 'r': r,
3025 'count': len(r),
3026 'tag': tag},
3027 expected_retval=expected_retval)
3028
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003029 def acl_del(self, acl_index, expected_retval=0):
3030 """
3031
3032 :param acl_index:
3033 :return:
3034 """
3035 return self.api(self.papi.acl_del,
3036 {'acl_index': acl_index},
3037 expected_retval=expected_retval)
3038
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003039 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3040 expected_retval=0):
3041 return self.api(self.papi.acl_interface_set_acl_list,
3042 {'sw_if_index': sw_if_index,
3043 'count': len(acls),
3044 'n_input': n_input,
3045 'acls': acls},
3046 expected_retval=expected_retval)
3047
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003048 def acl_interface_set_etype_whitelist(self, sw_if_index,
3049 n_input, whitelist,
3050 expected_retval=0):
3051 return self.api(self.papi.acl_interface_set_etype_whitelist,
3052 {'sw_if_index': sw_if_index,
3053 'count': len(whitelist),
3054 'n_input': n_input,
3055 'whitelist': whitelist},
3056 expected_retval=expected_retval)
3057
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003058 def acl_interface_add_del(self,
3059 sw_if_index,
3060 acl_index,
3061 is_add=1):
3062 """ Add/Delete ACL to/from interface
3063
3064 :param sw_if_index:
3065 :param acl_index:
3066 :param is_add: (Default value = 1)
3067 """
3068
3069 return self.api(self.papi.acl_interface_add_del,
3070 {'is_add': is_add,
3071 'is_input': 1,
3072 'sw_if_index': sw_if_index,
3073 'acl_index': acl_index})
3074
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003075 def acl_dump(self, acl_index, expected_retval=0):
3076 return self.api(self.papi.acl_dump,
3077 {'acl_index': acl_index},
3078 expected_retval=expected_retval)
3079
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003080 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3081 expected_retval=0):
3082 return self.api(self.papi.acl_interface_list_dump,
3083 {'sw_if_index': sw_if_index},
3084 expected_retval=expected_retval)
3085
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003086 def macip_acl_add(self, rules, tag=""):
3087 """ Add MACIP acl
3088
3089 :param rules: list of rules for given acl
3090 :param tag: acl tag
3091 """
3092
3093 return self.api(self.papi.macip_acl_add,
3094 {'r': rules,
3095 'count': len(rules),
3096 'tag': tag})
3097
Pavel Kotucek932f7412017-09-07 14:44:52 +02003098 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3099 """ Add MACIP acl
3100
3101 :param rules: list of rules for given acl
3102 :param tag: acl tag
3103 """
3104
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003105 return self.api(self.papi.macip_acl_add_replace,
3106 {'acl_index': acl_index,
3107 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003108 'count': len(rules),
3109 'tag': tag})
3110
3111 def macip_acl_del(self, acl_index):
3112 """
3113
3114 :param acl_index:
3115 :return:
3116 """
3117 return self.api(self.papi.macip_acl_del,
3118 {'acl_index': acl_index})
3119
3120 def macip_acl_interface_add_del(self,
3121 sw_if_index,
3122 acl_index,
3123 is_add=1):
3124 """ Add MACIP acl to interface
3125
3126 :param sw_if_index:
3127 :param acl_index:
3128 :param is_add: (Default value = 1)
3129 """
3130
3131 return self.api(self.papi.macip_acl_interface_add_del,
3132 {'is_add': is_add,
3133 'sw_if_index': sw_if_index,
3134 'acl_index': acl_index})
3135
3136 def macip_acl_interface_get(self):
3137 """ Return interface acls dump
3138 """
3139 return self.api(
3140 self.papi.macip_acl_interface_get, {})
3141
3142 def macip_acl_dump(self, acl_index=4294967295):
3143 """ Return MACIP acl dump
3144 """
3145
3146 return self.api(
3147 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003148
3149 def policer_add_del(self,
3150 name,
3151 cir,
3152 eir,
3153 cb,
3154 eb,
3155 is_add=1,
3156 rate_type=0,
3157 round_type=0,
3158 ptype=0,
3159 color_aware=0,
3160 conform_action_type=1,
3161 conform_dscp=0,
3162 exceed_action_type=0,
3163 exceed_dscp=0,
3164 violate_action_type=0,
3165 violate_dscp=0):
3166 return self.api(self.papi.policer_add_del,
3167 {'name': name,
3168 'cir': cir,
3169 'eir': eir,
3170 'cb': cb,
3171 'eb': eb,
3172 'is_add': is_add,
3173 'rate_type': rate_type,
3174 'round_type': round_type,
3175 'type': ptype,
3176 'color_aware': color_aware,
3177 'conform_action_type': conform_action_type,
3178 'conform_dscp': conform_dscp,
3179 'exceed_action_type': exceed_action_type,
3180 'exceed_dscp': exceed_dscp,
3181 'violate_action_type': violate_action_type,
3182 'violate_dscp': violate_dscp})
3183
3184 def ip_punt_police(self,
3185 policer_index,
3186 is_ip6=0,
3187 is_add=1):
3188 return self.api(self.papi.ip_punt_police,
3189 {'policer_index': policer_index,
3190 'is_add': is_add,
3191 'is_ip6': is_ip6})
3192
3193 def ip_punt_redirect(self,
3194 rx_sw_if_index,
3195 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003196 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07003197 is_add=1):
3198 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003199 {'punt': {'rx_sw_if_index': rx_sw_if_index,
3200 'tx_sw_if_index': tx_sw_if_index,
3201 'nh': address},
3202 'is_add': is_add})
3203
3204 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
3205 return self.api(self.papi.ip_punt_redirect_dump,
3206 {'sw_if_index': sw_if_index,
3207 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003208
3209 def bier_table_add_del(self,
3210 bti,
3211 mpls_label,
3212 is_add=1):
3213 """ BIER Table add/del """
3214 return self.api(
3215 self.papi.bier_table_add_del,
3216 {'bt_tbl_id': {"bt_set": bti.set_id,
3217 "bt_sub_domain": bti.sub_domain_id,
3218 "bt_hdr_len_id": bti.hdr_len_id},
3219 'bt_label': mpls_label,
3220 'bt_is_add': is_add})
3221
3222 def bier_table_dump(self):
3223 return self.api(self.papi.bier_table_dump, {})
3224
3225 def bier_route_add_del(self,
3226 bti,
3227 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003228 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003229 is_add=1,
3230 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003231 """ BIER Route add/del """
3232 return self.api(
3233 self.papi.bier_route_add_del,
3234 {'br_tbl_id': {"bt_set": bti.set_id,
3235 "bt_sub_domain": bti.sub_domain_id,
3236 "bt_hdr_len_id": bti.hdr_len_id},
3237 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003238 'br_n_paths': len(paths),
3239 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003240 'br_is_add': is_add,
3241 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003242
3243 def bier_route_dump(self, bti):
3244 return self.api(
3245 self.papi.bier_route_dump,
3246 {'br_tbl_id': {"bt_set": bti.set_id,
3247 "bt_sub_domain": bti.sub_domain_id,
3248 "bt_hdr_len_id": bti.hdr_len_id}})
3249
3250 def bier_imp_add(self,
3251 bti,
3252 src,
3253 ibytes,
3254 is_add=1):
3255 """ BIER Imposition Add """
3256 return self.api(
3257 self.papi.bier_imp_add,
3258 {'bi_tbl_id': {"bt_set": bti.set_id,
3259 "bt_sub_domain": bti.sub_domain_id,
3260 "bt_hdr_len_id": bti.hdr_len_id},
3261 'bi_src': src,
3262 'bi_n_bytes': len(ibytes),
3263 'bi_bytes': ibytes})
3264
3265 def bier_imp_del(self, bi_index):
3266 """ BIER Imposition del """
3267 return self.api(
3268 self.papi.bier_imp_del,
3269 {'bi_index': bi_index})
3270
3271 def bier_imp_dump(self):
3272 return self.api(self.papi.bier_imp_dump, {})
3273
3274 def bier_disp_table_add_del(self,
3275 bdti,
3276 is_add=1):
3277 """ BIER Disposition Table add/del """
3278 return self.api(
3279 self.papi.bier_disp_table_add_del,
3280 {'bdt_tbl_id': bdti,
3281 'bdt_is_add': is_add})
3282
3283 def bier_disp_table_dump(self):
3284 return self.api(self.papi.bier_disp_table_dump, {})
3285
3286 def bier_disp_entry_add_del(self,
3287 bdti,
3288 bp,
3289 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003290 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003291 next_hop,
3292 next_hop_tbl_id=0,
3293 next_hop_rpf_id=~0,
3294 next_hop_is_ip4=1,
3295 is_add=1):
3296 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003297 lstack = []
3298 while (len(lstack) < 16):
3299 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003300 return self.api(
3301 self.papi.bier_disp_entry_add_del,
3302 {'bde_tbl_id': bdti,
3303 'bde_bp': bp,
3304 'bde_payload_proto': payload_proto,
3305 'bde_n_paths': 1,
3306 'bde_paths': [{'next_hop': next_hop,
3307 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003308 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003309 'rpf_id': next_hop_rpf_id,
3310 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003311 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003312 'bde_is_add': is_add})
3313
3314 def bier_disp_entry_dump(self, bdti):
3315 return self.api(
3316 self.papi.bier_disp_entry_dump,
3317 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003318
3319 def add_node_next(self, node_name, next_name):
3320 """ Set the next node for a given node request
3321
3322 :param node_name:
3323 :param next_name:
3324 """
3325 return self.api(self.papi.add_node_next,
3326 {'node_name': node_name,
3327 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003328
3329 def session_enable_disable(self, is_enabled):
3330 return self.api(
3331 self.papi.session_enable_disable,
3332 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003333
3334 def ipsec_spd_add_del(self, spd_id, is_add=1):
3335 """ SPD add/del - Wrapper to add or del ipsec SPD
3336 Sample CLI : 'ipsec spd add 1'
3337
3338 :param spd_id - SPD ID to be created in the vpp . mandatory
3339 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3340 optional
3341 :returns: reply from the API
3342 """
3343 return self.api(
3344 self.papi.ipsec_spd_add_del, {
3345 'spd_id': spd_id, 'is_add': is_add})
3346
Neale Ranns311124e2019-01-24 04:52:25 -08003347 def ipsec_spds_dump(self):
3348 return self.api(self.papi.ipsec_spds_dump, {})
3349
“mystarrocks”23f0c452017-12-11 07:11:51 -08003350 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3351 """ IPSEC interface SPD add/del - \
3352 Wrapper to associate/disassociate SPD to interface in VPP
3353 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3354
3355 :param spd_id - SPD ID to associate with the interface . mandatory
3356 :param sw_if_index - Interface Index which needs to ipsec \
3357 association mandatory
3358 :param is_add - add(1) or del(0) association with interface \
3359 (Default 1 - add) . optional
3360 :returns: reply from the API
3361 """
3362 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003363 self.papi.ipsec_interface_add_del_spd,
3364 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003365
Neale Ranns311124e2019-01-24 04:52:25 -08003366 def ipsec_spd_interface_dump(self, spd_index=None):
3367 return self.api(self.papi.ipsec_spd_interface_dump,
3368 {'spd_index': spd_index if spd_index else 0,
3369 'spd_index_valid': 1 if spd_index else 0})
3370
Neale Ranns17dcec02019-01-09 21:22:20 -08003371 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003372 sad_id,
3373 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003374 integrity_algorithm,
3375 integrity_key,
3376 crypto_algorithm,
3377 crypto_key,
3378 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003379 tunnel_src_address='',
3380 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08003381 flags=0,
3382 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003383 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003384 :param sad_id: security association ID
3385 :param spi: security param index of the SA in decimal
3386 :param integrity_algorithm:
3387 :param integrity_key:
3388 :param crypto_algorithm:
3389 :param crypto_key:
3390 :param protocol: AH(0) or ESP(1) protocol
3391 :param tunnel_src_address: tunnel mode outer src address
3392 :param tunnel_dst_address: tunnel mode outer dst address
3393 :param is_add:
3394 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003395 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3396 crypto and ipsec algorithms
3397 """
3398 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08003399 self.papi.ipsec_sad_entry_add_del,
3400 {
3401 'is_add': is_add,
3402 'entry':
3403 {
3404 'sad_id': sad_id,
3405 'spi': spi,
3406 'tunnel_src': tunnel_src_address,
3407 'tunnel_dst': tunnel_dst_address,
3408 'protocol': protocol,
3409 'integrity_algorithm': integrity_algorithm,
3410 'integrity_key': {
3411 'length': len(integrity_key),
3412 'data': integrity_key,
3413 },
3414 'crypto_algorithm': crypto_algorithm,
3415 'crypto_key': {
3416 'length': len(crypto_key),
3417 'data': crypto_key,
3418 },
3419 'flags': flags,
3420 }
3421 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08003422
Neale Ranns311124e2019-01-24 04:52:25 -08003423 def ipsec_sa_dump(self, sa_id=None):
3424 return self.api(self.papi.ipsec_sa_dump,
3425 {'sa_id': sa_id if sa_id else 0xffffffff})
3426
Neale Ranns17dcec02019-01-09 21:22:20 -08003427 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003428 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003429 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003430 local_address_start,
3431 local_address_stop,
3432 remote_address_start,
3433 remote_address_stop,
3434 local_port_start=0,
3435 local_port_stop=65535,
3436 remote_port_start=0,
3437 remote_port_stop=65535,
3438 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003439 policy=0,
3440 priority=100,
3441 is_outbound=1,
3442 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003443 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003444 is_ip_any=0):
3445 """ IPSEC policy SPD add/del -
3446 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003447 :param spd_id: SPD ID for the policy
3448 :param local_address_start: local-ip-range start address
3449 :param local_address_stop : local-ip-range stop address
3450 :param remote_address_start: remote-ip-range start address
3451 :param remote_address_stop : remote-ip-range stop address
3452 :param local_port_start: (Default value = 0)
3453 :param local_port_stop: (Default value = 65535)
3454 :param remote_port_start: (Default value = 0)
3455 :param remote_port_stop: (Default value = 65535)
3456 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3457 :param sa_id: Security Association ID for mapping it to SPD
3458 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3459 (Default value = 0)
3460 :param priority: value for the spd action (Default value = 100)
3461 :param is_outbound: flag for inbound(0) or outbound(1)
3462 (Default value = 1)
3463 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003464 """
3465 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08003466 self.papi.ipsec_spd_entry_add_del,
3467 {
3468 'is_add': is_add,
3469 'entry':
3470 {
3471 'spd_id': spd_id,
3472 'sa_id': sa_id,
3473 'local_address_start': local_address_start,
3474 'local_address_stop': local_address_stop,
3475 'remote_address_start': remote_address_start,
3476 'remote_address_stop': remote_address_stop,
3477 'local_port_start': local_port_start,
3478 'local_port_stop': local_port_stop,
3479 'remote_port_start': remote_port_start,
3480 'remote_port_stop': remote_port_stop,
3481 'protocol': protocol,
3482 'policy': policy,
3483 'priority': priority,
3484 'is_outbound': is_outbound,
3485 'is_ip_any': is_ip_any
3486 }
3487 })
Florin Corasb795bd02017-12-14 11:30:48 -08003488
Neale Ranns311124e2019-01-24 04:52:25 -08003489 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
3490 return self.api(self.papi.ipsec_spd_dump,
3491 {'spd_id': spd_id,
3492 'sa_id': sa_id})
3493
Klement Sekera31da2e32018-06-24 22:49:55 +02003494 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3495 remote_spi, crypto_alg, local_crypto_key,
3496 remote_crypto_key, integ_alg, local_integ_key,
3497 remote_integ_key, is_add=1, esn=0,
3498 anti_replay=1, renumber=0, show_instance=0):
3499 return self.api(
3500 self.papi.ipsec_tunnel_if_add_del,
3501 {'local_ip': local_ip, 'remote_ip': remote_ip,
3502 'local_spi': local_spi, 'remote_spi': remote_spi,
3503 'crypto_alg': crypto_alg,
3504 'local_crypto_key_len': len(local_crypto_key),
3505 'local_crypto_key': local_crypto_key,
3506 'remote_crypto_key_len': len(remote_crypto_key),
3507 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3508 'local_integ_key_len': len(local_integ_key),
3509 'local_integ_key': local_integ_key,
3510 'remote_integ_key_len': len(remote_integ_key),
3511 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3512 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3513 'show_instance': show_instance
3514 })
3515
Klement Sekerab4d30532018-11-08 13:00:02 +01003516 def ipsec_select_backend(self, protocol, index):
3517 return self.api(self.papi.ipsec_select_backend,
3518 {'protocol': protocol, 'index': index})
3519
3520 def ipsec_backend_dump(self):
3521 return self.api(self.papi.ipsec_backend_dump, {})
3522
Florin Corasb795bd02017-12-14 11:30:48 -08003523 def app_namespace_add(self,
3524 namespace_id,
3525 ip4_fib_id=0,
3526 ip6_fib_id=0,
3527 sw_if_index=0xFFFFFFFF,
3528 secret=0):
3529 return self.api(
3530 self.papi.app_namespace_add_del,
3531 {'secret': secret,
3532 'sw_if_index': sw_if_index,
3533 'ip4_fib_id': ip4_fib_id,
3534 'ip6_fib_id': ip6_fib_id,
3535 'namespace_id': namespace_id,
3536 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003537
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003538 def punt_socket_register(self, port, pathname, protocol=0x11,
3539 header_version=1, is_ip4=1):
3540 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02003541 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003542 {'header_version': header_version,
3543 'punt': {'ipv': is_ip4,
3544 'l4_protocol': protocol,
3545 'l4_port': port},
3546 'pathname': pathname})
3547
3548 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
3549 """ Unregister punt socket """
3550 return self.api(self.papi.punt_socket_deregister,
3551 {'punt': {'ipv': is_ip4,
3552 'l4_protocol': protocol,
3553 'l4_port': port}})
3554
3555 def punt_socket_dump(self, is_ip6=1):
3556 """ Dump punt socket"""
3557 return self.api(self.papi.punt_socket_dump,
3558 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02003559
3560 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3561 expire_walk_interval_ms, is_ip6=0):
3562 """ Set IP reassembly parameters """
3563 return self.api(self.papi.ip_reassembly_set,
3564 {'is_ip6': is_ip6,
3565 'timeout_ms': timeout_ms,
3566 'expire_walk_interval_ms': expire_walk_interval_ms,
3567 'max_reassemblies': max_reassemblies})
3568
3569 def ip_reassembly_get(self, is_ip6=0):
3570 """ Get IP reassembly parameters """
3571 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003572
Klement Sekera4c533132018-02-22 11:41:12 +01003573 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3574 enable_ip6=False):
3575 """ Enable/disable IP reassembly """
3576 return self.api(self.papi.ip_reassembly_enable_disable,
3577 {'sw_if_index': sw_if_index,
3578 'enable_ip4': 1 if enable_ip4 else 0,
3579 'enable_ip6': 1 if enable_ip6 else 0,
3580 })
3581
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003582 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3583 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003584 """ GBP endpoint Add """
3585 return self.api(self.papi.gbp_endpoint_add,
3586 {'endpoint': {
3587 'sw_if_index': sw_if_index,
3588 'ips': ips,
3589 'n_ips': len(ips),
3590 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003591 'epg_id': epg,
3592 'flags': flags,
3593 'tun': {
3594 'src': tun_src,
3595 'dst': tun_dst,
3596 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003597
3598 def gbp_endpoint_del(self, handle):
3599 """ GBP endpoint Del """
3600 return self.api(self.papi.gbp_endpoint_del,
3601 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003602
3603 def gbp_endpoint_dump(self):
3604 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003605 return self.api(self.papi.gbp_endpoint_dump,
3606 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003607
Neale Ranns879d11c2019-01-21 23:34:18 -08003608 def gbp_endpoint_group_add(self, epg, sclass, bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003609 rd, uplink_sw_if_index):
3610 """ GBP endpoint group Add """
3611 return self.api(self.papi.gbp_endpoint_group_add,
3612 {'epg':
3613 {
Neale Ranns25b04942018-04-04 09:34:50 -07003614 'uplink_sw_if_index': uplink_sw_if_index,
3615 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003616 'rd_id': rd,
Neale Ranns879d11c2019-01-21 23:34:18 -08003617 'epg_id': epg,
3618 'sclass': sclass
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003619 }})
3620
3621 def gbp_endpoint_group_del(self, epg):
3622 """ GBP endpoint group Del """
3623 return self.api(self.papi.gbp_endpoint_group_del,
3624 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003625
3626 def gbp_endpoint_group_dump(self):
3627 """ GBP endpoint group Dump """
3628 return self.api(self.papi.gbp_endpoint_group_dump, {})
3629
Neale Rannsc29c0af2018-11-07 04:21:12 -08003630 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003631 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08003632 uu_fwd_sw_if_index,
3633 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003634 """ GBP bridge-domain Add """
3635 return self.api(self.papi.gbp_bridge_domain_add,
3636 {'bd':
3637 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003638 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003639 'bvi_sw_if_index': bvi_sw_if_index,
3640 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08003641 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003642 'bd_id': bd_id
3643 }})
3644
3645 def gbp_bridge_domain_del(self, bd_id):
3646 """ GBP bridge-domain Del """
3647 return self.api(self.papi.gbp_bridge_domain_del,
3648 {'bd_id': bd_id})
3649
3650 def gbp_bridge_domain_dump(self):
3651 """ GBP Bridge Domain Dump """
3652 return self.api(self.papi.gbp_bridge_domain_dump, {})
3653
3654 def gbp_route_domain_add(self, rd_id,
3655 ip4_table_id,
3656 ip6_table_id,
3657 ip4_uu_sw_if_index,
3658 ip6_uu_sw_if_index):
3659 """ GBP route-domain Add """
3660 return self.api(self.papi.gbp_route_domain_add,
3661 {'rd':
3662 {
3663 'ip4_table_id': ip4_table_id,
3664 'ip6_table_id': ip6_table_id,
3665 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3666 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3667 'rd_id': rd_id
3668 }})
3669
3670 def gbp_route_domain_del(self, rd_id):
3671 """ GBP route-domain Del """
3672 return self.api(self.papi.gbp_route_domain_del,
3673 {'rd_id': rd_id})
3674
3675 def gbp_route_domain_dump(self):
3676 """ GBP Route Domain Dump """
3677 return self.api(self.papi.gbp_route_domain_dump, {})
3678
Neale Ranns25b04942018-04-04 09:34:50 -07003679 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3680 """ GBP recirc Add/Del """
3681 return self.api(self.papi.gbp_recirc_add_del,
3682 {'is_add': is_add,
3683 'recirc': {
3684 'is_ext': is_ext,
3685 'sw_if_index': sw_if_index,
3686 'epg_id': epg}})
3687
3688 def gbp_recirc_dump(self):
3689 """ GBP recirc Dump """
3690 return self.api(self.papi.gbp_recirc_dump, {})
3691
Neale Rannsb6a47952018-11-21 05:44:35 -08003692 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
3693 """ GBP recirc Add/Del """
3694 return self.api(self.papi.gbp_ext_itf_add_del,
3695 {'is_add': is_add,
3696 'ext_itf': {
3697 'sw_if_index': sw_if_index,
3698 'bd_id': bd_id,
3699 'rd_id': rd_id}})
3700
3701 def gbp_ext_itf_dump(self):
3702 """ GBP recirc Dump """
3703 return self.api(self.papi.gbp_ext_itf_dump, {})
3704
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003705 def gbp_subnet_add_del(self, is_add, rd_id,
3706 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003707 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003708 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003709 """ GBP Subnet Add/Del """
3710 return self.api(self.papi.gbp_subnet_add_del,
3711 {'is_add': is_add,
3712 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003713 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003714 'sw_if_index': sw_if_index,
3715 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003716 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003717 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003718
3719 def gbp_subnet_dump(self):
3720 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003721 return self.api(self.papi.gbp_subnet_dump,
3722 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07003723
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003724 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index,
3725 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003726 """ GBP contract Add/Del """
3727 return self.api(self.papi.gbp_contract_add_del,
3728 {'is_add': is_add,
3729 'contract': {
3730 'acl_index': acl_index,
3731 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003732 'dst_epg': dst_epg,
3733 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003734 'rules': rules,
3735 'n_ether_types': len(allowed_ethertypes),
3736 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003737
3738 def gbp_contract_dump(self):
3739 """ GBP contract Dump """
3740 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003741
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003742 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3743 """ GBP set inactive threshold """
3744 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3745 {'threshold': threshold})
3746
3747 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3748 """ GBP VXLAN tunnel add """
3749 return self.api(self.papi.gbp_vxlan_tunnel_add,
3750 {
3751 'tunnel': {
3752 'vni': vni,
3753 'mode': mode,
3754 'bd_rd_id': bd_rd_id
3755 }
3756 })
3757
3758 def gbp_vxlan_tunnel_del(self, vni):
3759 """ GBP VXLAN tunnel del """
3760 return self.api(self.papi.gbp_vxlan_tunnel_del,
3761 {
3762 'vni': vni,
3763 })
3764
3765 def gbp_vxlan_tunnel_dump(self):
3766 """ GBP VXLAN tunnel add/del """
3767 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3768
Neale Ranns61502112018-08-22 00:21:14 -07003769 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3770 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003771 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003772 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003773 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003774 {'ip4_table_id': ip4_table_id,
3775 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003776 'ip6_prefix': ip6_prefix,
3777 'ip6_prefix_len': ip6_prefix_len,
3778 'ip4_prefix': ip4_prefix,
3779 'ip4_prefix_len': ip4_prefix_len,
3780 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003781 'security_check': security_check})
3782
Ole Troan298c6952018-03-08 12:30:43 +01003783 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003784 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003785 return self.api(self.papi.ipip_6rd_del_tunnel,
3786 {'sw_if_index': sw_if_index})
3787
3788 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003789 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003790 """ IPIP tunnel Add/Del """
3791 return self.api(self.papi.ipip_add_tunnel,
3792 {'is_ipv6': is_ipv6,
3793 'instance': instance,
3794 'src_address': src_address,
3795 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003796 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003797 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003798
3799 def ipip_del_tunnel(self, sw_if_index):
3800 """ IPIP tunnel Delete """
3801 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003802 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003803
3804 def qos_egress_map_update(self, id, outputs):
3805 """ QOS egress map update """
3806 return self.api(self.papi.qos_egress_map_update,
3807 {'map_id': id,
3808 'rows': outputs})
3809
3810 def qos_egress_map_delete(self, id):
3811 """ QOS egress map delete """
3812 return self.api(self.papi.qos_egress_map_delete,
3813 {'map_id': id})
3814
3815 def qos_mark_enable_disable(self, sw_if_index,
3816 output_source,
3817 map_id,
3818 enable):
3819 """ QOS Mark Enable/Disable """
3820 return self.api(self.papi.qos_mark_enable_disable,
3821 {'map_id': map_id,
3822 'sw_if_index': sw_if_index,
3823 'output_source': output_source,
3824 'enable': enable})
3825
3826 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3827 """ IP QoS recording Enble/Disable """
3828 return self.api(self.papi.qos_record_enable_disable,
3829 {'sw_if_index': sw_if_index,
3830 'input_source': input_source,
3831 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003832
Neale Ranns947ea622018-06-07 23:48:20 -07003833 def igmp_enable_disable(self, sw_if_index, enable, host):
3834 """ Enable/disable IGMP on a given interface """
3835 return self.api(self.papi.igmp_enable_disable,
3836 {'enable': enable,
3837 'mode': host,
3838 'sw_if_index': sw_if_index})
3839
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003840 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3841 """ Add/del IGMP proxy device """
3842 return self.api(self.papi.igmp_proxy_device_add_del,
3843 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3844 'add': add})
3845
3846 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3847 """ Add/del interface to/from IGMP proxy device """
3848 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3849 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3850 'add': add})
3851
Neale Ranns947ea622018-06-07 23:48:20 -07003852 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003853 """ Listen for new (S,G) on specified interface
3854
3855 :param enable: add/del
3856 :param sw_if_index: interface sw index
3857 :param saddr: source ip4 addr
3858 :param gaddr: group ip4 addr
3859 """
3860 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003861 {
3862 'group':
3863 {
3864 'filter': filter,
3865 'sw_if_index': sw_if_index,
3866 'n_srcs': len(saddrs),
3867 'saddrs': saddrs,
Ole Troan8c8acc02018-11-27 10:05:23 +01003868 'gaddr': gaddr
Neale Ranns947ea622018-06-07 23:48:20 -07003869 }
3870 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003871
3872 def igmp_dump(self, sw_if_index=None):
3873 """ Dump all (S,G) interface configurations """
3874 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003875 sw_if_index = 0xffffffff
3876 return self.api(self.papi.igmp_dump,
3877 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003878
3879 def igmp_clear_interface(self, sw_if_index):
3880 """ Remove all (S,G)s from specified interface
3881 doesn't send IGMP report!
3882 """
3883 return self.api(
3884 self.papi.igmp_clear_interface, {
3885 'sw_if_index': sw_if_index})
3886
3887 def want_igmp_events(self, enable=1):
3888 return self.api(self.papi.want_igmp_events, {'enable': enable,
3889 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003890
3891 def bond_create(
3892 self,
3893 mode,
3894 lb,
3895 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003896 mac_address='',
3897 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08003898 """
3899 :param mode: mode
3900 :param lb: load balance
3901 :param use_custom_mac: use custom mac
3902 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003903 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08003904 """
3905 return self.api(
3906 self.papi.bond_create,
3907 {'mode': mode,
3908 'lb': lb,
3909 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003910 'mac_address': mac_address,
3911 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08003912 })
3913
3914 def bond_delete(
3915 self,
3916 sw_if_index):
3917 """
3918 :param sw_if_index: interface the operation is applied to
3919 """
3920 return self.api(self.papi.bond_delete,
3921 {'sw_if_index': sw_if_index})
3922
3923 def bond_enslave(
3924 self,
3925 sw_if_index,
3926 bond_sw_if_index,
3927 is_passive,
3928 is_long_timeout):
3929 """
3930 :param sw_if_index: slave sw_if_index
3931 :param bond_sw_if_index: bond sw_if_index
3932 :param is_passive: is passive lacp speaker
3933 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3934 """
3935 return self.api(
3936 self.papi.bond_enslave,
3937 {'sw_if_index': sw_if_index,
3938 'bond_sw_if_index': bond_sw_if_index,
3939 'is_passive': is_passive,
3940 'is_long_timeout': is_long_timeout
3941 })
3942
3943 def bond_detach_slave(
3944 self,
3945 sw_if_index):
3946 """
3947 :param sw_if_index: slave interface the operation is applied to
3948 """
3949 return self.api(self.papi.bond_detach_slave,
3950 {'sw_if_index': sw_if_index})
3951
3952 def sw_interface_slave_dump(
3953 self,
3954 sw_if_index):
3955 """
3956 :param sw_if_index: bond sw_if_index
3957 """
3958 return self.api(self.papi.sw_interface_slave_dump,
3959 {'sw_if_index': sw_if_index})
3960
3961 def sw_interface_bond_dump(
3962 self):
3963 """
3964
3965 """
3966 return self.api(self.papi.sw_interface_bond_dump,
3967 {})
Stevene8fa6202017-08-30 14:36:45 -07003968
3969 def create_vhost_user_if(
3970 self,
3971 is_server,
3972 sock_filename,
3973 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003974 disable_mrg_rxbuf,
3975 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003976 custom_dev_instance,
3977 use_custom_mac,
3978 mac_address,
3979 tag=''):
3980 """
3981 :param is_server: is server
3982 :param sock_filename: socket name
3983 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003984 :param disable_mrg_rxbuf: disable mergable rx buffers
3985 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003986 :param custom_dev_instance: custom dev instance
3987 :param use_custom_mac: use custom mac
3988 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003989 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003990 """
3991 return self.api(
3992 self.papi.create_vhost_user_if,
3993 {'is_server': is_server,
3994 'sock_filename': sock_filename,
3995 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003996 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3997 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003998 'custom_dev_instance': custom_dev_instance,
3999 'use_custom_mac': use_custom_mac,
4000 'mac_address': mac_address,
4001 'tag': tag
4002 })
4003
4004 def delete_vhost_user_if(
4005 self,
4006 sw_if_index):
4007 """
4008 :param sw_if_index: interface the operation is applied to
4009 """
4010 return self.api(self.papi.delete_vhost_user_if,
4011 {'sw_if_index': sw_if_index, })
4012
4013 def sw_interface_vhost_user_dump(
4014 self):
4015 """
4016
4017 """
4018 return self.api(self.papi.sw_interface_vhost_user_dump,
4019 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01004020
4021 def abf_policy_add_del(self, is_add, policy):
4022 return self.api(
4023 self.papi.abf_policy_add_del,
4024 {'is_add': is_add,
4025 'policy': policy})
4026
4027 def abf_itf_attach_add_del(self, is_add, attach):
4028 return self.api(
4029 self.papi.abf_itf_attach_add_del,
4030 {'is_add': is_add,
4031 'attach': attach})
4032
4033 def abf_policy_dump(self):
4034 return self.api(
4035 self.papi.abf_policy_dump, {})
4036
4037 def abf_itf_attach_dump(self):
4038 return self.api(
4039 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07004040
4041 def pipe_create(self, is_specified, user_instance):
4042 return self.api(self.papi.pipe_create,
4043 {'is_specified': is_specified,
4044 'user_instance': user_instance})
4045
4046 def pipe_delete(self, parent_sw_if_index):
4047 return self.api(self.papi.pipe_delete,
4048 {'parent_sw_if_index': parent_sw_if_index})
4049
4050 def pipe_dump(self):
4051 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02004052
4053 def memif_create(
4054 self,
4055 role,
4056 mode,
4057 rx_queues=None,
4058 tx_queues=None,
4059 _id=None,
4060 socket_id=None,
4061 secret=None,
4062 ring_size=None,
4063 buffer_size=None,
4064 hw_addr=None):
4065 return self.api(self.papi.memif_create,
4066 {'role': role,
4067 'mode': mode,
4068 'rx_queues': rx_queues,
4069 'tx_queues': tx_queues,
4070 'id': _id,
4071 'socket_id': socket_id,
4072 'secret': secret,
4073 'ring_size': ring_size,
4074 'buffer_size': buffer_size,
4075 'hw_addr': hw_addr})
4076
4077 def memif_delete(self, sw_if_index):
4078 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
4079
4080 def memif_dump(self):
4081 return self.api(self.papi.memif_dump, {})
4082
4083 def memif_socket_filename_add_del(
4084 self, is_add, socket_id, socket_filename):
4085 return self.api(
4086 self.papi.memif_socket_filename_add_del,
4087 {'is_add': is_add,
4088 'socket_id': socket_id,
4089 'socket_filename': socket_filename})
4090
4091 def memif_socket_filename_dump(self):
4092 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004093
4094 def svs_table_add_del(self, af, table_id, is_add=1):
4095 return self.api(self.papi.svs_table_add_del,
4096 {
4097 'table_id': table_id,
4098 'is_add': is_add,
4099 'af': af,
4100 })
4101
4102 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4103 return self.api(self.papi.svs_route_add_del,
4104 {
4105 'table_id': table_id,
4106 'source_table_id': src_table_id,
4107 'prefix': prefix,
4108 'is_add': is_add,
4109 })
4110
4111 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4112 return self.api(self.papi.svs_enable_disable,
4113 {
4114 'af': af,
4115 'table_id': table_id,
4116 'sw_if_index': sw_if_index,
4117 'is_enable': is_enable,
4118 })
4119
4120 def svs_dump(self):
4121 return self.api(self.papi.svs_dump, {})
Matus Fabianb4515b42018-11-19 04:25:32 -08004122
4123 def syslog_set_sender(
4124 self,
4125 collector,
4126 src,
4127 collector_port=514,
4128 vrf_id=0,
4129 max_msg_size=480):
4130 """Set syslog sender configuration
4131
4132 :param collector: colector IP address
4133 :param src: source IP address
4134 :param collector_port: collector UDP port (Default value = 514)
4135 :param vrf_id: VRF id (Default value = 0)
4136 :param max_msg_size: maximum message length (Default value = 480)
4137 """
4138 return self.api(self.papi.syslog_set_sender,
Ole Troan8c8acc02018-11-27 10:05:23 +01004139 {'collector_address': collector,
4140 'src_address': src,
Matus Fabianb4515b42018-11-19 04:25:32 -08004141 'collector_port': collector_port,
4142 'vrf_id': vrf_id,
4143 'max_msg_size': max_msg_size})
4144
4145 def syslog_get_sender(self):
4146 """Return syslog sender configuration"""
4147 return self.api(self.papi.syslog_get_sender, {})
4148
4149 def syslog_set_filter(self, severity):
4150 """Set syslog filter parameters
4151
4152 :param severity: severity filter (specified severity and greater match)
4153 """
4154 return self.api(self.papi.syslog_set_filter, {'severity': severity})
4155
4156 def syslog_get_filter(self):
4157 """Return syslog filter parameters"""
4158 return self.api(self.papi.syslog_get_filter, {})