blob: 9955518b2ef6d169bd6da5711b80ee4313243d46 [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
Ole Troanf159f582019-02-28 20:20:47 +01005from six import moves, iteritems
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
Ole Troanf159f582019-02-28 20:20:47 +010044#
45# Dictionary keyed on message name to override default values for
46# named parameters
47#
48defaultmapping = {'map_add_domain': {'mtu': 1280},
49 'syslog_set_sender': {'collector_port': 514,
50 'max_msg_size': 480}}
51
Matus Fabianb4515b42018-11-19 04:25:32 -080052
Klement Sekera73884482017-02-23 09:26:30 +010053class UnexpectedApiReturnValueError(Exception):
54 """ exception raised when the API return value is unexpected """
55 pass
56
57
Klement Sekeraf62ae122016-10-11 11:47:09 +020058class VppPapiProvider(object):
59 """VPP-api provider using vpp-papi
60
61 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020062 """
63
Klement Sekerae0545ef2017-01-25 08:00:40 +010064 _zero, _negative = range(2)
65
Klement Sekera611864f2018-09-26 11:19:00 +020066 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -080067 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +020068 self.name = name
69 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010070 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010071 self._expect_api_retval = self._zero
72 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010073
Klement Sekerab8c72a42018-11-08 11:21:39 +010074 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010075
Paul Vinciguerra04575c52019-01-13 10:26:05 -080076 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
77 if 'VPP_API_DIR' not in os.environ:
78 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
79
80 self.vpp = VPP(logger=test_class.logger,
Klement Sekera611864f2018-09-26 11:19:00 +020081 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010082 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020083
Klement Sekerae0545ef2017-01-25 08:00:40 +010084 def __enter__(self):
85 return self
86
Klement Sekera7d6afb32018-11-08 11:52:04 +010087 def assert_negative_api_retval(self):
88 """ Expect API failure - used with with, e.g.:
89 with self.vapi.assert_negative_api_retval():
90 self.vapi.<api call expected to fail>
91 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010092 self._expect_stack.append(self._expect_api_retval)
93 self._expect_api_retval = self._negative
94 return self
95
Klement Sekera7d6afb32018-11-08 11:52:04 +010096 def assert_zero_api_retval(self):
97 """ Expect API success - used with with, e.g.:
98 with self.vapi.assert_negative_api_retval():
99 self.vapi.<api call expected to succeed>
100
101 note: this is useful only inside another with block
102 as success is the default expected value
103 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100104 self._expect_stack.append(self._expect_api_retval)
105 self._expect_api_retval = self._zero
106 return self
107
108 def __exit__(self, exc_type, exc_value, traceback):
109 self._expect_api_retval = self._expect_stack.pop()
110
Klement Sekeraf62ae122016-10-11 11:47:09 +0200111 def register_hook(self, hook):
112 """Replace hook registration with new hook
113
114 :param hook:
115
116 """
117 self.hook = hook
118
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200119 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100120 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200121 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100122 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200123 return e
124
125 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100127 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100128 self.test_class.logger.debug("Expecting event '%s' within %ss",
129 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300130 else:
131 self.test_class.logger.debug("Expecting event within %ss",
132 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100133 if self._events:
134 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200135 limit = time.time() + timeout
136 while time.time() < limit:
137 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100138 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200139 if name and type(e).__name__ != name:
140 raise Exception(
141 "Unexpected event received: %s, expected: %s" %
142 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 self.test_class.logger.debug("Returning event %s:%s" %
144 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200145 return e
146 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200147 raise Exception("Event did not occur within timeout")
148
149 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100150 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200151 # FIXME use the name instead of relying on type(e).__name__ ?
152 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100153 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200154 self._events.append(event)
155
Ole Troanf159f582019-02-28 20:20:47 +0100156 def factory(self, name, apifn):
157 def f(*a, **ka):
158 fields = apifn._func.msg.fields
159
160 # add positional and kw arguments
161 d = ka
162 for i, o in enumerate(fields[3:]):
163 try:
164 d[o] = a[i]
165 except:
166 break
167
168 # Default override
169 if name in defaultmapping:
170 for k, v in iteritems(defaultmapping[name]):
171 if k in d:
172 continue
173 d[k] = v
174 return self.api(apifn, d)
175 return f
176
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800177 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100178 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800179 method = super(VppPapiProvider, self).__getattribute__(name)
180 except AttributeError:
181 method = self.factory(name, getattr(self.papi, name))
182 # lazily load the method so we don't need to call factory
183 # again for this name.
184 setattr(self, name, method)
185 return method
Ole Troanf159f582019-02-28 20:20:47 +0100186
Klement Sekeraf62ae122016-10-11 11:47:09 +0200187 def connect(self):
188 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100189 self.vpp.connect(self.name, self.shm_prefix)
190 self.papi = self.vpp.api
191 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200192
193 def disconnect(self):
194 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100195 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200196
197 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100198 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200199 Call the appropriate hooks before and after the API call
200
201 :param api_fn: API function to call
202 :param api_args: tuple of API function arguments
203 :param expected_retval: Expected return value (Default value = 0)
204 :returns: reply from the API
205
206 """
207 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100208 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100209 if self._expect_api_retval == self._negative:
210 if hasattr(reply, 'retval') and reply.retval >= 0:
211 msg = "API call passed unexpectedly: expected negative "\
212 "return value instead of %d in %s" % \
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800213 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100214 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100215 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100216 elif self._expect_api_retval == self._zero:
217 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700218 msg = "API call failed, expected %d return value instead "\
219 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800220 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100221 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100222 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100223 else:
224 raise Exception("Internal error, unexpected value for "
225 "self._expect_api_retval %s" %
226 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200227 self.hook.after_api(api_fn.__name__, api_args)
228 return reply
229
230 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100231 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200232
233 :param cli: CLI to execute
234 :returns: CLI output
235
236 """
237 self.hook.before_cli(cli)
238 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100239 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200240 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200241 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100242 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200243
Jan49c0fca2016-10-26 15:44:27 +0200244 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100245 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200246
247 :param cli: CLI to execute
248 :returns: CLI output
249 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600250 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200251
Klement Sekeraf62ae122016-10-11 11:47:09 +0200252 def show_version(self):
253 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100254 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200255
256 def pg_create_interface(self, pg_index):
257 """
258
259 :param pg_index:
260
261 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100262 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200263 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200264
265 def sw_interface_dump(self, filter=None):
266 """
267
268 :param filter: (Default value = None)
269
270 """
271 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200272 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200273 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100274 args = {}
275 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200276
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000277 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100278 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000279
280 :param sw_if_index:
281 :param is_ipv6:
282 :param table_id:
283
284 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100285 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200286 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
287 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000288
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700289 def sw_interface_get_table(self, sw_if_index, is_ipv6):
290 """ Get the IPvX Table-id for the Interface
291
292 :param sw_if_index:
293 :param is_ipv6:
294 :return table_id
295
296 """
297 return self.api(self.papi.sw_interface_get_table,
298 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
299
Klement Sekeraf62ae122016-10-11 11:47:09 +0200300 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
301 is_ipv6=0, is_add=1, del_all=0):
302 """
303
304 :param addr: param is_ipv6: (Default value = 0)
305 :param sw_if_index:
306 :param addr_len:
307 :param is_ipv6: (Default value = 0)
308 :param is_add: (Default value = 1)
309 :param del_all: (Default value = 0)
310
311 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100312 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200313 {'sw_if_index': sw_if_index,
314 'is_add': is_add,
315 'is_ipv6': is_ipv6,
316 'del_all': del_all,
317 'address_length': addr_len,
318 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200319
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700320 def ip_address_dump(self, sw_if_index, is_ipv6=0):
321 return self.api(self.papi.ip_address_dump,
322 {'sw_if_index': sw_if_index,
323 'is_ipv6': is_ipv6})
324
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800325 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
326 is_add=1):
327 """ Set the Interface to be unnumbered
328
329 :param is_add: (Default value = 1)
330 :param sw_if_index - interface That will be unnumbered
331 :param ip_sw_if_index - interface with an IP addres
332
333 """
334 return self.api(self.papi.sw_interface_set_unnumbered,
335 {'sw_if_index': ip_sw_if_index,
336 'unnumbered_sw_if_index': sw_if_index,
337 'is_add': is_add})
338
Neale Ranns404d88e2018-08-08 06:37:33 -0700339 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
340 return self.api(self.papi.ip_unnumbered_dump,
341 {'sw_if_index': sw_if_index})
342
Ole Troane1ade682019-03-04 23:55:43 +0100343 def sw_interface_set_mpls_enable(self, sw_if_index,
344 is_enable=1):
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000345 """
346 Enable/Disable MPLS on the interface
347 :param sw_if_index:
348 :param is_enable: (Default value = 1)
349
350 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100351 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200352 {'sw_if_index': sw_if_index,
353 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000354
Neale Ranns227038a2017-04-21 01:07:59 -0700355 def set_ip_flow_hash(self,
356 table_id,
357 src=1,
358 dst=1,
359 sport=1,
360 dport=1,
361 proto=1,
362 reverse=0,
363 is_ip6=0):
364 return self.api(self.papi.set_ip_flow_hash,
365 {'vrf_id': table_id,
366 'src': src,
367 'dst': dst,
368 'dport': dport,
369 'sport': sport,
370 'proto': proto,
371 'reverse': reverse,
372 'is_ipv6': is_ip6})
373
Ole Troane1ade682019-03-04 23:55:43 +0100374 def ip6nd_proxy_add_del(self, ip, sw_if_index, is_del=0):
Neale Ranns3f844d02017-02-18 00:03:54 -0800375 return self.api(self.papi.ip6nd_proxy_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700376 {'ip': ip,
Neale Ranns3f844d02017-02-18 00:03:54 -0800377 'sw_if_index': sw_if_index,
378 'is_del': is_del})
379
Ole Troane1ade682019-03-04 23:55:43 +0100380 def sw_interface_ip6nd_ra_prefix(self,
381 sw_if_index,
382 address,
383 address_length,
384 use_default=0,
385 no_advertise=0,
386 off_link=0,
387 no_autoconfig=0,
388 no_onlink=0,
389 is_no=0,
390 val_lifetime=0xffffffff,
391 pref_lifetime=0xffffffff):
Neale Ranns87df12d2017-02-18 08:16:41 -0800392 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
393 {'sw_if_index': sw_if_index,
Neale Ranns37029302018-08-10 05:30:06 -0700394 'prefix': {
395 'address': address,
396 'address_length': address_length,
397 },
Neale Ranns87df12d2017-02-18 08:16:41 -0800398 'use_default': use_default,
399 'no_advertise': no_advertise,
400 'off_link': off_link,
401 'no_autoconfig': no_autoconfig,
402 'no_onlink': no_onlink,
403 'is_no': is_no,
404 'val_lifetime': val_lifetime,
405 'pref_lifetime': pref_lifetime})
406
Ole Troane1ade682019-03-04 23:55:43 +0100407 def sw_interface_ip6_enable_disable(self, sw_if_index, enable):
Neale Ranns75152282017-01-09 01:00:45 -0800408 """
409 Enable/Disable An interface for IPv6
410 """
411 return self.api(self.papi.sw_interface_ip6_enable_disable,
412 {'sw_if_index': sw_if_index,
413 'enable': enable})
414
Klement Sekeraf62ae122016-10-11 11:47:09 +0200415 def vxlan_add_del_tunnel(
416 self,
417 src_addr,
418 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200419 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200420 is_add=1,
421 is_ipv6=0,
422 encap_vrf_id=0,
423 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600424 vni=0,
425 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200426 """
427
428 :param dst_addr:
429 :param src_addr:
430 :param is_add: (Default value = 1)
431 :param is_ipv6: (Default value = 0)
432 :param encap_vrf_id: (Default value = 0)
433 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200434 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200435 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600436 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200437
438 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100439 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200440 {'is_add': is_add,
441 'is_ipv6': is_ipv6,
442 'src_address': src_addr,
443 'dst_address': dst_addr,
444 'mcast_sw_if_index': mcast_sw_if_index,
445 'encap_vrf_id': encap_vrf_id,
446 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600447 'vni': vni,
448 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200449
Marco Varleseb598f1d2017-09-19 14:25:28 +0200450 def geneve_add_del_tunnel(
451 self,
452 local_addr,
453 remote_addr,
454 mcast_sw_if_index=0xFFFFFFFF,
455 is_add=1,
456 is_ipv6=0,
457 encap_vrf_id=0,
458 decap_next_index=0xFFFFFFFF,
459 vni=0):
460 """
461
462 :param remote_addr:
463 :param local_addr:
464 :param is_add: (Default value = 1)
465 :param is_ipv6: (Default value = 0)
466 :param encap_vrf_id: (Default value = 0)
467 :param decap_next_index: (Default value = 0xFFFFFFFF)
468 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
469 :param vni: (Default value = 0)
470
471 """
472 return self.api(self.papi.geneve_add_del_tunnel,
473 {'is_add': is_add,
474 'is_ipv6': is_ipv6,
475 'local_address': local_addr,
476 'remote_address': remote_addr,
477 'mcast_sw_if_index': mcast_sw_if_index,
478 'encap_vrf_id': encap_vrf_id,
479 'decap_next_index': decap_next_index,
480 'vni': vni})
481
Jan4af521d2016-11-15 17:05:00 +0100482 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
483 learn=1, arp_term=0, is_add=1):
484 """Create/delete bridge domain.
485
486 :param int bd_id: Bridge domain index.
487 :param int flood: Enable/disable bcast/mcast flooding in the BD.
488 (Default value = 1)
489 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
490 (Default value = 1)
491 :param int forward: Enable/disable forwarding on all interfaces in
492 the BD. (Default value = 1)
493 :param int learn: Enable/disable learning on all interfaces in the BD.
494 (Default value = 1)
495 :param int arp_term: Enable/disable arp termination in the BD.
496 (Default value = 1)
497 :param int is_add: Add or delete flag. (Default value = 1)
498 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100499 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200500 {'bd_id': bd_id,
501 'flood': flood,
502 'uu_flood': uu_flood,
503 'forward': forward,
504 'learn': learn,
505 'arp_term': arp_term,
506 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100507
Eyal Baric86e5922017-07-02 18:33:16 +0300508 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
509 return self.api(self.papi.bd_ip_mac_add_del,
510 {'bd_id': bd_id,
511 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700512 'ip': ip,
513 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300514
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700515 def bd_ip_mac_dump(self, bd_id):
516 return self.api(self.papi.bd_ip_mac_dump,
517 {'bd_id': bd_id})
518
Neale Ranns37029302018-08-10 05:30:06 -0700519 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300520 return self.api(self.papi.want_ip4_arp_events,
521 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700522 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300523 'pid': os.getpid(), })
524
Neale Ranns37029302018-08-10 05:30:06 -0700525 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300526 return self.api(self.papi.want_ip6_nd_events,
527 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700528 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300529 'pid': os.getpid(), })
530
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100531 def want_ip6_ra_events(self, enable_disable=1):
532 return self.api(self.papi.want_ip6_ra_events,
533 {'enable_disable': enable_disable,
534 'pid': os.getpid(), })
535
536 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
537 mrc=0, mrd=0):
538 return self.api(self.papi.ip6nd_send_router_solicitation,
539 {'irt': irt,
540 'mrt': mrt,
541 'mrc': mrc,
542 'mrd': mrd,
543 'sw_if_index': sw_if_index})
544
Juraj Slobodac0374232018-02-01 15:18:49 +0100545 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
546 install_default_routes):
547 return self.api(self.papi.ip6_nd_address_autoconfig,
548 {'sw_if_index': sw_if_index,
549 'enable': enable,
550 'install_default_routes': install_default_routes})
551
Juraj Slobodab3f90502018-10-04 15:15:16 +0200552 def want_interface_events(self, enable_disable=1):
553 return self.api(self.papi.want_interface_events,
554 {'enable_disable': enable_disable,
555 'pid': os.getpid(), })
556
Ole Troane1ade682019-03-04 23:55:43 +0100557 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
558 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300559 return self.api(self.papi.want_l2_macs_events,
560 {'enable_disable': enable_disable,
561 'scan_delay': scan_delay,
562 'max_macs_in_event': max_macs_in_event,
563 'learn_limit': learn_limit,
564 'pid': os.getpid(), })
565
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200566 def want_dhcp6_reply_events(self, enable_disable=1):
567 return self.api(self.papi.want_dhcp6_reply_events,
568 {'enable_disable': enable_disable,
569 'pid': os.getpid()})
570
Juraj Sloboda81119e82018-05-25 14:02:20 +0200571 def want_dhcp6_pd_reply_events(self, enable_disable=1):
572 return self.api(self.papi.want_dhcp6_pd_reply_events,
573 {'enable_disable': enable_disable,
574 'pid': os.getpid()})
575
576 def dhcp6_clients_enable_disable(self, enable=1):
577 return self.api(self.papi.dhcp6_clients_enable_disable,
578 {'enable': enable})
579
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200580 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
581 addresses, server_index=0xFFFFFFFF,
582 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
583 ):
584 return self.api(self.papi.dhcp6_send_client_message,
585 {'sw_if_index': sw_if_index,
586 'server_index': server_index,
587 'irt': irt,
588 'mrt': mrt,
589 'mrc': mrc,
590 'mrd': mrd,
591 'stop': stop,
592 'msg_type': msg_type,
593 'T1': T1,
594 'T2': T2,
595 'n_addresses': len(addresses),
596 'addresses': addresses})
597
Juraj Sloboda81119e82018-05-25 14:02:20 +0200598 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
599 prefixes, server_index=0xFFFFFFFF,
600 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
601 ):
602 return self.api(self.papi.dhcp6_pd_send_client_message,
603 {'sw_if_index': sw_if_index,
604 'server_index': server_index,
605 'irt': irt,
606 'mrt': mrt,
607 'mrc': mrc,
608 'mrd': mrd,
609 'stop': stop,
610 'msg_type': msg_type,
611 'T1': T1,
612 'T2': T2,
613 'n_prefixes': len(prefixes),
614 'prefixes': prefixes})
615
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200616 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
617 enable=1):
618 return self.api(self.papi.dhcp6_client_enable_disable,
619 {'sw_if_index': sw_if_index,
620 'enable': enable})
621
Juraj Sloboda81119e82018-05-25 14:02:20 +0200622 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
623 enable=1):
624 return self.api(self.papi.dhcp6_pd_client_enable_disable,
625 {'sw_if_index': sw_if_index,
626 'prefix_group': prefix_group,
627 'enable': enable})
628
629 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
630 prefix_length, prefix_group,
631 is_add=1):
632 return self.api(self.papi.ip6_add_del_address_using_prefix,
633 {'sw_if_index': sw_if_index,
634 'prefix_group': prefix_group,
635 'address': address,
636 'prefix_length': prefix_length,
637 'is_add': is_add})
638
Jan4af521d2016-11-15 17:05:00 +0100639 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
640 filter_mac=0, bvi_mac=0):
641 """Create/delete L2 FIB entry.
642
643 :param str mac: MAC address to create FIB entry for.
644 :param int bd_id: Bridge domain index.
645 :param int sw_if_index: Software interface index of the interface.
646 :param int is_add: Add or delete flag. (Default value = 1)
647 :param int static_mac: Set to 1 to create static MAC entry.
648 (Default value = 0)
649 :param int filter_mac: Set to 1 to drop packet that's source or
650 destination MAC address contains defined MAC address.
651 (Default value = 0)
652 :param int bvi_mac: Set to 1 to create entry that points to BVI
653 interface. (Default value = 0)
654 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100655 return self.api(self.papi.l2fib_add_del,
Ole Troan8006c6a2018-12-17 12:02:26 +0100656 {'mac': mac,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200657 'bd_id': bd_id,
658 'sw_if_index': sw_if_index,
659 'is_add': is_add,
660 'static_mac': static_mac,
661 'filter_mac': filter_mac,
662 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100663
Eyal Bari93b503e2017-05-15 10:13:15 +0300664 def l2fib_flush_int(self, sw_if_index):
665 """Flush L2 FIB entries for sw_if_index.
666
667 :param int sw_if_index: Software interface index of the interface.
668 """
669 return self.api(self.papi.l2fib_flush_int,
670 {'sw_if_index': sw_if_index})
671
672 def l2fib_flush_bd(self, bd_id):
673 """Flush L2 FIB entries for bd_id.
674
675 :param int sw_if_index: Bridge Domain id.
676 """
677 return self.api(self.papi.l2fib_flush_bd,
678 {'bd_id': bd_id})
679
680 def l2fib_flush_all(self):
681 """Flush all L2 FIB.
682 """
683 return self.api(self.papi.l2fib_flush_all, {})
684
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700685 def l2_fib_table_dump(self, bd_id):
686 """ Dump the L2 FIB """
687 return self.api(self.papi.l2_fib_table_dump,
688 {'bd_id': bd_id})
689
Klement Sekeraf62ae122016-10-11 11:47:09 +0200690 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700691 shg=0, port_type=L2_PORT_TYPE.NORMAL,
692 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100693 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200694
Jan4af521d2016-11-15 17:05:00 +0100695 :param int sw_if_index: Software interface index of the interface.
696 :param int bd_id: Bridge domain index.
697 :param int shg: Split-horizon group index. (Default value = 0)
698 :param int bvi: Set interface as a bridge group virtual interface.
699 (Default value = 0)
700 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200701 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100702 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200703 {'rx_sw_if_index': sw_if_index,
704 'bd_id': bd_id,
705 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700706 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200707 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200708
Jan00dad122016-11-29 10:04:53 +0100709 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400710 """Enable/disable required feature of the bridge domain with defined
711 ID.
Jan00dad122016-11-29 10:04:53 +0100712
713 :param int bd_id: Bridge domain ID.
714 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700715 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100716 - learn (1 << 0),
717 - forward (1 << 1),
718 - flood (1 << 2),
719 - uu-flood (1 << 3) or
720 - arp-term (1 << 4).
721 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100722 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200723 {'bd_id': bd_id,
724 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700725 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100726
727 def bridge_domain_dump(self, bd_id=0):
728 """
729
730 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
731 existing bridge domains returned)
732 :return: Dictionary of bridge domain(s) data.
733 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100734 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200735 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100736
Klement Sekeraf62ae122016-10-11 11:47:09 +0200737 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
738 enable):
739 """Create or delete unidirectional cross-connect from Tx interface to
740 Rx interface.
741
Jan4af521d2016-11-15 17:05:00 +0100742 :param int rx_sw_if_index: Software interface index of Rx interface.
743 :param int tx_sw_if_index: Software interface index of Tx interface.
744 :param int enable: Create cross-connect if equal to 1, delete
745 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200746
747 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100748 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200749 {'rx_sw_if_index': rx_sw_if_index,
750 'tx_sw_if_index': tx_sw_if_index,
751 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200752
Ole Troane1ade682019-03-04 23:55:43 +0100753 def l2_interface_vlan_tag_rewrite(
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200754 self,
755 sw_if_index,
756 vtr_oper,
757 push=0,
758 tag1=0,
759 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000760 """L2 interface vlan tag rewrite configure request
761 :param client_index - opaque cookie to identify the sender
762 :param context - sender context, to match reply w/ request
763 :param sw_if_index - interface the operation is applied to
764 :param vtr_op - Choose from l2_vtr_op_t enum values
765 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
766 :param tag1 - Needed for any push or translate vtr op
767 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
768
769 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100770 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200771 {'sw_if_index': sw_if_index,
772 'vtr_op': vtr_oper,
773 'push_dot1q': push,
774 'tag1': tag1,
775 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000776
Ole Troane1ade682019-03-04 23:55:43 +0100777 def l2_emulation(
Neale Ranns55d03782017-10-21 06:34:22 -0700778 self,
779 sw_if_index,
780 enable=1):
781 """L2 Emulation
782 :param sw_if_index - interface the operation is applied to
783
784 """
785 return self.api(self.papi.l2_emulation,
786 {'sw_if_index': sw_if_index,
787 'enable': enable})
788
Neale Ranns1855b8e2018-07-11 10:31:26 -0700789 def sw_interface_set_ip_directed_broadcast(
790 self,
791 sw_if_index,
792 enable=1):
793 """IP Directed broadcast
794 :param sw_if_index - interface the operation is applied to
795
796 """
797 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
798 {'sw_if_index': sw_if_index,
799 'enable': enable})
800
Neale Rannsa07bd702017-08-07 07:53:49 -0700801 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200802 """
803
804 :param admin_up_down:
805 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200806
807 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100808 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200809 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700810 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200811
Ole Troand7231612018-06-07 10:17:57 +0200812 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800813 """
814 :param sw_if_index:
815 :param mtu:
816
817 """
818 return self.api(self.papi.sw_interface_set_mtu,
819 {'sw_if_index': sw_if_index,
820 'mtu': mtu})
821
Neale Rannsc819fc62018-02-16 02:44:05 -0800822 def sw_interface_set_mac_address(self, sw_if_index, mac):
823 return self.api(self.papi.sw_interface_set_mac_address,
824 {'sw_if_index': sw_if_index,
825 'mac_address': mac})
826
Klement Sekeraf62ae122016-10-11 11:47:09 +0200827 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
828 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
829 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
830 """Create subinterface
831 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
832
833 :param sub_id: param inner_vlan:
834 :param sw_if_index:
835 :param outer_vlan:
836 :param inner_vlan:
837 :param no_tags: (Default value = 0)
838 :param one_tag: (Default value = 0)
839 :param two_tags: (Default value = 0)
840 :param dot1ad: (Default value = 0)
841 :param exact_match: (Default value = 0)
842 :param default_sub: (Default value = 0)
843 :param outer_vlan_id_any: (Default value = 0)
844 :param inner_vlan_id_any: (Default value = 0)
845
846 """
847 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100848 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200849 {'sw_if_index': sw_if_index,
850 'sub_id': sub_id,
851 'no_tags': no_tags,
852 'one_tag': one_tag,
853 'two_tags': two_tags,
854 'dot1ad': dot1ad,
855 'exact_match': exact_match,
856 'default_sub': default_sub,
857 'outer_vlan_id_any': outer_vlan_id_any,
858 'inner_vlan_id_any': inner_vlan_id_any,
859 'outer_vlan_id': outer_vlan,
860 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200861
Ole Troane1ade682019-03-04 23:55:43 +0100862 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200863 """Create p2p ethernet subinterface
864
865 :param sw_if_index: main (parent) interface
866 :param remote_mac: client (remote) mac address
867
868 """
869 return self.api(
870 self.papi.p2p_ethernet_add,
871 {'parent_if_index': sw_if_index,
872 'remote_mac': remote_mac,
873 'subif_id': subif_id})
874
Neale Ranns177bbdc2016-11-15 09:46:51 +0000875 def delete_subif(self, sw_if_index):
876 """Delete subinterface
877
878 :param sw_if_index:
879 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100880 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200881 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000882
Ole Troane1ade682019-03-04 23:55:43 +0100883 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200884 """Delete p2p ethernet subinterface
885
886 :param sw_if_index: main (parent) interface
887 :param remote_mac: client (remote) mac address
888
889 """
890 return self.api(
891 self.papi.p2p_ethernet_del,
892 {'parent_if_index': sw_if_index,
893 'remote_mac': remote_mac})
894
Klement Sekeraf62ae122016-10-11 11:47:09 +0200895 def create_vlan_subif(self, sw_if_index, vlan):
896 """
897
898 :param vlan:
899 :param sw_if_index:
900
901 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100902 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200903 {'sw_if_index': sw_if_index,
904 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200905
Matej Klotton0178d522016-11-04 11:11:44 +0100906 def create_loopback(self, mac=''):
907 """
908
909 :param mac: (Optional)
910 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100911 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200912 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100913
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100914 def delete_loopback(self, sw_if_index):
915 return self.api(self.papi.delete_loopback,
916 {'sw_if_index': sw_if_index, })
917
Neale Ranns15002542017-09-10 04:39:11 -0700918 def ip_table_add_del(self,
919 table_id,
920 is_add=1,
921 is_ipv6=0):
922 """
923
924 :param table_id
925 :param is_add: (Default value = 1)
926 :param is_ipv6: (Default value = 0)
927
928 """
929
930 return self.api(
931 self.papi.ip_table_add_del,
932 {'table_id': table_id,
933 'is_add': is_add,
934 'is_ipv6': is_ipv6})
935
Klement Sekeraf62ae122016-10-11 11:47:09 +0200936 def ip_add_del_route(
937 self,
938 dst_address,
939 dst_address_length,
940 next_hop_address,
941 next_hop_sw_if_index=0xFFFFFFFF,
942 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200943 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000944 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200945 next_hop_n_out_labels=0,
946 next_hop_out_label_stack=[],
947 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800948 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000949 is_resolve_host=0,
950 is_resolve_attached=0,
951 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200952 is_add=1,
953 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200954 is_unreach=0,
955 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200956 is_ipv6=0,
957 is_local=0,
958 is_classify=0,
959 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800960 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800961 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200962 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200963 """
964
965 :param dst_address_length:
966 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
967 :param dst_address:
968 :param next_hop_address:
969 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
970 :param vrf_id: (Default value = 0)
971 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200972 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200973 :param is_add: (Default value = 1)
974 :param is_drop: (Default value = 0)
975 :param is_ipv6: (Default value = 0)
976 :param is_local: (Default value = 0)
977 :param is_classify: (Default value = 0)
978 :param is_multipath: (Default value = 0)
979 :param is_resolve_host: (Default value = 0)
980 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800981 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700982 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200983 :param next_hop_weight: (Default value = 1)
984
985 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000986
Klement Sekeraf62ae122016-10-11 11:47:09 +0200987 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100988 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200989 {'next_hop_sw_if_index': next_hop_sw_if_index,
990 'table_id': table_id,
991 'classify_table_index': classify_table_index,
992 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200993 'is_add': is_add,
994 'is_drop': is_drop,
995 'is_unreach': is_unreach,
996 'is_prohibit': is_prohibit,
997 'is_ipv6': is_ipv6,
998 'is_local': is_local,
999 'is_classify': is_classify,
1000 'is_multipath': is_multipath,
1001 'is_resolve_host': is_resolve_host,
1002 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -08001003 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -07001004 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -08001005 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001006 'next_hop_weight': next_hop_weight,
1007 'dst_address_length': dst_address_length,
1008 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -08001009 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001010 'next_hop_address': next_hop_address,
1011 'next_hop_n_out_labels': next_hop_n_out_labels,
1012 'next_hop_via_label': next_hop_via_label,
1013 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001014
Matej Klotton16a14cd2016-12-07 15:09:13 +01001015 def ip_fib_dump(self):
1016 return self.api(self.papi.ip_fib_dump, {})
1017
Jan Gelety057bb8c2016-12-20 17:32:45 +01001018 def ip6_fib_dump(self):
1019 return self.api(self.papi.ip6_fib_dump, {})
1020
Matej Klotton0178d522016-11-04 11:11:44 +01001021 def ip_neighbor_add_del(self,
1022 sw_if_index,
1023 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -07001024 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001025 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -07001026 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +01001027 """ Add neighbor MAC to IPv4 or IPv6 address.
1028
1029 :param sw_if_index:
1030 :param mac_address:
1031 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001032 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -07001033 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +01001034 """
Matej Klotton0178d522016-11-04 11:11:44 +01001035 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001036 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -07001037 {
1038 'is_add': is_add,
1039 'neighbor': {
1040 'sw_if_index': sw_if_index,
1041 'flags': flags,
1042 'mac_address': mac_address,
1043 'ip_address': ip_address
1044 }
1045 }
Matej Klotton0178d522016-11-04 11:11:44 +01001046 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001047
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001048 def ip_neighbor_dump(self,
1049 sw_if_index,
1050 is_ipv6=0):
1051 """ Return IP neighbor dump.
1052
1053 :param sw_if_index:
1054 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1055 """
1056
1057 return self.api(
1058 self.papi.ip_neighbor_dump,
1059 {'is_ipv6': is_ipv6,
1060 'sw_if_index': sw_if_index
1061 }
1062 )
1063
1064 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -07001065 low,
1066 hi,
1067 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001068 is_add=1):
1069 """ Config Proxy Arp Range.
1070
1071 :param low_address: Start address in the rnage to Proxy for
1072 :param hi_address: End address in the rnage to Proxy for
1073 :param vrf_id: The VRF/table in which to proxy
1074 """
1075
1076 return self.api(
1077 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001078 {'proxy':
1079 {
Neale Ranns37029302018-08-10 05:30:06 -07001080 'table_id': table_id,
1081 'low': low,
1082 'hi': hi,
Neale Ranns0053de62018-05-22 08:40:52 -07001083 },
1084 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001085
1086 def proxy_arp_intfc_enable_disable(self,
1087 sw_if_index,
1088 is_enable=1):
1089 """ Enable/Disable an interface for proxy ARP requests
1090
1091 :param sw_if_index: Interface
1092 :param enable_disable: Enable/Disable
1093 """
1094
1095 return self.api(
1096 self.papi.proxy_arp_intfc_enable_disable,
1097 {'sw_if_index': sw_if_index,
1098 'enable_disable': is_enable
1099 }
1100 )
1101
Jane546d3b2016-12-08 13:10:03 +01001102 def reset_fib(self,
1103 vrf_id,
1104 is_ipv6=0,
1105 ):
1106 """ Reset VRF (remove all routes etc.) request.
1107
1108 :param int vrf_id: ID of the FIB table / VRF to reset.
1109 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1110 """
1111
1112 return self.api(
1113 self.papi.reset_fib,
1114 {'vrf_id': vrf_id,
1115 'is_ipv6': is_ipv6,
1116 }
1117 )
1118
1119 def ip_dump(self,
1120 is_ipv6=0,
1121 ):
1122 """ Return IP dump.
1123
1124 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1125 """
1126
1127 return self.api(
1128 self.papi.ip_dump,
1129 {'is_ipv6': is_ipv6,
1130 }
1131 )
1132
Klement Sekera7bb873a2016-11-18 07:38:42 +01001133 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001134 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001135 """
1136
1137 :param sw_if_index_from:
1138 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001139 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001140 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001141 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001142 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001143 {'sw_if_index_from': sw_if_index_from,
1144 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001145 'state': state,
1146 'is_l2': is_l2,
1147 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001148
Ole Troane1ade682019-03-04 23:55:43 +01001149 def gre_add_del_tunnel(self,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001150 src_address,
1151 dst_address,
1152 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001153 tunnel_type=0,
1154 instance=0xFFFFFFFF,
1155 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001156 is_add=1,
1157 is_ip6=0):
1158 """ Add a GRE tunnel
1159
1160 :param src_address:
1161 :param dst_address:
1162 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001163 :param tunnel_type: (Default value = 0)
1164 :param instance: (Default value = 0xFFFFFFFF)
1165 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001166 :param is_add: (Default value = 1)
1167 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001168 """
1169
1170 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001171 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001172 {'is_add': is_add,
1173 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001174 'tunnel_type': tunnel_type,
1175 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001176 'src_address': src_address,
1177 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001178 'outer_fib_id': outer_fib_id,
1179 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001180 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001181
Neale Rannsd0df49f2018-08-08 01:06:40 -07001182 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001183 src_ip,
1184 dst_ip,
1185 src_port,
1186 dst_port,
1187 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001188 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001189 :param src_ip:
1190 :param dst_ip:
1191 :param src_port:
1192 :param dst_port:
1193 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001194 """
1195
1196 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001197 self.papi.udp_encap_add,
1198 {
1199 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001200 'src_ip': src_ip,
1201 'dst_ip': dst_ip,
1202 'src_port': src_port,
1203 'dst_port': dst_port,
1204 'table_id': table_id
1205 }
1206 })
1207
1208 def udp_encap_del(self, id):
1209 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001210
1211 def udp_encap_dump(self):
1212 return self.api(self.papi.udp_encap_dump, {})
1213
Neale Ranns5a8123b2017-01-26 01:18:23 -08001214 def mpls_fib_dump(self):
1215 return self.api(self.papi.mpls_fib_dump, {})
1216
Neale Ranns15002542017-09-10 04:39:11 -07001217 def mpls_table_add_del(
1218 self,
1219 table_id,
1220 is_add=1):
1221 """
1222
1223 :param table_id
1224 :param is_add: (Default value = 1)
1225
1226 """
1227
1228 return self.api(
1229 self.papi.mpls_table_add_del,
1230 {'mt_table_id': table_id,
1231 'mt_is_add': is_add})
1232
Neale Rannsad422ed2016-11-02 14:20:04 +00001233 def mpls_route_add_del(
1234 self,
1235 label,
1236 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001237 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001238 next_hop_address,
1239 next_hop_sw_if_index=0xFFFFFFFF,
1240 table_id=0,
1241 next_hop_table_id=0,
1242 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001243 next_hop_n_out_labels=0,
1244 next_hop_out_label_stack=[],
1245 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001246 is_resolve_host=0,
1247 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001248 is_interface_rx=0,
1249 is_rpf_id=0,
1250 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001251 is_add=1,
1252 is_drop=0,
1253 is_multipath=0,
1254 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001255 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001256 """
1257
1258 :param dst_address_length:
1259 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1260 :param dst_address:
1261 :param next_hop_address:
1262 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1263 :param vrf_id: (Default value = 0)
1264 :param lookup_in_vrf: (Default value = 0)
1265 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001266 :param is_add: (Default value = 1)
1267 :param is_drop: (Default value = 0)
1268 :param is_ipv6: (Default value = 0)
1269 :param is_local: (Default value = 0)
1270 :param is_classify: (Default value = 0)
1271 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001272 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001273 :param is_resolve_host: (Default value = 0)
1274 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001275 :param next_hop_weight: (Default value = 1)
1276
1277 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001278 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001279 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001280 {'mr_label': label,
1281 'mr_eos': eos,
1282 'mr_table_id': table_id,
1283 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001284 'mr_is_add': is_add,
1285 'mr_is_classify': is_classify,
1286 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001287 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001288 'mr_is_resolve_host': is_resolve_host,
1289 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001290 'mr_is_interface_rx': is_interface_rx,
1291 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001292 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001293 'mr_next_hop_weight': next_hop_weight,
1294 'mr_next_hop': next_hop_address,
1295 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1296 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1297 'mr_next_hop_table_id': next_hop_table_id,
1298 'mr_next_hop_via_label': next_hop_via_label,
1299 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001300
1301 def mpls_ip_bind_unbind(
1302 self,
1303 label,
1304 dst_address,
1305 dst_address_length,
1306 table_id=0,
1307 ip_table_id=0,
1308 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001309 is_bind=1):
1310 """
1311 """
1312 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001313 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001314 {'mb_mpls_table_id': table_id,
1315 'mb_label': label,
1316 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001317 'mb_is_bind': is_bind,
1318 'mb_is_ip4': is_ip4,
1319 'mb_address_length': dst_address_length,
1320 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001321
1322 def mpls_tunnel_add_del(
1323 self,
1324 tun_sw_if_index,
1325 next_hop_proto_is_ip4,
1326 next_hop_address,
1327 next_hop_sw_if_index=0xFFFFFFFF,
1328 next_hop_table_id=0,
1329 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001330 next_hop_n_out_labels=0,
1331 next_hop_out_label_stack=[],
1332 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001333 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001334 l2_only=0,
1335 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001336 """
1337
1338 :param dst_address_length:
1339 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1340 :param dst_address:
1341 :param next_hop_address:
1342 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1343 :param vrf_id: (Default value = 0)
1344 :param lookup_in_vrf: (Default value = 0)
1345 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001346 :param is_add: (Default value = 1)
1347 :param is_drop: (Default value = 0)
1348 :param is_ipv6: (Default value = 0)
1349 :param is_local: (Default value = 0)
1350 :param is_classify: (Default value = 0)
1351 :param is_multipath: (Default value = 0)
1352 :param is_resolve_host: (Default value = 0)
1353 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001354 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001355 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001356
1357 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001358 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001359 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001360 {'mt_sw_if_index': tun_sw_if_index,
1361 'mt_is_add': is_add,
1362 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001363 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001364 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1365 'mt_next_hop_weight': next_hop_weight,
1366 'mt_next_hop': next_hop_address,
1367 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1368 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1369 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001370 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001371 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001372
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001373 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1374 return self.api(self.papi.mpls_tunnel_dump,
1375 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001376
Matus Fabian2ba92e32017-08-21 07:05:03 -07001377 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001378 self,
1379 sw_if_index,
1380 is_inside=1,
1381 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001382 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001383
1384 :param sw_if_index: Software index of the interface
1385 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1386 :param is_add: 1 if add, 0 if delete (Default value = 1)
1387 """
1388 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001389 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001390 {'is_add': is_add,
1391 'is_inside': is_inside,
1392 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001393
Matus Fabian2ba92e32017-08-21 07:05:03 -07001394 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001395 self,
1396 sw_if_index,
1397 is_inside=1,
1398 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001399 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001400
1401 :param sw_if_index: Software index of the interface
1402 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1403 :param is_add: 1 if add, 0 if delete (Default value = 1)
1404 """
1405 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001406 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001407 {'is_add': is_add,
1408 'is_inside': is_inside,
1409 'sw_if_index': sw_if_index})
1410
Matus Fabian2ba92e32017-08-21 07:05:03 -07001411 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001412 self,
1413 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001414 external_ip=0,
1415 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001416 local_port=0,
1417 external_port=0,
1418 addr_only=1,
1419 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001420 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001421 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001422 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001423 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001424 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001425 is_add=1):
1426 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001427
1428 :param local_ip: Local IP address
1429 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001430 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001431 :param local_port: Local port number (Default value = 0)
1432 :param external_port: External port number (Default value = 0)
1433 :param addr_only: 1 if address only mapping, 0 if address and port
1434 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001435 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001436 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001437 :param self_twice_nat: 1 if translate external host address and port
1438 whenever external host address equals
1439 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001440 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001441 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001442 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001443 """
1444 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001445 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001446 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001447 'addr_only': addr_only,
1448 'local_ip_address': local_ip,
1449 'external_ip_address': external_ip,
1450 'local_port': local_port,
1451 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001452 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001453 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001454 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001455 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001456 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001457 'out2in_only': out2in_only,
1458 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001459
Matus Fabianab7a8052017-11-28 04:29:41 -08001460 def nat44_add_del_identity_mapping(
1461 self,
1462 ip='0',
1463 sw_if_index=0xFFFFFFFF,
1464 port=0,
1465 addr_only=1,
1466 vrf_id=0,
1467 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001468 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001469 is_add=1):
1470 """Add/delete NAT44 identity mapping
1471
1472 :param ip: IP address (Default value = 0)
1473 :param sw_if_index: Interface instead of IP address
1474 :param port: Port number (Default value = 0)
1475 :param addr_only: 1 if address only mapping, 0 if address and port
1476 :param vrf_id: VRF ID
1477 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001478 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001479 :param is_add: 1 if add, 0 if delete (Default value = 1)
1480 """
1481 return self.api(
1482 self.papi.nat44_add_del_identity_mapping,
1483 {'is_add': is_add,
1484 'addr_only': addr_only,
1485 'ip_address': ip,
1486 'port': port,
1487 'sw_if_index': sw_if_index,
1488 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001489 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001490 'protocol': protocol})
1491
Matus Fabian2ba92e32017-08-21 07:05:03 -07001492 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001493 self,
1494 first_ip_address,
1495 last_ip_address,
1496 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001497 vrf_id=0xFFFFFFFF,
1498 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001499 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001500
1501 :param first_ip_address: First IP address
1502 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001503 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001504 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001505 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001506 """
1507 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001508 self.papi.nat44_add_del_address_range,
1509 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001510 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001511 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001512 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001513 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001514
Matus Fabian2ba92e32017-08-21 07:05:03 -07001515 def nat44_address_dump(self):
1516 """Dump NAT44 addresses
1517 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001518 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001519 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001520
Matus Fabian2ba92e32017-08-21 07:05:03 -07001521 def nat44_interface_dump(self):
1522 """Dump interfaces with NAT44 feature
1523 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001524 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001525 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001526
Matus Fabian2ba92e32017-08-21 07:05:03 -07001527 def nat44_interface_output_feature_dump(self):
1528 """Dump interfaces with NAT44 output feature
1529 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001530 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001531 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001532
Matus Fabian2ba92e32017-08-21 07:05:03 -07001533 def nat44_static_mapping_dump(self):
1534 """Dump NAT44 static mappings
1535 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001536 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001537 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001538
Matus Fabianab7a8052017-11-28 04:29:41 -08001539 def nat44_identity_mapping_dump(self):
1540 """Dump NAT44 identity mappings
1541 :return: Dictionary of NAT44 identity mappings
1542 """
1543 return self.api(self.papi.nat44_identity_mapping_dump, {})
1544
Matus Fabian2ba92e32017-08-21 07:05:03 -07001545 def nat_show_config(self):
1546 """Show NAT plugin config
1547 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001548 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001549 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001550
Ole Troane1ade682019-03-04 23:55:43 +01001551 def nat44_add_del_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001552 self,
1553 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001554 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001555 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001556 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001557
1558 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001559 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001560 :param is_add: 1 if add, 0 if delete (Default value = 1)
1561 """
Matus Fabianb932d262017-12-18 05:38:24 -08001562 return self.api(
1563 self.papi.nat44_add_del_interface_addr,
1564 {'is_add': is_add,
1565 'sw_if_index': sw_if_index,
1566 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001567
Matus Fabian2ba92e32017-08-21 07:05:03 -07001568 def nat44_interface_addr_dump(self):
1569 """Dump NAT44 addresses interfaces
1570 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001571 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001572 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001573
Ole Troane1ade682019-03-04 23:55:43 +01001574 def nat_ipfix_enable_disable(
Matus Fabianeea28d72017-01-13 04:15:54 -08001575 self,
1576 domain_id=1,
1577 src_port=4739,
1578 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001580
1581 :param domain_id: Observation domain ID (Default value = 1)
1582 :param src_port: Source port number (Default value = 4739)
1583 :param enable: 1 if enable, 0 if disable (Default value = 1)
1584 """
1585 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001586 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001587 {'domain_id': domain_id,
1588 'src_port': src_port,
1589 'enable': enable})
1590
Matus Fabian2ba92e32017-08-21 07:05:03 -07001591 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001592 self,
1593 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001594 vrf_id):
1595 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001596
1597 :param ip_address: ip adress of the user to be dumped
1598 :param cpu_index: cpu_index on which the user is
1599 :param vrf_id: VRF ID
1600 :return: Dictionary of S-NAT sessions
1601 """
1602 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001603 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001604 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001605 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001606
Matus Fabian2ba92e32017-08-21 07:05:03 -07001607 def nat44_user_dump(self):
1608 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001609
Matus Fabian2ba92e32017-08-21 07:05:03 -07001610 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001611 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001612 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001613
Matus Fabian704018c2017-09-04 02:17:18 -07001614 def nat44_add_del_lb_static_mapping(
1615 self,
1616 external_addr,
1617 external_port,
1618 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001619 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001620 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001621 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001622 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001623 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001624 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001625 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001626 is_add=1):
1627 """Add/delete NAT44 load balancing static mapping
1628
Matus Fabianb932d262017-12-18 05:38:24 -08001629 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001630 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001631 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001632 :param is_add - 1 if add, 0 if delete
1633 """
1634 return self.api(
1635 self.papi.nat44_add_del_lb_static_mapping,
1636 {'is_add': is_add,
1637 'external_addr': external_addr,
1638 'external_port': external_port,
1639 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001640 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001641 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001642 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001643 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001644 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001645 'local_num': local_num,
1646 'locals': locals})
1647
Matus Fabianb6865082018-12-06 03:11:09 -08001648 def nat44_lb_static_mapping_add_del_local(
1649 self,
1650 external_addr,
1651 external_port,
1652 local_addr,
1653 local_port,
1654 protocol,
1655 probability,
1656 vrf_id=0,
1657 is_add=1):
1658 """Add/delete NAT44 load-balancing static mapping rule backend
1659
1660 :param external_addr: external IPv4 address of the servic
1661 :param external_port: external L4 port number of the service
1662 :param local_addr: IPv4 address of the internal node
1663 :param local_port: L4 port number of the internal node
1664 :param protocol: IP protocol number
1665 :param probability: probability of the internal node
1666 :param vrf_id: VRF id of the internal node
1667 :param is_add: 1 if add, 0 if delete
1668 """
1669 return self.api(
1670 self.papi.nat44_lb_static_mapping_add_del_local,
1671 {'is_add': is_add,
1672 'external_addr': external_addr,
1673 'external_port': external_port,
1674 'local': {
1675 'addr': local_addr,
1676 'port': local_port,
1677 'probability': probability,
1678 'vrf_id': vrf_id},
1679 'protocol': protocol})
1680
Matus Fabian704018c2017-09-04 02:17:18 -07001681 def nat44_lb_static_mapping_dump(self):
1682 """Dump NAT44 load balancing static mappings
1683
1684 :return: Dictionary of NAT44 load balancing static mapping
1685 """
1686 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1687
Matus Fabian5ba86f72017-10-26 03:37:38 -07001688 def nat44_del_session(
1689 self,
1690 addr,
1691 port,
1692 protocol,
1693 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001694 is_in=1,
1695 ext_host_address=None,
1696 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001697 """Delete NAT44 session
1698
1699 :param addr: IPv4 address
1700 :param por: port number
1701 :param protocol: IP protocol number
1702 :param vrf_id: VRF ID
1703 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001704 :param ext_host_address: external host IPv4 address
1705 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001706 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001707 if ext_host_address is None:
1708 return self.api(
1709 self.papi.nat44_del_session,
1710 {'address': addr,
1711 'port': port,
1712 'protocol': protocol,
1713 'vrf_id': vrf_id,
1714 'is_in': is_in})
1715 else:
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 'ext_host_valid': 1,
1724 'ext_host_address': ext_host_address,
1725 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001726
Juraj Sloboda7b929792017-11-23 13:20:48 +01001727 def nat44_forwarding_enable_disable(
1728 self,
1729 enable):
1730 """Enable/disable forwarding for NAT44
1731
1732 :param enable: 1 for enable, 0 for disable
1733 """
1734 return self.api(
1735 self.papi.nat44_forwarding_enable_disable,
1736 {'enable': enable})
1737
Matus Fabianefcd1e92017-08-15 06:59:19 -07001738 def nat_set_reass(
1739 self,
1740 timeout=2,
1741 max_reass=1024,
1742 max_frag=5,
1743 drop_frag=0,
1744 is_ip6=0):
1745 """Set NAT virtual fragmentation reassembly
1746
1747 :param timeout: reassembly timeout (Default 2sec)
1748 :param max_reass: maximum concurrent reassemblies (Default 1024)
1749 :param max_frag: maximum fragmets per reassembly (Default 5)
1750 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1751 :param is_ip6: 1 if IPv6, 0 if IPv4
1752 """
1753 return self.api(
1754 self.papi.nat_set_reass,
1755 {'timeout': timeout,
1756 'max_reass': max_reass,
1757 'max_frag': max_frag,
1758 'drop_frag': drop_frag,
1759 'is_ip6': is_ip6})
1760
1761 def nat_get_reass(self):
1762 """Get NAT virtual fragmentation reassembly configuration
1763
1764 :return: NAT virtual fragmentation reassembly configuration
1765 """
1766 return self.api(self.papi.nat_get_reass, {})
1767
1768 def nat_reass_dump(self):
1769 """Dump NAT virtual fragmentation reassemblies
1770
1771 :return: Dictionary of NAT virtual fragmentation reassemblies
1772 """
1773 return self.api(self.papi.nat_reass_dump, {})
1774
Matus Fabian2ba92e32017-08-21 07:05:03 -07001775 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001776 self,
1777 in_addr,
1778 in_plen,
1779 out_addr,
1780 out_plen,
1781 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001782 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001783
1784 :param is_add - 1 if add, 0 if delete
1785 :param in_addr - inside IP address
1786 :param in_plen - inside IP address prefix length
1787 :param out_addr - outside IP address
1788 :param out_plen - outside IP address prefix length
1789 """
1790 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001791 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001792 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001793 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001794 'in_addr': in_addr,
1795 'in_plen': in_plen,
1796 'out_addr': out_addr,
1797 'out_plen': out_plen})
1798
Matus Fabian2ba92e32017-08-21 07:05:03 -07001799 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001800 self,
1801 in_addr):
1802 """Get outside address and port range from inside address
1803
1804 :param in_addr - inside IP address
1805 """
1806 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001807 self.papi.nat_det_forward,
1808 {'in_addr': in_addr,
1809 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001810
Matus Fabian2ba92e32017-08-21 07:05:03 -07001811 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001812 self,
1813 out_addr,
1814 out_port):
1815 """Get inside address from outside address and port
1816
1817 :param out_addr - outside IP address
1818 :param out_port - outside port
1819 """
1820 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001821 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001822 {'out_addr': out_addr,
1823 'out_port': out_port})
1824
Matus Fabian2ba92e32017-08-21 07:05:03 -07001825 def nat_det_map_dump(self):
1826 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001827
Matus Fabian2ba92e32017-08-21 07:05:03 -07001828 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001829 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001830 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001831
Matus Fabian878c6462018-08-23 00:33:35 -07001832 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001833 self,
1834 udp=300,
1835 tcp_established=7440,
1836 tcp_transitory=240,
1837 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001838 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001839
1840 :param udp - UDP timeout (Default value = 300)
1841 :param tcp_established - TCP established timeout (Default value = 7440)
1842 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1843 :param icmp - ICMP timeout (Default value = 60)
1844 """
1845 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001846 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001847 {'udp': udp,
1848 'tcp_established': tcp_established,
1849 'tcp_transitory': tcp_transitory,
1850 'icmp': icmp})
1851
Matus Fabian878c6462018-08-23 00:33:35 -07001852 def nat_get_timeouts(self):
1853 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001854
Matus Fabian878c6462018-08-23 00:33:35 -07001855 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001856 """
Matus Fabian878c6462018-08-23 00:33:35 -07001857 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001858
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001859 def nat_set_addr_and_port_alloc_alg(
1860 self,
1861 alg=0,
1862 psid_offset=0,
1863 psid_length=0,
1864 psid=0,
1865 start_port=0,
1866 end_port=0):
1867 """Set address and port assignment algorithm
1868
1869 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1870 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1871 :param psid_length: length of PSID (valid only for MAP-E alg)
1872 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1873 :param start_port: beginning of the port range
1874 :param end_port: end of the port range
1875 """
1876 return self.api(
1877 self.papi.nat_set_addr_and_port_alloc_alg,
1878 {'alg': alg,
1879 'psid_offset': psid_offset,
1880 'psid_length': psid_length,
1881 'psid': psid,
1882 'start_port': start_port,
1883 'end_port': end_port})
1884
1885 def nat_get_addr_and_port_alloc_alg(self):
1886 """Get address and port assignment algorithm"""
1887 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1888
Matus Fabianbb4e0222018-09-13 02:36:25 -07001889 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1890 """Set TCP MSS rewriting configuration
1891
1892 :param enable: disable(0)/enable(1) MSS rewriting feature
1893 :param mss_value: MSS value to be used for MSS rewriting
1894 """
1895 return self.api(
1896 self.papi.nat_set_mss_clamping,
1897 {'enable': enable, 'mss_value': mss_value})
1898
1899 def nat_get_mss_clamping(self):
1900 """Get TCP MSS rewriting configuration"""
1901 return self.api(self.papi.nat_get_mss_clamping, {})
1902
Matus Fabian2ba92e32017-08-21 07:05:03 -07001903 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001904 self,
1905 out_addr,
1906 out_port,
1907 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001908 ext_port):
1909 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001910
1911 :param out_addr - outside IP address
1912 :param out_port - outside port
1913 :param ext_addr - external host IP address
1914 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001915 """
1916 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001917 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001918 {'out_addr': out_addr,
1919 'out_port': out_port,
1920 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001921 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001922
Matus Fabian2ba92e32017-08-21 07:05:03 -07001923 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001924 self,
1925 in_addr,
1926 in_port,
1927 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001928 ext_port):
1929 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001930
1931 :param in_addr - inside IP address
1932 :param in_port - inside port
1933 :param ext_addr - external host IP address
1934 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001935 """
1936 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001937 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001938 {'in_addr': in_addr,
1939 'in_port': in_port,
1940 'ext_addr': ext_addr,
1941 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001942 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001943
Matus Fabian2ba92e32017-08-21 07:05:03 -07001944 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001945 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001946 user_addr):
1947 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001948
1949 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001950 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001951 """
1952 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001953 self.papi.nat_det_session_dump,
1954 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001955 'user_addr': user_addr})
1956
Matus Fabian06596c52017-06-06 04:53:28 -07001957 def nat64_add_del_pool_addr_range(
1958 self,
1959 start_addr,
1960 end_addr,
1961 vrf_id=0xFFFFFFFF,
1962 is_add=1):
1963 """Add/del address range to NAT64 pool
1964
1965 :param start_addr: First IP address
1966 :param end_addr: Last IP address
1967 :param vrf_id: VRF id for the address range
1968 :param is_add: 1 if add, 0 if delete (Default value = 1)
1969 """
1970 return self.api(
1971 self.papi.nat64_add_del_pool_addr_range,
1972 {'start_addr': start_addr,
1973 'end_addr': end_addr,
1974 'vrf_id': vrf_id,
1975 'is_add': is_add})
1976
1977 def nat64_pool_addr_dump(self):
1978 """Dump NAT64 pool addresses
1979 :return: Dictionary of NAT64 pool addresses
1980 """
1981 return self.api(self.papi.nat64_pool_addr_dump, {})
1982
1983 def nat64_add_del_interface(
1984 self,
1985 sw_if_index,
1986 is_inside=1,
1987 is_add=1):
1988 """Enable/disable NAT64 feature on the interface
1989 :param sw_if_index: Index of the interface
1990 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1991 :param is_add: 1 if add, 0 if delete (Default value = 1)
1992 """
1993 return self.api(
1994 self.papi.nat64_add_del_interface,
1995 {'sw_if_index': sw_if_index,
1996 'is_inside': is_inside,
1997 'is_add': is_add})
1998
1999 def nat64_interface_dump(self):
2000 """Dump interfaces with NAT64 feature
2001 :return: Dictionary of interfaces with NAT64 feature
2002 """
2003 return self.api(self.papi.nat64_interface_dump, {})
2004
2005 def nat64_add_del_static_bib(
2006 self,
2007 in_ip,
2008 out_ip,
2009 in_port,
2010 out_port,
2011 protocol,
2012 vrf_id=0,
2013 is_add=1):
2014 """Add/delete S-NAT static BIB entry
2015
2016 :param in_ip: Inside IPv6 address
2017 :param out_ip: Outside IPv4 address
2018 :param in_port: Inside port number
2019 :param out_port: Outside port number
2020 :param protocol: IP protocol
2021 :param vrf_id: VRF ID (Default value = 0)
2022 :param is_add: 1 if add, 0 if delete (Default value = 1)
2023 """
2024 return self.api(
2025 self.papi.nat64_add_del_static_bib,
2026 {'i_addr': in_ip,
2027 'o_addr': out_ip,
2028 'i_port': in_port,
2029 'o_port': out_port,
2030 'vrf_id': vrf_id,
2031 'proto': protocol,
2032 'is_add': is_add})
2033
Matus Fabianab9a59c2017-08-16 05:37:36 -07002034 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002035 """Dump NAT64 BIB
2036
Matus Fabianab9a59c2017-08-16 05:37:36 -07002037 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002038 :returns: Dictionary of NAT64 BIB entries
2039 """
2040 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2041
Matus Fabianab9a59c2017-08-16 05:37:36 -07002042 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002043 """Dump NAT64 session table
2044
Matus Fabianab9a59c2017-08-16 05:37:36 -07002045 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002046 :returns: Dictionary of NAT64 sesstion table entries
2047 """
2048 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2049
Matus Fabian428dc912017-06-21 06:15:18 -07002050 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2051 """Add/del NAT64 prefix
2052
2053 :param prefix: NAT64 prefix
2054 :param plen: NAT64 prefix length
2055 :param vrf_id: VRF id of tenant (Default 0)
2056 :param is_add: 1 if add, 0 if delete (Default value = 1)
2057 """
2058 return self.api(
2059 self.papi.nat64_add_del_prefix,
2060 {'prefix': prefix,
2061 'prefix_len': plen,
2062 'vrf_id': vrf_id,
2063 'is_add': is_add})
2064
2065 def nat64_prefix_dump(self):
2066 """Dump NAT64 prefix
2067
2068 :returns: Dictionary of NAT64 prefixes
2069 """
2070 return self.api(self.papi.nat64_prefix_dump, {})
2071
Ole Troane1ade682019-03-04 23:55:43 +01002072 def nat64_add_del_interface_addr(
Matus Fabian0938dcf2017-11-08 01:59:38 -08002073 self,
2074 sw_if_index,
2075 is_add=1):
2076 """Add/del NAT64 address from interface
2077
2078 :param sw_if_index: Software index of the interface
2079 :param is_add: 1 if add, 0 if delete (Default value = 1)
2080 """
2081 return self.api(self.papi.nat64_add_del_interface_addr,
2082 {'is_add': is_add, 'sw_if_index': sw_if_index})
2083
Matus Fabian8ebe6252017-11-06 05:04:53 -08002084 def dslite_set_aftr_addr(self, ip6, ip4):
2085 """Set DS-Lite AFTR addresses
2086
2087 :param ip4: IPv4 address
2088 :param ip6: IPv6 address
2089 """
2090 return self.api(
2091 self.papi.dslite_set_aftr_addr,
2092 {'ip4_addr': ip4,
2093 'ip6_addr': ip6})
2094
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002095 def dslite_set_b4_addr(self, ip6, ip4):
2096 """Set DS-Lite B4 IPv6 address
2097
2098 :param ip4: IPv4 address
2099 :param ip6: IPv6 address
2100 """
2101 return self.api(
2102 self.papi.dslite_set_b4_addr,
2103 {'ip4_addr': ip4,
2104 'ip6_addr': ip6})
2105
Matus Fabian8ebe6252017-11-06 05:04:53 -08002106 def dslite_add_del_pool_addr_range(
2107 self,
2108 start_addr,
2109 end_addr,
2110 is_add=1):
2111 """Add/del address range to DS-Lite pool
2112
2113 :param start_addr: First IP address
2114 :param end_addr: Last IP address
2115 :param is_add: 1 if add, 0 if delete (Default value = 1)
2116 """
2117 return self.api(
2118 self.papi.dslite_add_del_pool_addr_range,
2119 {'start_addr': start_addr,
2120 'end_addr': end_addr,
2121 'is_add': is_add})
2122
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002123 def nat66_add_del_interface(
2124 self,
2125 sw_if_index,
2126 is_inside=1,
2127 is_add=1):
2128 """Enable/disable NAT66 feature on the interface
2129 :param sw_if_index: Index of the interface
2130 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2131 :param is_add: 1 if add, 0 if delete (Default value = 1)
2132 """
2133 return self.api(
2134 self.papi.nat66_add_del_interface,
2135 {'sw_if_index': sw_if_index,
2136 'is_inside': is_inside,
2137 'is_add': is_add})
2138
2139 def nat66_add_del_static_mapping(
2140 self,
2141 in_ip,
2142 out_ip,
2143 vrf_id=0,
2144 is_add=1):
2145 """Add/delete NAT66 static mapping
2146
2147 :param in_ip: Inside IPv6 address
2148 :param out_ip: Outside IPv6 address
2149 :param vrf_id: VRF ID (Default value = 0)
2150 :param is_add: 1 if add, 0 if delete (Default value = 1)
2151 """
2152 return self.api(
2153 self.papi.nat66_add_del_static_mapping,
2154 {'local_ip_address': in_ip,
2155 'external_ip_address': out_ip,
2156 'vrf_id': vrf_id,
2157 'is_add': is_add})
2158
2159 def nat66_interface_dump(self):
2160 """Dump interfaces with NAT66 feature
2161 :return: Dictionary of interfaces with NAT66 feature
2162 """
2163 return self.api(self.papi.nat66_interface_dump, {})
2164
2165 def nat66_static_mapping_dump(self):
2166 """Dump NAT66 static mappings
2167 :return: Dictionary of NAT66 static mappings
2168 """
2169 return self.api(self.papi.nat66_static_mapping_dump, {})
2170
Matus Fabian34931eb2019-02-26 09:05:23 -08002171 def nat_ha_set_listener(self, addr, port, path_mtu=512):
2172 """Set HA listener (local settings)
2173
2174 :param addr: local IP4 address
2175 :param port: local UDP port number
2176 :param path_mtu: path MTU (Default value = 512)
2177 """
2178 return self.api(self.papi.nat_ha_set_listener,
2179 {'ip_address': addr,
2180 'port': port,
2181 'path_mtu': path_mtu})
2182
2183 def nat_ha_get_listener(self):
2184 """Get HA listener/local configuration"""
2185 return self.api(self.papi.nat_ha_get_listener, {})
2186
2187 def nat_ha_set_failover(self, addr, port, refresh=10):
2188 """Set HA failover (remote settings)
2189
2190 :param addr: failover IP4 address
2191 :param port: failvoer UDP port number
2192 :param refresh: number of seconds after which to send session refresh
2193 """
2194 return self.api(self.papi.nat_ha_set_failover,
2195 {'ip_address': addr,
2196 'port': port,
2197 'session_refresh_interval': refresh})
2198
2199 def nat_ha_get_failover(self):
2200 """Get HA failover/remote settings reply"""
2201 return self.api(self.papi.nat_ha_get_failover, {})
2202
2203 def nat_ha_flush(self):
2204 """Flush the current HA data"""
2205 return self.api(self.papi.nat_ha_flush, {})
2206
2207 def nat_ha_resync(self, want_resync_event=1):
2208 """Resync HA (resend existing sessions to new failover)
2209 :param want_resync_event: if non-zero resync completed event sent
2210 """
2211 return self.api(self.papi.nat_ha_resync,
2212 {'want_resync_event': want_resync_event,
2213 'pid': os.getpid()})
2214
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002215 def control_ping(self):
2216 self.api(self.papi.control_ping)
2217
2218 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002219 detect_mult, local_addr, peer_addr, is_ipv6=0,
2220 bfd_key_id=None, conf_key_id=None):
2221 if bfd_key_id is None:
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 })
2232 else:
2233 return self.api(self.papi.bfd_udp_add,
2234 {
2235 'sw_if_index': sw_if_index,
2236 'desired_min_tx': desired_min_tx,
2237 'required_min_rx': required_min_rx,
2238 'local_addr': local_addr,
2239 'peer_addr': peer_addr,
2240 'is_ipv6': is_ipv6,
2241 'detect_mult': detect_mult,
2242 'is_authenticated': 1,
2243 'bfd_key_id': bfd_key_id,
2244 'conf_key_id': conf_key_id,
2245 })
2246
Klement Sekeraa57a9702017-02-02 06:58:07 +01002247 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2248 detect_mult, local_addr, peer_addr, is_ipv6=0):
2249 return self.api(self.papi.bfd_udp_mod,
2250 {
2251 'sw_if_index': sw_if_index,
2252 'desired_min_tx': desired_min_tx,
2253 'required_min_rx': required_min_rx,
2254 'local_addr': local_addr,
2255 'peer_addr': peer_addr,
2256 'is_ipv6': is_ipv6,
2257 'detect_mult': detect_mult,
2258 })
2259
Klement Sekerab17dd962017-01-09 07:43:48 +01002260 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2261 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2262 is_delayed=False):
2263 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002264 {
2265 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002266 'local_addr': local_addr,
2267 'peer_addr': peer_addr,
2268 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002269 'is_delayed': 1 if is_delayed else 0,
2270 'bfd_key_id': bfd_key_id,
2271 'conf_key_id': conf_key_id,
2272 })
2273
2274 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2275 is_ipv6=0, is_delayed=False):
2276 return self.api(self.papi.bfd_udp_auth_deactivate,
2277 {
2278 'sw_if_index': sw_if_index,
2279 'local_addr': local_addr,
2280 'peer_addr': peer_addr,
2281 'is_ipv6': is_ipv6,
2282 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002283 })
2284
2285 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2286 return self.api(self.papi.bfd_udp_del,
2287 {
2288 'sw_if_index': sw_if_index,
2289 'local_addr': local_addr,
2290 'peer_addr': peer_addr,
2291 'is_ipv6': is_ipv6,
2292 })
2293
2294 def bfd_udp_session_dump(self):
2295 return self.api(self.papi.bfd_udp_session_dump, {})
2296
Klement Sekerab17dd962017-01-09 07:43:48 +01002297 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2298 peer_addr, is_ipv6=0):
2299 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002300 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002301 'sw_if_index': sw_if_index,
2302 'local_addr': local_addr,
2303 'peer_addr': peer_addr,
2304 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002305 })
2306
2307 def want_bfd_events(self, enable_disable=1):
2308 return self.api(self.papi.want_bfd_events, {
2309 'enable_disable': enable_disable,
2310 'pid': os.getpid(),
2311 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002312
Klement Sekerab17dd962017-01-09 07:43:48 +01002313 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2314 return self.api(self.papi.bfd_auth_set_key, {
2315 'conf_key_id': conf_key_id,
2316 'auth_type': auth_type,
2317 'key': key,
2318 'key_len': len(key),
2319 })
2320
2321 def bfd_auth_del_key(self, conf_key_id):
2322 return self.api(self.papi.bfd_auth_del_key, {
2323 'conf_key_id': conf_key_id,
2324 })
2325
2326 def bfd_auth_keys_dump(self):
2327 return self.api(self.papi.bfd_auth_keys_dump, {})
2328
Klement Sekera239790f2017-02-16 10:53:53 +01002329 def bfd_udp_set_echo_source(self, sw_if_index):
2330 return self.api(self.papi.bfd_udp_set_echo_source,
2331 {'sw_if_index': sw_if_index})
2332
Klement Sekera73884482017-02-23 09:26:30 +01002333 def bfd_udp_del_echo_source(self):
2334 return self.api(self.papi.bfd_udp_del_echo_source, {})
2335
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002336 def bfd_udp_get_echo_source(self):
2337 return self.api(self.papi.bfd_udp_get_echo_source, {})
2338
Steve Shin7957d6e2016-12-19 09:24:50 -08002339 def classify_add_del_table(
2340 self,
2341 is_add,
2342 mask,
2343 match_n_vectors=1,
2344 table_index=0xFFFFFFFF,
2345 nbuckets=2,
2346 memory_size=2097152,
2347 skip_n_vectors=0,
2348 next_table_index=0xFFFFFFFF,
2349 miss_next_index=0xFFFFFFFF,
2350 current_data_flag=0,
2351 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002352 """
2353 :param is_add:
2354 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002355 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002356 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002357 :param nbuckets: (Default value = 2)
2358 :param memory_size: (Default value = 2097152)
2359 :param skip_n_vectors: (Default value = 0)
2360 :param next_table_index: (Default value = 0xFFFFFFFF)
2361 :param miss_next_index: (Default value = 0xFFFFFFFF)
2362 :param current_data_flag: (Default value = 0)
2363 :param current_data_offset: (Default value = 0)
2364 """
2365
Juraj Sloboda75282452018-06-12 14:20:49 +02002366 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2367 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002368 return self.api(
2369 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002370 {'is_add': is_add,
2371 'table_index': table_index,
2372 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002373 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002374 'skip_n_vectors': skip_n_vectors,
2375 'match_n_vectors': match_n_vectors,
2376 'next_table_index': next_table_index,
2377 'miss_next_index': miss_next_index,
2378 'current_data_flag': current_data_flag,
2379 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002380 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002381 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002382
2383 def classify_add_del_session(
2384 self,
2385 is_add,
2386 table_index,
2387 match,
2388 opaque_index=0xFFFFFFFF,
2389 hit_next_index=0xFFFFFFFF,
2390 advance=0,
2391 action=0,
2392 metadata=0):
2393 """
2394 :param is_add:
2395 :param table_index:
2396 :param match:
2397 :param opaque_index: (Default value = 0xFFFFFFFF)
2398 :param hit_next_index: (Default value = 0xFFFFFFFF)
2399 :param advance: (Default value = 0)
2400 :param action: (Default value = 0)
2401 :param metadata: (Default value = 0)
2402 """
2403
Juraj Sloboda75282452018-06-12 14:20:49 +02002404 match_len = ((len(match) - 1) / 16 + 1) * 16
2405 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002406 return self.api(
2407 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002408 {'is_add': is_add,
2409 'table_index': table_index,
2410 'hit_next_index': hit_next_index,
2411 'opaque_index': opaque_index,
2412 'advance': advance,
2413 'action': action,
2414 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002415 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002416 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002417
2418 def input_acl_set_interface(
2419 self,
2420 is_add,
2421 sw_if_index,
2422 ip4_table_index=0xFFFFFFFF,
2423 ip6_table_index=0xFFFFFFFF,
2424 l2_table_index=0xFFFFFFFF):
2425 """
2426 :param is_add:
2427 :param sw_if_index:
2428 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2429 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2430 :param l2_table_index: (Default value = 0xFFFFFFFF)
2431 """
2432
2433 return self.api(
2434 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002435 {'sw_if_index': sw_if_index,
2436 'ip4_table_index': ip4_table_index,
2437 'ip6_table_index': ip6_table_index,
2438 'l2_table_index': l2_table_index,
2439 'is_add': is_add})
2440
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002441 def output_acl_set_interface(
2442 self,
2443 is_add,
2444 sw_if_index,
2445 ip4_table_index=0xFFFFFFFF,
2446 ip6_table_index=0xFFFFFFFF,
2447 l2_table_index=0xFFFFFFFF):
2448 """
2449 :param is_add:
2450 :param sw_if_index:
2451 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2452 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2453 :param l2_table_index: (Default value = 0xFFFFFFFF)
2454 """
2455
2456 return self.api(
2457 self.papi.output_acl_set_interface,
2458 {'sw_if_index': sw_if_index,
2459 'ip4_table_index': ip4_table_index,
2460 'ip6_table_index': ip6_table_index,
2461 'l2_table_index': l2_table_index,
2462 'is_add': is_add})
2463
Klement Sekera77fabdb2017-01-02 07:46:14 +01002464 def set_ipfix_exporter(
2465 self,
2466 collector_address,
2467 src_address,
2468 path_mtu,
2469 template_interval,
2470 vrf_id=0,
2471 collector_port=4739,
2472 udp_checksum=0):
2473 return self.api(
2474 self.papi.set_ipfix_exporter,
2475 {
2476 'collector_address': collector_address,
2477 'collector_port': collector_port,
2478 'src_address': src_address,
2479 'vrf_id': vrf_id,
2480 'path_mtu': path_mtu,
2481 'template_interval': template_interval,
2482 'udp_checksum': udp_checksum,
2483 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002484
2485 def dhcp_proxy_config(self,
2486 dhcp_server,
2487 dhcp_src_address,
2488 rx_table_id=0,
2489 server_table_id=0,
2490 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002491 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002492 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002493 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002494 {
2495 'rx_vrf_id': rx_table_id,
2496 'server_vrf_id': server_table_id,
2497 'is_ipv6': is_ipv6,
2498 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002499 'dhcp_server': dhcp_server,
2500 'dhcp_src_address': dhcp_src_address,
2501 })
2502
2503 def dhcp_proxy_set_vss(self,
2504 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002505 vss_type=255,
2506 vpn_ascii_id="",
2507 oui=0,
2508 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002509 is_add=1,
2510 is_ip6=0):
2511 return self.api(
2512 self.papi.dhcp_proxy_set_vss,
2513 {
2514 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002515 'vss_type': vss_type,
2516 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002517 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002518 'vpn_index': vpn_index,
2519 'is_add': is_add,
2520 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002521 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002522
Neale Rannsdaff1782018-05-16 04:12:18 -07002523 def dhcp_client_dump(self):
2524 return self.api(self.papi.dhcp_client_dump, {})
2525
Ole Troane1ade682019-03-04 23:55:43 +01002526 def dhcp_client_config(self,
2527 sw_if_index,
2528 hostname,
2529 client_id='',
2530 is_add=1,
2531 set_broadcast_flag=1,
2532 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002533 return self.api(
2534 self.papi.dhcp_client_config,
2535 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002536 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002537 'client': {
2538 'sw_if_index': sw_if_index,
2539 'hostname': hostname,
2540 'id': client_id,
2541 'want_dhcp_event': want_dhcp_events,
2542 'set_broadcast_flag': set_broadcast_flag,
2543 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002544 })
2545
Neale Ranns32e1c012016-11-22 17:07:28 +00002546 def ip_mroute_add_del(self,
2547 src_address,
2548 grp_address,
2549 grp_address_length,
2550 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002551 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002552 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002553 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002554 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002555 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002556 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002557 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002558 is_add=1,
2559 is_ipv6=0,
2560 is_local=0):
2561 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002562 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002563 """
2564 return self.api(
2565 self.papi.ip_mroute_add_del,
2566 {'next_hop_sw_if_index': next_hop_sw_if_index,
2567 'entry_flags': e_flags,
2568 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002569 'table_id': table_id,
2570 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002571 'is_add': is_add,
2572 'is_ipv6': is_ipv6,
2573 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002574 'bier_imp': bier_imp,
2575 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002576 'grp_address_length': grp_address_length,
2577 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002578 'src_address': src_address,
2579 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002580
2581 def mfib_signal_dump(self):
2582 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002583
2584 def ip_mfib_dump(self):
2585 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002586
Neale Rannsd792d9c2017-10-21 10:53:20 -07002587 def ip6_mfib_dump(self):
2588 return self.api(self.papi.ip6_mfib_dump, {})
2589
Filip Tehlar770e89e2017-01-31 10:39:16 +01002590 def lisp_enable_disable(self, is_enabled):
2591 return self.api(
2592 self.papi.lisp_enable_disable,
2593 {
2594 'is_en': is_enabled,
2595 })
2596
Ole Troane1ade682019-03-04 23:55:43 +01002597 def lisp_add_del_locator_set(self,
2598 ls_name,
2599 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01002600 return self.api(
2601 self.papi.lisp_add_del_locator_set,
2602 {
2603 'is_add': is_add,
2604 'locator_set_name': ls_name
2605 })
2606
2607 def lisp_locator_set_dump(self):
2608 return self.api(self.papi.lisp_locator_set_dump, {})
2609
Ole Troane1ade682019-03-04 23:55:43 +01002610 def lisp_add_del_locator(self,
2611 ls_name,
2612 sw_if_index,
2613 priority=1,
2614 weight=1,
2615 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01002616 return self.api(
2617 self.papi.lisp_add_del_locator,
2618 {
2619 'is_add': is_add,
2620 'locator_set_name': ls_name,
2621 'sw_if_index': sw_if_index,
2622 'priority': priority,
2623 'weight': weight
2624 })
2625
2626 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2627 return self.api(
2628 self.papi.lisp_locator_dump,
2629 {
2630 'is_index_set': is_index_set,
2631 'ls_name': ls_name,
2632 'ls_index': ls_index,
2633 })
2634
Ole Troane1ade682019-03-04 23:55:43 +01002635 def lisp_add_del_local_eid(self,
2636 ls_name,
2637 eid_type,
2638 eid,
2639 prefix_len,
2640 vni=0,
2641 key_id=0,
2642 key="",
2643 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01002644 return self.api(
2645 self.papi.lisp_add_del_local_eid,
2646 {
2647 'locator_set_name': ls_name,
2648 'is_add': is_add,
2649 'eid_type': eid_type,
2650 'eid': eid,
2651 'prefix_len': prefix_len,
2652 'vni': vni,
2653 'key_id': key_id,
2654 'key': key
2655 })
2656
2657 def lisp_eid_table_dump(self,
2658 eid_set=0,
2659 prefix_length=0,
2660 vni=0,
2661 eid_type=0,
2662 eid=None,
2663 filter_opt=0):
2664 return self.api(
2665 self.papi.lisp_eid_table_dump,
2666 {
2667 'eid_set': eid_set,
2668 'prefix_length': prefix_length,
2669 'vni': vni,
2670 'eid_type': eid_type,
2671 'eid': eid,
2672 'filter': filter_opt,
2673 })
2674
Ole Troane1ade682019-03-04 23:55:43 +01002675 def lisp_add_del_remote_mapping(self,
2676 eid_type,
2677 eid,
2678 eid_prefix_len=0,
2679 vni=0,
2680 rlocs=[],
2681 rlocs_num=0,
2682 is_src_dst=0,
2683 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01002684 return self.api(
2685 self.papi.lisp_add_del_remote_mapping,
2686 {
2687 'is_add': is_add,
2688 'eid_type': eid_type,
2689 'eid': eid,
2690 'eid_len': eid_prefix_len,
2691 'rloc_num': rlocs_num,
2692 'rlocs': rlocs,
2693 'vni': vni,
2694 'is_src_dst': is_src_dst,
2695 })
2696
Ole Troane1ade682019-03-04 23:55:43 +01002697 def lisp_add_del_adjacency(self,
2698 leid,
2699 reid,
2700 leid_len,
2701 reid_len,
2702 eid_type,
2703 is_add=1,
2704 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01002705 return self.api(
2706 self.papi.lisp_add_del_adjacency,
2707 {
2708 'is_add': is_add,
2709 'vni': vni,
2710 'eid_type': eid_type,
2711 'leid': leid,
2712 'reid': reid,
2713 'leid_len': leid_len,
2714 'reid_len': reid_len,
2715 })
2716
2717 def lisp_adjacencies_get(self, vni=0):
2718 return self.api(
2719 self.papi.lisp_adjacencies_get,
2720 {
2721 'vni': vni
2722 })
Neale Ranns80823802017-02-20 18:23:41 -08002723
Hongjun Nief486b12017-04-12 19:21:16 +08002724 def gtpu_add_del_tunnel(
2725 self,
2726 src_addr,
2727 dst_addr,
2728 is_add=1,
2729 is_ipv6=0,
2730 mcast_sw_if_index=0xFFFFFFFF,
2731 encap_vrf_id=0,
2732 decap_next_index=0xFFFFFFFF,
2733 teid=0):
2734 """
2735
2736 :param is_add: (Default value = 1)
2737 :param is_ipv6: (Default value = 0)
2738 :param src_addr:
2739 :param dst_addr:
2740 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2741 :param encap_vrf_id: (Default value = 0)
2742 :param decap_next_index: (Default value = 0xFFFFFFFF)
2743 :param teid: (Default value = 0)
2744
2745 """
2746 return self.api(self.papi.gtpu_add_del_tunnel,
2747 {'is_add': is_add,
2748 'is_ipv6': is_ipv6,
2749 'src_address': src_addr,
2750 'dst_address': dst_addr,
2751 'mcast_sw_if_index': mcast_sw_if_index,
2752 'encap_vrf_id': encap_vrf_id,
2753 'decap_next_index': decap_next_index,
2754 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002755
2756 def vxlan_gpe_add_del_tunnel(
2757 self,
2758 src_addr,
2759 dst_addr,
2760 mcast_sw_if_index=0xFFFFFFFF,
2761 is_add=1,
2762 is_ipv6=0,
2763 encap_vrf_id=0,
2764 decap_vrf_id=0,
2765 protocol=3,
2766 vni=0):
2767 """
2768
2769 :param local:
2770 :param remote:
2771 :param is_add: (Default value = 1)
2772 :param is_ipv6: (Default value = 0)
2773 :param encap_vrf_id: (Default value = 0)
2774 :param decap_vrf_id: (Default value = 0)
2775 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2776 :param protocol: (Default value = 3)
2777 :param vni: (Default value = 0)
2778
2779 """
2780 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2781 {'is_add': is_add,
2782 'is_ipv6': is_ipv6,
2783 'local': src_addr,
2784 'remote': dst_addr,
2785 'mcast_sw_if_index': mcast_sw_if_index,
2786 'encap_vrf_id': encap_vrf_id,
2787 'decap_vrf_id': decap_vrf_id,
2788 'protocol': protocol,
2789 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002790
Neale Ranns79a05f52018-09-11 07:39:43 -07002791 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002792 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002793 src,
2794 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002795 mcast_sw_if_index=0xFFFFFFFF,
2796 is_add=1,
2797 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002798 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002799 vni=0,
2800 instance=0xFFFFFFFF):
2801 """
2802
2803 :param dst_addr:
2804 :param src_addr:
2805 :param is_add: (Default value = 1)
2806 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002807 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002808 :param decap_next_index: (Default value = 0xFFFFFFFF)
2809 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2810 :param vni: (Default value = 0)
2811 :param instance: (Default value = 0xFFFFFFFF)
2812
2813 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002814 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002815 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002816 'tunnel': {
2817 'src': src,
2818 'dst': dst,
2819 'mcast_sw_if_index': mcast_sw_if_index,
2820 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002821 'vni': vni,
2822 'instance': instance}})
2823
2824 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2825 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01002826 {'sw_if_index': sw_if_index,
2827 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002828
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002829 def pppoe_add_del_session(
2830 self,
2831 client_ip,
2832 client_mac,
2833 session_id=0,
2834 is_add=1,
2835 is_ipv6=0,
2836 decap_vrf_id=0):
2837 """
2838
2839 :param is_add: (Default value = 1)
2840 :param is_ipv6: (Default value = 0)
2841 :param client_ip:
2842 :param session_id: (Default value = 0)
2843 :param client_mac:
2844 :param decap_vrf_id: (Default value = 0)
2845
2846 """
2847 return self.api(self.papi.pppoe_add_del_session,
2848 {'is_add': is_add,
2849 'is_ipv6': is_ipv6,
2850 'session_id': session_id,
2851 'client_ip': client_ip,
2852 'decap_vrf_id': decap_vrf_id,
2853 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002854
Neale Ranns7c922dc2018-08-30 06:12:27 -07002855 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2856 return self.api(self.papi.sr_mpls_policy_add,
2857 {'bsid': bsid,
2858 'weight': weight,
2859 'type': type,
2860 'n_segments': len(segments),
2861 'segments': segments})
2862
2863 def sr_mpls_policy_del(self, bsid):
2864 return self.api(self.papi.sr_mpls_policy_del,
2865 {'bsid': bsid})
2866
Kris Michielsen91074432017-06-22 13:00:20 +02002867 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002868 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002869 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002870 nh_addr4,
2871 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002872 is_del=0,
2873 end_psp=0,
2874 sw_if_index=0xFFFFFFFF,
2875 vlan_index=0,
2876 fib_table=0,
2877 ):
2878 """ Add/del IPv6 SR local-SID.
2879
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002880 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002881 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2882 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002883 :param nh_addr4:
2884 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002885 :param is_del: (Default value = 0)
2886 :param end_psp: (Default value = 0)
2887 :param sw_if_index: (Default value = 0xFFFFFFFF)
2888 :param vlan_index: (Default value = 0)
2889 :param fib_table: (Default value = 0)
2890 """
2891 return self.api(
2892 self.papi.sr_localsid_add_del,
2893 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002894 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002895 'end_psp': end_psp,
2896 'behavior': behavior,
2897 'sw_if_index': sw_if_index,
2898 'vlan_index': vlan_index,
2899 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002900 'nh_addr4': nh_addr4,
2901 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002902 }
2903 )
2904
2905 def sr_policy_add(
2906 self,
2907 bsid_addr,
2908 weight=1,
2909 is_encap=1,
2910 type=0,
2911 fib_table=0,
2912 n_segments=0,
2913 segments=[]):
2914 """
2915 :param bsid_addr: bindingSID of the SR Policy
2916 :param weight: weight of the sid list. optional. (default: 1)
2917 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2918 (default: Encap)
2919 :param type: type/behavior of the SR policy. (default or spray) \
2920 (default: default)
2921 :param fib_table: VRF where to install the FIB entry for the BSID \
2922 (default: 0)
2923 :param n_segments: number of segments \
2924 (default: 0)
2925 :param segments: a vector of IPv6 address composing the segment list \
2926 (default: [])
2927 """
2928 return self.api(
2929 self.papi.sr_policy_add,
2930 {'bsid_addr': bsid_addr,
2931 'weight': weight,
2932 'is_encap': is_encap,
2933 'type': type,
2934 'fib_table': fib_table,
2935 'n_segments': n_segments,
2936 'segments': segments
2937 }
2938 )
2939
2940 def sr_policy_del(
2941 self,
2942 bsid_addr,
2943 sr_policy_index=0):
2944 """
2945 :param bsid: bindingSID of the SR Policy
2946 :param sr_policy_index: index of the sr policy (default: 0)
2947 """
2948 return self.api(
2949 self.papi.sr_policy_del,
2950 {'bsid_addr': bsid_addr,
2951 'sr_policy_index': sr_policy_index
2952 })
2953
2954 def sr_steering_add_del(
2955 self,
2956 is_del,
2957 bsid_addr,
2958 sr_policy_index,
2959 table_id,
2960 prefix_addr,
2961 mask_width,
2962 sw_if_index,
2963 traffic_type):
2964 """
2965 Steer traffic L2 and L3 traffic through a given SR policy
2966
2967 :param is_del: delete or add
2968 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2969 :param sr_policy: is the index of the SR Policy (alt to bsid)
2970 :param table_id: is the VRF where to install the FIB entry for the BSID
2971 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2972 :param mask_width: is the mask for L3 traffic type
2973 :param sw_if_index: is the incoming interface for L2 traffic
2974 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2975 """
2976 return self.api(
2977 self.papi.sr_steering_add_del,
2978 {'is_del': is_del,
2979 'bsid_addr': bsid_addr,
2980 'sr_policy_index': sr_policy_index,
2981 'table_id': table_id,
2982 'prefix_addr': prefix_addr,
2983 'mask_width': mask_width,
2984 'sw_if_index': sw_if_index,
2985 'traffic_type': traffic_type
2986 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002987
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002988 def acl_add_replace(self, acl_index, r, tag='',
2989 expected_retval=0):
2990 """Add/replace an ACL
2991 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2992 :param acl_rule r: ACL rules array.
2993 :param str tag: symbolic tag (description) for this ACL.
2994 :param int count: number of rules.
2995 """
2996 return self.api(self.papi.acl_add_replace,
2997 {'acl_index': acl_index,
2998 'r': r,
2999 'count': len(r),
3000 'tag': tag},
3001 expected_retval=expected_retval)
3002
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003003 def acl_del(self, acl_index, expected_retval=0):
3004 """
3005
3006 :param acl_index:
3007 :return:
3008 """
3009 return self.api(self.papi.acl_del,
3010 {'acl_index': acl_index},
3011 expected_retval=expected_retval)
3012
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003013 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3014 expected_retval=0):
3015 return self.api(self.papi.acl_interface_set_acl_list,
3016 {'sw_if_index': sw_if_index,
3017 'count': len(acls),
3018 'n_input': n_input,
3019 'acls': acls},
3020 expected_retval=expected_retval)
3021
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003022 def acl_interface_set_etype_whitelist(self, sw_if_index,
3023 n_input, whitelist,
3024 expected_retval=0):
3025 return self.api(self.papi.acl_interface_set_etype_whitelist,
3026 {'sw_if_index': sw_if_index,
3027 'count': len(whitelist),
3028 'n_input': n_input,
3029 'whitelist': whitelist},
3030 expected_retval=expected_retval)
3031
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003032 def acl_interface_add_del(self,
3033 sw_if_index,
3034 acl_index,
3035 is_add=1):
3036 """ Add/Delete ACL to/from interface
3037
3038 :param sw_if_index:
3039 :param acl_index:
3040 :param is_add: (Default value = 1)
3041 """
3042
3043 return self.api(self.papi.acl_interface_add_del,
3044 {'is_add': is_add,
3045 'is_input': 1,
3046 'sw_if_index': sw_if_index,
3047 'acl_index': acl_index})
3048
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003049 def acl_dump(self, acl_index, expected_retval=0):
3050 return self.api(self.papi.acl_dump,
3051 {'acl_index': acl_index},
3052 expected_retval=expected_retval)
3053
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003054 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3055 expected_retval=0):
3056 return self.api(self.papi.acl_interface_list_dump,
3057 {'sw_if_index': sw_if_index},
3058 expected_retval=expected_retval)
3059
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003060 def macip_acl_add(self, rules, tag=""):
3061 """ Add MACIP acl
3062
3063 :param rules: list of rules for given acl
3064 :param tag: acl tag
3065 """
3066
3067 return self.api(self.papi.macip_acl_add,
3068 {'r': rules,
3069 'count': len(rules),
3070 'tag': tag})
3071
Pavel Kotucek932f7412017-09-07 14:44:52 +02003072 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3073 """ Add MACIP acl
3074
3075 :param rules: list of rules for given acl
3076 :param tag: acl tag
3077 """
3078
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003079 return self.api(self.papi.macip_acl_add_replace,
3080 {'acl_index': acl_index,
3081 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003082 'count': len(rules),
3083 'tag': tag})
3084
3085 def macip_acl_del(self, acl_index):
3086 """
3087
3088 :param acl_index:
3089 :return:
3090 """
3091 return self.api(self.papi.macip_acl_del,
3092 {'acl_index': acl_index})
3093
3094 def macip_acl_interface_add_del(self,
3095 sw_if_index,
3096 acl_index,
3097 is_add=1):
3098 """ Add MACIP acl to interface
3099
3100 :param sw_if_index:
3101 :param acl_index:
3102 :param is_add: (Default value = 1)
3103 """
3104
3105 return self.api(self.papi.macip_acl_interface_add_del,
3106 {'is_add': is_add,
3107 'sw_if_index': sw_if_index,
3108 'acl_index': acl_index})
3109
3110 def macip_acl_interface_get(self):
3111 """ Return interface acls dump
3112 """
3113 return self.api(
3114 self.papi.macip_acl_interface_get, {})
3115
3116 def macip_acl_dump(self, acl_index=4294967295):
3117 """ Return MACIP acl dump
3118 """
3119
3120 return self.api(
3121 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003122
3123 def policer_add_del(self,
3124 name,
3125 cir,
3126 eir,
3127 cb,
3128 eb,
3129 is_add=1,
3130 rate_type=0,
3131 round_type=0,
3132 ptype=0,
3133 color_aware=0,
3134 conform_action_type=1,
3135 conform_dscp=0,
3136 exceed_action_type=0,
3137 exceed_dscp=0,
3138 violate_action_type=0,
3139 violate_dscp=0):
3140 return self.api(self.papi.policer_add_del,
3141 {'name': name,
3142 'cir': cir,
3143 'eir': eir,
3144 'cb': cb,
3145 'eb': eb,
3146 'is_add': is_add,
3147 'rate_type': rate_type,
3148 'round_type': round_type,
3149 'type': ptype,
3150 'color_aware': color_aware,
3151 'conform_action_type': conform_action_type,
3152 'conform_dscp': conform_dscp,
3153 'exceed_action_type': exceed_action_type,
3154 'exceed_dscp': exceed_dscp,
3155 'violate_action_type': violate_action_type,
3156 'violate_dscp': violate_dscp})
3157
3158 def ip_punt_police(self,
3159 policer_index,
3160 is_ip6=0,
3161 is_add=1):
3162 return self.api(self.papi.ip_punt_police,
3163 {'policer_index': policer_index,
3164 'is_add': is_add,
3165 'is_ip6': is_ip6})
3166
3167 def ip_punt_redirect(self,
3168 rx_sw_if_index,
3169 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003170 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07003171 is_add=1):
3172 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003173 {'punt': {'rx_sw_if_index': rx_sw_if_index,
3174 'tx_sw_if_index': tx_sw_if_index,
3175 'nh': address},
3176 'is_add': is_add})
3177
3178 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
3179 return self.api(self.papi.ip_punt_redirect_dump,
3180 {'sw_if_index': sw_if_index,
3181 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003182
3183 def bier_table_add_del(self,
3184 bti,
3185 mpls_label,
3186 is_add=1):
3187 """ BIER Table add/del """
3188 return self.api(
3189 self.papi.bier_table_add_del,
3190 {'bt_tbl_id': {"bt_set": bti.set_id,
3191 "bt_sub_domain": bti.sub_domain_id,
3192 "bt_hdr_len_id": bti.hdr_len_id},
3193 'bt_label': mpls_label,
3194 'bt_is_add': is_add})
3195
3196 def bier_table_dump(self):
3197 return self.api(self.papi.bier_table_dump, {})
3198
3199 def bier_route_add_del(self,
3200 bti,
3201 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003202 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003203 is_add=1,
3204 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003205 """ BIER Route add/del """
3206 return self.api(
3207 self.papi.bier_route_add_del,
3208 {'br_tbl_id': {"bt_set": bti.set_id,
3209 "bt_sub_domain": bti.sub_domain_id,
3210 "bt_hdr_len_id": bti.hdr_len_id},
3211 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003212 'br_n_paths': len(paths),
3213 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003214 'br_is_add': is_add,
3215 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003216
3217 def bier_route_dump(self, bti):
3218 return self.api(
3219 self.papi.bier_route_dump,
3220 {'br_tbl_id': {"bt_set": bti.set_id,
3221 "bt_sub_domain": bti.sub_domain_id,
3222 "bt_hdr_len_id": bti.hdr_len_id}})
3223
3224 def bier_imp_add(self,
3225 bti,
3226 src,
3227 ibytes,
3228 is_add=1):
3229 """ BIER Imposition Add """
3230 return self.api(
3231 self.papi.bier_imp_add,
3232 {'bi_tbl_id': {"bt_set": bti.set_id,
3233 "bt_sub_domain": bti.sub_domain_id,
3234 "bt_hdr_len_id": bti.hdr_len_id},
3235 'bi_src': src,
3236 'bi_n_bytes': len(ibytes),
3237 'bi_bytes': ibytes})
3238
3239 def bier_imp_del(self, bi_index):
3240 """ BIER Imposition del """
3241 return self.api(
3242 self.papi.bier_imp_del,
3243 {'bi_index': bi_index})
3244
3245 def bier_imp_dump(self):
3246 return self.api(self.papi.bier_imp_dump, {})
3247
3248 def bier_disp_table_add_del(self,
3249 bdti,
3250 is_add=1):
3251 """ BIER Disposition Table add/del """
3252 return self.api(
3253 self.papi.bier_disp_table_add_del,
3254 {'bdt_tbl_id': bdti,
3255 'bdt_is_add': is_add})
3256
3257 def bier_disp_table_dump(self):
3258 return self.api(self.papi.bier_disp_table_dump, {})
3259
3260 def bier_disp_entry_add_del(self,
3261 bdti,
3262 bp,
3263 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003264 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003265 next_hop,
3266 next_hop_tbl_id=0,
3267 next_hop_rpf_id=~0,
3268 next_hop_is_ip4=1,
3269 is_add=1):
3270 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003271 lstack = []
3272 while (len(lstack) < 16):
3273 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003274 return self.api(
3275 self.papi.bier_disp_entry_add_del,
3276 {'bde_tbl_id': bdti,
3277 'bde_bp': bp,
3278 'bde_payload_proto': payload_proto,
3279 'bde_n_paths': 1,
3280 'bde_paths': [{'next_hop': next_hop,
3281 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003282 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003283 'rpf_id': next_hop_rpf_id,
3284 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003285 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003286 'bde_is_add': is_add})
3287
3288 def bier_disp_entry_dump(self, bdti):
3289 return self.api(
3290 self.papi.bier_disp_entry_dump,
3291 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003292
3293 def add_node_next(self, node_name, next_name):
3294 """ Set the next node for a given node request
3295
3296 :param node_name:
3297 :param next_name:
3298 """
3299 return self.api(self.papi.add_node_next,
3300 {'node_name': node_name,
3301 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003302
3303 def session_enable_disable(self, is_enabled):
3304 return self.api(
3305 self.papi.session_enable_disable,
3306 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003307
3308 def ipsec_spd_add_del(self, spd_id, is_add=1):
3309 """ SPD add/del - Wrapper to add or del ipsec SPD
3310 Sample CLI : 'ipsec spd add 1'
3311
3312 :param spd_id - SPD ID to be created in the vpp . mandatory
3313 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3314 optional
3315 :returns: reply from the API
3316 """
3317 return self.api(
3318 self.papi.ipsec_spd_add_del, {
3319 'spd_id': spd_id, 'is_add': is_add})
3320
Neale Ranns311124e2019-01-24 04:52:25 -08003321 def ipsec_spds_dump(self):
3322 return self.api(self.papi.ipsec_spds_dump, {})
3323
“mystarrocks”23f0c452017-12-11 07:11:51 -08003324 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3325 """ IPSEC interface SPD add/del - \
3326 Wrapper to associate/disassociate SPD to interface in VPP
3327 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3328
3329 :param spd_id - SPD ID to associate with the interface . mandatory
3330 :param sw_if_index - Interface Index which needs to ipsec \
3331 association mandatory
3332 :param is_add - add(1) or del(0) association with interface \
3333 (Default 1 - add) . optional
3334 :returns: reply from the API
3335 """
3336 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003337 self.papi.ipsec_interface_add_del_spd,
3338 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003339
Neale Ranns311124e2019-01-24 04:52:25 -08003340 def ipsec_spd_interface_dump(self, spd_index=None):
3341 return self.api(self.papi.ipsec_spd_interface_dump,
3342 {'spd_index': spd_index if spd_index else 0,
3343 'spd_index_valid': 1 if spd_index else 0})
3344
Neale Ranns17dcec02019-01-09 21:22:20 -08003345 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003346 sad_id,
3347 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003348 integrity_algorithm,
3349 integrity_key,
3350 crypto_algorithm,
3351 crypto_key,
3352 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003353 tunnel_src_address='',
3354 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08003355 flags=0,
3356 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003357 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003358 :param sad_id: security association ID
3359 :param spi: security param index of the SA in decimal
3360 :param integrity_algorithm:
3361 :param integrity_key:
3362 :param crypto_algorithm:
3363 :param crypto_key:
3364 :param protocol: AH(0) or ESP(1) protocol
3365 :param tunnel_src_address: tunnel mode outer src address
3366 :param tunnel_dst_address: tunnel mode outer dst address
3367 :param is_add:
3368 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003369 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3370 crypto and ipsec algorithms
3371 """
3372 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08003373 self.papi.ipsec_sad_entry_add_del,
3374 {
3375 'is_add': is_add,
3376 'entry':
3377 {
3378 'sad_id': sad_id,
3379 'spi': spi,
3380 'tunnel_src': tunnel_src_address,
3381 'tunnel_dst': tunnel_dst_address,
3382 'protocol': protocol,
3383 'integrity_algorithm': integrity_algorithm,
3384 'integrity_key': {
3385 'length': len(integrity_key),
3386 'data': integrity_key,
3387 },
3388 'crypto_algorithm': crypto_algorithm,
3389 'crypto_key': {
3390 'length': len(crypto_key),
3391 'data': crypto_key,
3392 },
3393 'flags': flags,
3394 }
3395 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08003396
Neale Ranns311124e2019-01-24 04:52:25 -08003397 def ipsec_sa_dump(self, sa_id=None):
3398 return self.api(self.papi.ipsec_sa_dump,
3399 {'sa_id': sa_id if sa_id else 0xffffffff})
3400
Neale Ranns17dcec02019-01-09 21:22:20 -08003401 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003402 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003403 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003404 local_address_start,
3405 local_address_stop,
3406 remote_address_start,
3407 remote_address_stop,
3408 local_port_start=0,
3409 local_port_stop=65535,
3410 remote_port_start=0,
3411 remote_port_stop=65535,
3412 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003413 policy=0,
3414 priority=100,
3415 is_outbound=1,
3416 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003417 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003418 is_ip_any=0):
3419 """ IPSEC policy SPD add/del -
3420 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003421 :param spd_id: SPD ID for the policy
3422 :param local_address_start: local-ip-range start address
3423 :param local_address_stop : local-ip-range stop address
3424 :param remote_address_start: remote-ip-range start address
3425 :param remote_address_stop : remote-ip-range stop address
3426 :param local_port_start: (Default value = 0)
3427 :param local_port_stop: (Default value = 65535)
3428 :param remote_port_start: (Default value = 0)
3429 :param remote_port_stop: (Default value = 65535)
3430 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3431 :param sa_id: Security Association ID for mapping it to SPD
3432 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3433 (Default value = 0)
3434 :param priority: value for the spd action (Default value = 100)
3435 :param is_outbound: flag for inbound(0) or outbound(1)
3436 (Default value = 1)
3437 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003438 """
3439 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08003440 self.papi.ipsec_spd_entry_add_del,
3441 {
3442 'is_add': is_add,
3443 'entry':
3444 {
3445 'spd_id': spd_id,
3446 'sa_id': sa_id,
3447 'local_address_start': local_address_start,
3448 'local_address_stop': local_address_stop,
3449 'remote_address_start': remote_address_start,
3450 'remote_address_stop': remote_address_stop,
3451 'local_port_start': local_port_start,
3452 'local_port_stop': local_port_stop,
3453 'remote_port_start': remote_port_start,
3454 'remote_port_stop': remote_port_stop,
3455 'protocol': protocol,
3456 'policy': policy,
3457 'priority': priority,
3458 'is_outbound': is_outbound,
3459 'is_ip_any': is_ip_any
3460 }
3461 })
Florin Corasb795bd02017-12-14 11:30:48 -08003462
Neale Ranns311124e2019-01-24 04:52:25 -08003463 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
3464 return self.api(self.papi.ipsec_spd_dump,
3465 {'spd_id': spd_id,
3466 'sa_id': sa_id})
3467
Klement Sekera31da2e32018-06-24 22:49:55 +02003468 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3469 remote_spi, crypto_alg, local_crypto_key,
3470 remote_crypto_key, integ_alg, local_integ_key,
3471 remote_integ_key, is_add=1, esn=0,
3472 anti_replay=1, renumber=0, show_instance=0):
3473 return self.api(
3474 self.papi.ipsec_tunnel_if_add_del,
3475 {'local_ip': local_ip, 'remote_ip': remote_ip,
3476 'local_spi': local_spi, 'remote_spi': remote_spi,
3477 'crypto_alg': crypto_alg,
3478 'local_crypto_key_len': len(local_crypto_key),
3479 'local_crypto_key': local_crypto_key,
3480 'remote_crypto_key_len': len(remote_crypto_key),
3481 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3482 'local_integ_key_len': len(local_integ_key),
3483 'local_integ_key': local_integ_key,
3484 'remote_integ_key_len': len(remote_integ_key),
3485 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3486 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3487 'show_instance': show_instance
3488 })
3489
Klement Sekerab4d30532018-11-08 13:00:02 +01003490 def ipsec_select_backend(self, protocol, index):
3491 return self.api(self.papi.ipsec_select_backend,
3492 {'protocol': protocol, 'index': index})
3493
3494 def ipsec_backend_dump(self):
3495 return self.api(self.papi.ipsec_backend_dump, {})
3496
Ole Troane1ade682019-03-04 23:55:43 +01003497 def app_namespace_add_del(self,
3498 namespace_id,
3499 ip4_fib_id=0,
3500 ip6_fib_id=0,
3501 sw_if_index=0xFFFFFFFF,
3502 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08003503 return self.api(
3504 self.papi.app_namespace_add_del,
3505 {'secret': secret,
3506 'sw_if_index': sw_if_index,
3507 'ip4_fib_id': ip4_fib_id,
3508 'ip6_fib_id': ip6_fib_id,
3509 'namespace_id': namespace_id,
3510 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003511
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003512 def punt_socket_register(self, port, pathname, protocol=0x11,
3513 header_version=1, is_ip4=1):
3514 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02003515 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003516 {'header_version': header_version,
3517 'punt': {'ipv': is_ip4,
3518 'l4_protocol': protocol,
3519 'l4_port': port},
3520 'pathname': pathname})
3521
3522 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
3523 """ Unregister punt socket """
3524 return self.api(self.papi.punt_socket_deregister,
3525 {'punt': {'ipv': is_ip4,
3526 'l4_protocol': protocol,
3527 'l4_port': port}})
3528
3529 def punt_socket_dump(self, is_ip6=1):
3530 """ Dump punt socket"""
3531 return self.api(self.papi.punt_socket_dump,
3532 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02003533
3534 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3535 expire_walk_interval_ms, is_ip6=0):
3536 """ Set IP reassembly parameters """
3537 return self.api(self.papi.ip_reassembly_set,
3538 {'is_ip6': is_ip6,
3539 'timeout_ms': timeout_ms,
3540 'expire_walk_interval_ms': expire_walk_interval_ms,
3541 'max_reassemblies': max_reassemblies})
3542
3543 def ip_reassembly_get(self, is_ip6=0):
3544 """ Get IP reassembly parameters """
3545 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003546
Klement Sekera4c533132018-02-22 11:41:12 +01003547 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3548 enable_ip6=False):
3549 """ Enable/disable IP reassembly """
3550 return self.api(self.papi.ip_reassembly_enable_disable,
3551 {'sw_if_index': sw_if_index,
3552 'enable_ip4': 1 if enable_ip4 else 0,
3553 'enable_ip6': 1 if enable_ip6 else 0,
3554 })
3555
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003556 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3557 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003558 """ GBP endpoint Add """
3559 return self.api(self.papi.gbp_endpoint_add,
3560 {'endpoint': {
3561 'sw_if_index': sw_if_index,
3562 'ips': ips,
3563 'n_ips': len(ips),
3564 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003565 'epg_id': epg,
3566 'flags': flags,
3567 'tun': {
3568 'src': tun_src,
3569 'dst': tun_dst,
3570 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003571
3572 def gbp_endpoint_del(self, handle):
3573 """ GBP endpoint Del """
3574 return self.api(self.papi.gbp_endpoint_del,
3575 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003576
3577 def gbp_endpoint_dump(self):
3578 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003579 return self.api(self.papi.gbp_endpoint_dump,
3580 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003581
Neale Ranns879d11c2019-01-21 23:34:18 -08003582 def gbp_endpoint_group_add(self, epg, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08003583 rd, uplink_sw_if_index,
3584 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003585 """ GBP endpoint group Add """
3586 return self.api(self.papi.gbp_endpoint_group_add,
3587 {'epg':
3588 {
Neale Ranns25b04942018-04-04 09:34:50 -07003589 'uplink_sw_if_index': uplink_sw_if_index,
3590 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003591 'rd_id': rd,
Neale Ranns879d11c2019-01-21 23:34:18 -08003592 'epg_id': epg,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08003593 'sclass': sclass,
3594 'retention': retention
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003595 }})
3596
3597 def gbp_endpoint_group_del(self, epg):
3598 """ GBP endpoint group Del """
3599 return self.api(self.papi.gbp_endpoint_group_del,
3600 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003601
3602 def gbp_endpoint_group_dump(self):
3603 """ GBP endpoint group Dump """
3604 return self.api(self.papi.gbp_endpoint_group_dump, {})
3605
Neale Rannsc29c0af2018-11-07 04:21:12 -08003606 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003607 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08003608 uu_fwd_sw_if_index,
3609 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003610 """ GBP bridge-domain Add """
3611 return self.api(self.papi.gbp_bridge_domain_add,
3612 {'bd':
3613 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003614 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003615 'bvi_sw_if_index': bvi_sw_if_index,
3616 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08003617 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003618 'bd_id': bd_id
3619 }})
3620
3621 def gbp_bridge_domain_del(self, bd_id):
3622 """ GBP bridge-domain Del """
3623 return self.api(self.papi.gbp_bridge_domain_del,
3624 {'bd_id': bd_id})
3625
3626 def gbp_bridge_domain_dump(self):
3627 """ GBP Bridge Domain Dump """
3628 return self.api(self.papi.gbp_bridge_domain_dump, {})
3629
3630 def gbp_route_domain_add(self, rd_id,
3631 ip4_table_id,
3632 ip6_table_id,
3633 ip4_uu_sw_if_index,
3634 ip6_uu_sw_if_index):
3635 """ GBP route-domain Add """
3636 return self.api(self.papi.gbp_route_domain_add,
3637 {'rd':
3638 {
3639 'ip4_table_id': ip4_table_id,
3640 'ip6_table_id': ip6_table_id,
3641 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3642 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3643 'rd_id': rd_id
3644 }})
3645
3646 def gbp_route_domain_del(self, rd_id):
3647 """ GBP route-domain Del """
3648 return self.api(self.papi.gbp_route_domain_del,
3649 {'rd_id': rd_id})
3650
3651 def gbp_route_domain_dump(self):
3652 """ GBP Route Domain Dump """
3653 return self.api(self.papi.gbp_route_domain_dump, {})
3654
Neale Ranns25b04942018-04-04 09:34:50 -07003655 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3656 """ GBP recirc Add/Del """
3657 return self.api(self.papi.gbp_recirc_add_del,
3658 {'is_add': is_add,
3659 'recirc': {
3660 'is_ext': is_ext,
3661 'sw_if_index': sw_if_index,
3662 'epg_id': epg}})
3663
3664 def gbp_recirc_dump(self):
3665 """ GBP recirc Dump """
3666 return self.api(self.papi.gbp_recirc_dump, {})
3667
Neale Rannsb6a47952018-11-21 05:44:35 -08003668 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
3669 """ GBP recirc Add/Del """
3670 return self.api(self.papi.gbp_ext_itf_add_del,
3671 {'is_add': is_add,
3672 'ext_itf': {
3673 'sw_if_index': sw_if_index,
3674 'bd_id': bd_id,
3675 'rd_id': rd_id}})
3676
3677 def gbp_ext_itf_dump(self):
3678 """ GBP recirc Dump """
3679 return self.api(self.papi.gbp_ext_itf_dump, {})
3680
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003681 def gbp_subnet_add_del(self, is_add, rd_id,
3682 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003683 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003684 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003685 """ GBP Subnet Add/Del """
3686 return self.api(self.papi.gbp_subnet_add_del,
3687 {'is_add': is_add,
3688 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003689 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003690 'sw_if_index': sw_if_index,
3691 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003692 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003693 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003694
3695 def gbp_subnet_dump(self):
3696 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003697 return self.api(self.papi.gbp_subnet_dump,
3698 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07003699
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003700 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index,
3701 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003702 """ GBP contract Add/Del """
3703 return self.api(self.papi.gbp_contract_add_del,
3704 {'is_add': is_add,
3705 'contract': {
3706 'acl_index': acl_index,
3707 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003708 'dst_epg': dst_epg,
3709 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003710 'rules': rules,
3711 'n_ether_types': len(allowed_ethertypes),
3712 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003713
3714 def gbp_contract_dump(self):
3715 """ GBP contract Dump """
3716 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003717
Neale Ranns8da9fc62019-03-04 14:08:11 -08003718 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003719 """ GBP VXLAN tunnel add """
3720 return self.api(self.papi.gbp_vxlan_tunnel_add,
3721 {
3722 'tunnel': {
3723 'vni': vni,
3724 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08003725 'bd_rd_id': bd_rd_id,
3726 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003727 }
3728 })
3729
3730 def gbp_vxlan_tunnel_del(self, vni):
3731 """ GBP VXLAN tunnel del """
3732 return self.api(self.papi.gbp_vxlan_tunnel_del,
3733 {
3734 'vni': vni,
3735 })
3736
3737 def gbp_vxlan_tunnel_dump(self):
3738 """ GBP VXLAN tunnel add/del """
3739 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3740
Neale Ranns61502112018-08-22 00:21:14 -07003741 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3742 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003743 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003744 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003745 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003746 {'ip4_table_id': ip4_table_id,
3747 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003748 'ip6_prefix': ip6_prefix,
3749 'ip6_prefix_len': ip6_prefix_len,
3750 'ip4_prefix': ip4_prefix,
3751 'ip4_prefix_len': ip4_prefix_len,
3752 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003753 'security_check': security_check})
3754
Ole Troan298c6952018-03-08 12:30:43 +01003755 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003756 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003757 return self.api(self.papi.ipip_6rd_del_tunnel,
3758 {'sw_if_index': sw_if_index})
3759
3760 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003761 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003762 """ IPIP tunnel Add/Del """
3763 return self.api(self.papi.ipip_add_tunnel,
3764 {'is_ipv6': is_ipv6,
3765 'instance': instance,
3766 'src_address': src_address,
3767 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003768 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003769 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003770
3771 def ipip_del_tunnel(self, sw_if_index):
3772 """ IPIP tunnel Delete """
3773 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003774 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003775
3776 def qos_egress_map_update(self, id, outputs):
3777 """ QOS egress map update """
3778 return self.api(self.papi.qos_egress_map_update,
3779 {'map_id': id,
3780 'rows': outputs})
3781
3782 def qos_egress_map_delete(self, id):
3783 """ QOS egress map delete """
3784 return self.api(self.papi.qos_egress_map_delete,
3785 {'map_id': id})
3786
3787 def qos_mark_enable_disable(self, sw_if_index,
3788 output_source,
3789 map_id,
3790 enable):
3791 """ QOS Mark Enable/Disable """
3792 return self.api(self.papi.qos_mark_enable_disable,
3793 {'map_id': map_id,
3794 'sw_if_index': sw_if_index,
3795 'output_source': output_source,
3796 'enable': enable})
3797
3798 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3799 """ IP QoS recording Enble/Disable """
3800 return self.api(self.papi.qos_record_enable_disable,
3801 {'sw_if_index': sw_if_index,
3802 'input_source': input_source,
3803 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003804
Neale Ranns947ea622018-06-07 23:48:20 -07003805 def igmp_enable_disable(self, sw_if_index, enable, host):
3806 """ Enable/disable IGMP on a given interface """
3807 return self.api(self.papi.igmp_enable_disable,
3808 {'enable': enable,
3809 'mode': host,
3810 'sw_if_index': sw_if_index})
3811
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003812 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3813 """ Add/del IGMP proxy device """
3814 return self.api(self.papi.igmp_proxy_device_add_del,
3815 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3816 'add': add})
3817
3818 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3819 """ Add/del interface to/from IGMP proxy device """
3820 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3821 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3822 'add': add})
3823
Neale Ranns947ea622018-06-07 23:48:20 -07003824 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003825 """ Listen for new (S,G) on specified interface
3826
3827 :param enable: add/del
3828 :param sw_if_index: interface sw index
3829 :param saddr: source ip4 addr
3830 :param gaddr: group ip4 addr
3831 """
3832 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003833 {
3834 'group':
3835 {
3836 'filter': filter,
3837 'sw_if_index': sw_if_index,
3838 'n_srcs': len(saddrs),
3839 'saddrs': saddrs,
Ole Troan8c8acc02018-11-27 10:05:23 +01003840 'gaddr': gaddr
Neale Ranns947ea622018-06-07 23:48:20 -07003841 }
3842 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003843
3844 def igmp_dump(self, sw_if_index=None):
3845 """ Dump all (S,G) interface configurations """
3846 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003847 sw_if_index = 0xffffffff
3848 return self.api(self.papi.igmp_dump,
3849 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003850
3851 def igmp_clear_interface(self, sw_if_index):
3852 """ Remove all (S,G)s from specified interface
3853 doesn't send IGMP report!
3854 """
3855 return self.api(
3856 self.papi.igmp_clear_interface, {
3857 'sw_if_index': sw_if_index})
3858
3859 def want_igmp_events(self, enable=1):
3860 return self.api(self.papi.want_igmp_events, {'enable': enable,
3861 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003862
3863 def bond_create(
3864 self,
3865 mode,
3866 lb,
3867 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003868 mac_address='',
3869 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08003870 """
3871 :param mode: mode
3872 :param lb: load balance
3873 :param use_custom_mac: use custom mac
3874 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003875 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08003876 """
3877 return self.api(
3878 self.papi.bond_create,
3879 {'mode': mode,
3880 'lb': lb,
3881 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05003882 'mac_address': mac_address,
3883 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08003884 })
3885
3886 def bond_delete(
3887 self,
3888 sw_if_index):
3889 """
3890 :param sw_if_index: interface the operation is applied to
3891 """
3892 return self.api(self.papi.bond_delete,
3893 {'sw_if_index': sw_if_index})
3894
3895 def bond_enslave(
3896 self,
3897 sw_if_index,
3898 bond_sw_if_index,
3899 is_passive,
3900 is_long_timeout):
3901 """
3902 :param sw_if_index: slave sw_if_index
3903 :param bond_sw_if_index: bond sw_if_index
3904 :param is_passive: is passive lacp speaker
3905 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3906 """
3907 return self.api(
3908 self.papi.bond_enslave,
3909 {'sw_if_index': sw_if_index,
3910 'bond_sw_if_index': bond_sw_if_index,
3911 'is_passive': is_passive,
3912 'is_long_timeout': is_long_timeout
3913 })
3914
3915 def bond_detach_slave(
3916 self,
3917 sw_if_index):
3918 """
3919 :param sw_if_index: slave interface the operation is applied to
3920 """
3921 return self.api(self.papi.bond_detach_slave,
3922 {'sw_if_index': sw_if_index})
3923
3924 def sw_interface_slave_dump(
3925 self,
3926 sw_if_index):
3927 """
3928 :param sw_if_index: bond sw_if_index
3929 """
3930 return self.api(self.papi.sw_interface_slave_dump,
3931 {'sw_if_index': sw_if_index})
3932
3933 def sw_interface_bond_dump(
3934 self):
3935 """
3936
3937 """
3938 return self.api(self.papi.sw_interface_bond_dump,
3939 {})
Stevene8fa6202017-08-30 14:36:45 -07003940
3941 def create_vhost_user_if(
3942 self,
3943 is_server,
3944 sock_filename,
3945 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003946 disable_mrg_rxbuf,
3947 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003948 custom_dev_instance,
3949 use_custom_mac,
3950 mac_address,
3951 tag=''):
3952 """
3953 :param is_server: is server
3954 :param sock_filename: socket name
3955 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003956 :param disable_mrg_rxbuf: disable mergable rx buffers
3957 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003958 :param custom_dev_instance: custom dev instance
3959 :param use_custom_mac: use custom mac
3960 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003961 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003962 """
3963 return self.api(
3964 self.papi.create_vhost_user_if,
3965 {'is_server': is_server,
3966 'sock_filename': sock_filename,
3967 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003968 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3969 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003970 'custom_dev_instance': custom_dev_instance,
3971 'use_custom_mac': use_custom_mac,
3972 'mac_address': mac_address,
3973 'tag': tag
3974 })
3975
3976 def delete_vhost_user_if(
3977 self,
3978 sw_if_index):
3979 """
3980 :param sw_if_index: interface the operation is applied to
3981 """
3982 return self.api(self.papi.delete_vhost_user_if,
3983 {'sw_if_index': sw_if_index, })
3984
3985 def sw_interface_vhost_user_dump(
3986 self):
3987 """
3988
3989 """
3990 return self.api(self.papi.sw_interface_vhost_user_dump,
3991 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003992
3993 def abf_policy_add_del(self, is_add, policy):
3994 return self.api(
3995 self.papi.abf_policy_add_del,
3996 {'is_add': is_add,
3997 'policy': policy})
3998
3999 def abf_itf_attach_add_del(self, is_add, attach):
4000 return self.api(
4001 self.papi.abf_itf_attach_add_del,
4002 {'is_add': is_add,
4003 'attach': attach})
4004
4005 def abf_policy_dump(self):
4006 return self.api(
4007 self.papi.abf_policy_dump, {})
4008
4009 def abf_itf_attach_dump(self):
4010 return self.api(
4011 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07004012
4013 def pipe_create(self, is_specified, user_instance):
4014 return self.api(self.papi.pipe_create,
4015 {'is_specified': is_specified,
4016 'user_instance': user_instance})
4017
4018 def pipe_delete(self, parent_sw_if_index):
4019 return self.api(self.papi.pipe_delete,
4020 {'parent_sw_if_index': parent_sw_if_index})
4021
4022 def pipe_dump(self):
4023 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02004024
4025 def memif_create(
4026 self,
4027 role,
4028 mode,
4029 rx_queues=None,
4030 tx_queues=None,
4031 _id=None,
4032 socket_id=None,
4033 secret=None,
4034 ring_size=None,
4035 buffer_size=None,
4036 hw_addr=None):
4037 return self.api(self.papi.memif_create,
4038 {'role': role,
4039 'mode': mode,
4040 'rx_queues': rx_queues,
4041 'tx_queues': tx_queues,
4042 'id': _id,
4043 'socket_id': socket_id,
4044 'secret': secret,
4045 'ring_size': ring_size,
4046 'buffer_size': buffer_size,
4047 'hw_addr': hw_addr})
4048
4049 def memif_delete(self, sw_if_index):
4050 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
4051
4052 def memif_dump(self):
4053 return self.api(self.papi.memif_dump, {})
4054
4055 def memif_socket_filename_add_del(
4056 self, is_add, socket_id, socket_filename):
4057 return self.api(
4058 self.papi.memif_socket_filename_add_del,
4059 {'is_add': is_add,
4060 'socket_id': socket_id,
4061 'socket_filename': socket_filename})
4062
4063 def memif_socket_filename_dump(self):
4064 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004065
4066 def svs_table_add_del(self, af, table_id, is_add=1):
4067 return self.api(self.papi.svs_table_add_del,
4068 {
4069 'table_id': table_id,
4070 'is_add': is_add,
4071 'af': af,
4072 })
4073
4074 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4075 return self.api(self.papi.svs_route_add_del,
4076 {
4077 'table_id': table_id,
4078 'source_table_id': src_table_id,
4079 'prefix': prefix,
4080 'is_add': is_add,
4081 })
4082
4083 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4084 return self.api(self.papi.svs_enable_disable,
4085 {
4086 'af': af,
4087 'table_id': table_id,
4088 'sw_if_index': sw_if_index,
4089 'is_enable': is_enable,
4090 })
4091
4092 def svs_dump(self):
4093 return self.api(self.papi.svs_dump, {})