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