blob: a51dea4685e3c8e88c1e5e72f7c90e9ed9ddcb8e [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import os
2import fnmatch
3import time
Klement Sekeraf62ae122016-10-11 11:47:09 +02004from hook import Hook
Klement Sekerae4504c62016-12-08 10:16:41 +01005from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02006
Klement Sekera0e3c0de2016-09-29 14:43:44 +02007# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +01008# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
9# the vpp_papi_provider.py file to be importable without having to build
10# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020011do_import = True
12try:
13 no_vpp_papi = os.getenv("NO_VPP_PAPI")
14 if no_vpp_papi == "1":
15 do_import = False
16except:
17 pass
18
19if do_import:
Ole Troan7e3a8752016-12-05 10:27:09 +010020 from vpp_papi import VPP
Klement Sekera277b89c2016-10-28 13:20:27 +020021
Klement Sekeraf62ae122016-10-11 11:47:09 +020022# from vnet/vnet/mpls/mpls_types.h
23MPLS_IETF_MAX_LABEL = 0xfffff
24MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
25
Klement Sekera0e3c0de2016-09-29 14:43:44 +020026
Neale Ranns177bbdc2016-11-15 09:46:51 +000027class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030028 L2_DISABLED = 0
29 L2_PUSH_1 = 1
30 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000031 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030032 L2_POP_2 = 4
33 L2_TRANSLATE_1_1 = 5
34 L2_TRANSLATE_1_2 = 6
35 L2_TRANSLATE_2_1 = 7
36 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000037
Klement Sekera0e3c0de2016-09-29 14:43:44 +020038
Neale Ranns039cbfe2018-02-27 03:45:38 -080039class QOS_SOURCE:
40 EXT = 0
41 VLAN = 1
42 MPLS = 2
43 IP = 3
44
45
Neale Rannsb4743802018-09-05 09:13:57 -070046class L2_PORT_TYPE:
47 NORMAL = 0
48 BVI = 1
49 UU_FWD = 2
50
51
52class BRIDGE_FLAGS:
53 NONE = 0
54 LEARN = 1
55 FWD = 2
56 FLOOD = 4
57 UU_FLOOD = 8
58 ARP_TERM = 16
59
60
Klement Sekera73884482017-02-23 09:26:30 +010061class UnexpectedApiReturnValueError(Exception):
62 """ exception raised when the API return value is unexpected """
63 pass
64
65
Klement Sekeraf62ae122016-10-11 11:47:09 +020066class VppPapiProvider(object):
67 """VPP-api provider using vpp-papi
68
69 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020070 """
71
Klement Sekerae0545ef2017-01-25 08:00:40 +010072 _zero, _negative = range(2)
73
Klement Sekera7bb873a2016-11-18 07:38:42 +010074 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020075 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020076 self.name = name
77 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010078 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010079 self._expect_api_retval = self._zero
80 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010081 jsonfiles = []
82
Klement Sekera0e3c0de2016-09-29 14:43:44 +020083 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010084 for root, dirnames, filenames in os.walk(install_dir):
85 for filename in fnmatch.filter(filenames, '*.api.json'):
86 jsonfiles.append(os.path.join(root, filename))
87
Ole Troana7564e82018-06-12 21:06:44 +020088 self.vpp = VPP(jsonfiles, logger=test_class.logger, read_timeout=5)
Klement Sekerae4504c62016-12-08 10:16:41 +010089 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020090
Klement Sekerae0545ef2017-01-25 08:00:40 +010091 def __enter__(self):
92 return self
93
94 def expect_negative_api_retval(self):
95 """ Expect API failure """
96 self._expect_stack.append(self._expect_api_retval)
97 self._expect_api_retval = self._negative
98 return self
99
100 def expect_zero_api_retval(self):
101 """ Expect API success """
102 self._expect_stack.append(self._expect_api_retval)
103 self._expect_api_retval = self._zero
104 return self
105
106 def __exit__(self, exc_type, exc_value, traceback):
107 self._expect_api_retval = self._expect_stack.pop()
108
Klement Sekeraf62ae122016-10-11 11:47:09 +0200109 def register_hook(self, hook):
110 """Replace hook registration with new hook
111
112 :param hook:
113
114 """
115 self.hook = hook
116
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200117 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100118 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200119 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100120 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200121 return e
122
123 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100124 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100125 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100126 self.test_class.logger.debug("Expecting event '%s' within %ss",
127 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300128 else:
129 self.test_class.logger.debug("Expecting event within %ss",
130 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100131 if self._events:
132 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200133 limit = time.time() + timeout
134 while time.time() < limit:
135 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100136 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200137 if name and type(e).__name__ != name:
138 raise Exception(
139 "Unexpected event received: %s, expected: %s" %
140 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100141 self.test_class.logger.debug("Returning event %s:%s" %
142 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200143 return e
144 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200145 raise Exception("Event did not occur within timeout")
146
147 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100148 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200149 # FIXME use the name instead of relying on type(e).__name__ ?
150 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100151 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200152 self._events.append(event)
153
Klement Sekeraf62ae122016-10-11 11:47:09 +0200154 def connect(self):
155 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100156 self.vpp.connect(self.name, self.shm_prefix)
157 self.papi = self.vpp.api
158 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200159
160 def disconnect(self):
161 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100162 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200163
164 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100165 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166 Call the appropriate hooks before and after the API call
167
168 :param api_fn: API function to call
169 :param api_args: tuple of API function arguments
170 :param expected_retval: Expected return value (Default value = 0)
171 :returns: reply from the API
172
173 """
174 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100175 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100176 if self._expect_api_retval == self._negative:
177 if hasattr(reply, 'retval') and reply.retval >= 0:
178 msg = "API call passed unexpectedly: expected negative "\
179 "return value instead of %d in %s" % \
180 (reply.retval, repr(reply))
181 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100182 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100183 elif self._expect_api_retval == self._zero:
184 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700185 msg = "API call failed, expected %d return value instead "\
186 "of %d in %s" % (expected_retval, reply.retval,
187 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100188 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100189 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100190 else:
191 raise Exception("Internal error, unexpected value for "
192 "self._expect_api_retval %s" %
193 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194 self.hook.after_api(api_fn.__name__, api_args)
195 return reply
196
197 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100198 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200199
200 :param cli: CLI to execute
201 :returns: CLI output
202
203 """
204 self.hook.before_cli(cli)
205 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100206 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200208 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100209 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210
Jan49c0fca2016-10-26 15:44:27 +0200211 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100212 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200213
214 :param cli: CLI to execute
215 :returns: CLI output
216 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600217 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200218
Jan4af521d2016-11-15 17:05:00 +0100219 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200220 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100221
Klement Sekeraf62ae122016-10-11 11:47:09 +0200222 def show_version(self):
223 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100224 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200225
226 def pg_create_interface(self, pg_index):
227 """
228
229 :param pg_index:
230
231 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100232 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200233 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200234
235 def sw_interface_dump(self, filter=None):
236 """
237
238 :param filter: (Default value = None)
239
240 """
241 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200242 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200243 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100244 args = {}
245 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200246
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000247 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100248 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000249
250 :param sw_if_index:
251 :param is_ipv6:
252 :param table_id:
253
254 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100255 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200256 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
257 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000258
Klement Sekeraf62ae122016-10-11 11:47:09 +0200259 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
260 is_ipv6=0, is_add=1, del_all=0):
261 """
262
263 :param addr: param is_ipv6: (Default value = 0)
264 :param sw_if_index:
265 :param addr_len:
266 :param is_ipv6: (Default value = 0)
267 :param is_add: (Default value = 1)
268 :param del_all: (Default value = 0)
269
270 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100271 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200272 {'sw_if_index': sw_if_index,
273 'is_add': is_add,
274 'is_ipv6': is_ipv6,
275 'del_all': del_all,
276 'address_length': addr_len,
277 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200278
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800279 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
280 is_add=1):
281 """ Set the Interface to be unnumbered
282
283 :param is_add: (Default value = 1)
284 :param sw_if_index - interface That will be unnumbered
285 :param ip_sw_if_index - interface with an IP addres
286
287 """
288 return self.api(self.papi.sw_interface_set_unnumbered,
289 {'sw_if_index': ip_sw_if_index,
290 'unnumbered_sw_if_index': sw_if_index,
291 'is_add': is_add})
292
Neale Ranns404d88e2018-08-08 06:37:33 -0700293 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
294 return self.api(self.papi.ip_unnumbered_dump,
295 {'sw_if_index': sw_if_index})
296
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000297 def sw_interface_enable_disable_mpls(self, sw_if_index,
298 is_enable=1):
299 """
300 Enable/Disable MPLS on the interface
301 :param sw_if_index:
302 :param is_enable: (Default value = 1)
303
304 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100305 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200306 {'sw_if_index': sw_if_index,
307 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000308
Jan Gelety057bb8c2016-12-20 17:32:45 +0100309 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100310 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100311 {'sw_if_index': sw_if_index,
312 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200313
Neale Ranns227038a2017-04-21 01:07:59 -0700314 def set_ip_flow_hash(self,
315 table_id,
316 src=1,
317 dst=1,
318 sport=1,
319 dport=1,
320 proto=1,
321 reverse=0,
322 is_ip6=0):
323 return self.api(self.papi.set_ip_flow_hash,
324 {'vrf_id': table_id,
325 'src': src,
326 'dst': dst,
327 'dport': dport,
328 'sport': sport,
329 'proto': proto,
330 'reverse': reverse,
331 'is_ipv6': is_ip6})
332
Neale Ranns3f844d02017-02-18 00:03:54 -0800333 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
334 return self.api(self.papi.ip6nd_proxy_add_del,
335 {'address': address,
336 'sw_if_index': sw_if_index,
337 'is_del': is_del})
338
Neale Ranns75152282017-01-09 01:00:45 -0800339 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000340 no,
Neale Ranns75152282017-01-09 01:00:45 -0800341 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000342 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800343 return self.api(self.papi.sw_interface_ip6nd_ra_config,
344 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000345 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100346 'suppress': suppress,
347 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800348
Neale Ranns87df12d2017-02-18 08:16:41 -0800349 def ip6_sw_interface_ra_prefix(self,
350 sw_if_index,
351 address,
352 address_length,
353 use_default=0,
354 no_advertise=0,
355 off_link=0,
356 no_autoconfig=0,
357 no_onlink=0,
358 is_no=0,
359 val_lifetime=0xffffffff,
360 pref_lifetime=0xffffffff):
361 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
362 {'sw_if_index': sw_if_index,
363 'address': address,
364 'address_length': address_length,
365 'use_default': use_default,
366 'no_advertise': no_advertise,
367 'off_link': off_link,
368 'no_autoconfig': no_autoconfig,
369 'no_onlink': no_onlink,
370 'is_no': is_no,
371 'val_lifetime': val_lifetime,
372 'pref_lifetime': pref_lifetime})
373
Neale Ranns75152282017-01-09 01:00:45 -0800374 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
375 """
376 Enable/Disable An interface for IPv6
377 """
378 return self.api(self.papi.sw_interface_ip6_enable_disable,
379 {'sw_if_index': sw_if_index,
380 'enable': enable})
381
Klement Sekeraf62ae122016-10-11 11:47:09 +0200382 def vxlan_add_del_tunnel(
383 self,
384 src_addr,
385 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200386 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387 is_add=1,
388 is_ipv6=0,
389 encap_vrf_id=0,
390 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600391 vni=0,
392 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200393 """
394
395 :param dst_addr:
396 :param src_addr:
397 :param is_add: (Default value = 1)
398 :param is_ipv6: (Default value = 0)
399 :param encap_vrf_id: (Default value = 0)
400 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200401 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200402 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600403 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200404
405 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100406 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200407 {'is_add': is_add,
408 'is_ipv6': is_ipv6,
409 'src_address': src_addr,
410 'dst_address': dst_addr,
411 'mcast_sw_if_index': mcast_sw_if_index,
412 'encap_vrf_id': encap_vrf_id,
413 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600414 'vni': vni,
415 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200416
Marco Varleseb598f1d2017-09-19 14:25:28 +0200417 def geneve_add_del_tunnel(
418 self,
419 local_addr,
420 remote_addr,
421 mcast_sw_if_index=0xFFFFFFFF,
422 is_add=1,
423 is_ipv6=0,
424 encap_vrf_id=0,
425 decap_next_index=0xFFFFFFFF,
426 vni=0):
427 """
428
429 :param remote_addr:
430 :param local_addr:
431 :param is_add: (Default value = 1)
432 :param is_ipv6: (Default value = 0)
433 :param encap_vrf_id: (Default value = 0)
434 :param decap_next_index: (Default value = 0xFFFFFFFF)
435 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
436 :param vni: (Default value = 0)
437
438 """
439 return self.api(self.papi.geneve_add_del_tunnel,
440 {'is_add': is_add,
441 'is_ipv6': is_ipv6,
442 'local_address': local_addr,
443 'remote_address': remote_addr,
444 'mcast_sw_if_index': mcast_sw_if_index,
445 'encap_vrf_id': encap_vrf_id,
446 'decap_next_index': decap_next_index,
447 'vni': vni})
448
Jan4af521d2016-11-15 17:05:00 +0100449 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
450 learn=1, arp_term=0, is_add=1):
451 """Create/delete bridge domain.
452
453 :param int bd_id: Bridge domain index.
454 :param int flood: Enable/disable bcast/mcast flooding in the BD.
455 (Default value = 1)
456 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
457 (Default value = 1)
458 :param int forward: Enable/disable forwarding on all interfaces in
459 the BD. (Default value = 1)
460 :param int learn: Enable/disable learning on all interfaces in the BD.
461 (Default value = 1)
462 :param int arp_term: Enable/disable arp termination in the BD.
463 (Default value = 1)
464 :param int is_add: Add or delete flag. (Default value = 1)
465 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100466 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200467 {'bd_id': bd_id,
468 'flood': flood,
469 'uu_flood': uu_flood,
470 'forward': forward,
471 'learn': learn,
472 'arp_term': arp_term,
473 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100474
Eyal Baric86e5922017-07-02 18:33:16 +0300475 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
476 return self.api(self.papi.bd_ip_mac_add_del,
477 {'bd_id': bd_id,
478 'is_add': is_add,
479 'is_ipv6': is_ipv6,
480 'ip_address': ip,
481 'mac_address': mac})
482
Eyal Bari20197482017-09-13 12:29:08 +0300483 def want_ip4_arp_events(self, enable_disable=1, address=0):
484 return self.api(self.papi.want_ip4_arp_events,
485 {'enable_disable': enable_disable,
486 'address': address,
487 'pid': os.getpid(), })
488
Eyal Baric125ecc2017-09-20 11:29:17 +0300489 def want_ip6_nd_events(self, enable_disable=1, address=0):
490 return self.api(self.papi.want_ip6_nd_events,
491 {'enable_disable': enable_disable,
492 'address': address,
493 'pid': os.getpid(), })
494
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100495 def want_ip6_ra_events(self, enable_disable=1):
496 return self.api(self.papi.want_ip6_ra_events,
497 {'enable_disable': enable_disable,
498 'pid': os.getpid(), })
499
500 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
501 mrc=0, mrd=0):
502 return self.api(self.papi.ip6nd_send_router_solicitation,
503 {'irt': irt,
504 'mrt': mrt,
505 'mrc': mrc,
506 'mrd': mrd,
507 'sw_if_index': sw_if_index})
508
Juraj Slobodac0374232018-02-01 15:18:49 +0100509 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
510 install_default_routes):
511 return self.api(self.papi.ip6_nd_address_autoconfig,
512 {'sw_if_index': sw_if_index,
513 'enable': enable,
514 'install_default_routes': install_default_routes})
515
Eyal Bari24db0ec2017-09-27 21:43:51 +0300516 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
517 max_macs_in_event=0, learn_limit=0):
518 return self.api(self.papi.want_l2_macs_events,
519 {'enable_disable': enable_disable,
520 'scan_delay': scan_delay,
521 'max_macs_in_event': max_macs_in_event,
522 'learn_limit': learn_limit,
523 'pid': os.getpid(), })
524
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200525 def want_dhcp6_reply_events(self, enable_disable=1):
526 return self.api(self.papi.want_dhcp6_reply_events,
527 {'enable_disable': enable_disable,
528 'pid': os.getpid()})
529
Juraj Sloboda81119e82018-05-25 14:02:20 +0200530 def want_dhcp6_pd_reply_events(self, enable_disable=1):
531 return self.api(self.papi.want_dhcp6_pd_reply_events,
532 {'enable_disable': enable_disable,
533 'pid': os.getpid()})
534
535 def dhcp6_clients_enable_disable(self, enable=1):
536 return self.api(self.papi.dhcp6_clients_enable_disable,
537 {'enable': enable})
538
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200539 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
540 addresses, server_index=0xFFFFFFFF,
541 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
542 ):
543 return self.api(self.papi.dhcp6_send_client_message,
544 {'sw_if_index': sw_if_index,
545 'server_index': server_index,
546 'irt': irt,
547 'mrt': mrt,
548 'mrc': mrc,
549 'mrd': mrd,
550 'stop': stop,
551 'msg_type': msg_type,
552 'T1': T1,
553 'T2': T2,
554 'n_addresses': len(addresses),
555 'addresses': addresses})
556
Juraj Sloboda81119e82018-05-25 14:02:20 +0200557 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
558 prefixes, server_index=0xFFFFFFFF,
559 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
560 ):
561 return self.api(self.papi.dhcp6_pd_send_client_message,
562 {'sw_if_index': sw_if_index,
563 'server_index': server_index,
564 'irt': irt,
565 'mrt': mrt,
566 'mrc': mrc,
567 'mrd': mrd,
568 'stop': stop,
569 'msg_type': msg_type,
570 'T1': T1,
571 'T2': T2,
572 'n_prefixes': len(prefixes),
573 'prefixes': prefixes})
574
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200575 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
576 enable=1):
577 return self.api(self.papi.dhcp6_client_enable_disable,
578 {'sw_if_index': sw_if_index,
579 'enable': enable})
580
Juraj Sloboda81119e82018-05-25 14:02:20 +0200581 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
582 enable=1):
583 return self.api(self.papi.dhcp6_pd_client_enable_disable,
584 {'sw_if_index': sw_if_index,
585 'prefix_group': prefix_group,
586 'enable': enable})
587
588 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
589 prefix_length, prefix_group,
590 is_add=1):
591 return self.api(self.papi.ip6_add_del_address_using_prefix,
592 {'sw_if_index': sw_if_index,
593 'prefix_group': prefix_group,
594 'address': address,
595 'prefix_length': prefix_length,
596 'is_add': is_add})
597
Jan4af521d2016-11-15 17:05:00 +0100598 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
599 filter_mac=0, bvi_mac=0):
600 """Create/delete L2 FIB entry.
601
602 :param str mac: MAC address to create FIB entry for.
603 :param int bd_id: Bridge domain index.
604 :param int sw_if_index: Software interface index of the interface.
605 :param int is_add: Add or delete flag. (Default value = 1)
606 :param int static_mac: Set to 1 to create static MAC entry.
607 (Default value = 0)
608 :param int filter_mac: Set to 1 to drop packet that's source or
609 destination MAC address contains defined MAC address.
610 (Default value = 0)
611 :param int bvi_mac: Set to 1 to create entry that points to BVI
612 interface. (Default value = 0)
613 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100614 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200615 {'mac': self._convert_mac(mac),
616 'bd_id': bd_id,
617 'sw_if_index': sw_if_index,
618 'is_add': is_add,
619 'static_mac': static_mac,
620 'filter_mac': filter_mac,
621 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100622
Eyal Bari93b503e2017-05-15 10:13:15 +0300623 def l2fib_flush_int(self, sw_if_index):
624 """Flush L2 FIB entries for sw_if_index.
625
626 :param int sw_if_index: Software interface index of the interface.
627 """
628 return self.api(self.papi.l2fib_flush_int,
629 {'sw_if_index': sw_if_index})
630
631 def l2fib_flush_bd(self, bd_id):
632 """Flush L2 FIB entries for bd_id.
633
634 :param int sw_if_index: Bridge Domain id.
635 """
636 return self.api(self.papi.l2fib_flush_bd,
637 {'bd_id': bd_id})
638
639 def l2fib_flush_all(self):
640 """Flush all L2 FIB.
641 """
642 return self.api(self.papi.l2fib_flush_all, {})
643
Klement Sekeraf62ae122016-10-11 11:47:09 +0200644 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700645 shg=0, port_type=L2_PORT_TYPE.NORMAL,
646 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100647 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200648
Jan4af521d2016-11-15 17:05:00 +0100649 :param int sw_if_index: Software interface index of the interface.
650 :param int bd_id: Bridge domain index.
651 :param int shg: Split-horizon group index. (Default value = 0)
652 :param int bvi: Set interface as a bridge group virtual interface.
653 (Default value = 0)
654 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200655 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100656 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200657 {'rx_sw_if_index': sw_if_index,
658 'bd_id': bd_id,
659 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700660 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200661 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200662
Jan00dad122016-11-29 10:04:53 +0100663 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400664 """Enable/disable required feature of the bridge domain with defined
665 ID.
Jan00dad122016-11-29 10:04:53 +0100666
667 :param int bd_id: Bridge domain ID.
668 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700669 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100670 - learn (1 << 0),
671 - forward (1 << 1),
672 - flood (1 << 2),
673 - uu-flood (1 << 3) or
674 - arp-term (1 << 4).
675 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100676 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200677 {'bd_id': bd_id,
678 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700679 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100680
681 def bridge_domain_dump(self, bd_id=0):
682 """
683
684 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
685 existing bridge domains returned)
686 :return: Dictionary of bridge domain(s) data.
687 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100688 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200689 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100690
Klement Sekeraf62ae122016-10-11 11:47:09 +0200691 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
692 enable):
693 """Create or delete unidirectional cross-connect from Tx interface to
694 Rx interface.
695
Jan4af521d2016-11-15 17:05:00 +0100696 :param int rx_sw_if_index: Software interface index of Rx interface.
697 :param int tx_sw_if_index: Software interface index of Tx interface.
698 :param int enable: Create cross-connect if equal to 1, delete
699 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200700
701 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100702 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200703 {'rx_sw_if_index': rx_sw_if_index,
704 'tx_sw_if_index': tx_sw_if_index,
705 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200706
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200707 def sw_interface_set_l2_tag_rewrite(
708 self,
709 sw_if_index,
710 vtr_oper,
711 push=0,
712 tag1=0,
713 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000714 """L2 interface vlan tag rewrite configure request
715 :param client_index - opaque cookie to identify the sender
716 :param context - sender context, to match reply w/ request
717 :param sw_if_index - interface the operation is applied to
718 :param vtr_op - Choose from l2_vtr_op_t enum values
719 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
720 :param tag1 - Needed for any push or translate vtr op
721 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
722
723 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100724 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200725 {'sw_if_index': sw_if_index,
726 'vtr_op': vtr_oper,
727 'push_dot1q': push,
728 'tag1': tag1,
729 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000730
Neale Ranns55d03782017-10-21 06:34:22 -0700731 def sw_interface_set_l2_emulation(
732 self,
733 sw_if_index,
734 enable=1):
735 """L2 Emulation
736 :param sw_if_index - interface the operation is applied to
737
738 """
739 return self.api(self.papi.l2_emulation,
740 {'sw_if_index': sw_if_index,
741 'enable': enable})
742
Neale Ranns1855b8e2018-07-11 10:31:26 -0700743 def sw_interface_set_ip_directed_broadcast(
744 self,
745 sw_if_index,
746 enable=1):
747 """IP Directed broadcast
748 :param sw_if_index - interface the operation is applied to
749
750 """
751 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
752 {'sw_if_index': sw_if_index,
753 'enable': enable})
754
Neale Rannsa07bd702017-08-07 07:53:49 -0700755 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200756 """
757
758 :param admin_up_down:
759 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200760
761 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100762 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200763 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700764 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200765
Ole Troand7231612018-06-07 10:17:57 +0200766 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800767 """
768 :param sw_if_index:
769 :param mtu:
770
771 """
772 return self.api(self.papi.sw_interface_set_mtu,
773 {'sw_if_index': sw_if_index,
774 'mtu': mtu})
775
Neale Ranns25b04942018-04-04 09:34:50 -0700776 def sw_interface_set_promiscuous(self, sw_if_index, enable):
777 """
778 :param sw_if_index:
779 :param enable:
780
781 """
782 return self.api(self.papi.sw_interface_set_promiscuous,
783 {'sw_if_index': sw_if_index,
784 'enable': enable})
785
Neale Rannsc819fc62018-02-16 02:44:05 -0800786 def sw_interface_set_mac_address(self, sw_if_index, mac):
787 return self.api(self.papi.sw_interface_set_mac_address,
788 {'sw_if_index': sw_if_index,
789 'mac_address': mac})
790
Klement Sekeraf62ae122016-10-11 11:47:09 +0200791 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
792 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
793 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
794 """Create subinterface
795 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
796
797 :param sub_id: param inner_vlan:
798 :param sw_if_index:
799 :param outer_vlan:
800 :param inner_vlan:
801 :param no_tags: (Default value = 0)
802 :param one_tag: (Default value = 0)
803 :param two_tags: (Default value = 0)
804 :param dot1ad: (Default value = 0)
805 :param exact_match: (Default value = 0)
806 :param default_sub: (Default value = 0)
807 :param outer_vlan_id_any: (Default value = 0)
808 :param inner_vlan_id_any: (Default value = 0)
809
810 """
811 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100812 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200813 {'sw_if_index': sw_if_index,
814 'sub_id': sub_id,
815 'no_tags': no_tags,
816 'one_tag': one_tag,
817 'two_tags': two_tags,
818 'dot1ad': dot1ad,
819 'exact_match': exact_match,
820 'default_sub': default_sub,
821 'outer_vlan_id_any': outer_vlan_id_any,
822 'inner_vlan_id_any': inner_vlan_id_any,
823 'outer_vlan_id': outer_vlan,
824 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200825
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200826 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
827 """Create p2p ethernet subinterface
828
829 :param sw_if_index: main (parent) interface
830 :param remote_mac: client (remote) mac address
831
832 """
833 return self.api(
834 self.papi.p2p_ethernet_add,
835 {'parent_if_index': sw_if_index,
836 'remote_mac': remote_mac,
837 'subif_id': subif_id})
838
Neale Ranns177bbdc2016-11-15 09:46:51 +0000839 def delete_subif(self, sw_if_index):
840 """Delete subinterface
841
842 :param sw_if_index:
843 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100844 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200845 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000846
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200847 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
848 """Delete p2p ethernet subinterface
849
850 :param sw_if_index: main (parent) interface
851 :param remote_mac: client (remote) mac address
852
853 """
854 return self.api(
855 self.papi.p2p_ethernet_del,
856 {'parent_if_index': sw_if_index,
857 'remote_mac': remote_mac})
858
Klement Sekeraf62ae122016-10-11 11:47:09 +0200859 def create_vlan_subif(self, sw_if_index, vlan):
860 """
861
862 :param vlan:
863 :param sw_if_index:
864
865 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100866 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200867 {'sw_if_index': sw_if_index,
868 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200869
Matej Klotton0178d522016-11-04 11:11:44 +0100870 def create_loopback(self, mac=''):
871 """
872
873 :param mac: (Optional)
874 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100875 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200876 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100877
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100878 def delete_loopback(self, sw_if_index):
879 return self.api(self.papi.delete_loopback,
880 {'sw_if_index': sw_if_index, })
881
Neale Ranns15002542017-09-10 04:39:11 -0700882 def ip_table_add_del(self,
883 table_id,
884 is_add=1,
885 is_ipv6=0):
886 """
887
888 :param table_id
889 :param is_add: (Default value = 1)
890 :param is_ipv6: (Default value = 0)
891
892 """
893
894 return self.api(
895 self.papi.ip_table_add_del,
896 {'table_id': table_id,
897 'is_add': is_add,
898 'is_ipv6': is_ipv6})
899
Klement Sekeraf62ae122016-10-11 11:47:09 +0200900 def ip_add_del_route(
901 self,
902 dst_address,
903 dst_address_length,
904 next_hop_address,
905 next_hop_sw_if_index=0xFFFFFFFF,
906 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200907 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000908 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200909 next_hop_n_out_labels=0,
910 next_hop_out_label_stack=[],
911 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800912 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000913 is_resolve_host=0,
914 is_resolve_attached=0,
915 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200916 is_add=1,
917 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200918 is_unreach=0,
919 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200920 is_ipv6=0,
921 is_local=0,
922 is_classify=0,
923 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800924 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800925 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200926 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200927 """
928
929 :param dst_address_length:
930 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
931 :param dst_address:
932 :param next_hop_address:
933 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
934 :param vrf_id: (Default value = 0)
935 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200936 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200937 :param is_add: (Default value = 1)
938 :param is_drop: (Default value = 0)
939 :param is_ipv6: (Default value = 0)
940 :param is_local: (Default value = 0)
941 :param is_classify: (Default value = 0)
942 :param is_multipath: (Default value = 0)
943 :param is_resolve_host: (Default value = 0)
944 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800945 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700946 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200947 :param next_hop_weight: (Default value = 1)
948
949 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000950
Klement Sekeraf62ae122016-10-11 11:47:09 +0200951 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100952 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200953 {'next_hop_sw_if_index': next_hop_sw_if_index,
954 'table_id': table_id,
955 'classify_table_index': classify_table_index,
956 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200957 'is_add': is_add,
958 'is_drop': is_drop,
959 'is_unreach': is_unreach,
960 'is_prohibit': is_prohibit,
961 'is_ipv6': is_ipv6,
962 'is_local': is_local,
963 'is_classify': is_classify,
964 'is_multipath': is_multipath,
965 'is_resolve_host': is_resolve_host,
966 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800967 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700968 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800969 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200970 'next_hop_weight': next_hop_weight,
971 'dst_address_length': dst_address_length,
972 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800973 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200974 'next_hop_address': next_hop_address,
975 'next_hop_n_out_labels': next_hop_n_out_labels,
976 'next_hop_via_label': next_hop_via_label,
977 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100978
Matej Klotton16a14cd2016-12-07 15:09:13 +0100979 def ip_fib_dump(self):
980 return self.api(self.papi.ip_fib_dump, {})
981
Jan Gelety057bb8c2016-12-20 17:32:45 +0100982 def ip6_fib_dump(self):
983 return self.api(self.papi.ip6_fib_dump, {})
984
Matej Klotton0178d522016-11-04 11:11:44 +0100985 def ip_neighbor_add_del(self,
986 sw_if_index,
987 mac_address,
988 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100989 is_add=1,
990 is_ipv6=0,
991 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800992 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100993 ):
994 """ Add neighbor MAC to IPv4 or IPv6 address.
995
996 :param sw_if_index:
997 :param mac_address:
998 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100999 :param is_add: (Default value = 1)
1000 :param is_ipv6: (Default value = 0)
1001 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001002 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001003 """
1004
1005 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001006 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001007 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001008 'is_add': is_add,
1009 'is_ipv6': is_ipv6,
1010 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001011 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001012 'mac_address': mac_address,
1013 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001014 }
Matej Klotton0178d522016-11-04 11:11:44 +01001015 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001016
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001017 def ip_neighbor_dump(self,
1018 sw_if_index,
1019 is_ipv6=0):
1020 """ Return IP neighbor dump.
1021
1022 :param sw_if_index:
1023 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1024 """
1025
1026 return self.api(
1027 self.papi.ip_neighbor_dump,
1028 {'is_ipv6': is_ipv6,
1029 'sw_if_index': sw_if_index
1030 }
1031 )
1032
1033 def proxy_arp_add_del(self,
1034 low_address,
1035 hi_address,
1036 vrf_id=0,
1037 is_add=1):
1038 """ Config Proxy Arp Range.
1039
1040 :param low_address: Start address in the rnage to Proxy for
1041 :param hi_address: End address in the rnage to Proxy for
1042 :param vrf_id: The VRF/table in which to proxy
1043 """
1044
1045 return self.api(
1046 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001047 {'proxy':
1048 {
1049 'vrf_id': vrf_id,
1050 'low_address': low_address,
1051 'hi_address': hi_address,
1052 },
1053 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001054
1055 def proxy_arp_intfc_enable_disable(self,
1056 sw_if_index,
1057 is_enable=1):
1058 """ Enable/Disable an interface for proxy ARP requests
1059
1060 :param sw_if_index: Interface
1061 :param enable_disable: Enable/Disable
1062 """
1063
1064 return self.api(
1065 self.papi.proxy_arp_intfc_enable_disable,
1066 {'sw_if_index': sw_if_index,
1067 'enable_disable': is_enable
1068 }
1069 )
1070
Jane546d3b2016-12-08 13:10:03 +01001071 def reset_vrf(self,
1072 vrf_id,
1073 is_ipv6=0,
1074 ):
1075 """ Reset VRF (remove all routes etc.) request.
1076
1077 :param int vrf_id: ID of the FIB table / VRF to reset.
1078 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1079 """
1080
1081 return self.api(
1082 self.papi.reset_vrf,
1083 {'vrf_id': vrf_id,
1084 'is_ipv6': is_ipv6,
1085 }
1086 )
1087
1088 def reset_fib(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_fib,
1100 {'vrf_id': vrf_id,
1101 'is_ipv6': is_ipv6,
1102 }
1103 )
1104
1105 def ip_dump(self,
1106 is_ipv6=0,
1107 ):
1108 """ Return IP dump.
1109
1110 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1111 """
1112
1113 return self.api(
1114 self.papi.ip_dump,
1115 {'is_ipv6': is_ipv6,
1116 }
1117 )
1118
Klement Sekera7bb873a2016-11-18 07:38:42 +01001119 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001120 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001121 """
1122
1123 :param sw_if_index_from:
1124 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001125 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001126 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001127 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001128 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001129 {'sw_if_index_from': sw_if_index_from,
1130 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001131 'state': state,
1132 'is_l2': is_l2,
1133 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001134
1135 def gre_tunnel_add_del(self,
1136 src_address,
1137 dst_address,
1138 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001139 tunnel_type=0,
1140 instance=0xFFFFFFFF,
1141 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001142 is_add=1,
1143 is_ip6=0):
1144 """ Add a GRE tunnel
1145
1146 :param src_address:
1147 :param dst_address:
1148 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001149 :param tunnel_type: (Default value = 0)
1150 :param instance: (Default value = 0xFFFFFFFF)
1151 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001152 :param is_add: (Default value = 1)
1153 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001154 """
1155
1156 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001157 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001158 {'is_add': is_add,
1159 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001160 'tunnel_type': tunnel_type,
1161 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001162 'src_address': src_address,
1163 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001164 'outer_fib_id': outer_fib_id,
1165 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001166 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001167
Neale Rannsd0df49f2018-08-08 01:06:40 -07001168 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001169 src_ip,
1170 dst_ip,
1171 src_port,
1172 dst_port,
1173 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001174 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001175 :param src_ip:
1176 :param dst_ip:
1177 :param src_port:
1178 :param dst_port:
1179 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001180 """
1181
1182 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001183 self.papi.udp_encap_add,
1184 {
1185 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001186 'src_ip': src_ip,
1187 'dst_ip': dst_ip,
1188 'src_port': src_port,
1189 'dst_port': dst_port,
1190 'table_id': table_id
1191 }
1192 })
1193
1194 def udp_encap_del(self, id):
1195 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001196
1197 def udp_encap_dump(self):
1198 return self.api(self.papi.udp_encap_dump, {})
1199
Neale Ranns43b1f442018-03-20 01:47:35 -07001200 def want_udp_encap_stats(self, enable=1):
1201 return self.api(self.papi.want_udp_encap_stats,
1202 {'enable': enable,
1203 'pid': os.getpid()})
1204
Neale Ranns5a8123b2017-01-26 01:18:23 -08001205 def mpls_fib_dump(self):
1206 return self.api(self.papi.mpls_fib_dump, {})
1207
Neale Ranns15002542017-09-10 04:39:11 -07001208 def mpls_table_add_del(
1209 self,
1210 table_id,
1211 is_add=1):
1212 """
1213
1214 :param table_id
1215 :param is_add: (Default value = 1)
1216
1217 """
1218
1219 return self.api(
1220 self.papi.mpls_table_add_del,
1221 {'mt_table_id': table_id,
1222 'mt_is_add': is_add})
1223
Neale Rannsad422ed2016-11-02 14:20:04 +00001224 def mpls_route_add_del(
1225 self,
1226 label,
1227 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001228 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001229 next_hop_address,
1230 next_hop_sw_if_index=0xFFFFFFFF,
1231 table_id=0,
1232 next_hop_table_id=0,
1233 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001234 next_hop_n_out_labels=0,
1235 next_hop_out_label_stack=[],
1236 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001237 is_resolve_host=0,
1238 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001239 is_interface_rx=0,
1240 is_rpf_id=0,
1241 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001242 is_add=1,
1243 is_drop=0,
1244 is_multipath=0,
1245 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001246 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001247 """
1248
1249 :param dst_address_length:
1250 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1251 :param dst_address:
1252 :param next_hop_address:
1253 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1254 :param vrf_id: (Default value = 0)
1255 :param lookup_in_vrf: (Default value = 0)
1256 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001257 :param is_add: (Default value = 1)
1258 :param is_drop: (Default value = 0)
1259 :param is_ipv6: (Default value = 0)
1260 :param is_local: (Default value = 0)
1261 :param is_classify: (Default value = 0)
1262 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001263 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001264 :param is_resolve_host: (Default value = 0)
1265 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001266 :param next_hop_weight: (Default value = 1)
1267
1268 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001269 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001270 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001271 {'mr_label': label,
1272 'mr_eos': eos,
1273 'mr_table_id': table_id,
1274 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001275 'mr_is_add': is_add,
1276 'mr_is_classify': is_classify,
1277 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001278 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001279 'mr_is_resolve_host': is_resolve_host,
1280 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001281 'mr_is_interface_rx': is_interface_rx,
1282 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001283 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001284 'mr_next_hop_weight': next_hop_weight,
1285 'mr_next_hop': next_hop_address,
1286 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1287 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1288 'mr_next_hop_table_id': next_hop_table_id,
1289 'mr_next_hop_via_label': next_hop_via_label,
1290 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001291
1292 def mpls_ip_bind_unbind(
1293 self,
1294 label,
1295 dst_address,
1296 dst_address_length,
1297 table_id=0,
1298 ip_table_id=0,
1299 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001300 is_bind=1):
1301 """
1302 """
1303 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001304 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001305 {'mb_mpls_table_id': table_id,
1306 'mb_label': label,
1307 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001308 'mb_is_bind': is_bind,
1309 'mb_is_ip4': is_ip4,
1310 'mb_address_length': dst_address_length,
1311 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001312
1313 def mpls_tunnel_add_del(
1314 self,
1315 tun_sw_if_index,
1316 next_hop_proto_is_ip4,
1317 next_hop_address,
1318 next_hop_sw_if_index=0xFFFFFFFF,
1319 next_hop_table_id=0,
1320 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001321 next_hop_n_out_labels=0,
1322 next_hop_out_label_stack=[],
1323 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001324 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001325 l2_only=0,
1326 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001327 """
1328
1329 :param dst_address_length:
1330 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1331 :param dst_address:
1332 :param next_hop_address:
1333 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1334 :param vrf_id: (Default value = 0)
1335 :param lookup_in_vrf: (Default value = 0)
1336 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001337 :param is_add: (Default value = 1)
1338 :param is_drop: (Default value = 0)
1339 :param is_ipv6: (Default value = 0)
1340 :param is_local: (Default value = 0)
1341 :param is_classify: (Default value = 0)
1342 :param is_multipath: (Default value = 0)
1343 :param is_resolve_host: (Default value = 0)
1344 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001345 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001346 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001347
1348 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001349 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001350 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001351 {'mt_sw_if_index': tun_sw_if_index,
1352 'mt_is_add': is_add,
1353 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001354 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001355 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1356 'mt_next_hop_weight': next_hop_weight,
1357 'mt_next_hop': next_hop_address,
1358 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1359 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1360 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001361 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001362 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001363
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001364 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1365 return self.api(self.papi.mpls_tunnel_dump,
1366 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001367
Matus Fabian2ba92e32017-08-21 07:05:03 -07001368 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001369 self,
1370 sw_if_index,
1371 is_inside=1,
1372 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001373 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001374
1375 :param sw_if_index: Software index of the interface
1376 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1377 :param is_add: 1 if add, 0 if delete (Default value = 1)
1378 """
1379 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001380 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001381 {'is_add': is_add,
1382 'is_inside': is_inside,
1383 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001384
Matus Fabian2ba92e32017-08-21 07:05:03 -07001385 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001386 self,
1387 sw_if_index,
1388 is_inside=1,
1389 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001390 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001391
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_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001398 {'is_add': is_add,
1399 'is_inside': is_inside,
1400 'sw_if_index': sw_if_index})
1401
Matus Fabian2ba92e32017-08-21 07:05:03 -07001402 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001403 self,
1404 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001405 external_ip=0,
1406 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001407 local_port=0,
1408 external_port=0,
1409 addr_only=1,
1410 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001411 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001412 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001413 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001414 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001415 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001416 is_add=1):
1417 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001418
1419 :param local_ip: Local IP address
1420 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001421 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001422 :param local_port: Local port number (Default value = 0)
1423 :param external_port: External port number (Default value = 0)
1424 :param addr_only: 1 if address only mapping, 0 if address and port
1425 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001426 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001427 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001428 :param self_twice_nat: 1 if translate external host address and port
1429 whenever external host address equals
1430 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001431 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001432 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001433 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001434 """
1435 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001436 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001437 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001438 'addr_only': addr_only,
1439 'local_ip_address': local_ip,
1440 'external_ip_address': external_ip,
1441 'local_port': local_port,
1442 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001443 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001444 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001445 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001446 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001447 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001448 'out2in_only': out2in_only,
1449 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001450
Matus Fabianab7a8052017-11-28 04:29:41 -08001451 def nat44_add_del_identity_mapping(
1452 self,
1453 ip='0',
1454 sw_if_index=0xFFFFFFFF,
1455 port=0,
1456 addr_only=1,
1457 vrf_id=0,
1458 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001459 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001460 is_add=1):
1461 """Add/delete NAT44 identity mapping
1462
1463 :param ip: IP address (Default value = 0)
1464 :param sw_if_index: Interface instead of IP address
1465 :param port: Port number (Default value = 0)
1466 :param addr_only: 1 if address only mapping, 0 if address and port
1467 :param vrf_id: VRF ID
1468 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001469 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001470 :param is_add: 1 if add, 0 if delete (Default value = 1)
1471 """
1472 return self.api(
1473 self.papi.nat44_add_del_identity_mapping,
1474 {'is_add': is_add,
1475 'addr_only': addr_only,
1476 'ip_address': ip,
1477 'port': port,
1478 'sw_if_index': sw_if_index,
1479 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001480 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001481 'protocol': protocol})
1482
Matus Fabian2ba92e32017-08-21 07:05:03 -07001483 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001484 self,
1485 first_ip_address,
1486 last_ip_address,
1487 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001488 vrf_id=0xFFFFFFFF,
1489 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001490 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001491
1492 :param first_ip_address: First IP address
1493 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001494 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001495 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001496 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001497 """
1498 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001499 self.papi.nat44_add_del_address_range,
1500 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001501 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001502 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001503 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001504 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001505
Matus Fabian2ba92e32017-08-21 07:05:03 -07001506 def nat44_address_dump(self):
1507 """Dump NAT44 addresses
1508 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001509 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001510 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001511
Matus Fabian2ba92e32017-08-21 07:05:03 -07001512 def nat44_interface_dump(self):
1513 """Dump interfaces with NAT44 feature
1514 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001515 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001516 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001517
Matus Fabian2ba92e32017-08-21 07:05:03 -07001518 def nat44_interface_output_feature_dump(self):
1519 """Dump interfaces with NAT44 output feature
1520 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001521 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001523
Matus Fabian2ba92e32017-08-21 07:05:03 -07001524 def nat44_static_mapping_dump(self):
1525 """Dump NAT44 static mappings
1526 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001527 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001528 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001529
Matus Fabianab7a8052017-11-28 04:29:41 -08001530 def nat44_identity_mapping_dump(self):
1531 """Dump NAT44 identity mappings
1532 :return: Dictionary of NAT44 identity mappings
1533 """
1534 return self.api(self.papi.nat44_identity_mapping_dump, {})
1535
Matus Fabian2ba92e32017-08-21 07:05:03 -07001536 def nat_show_config(self):
1537 """Show NAT plugin config
1538 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001539 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001540 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001541
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001543 self,
1544 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001545 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001546 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001547 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001548
1549 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001550 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001551 :param is_add: 1 if add, 0 if delete (Default value = 1)
1552 """
Matus Fabianb932d262017-12-18 05:38:24 -08001553 return self.api(
1554 self.papi.nat44_add_del_interface_addr,
1555 {'is_add': is_add,
1556 'sw_if_index': sw_if_index,
1557 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001558
Matus Fabian2ba92e32017-08-21 07:05:03 -07001559 def nat44_interface_addr_dump(self):
1560 """Dump NAT44 addresses interfaces
1561 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001562 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001563 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001564
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001566 self,
1567 domain_id=1,
1568 src_port=4739,
1569 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001570 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001571
1572 :param domain_id: Observation domain ID (Default value = 1)
1573 :param src_port: Source port number (Default value = 4739)
1574 :param enable: 1 if enable, 0 if disable (Default value = 1)
1575 """
1576 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001577 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001578 {'domain_id': domain_id,
1579 'src_port': src_port,
1580 'enable': enable})
1581
Matus Fabian2ba92e32017-08-21 07:05:03 -07001582 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001583 self,
1584 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001585 vrf_id):
1586 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001587
1588 :param ip_address: ip adress of the user to be dumped
1589 :param cpu_index: cpu_index on which the user is
1590 :param vrf_id: VRF ID
1591 :return: Dictionary of S-NAT sessions
1592 """
1593 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001594 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001595 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001596 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001597
Matus Fabian2ba92e32017-08-21 07:05:03 -07001598 def nat44_user_dump(self):
1599 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001600
Matus Fabian2ba92e32017-08-21 07:05:03 -07001601 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001602 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001603 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001604
Matus Fabian704018c2017-09-04 02:17:18 -07001605 def nat44_add_del_lb_static_mapping(
1606 self,
1607 external_addr,
1608 external_port,
1609 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001610 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001611 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001612 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001613 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001614 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001615 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001616 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001617 is_add=1):
1618 """Add/delete NAT44 load balancing static mapping
1619
Matus Fabianb932d262017-12-18 05:38:24 -08001620 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001621 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001622 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001623 :param is_add - 1 if add, 0 if delete
1624 """
1625 return self.api(
1626 self.papi.nat44_add_del_lb_static_mapping,
1627 {'is_add': is_add,
1628 'external_addr': external_addr,
1629 'external_port': external_port,
1630 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001631 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001632 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001633 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001634 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001635 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001636 'local_num': local_num,
1637 'locals': locals})
1638
1639 def nat44_lb_static_mapping_dump(self):
1640 """Dump NAT44 load balancing static mappings
1641
1642 :return: Dictionary of NAT44 load balancing static mapping
1643 """
1644 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1645
Matus Fabian5ba86f72017-10-26 03:37:38 -07001646 def nat44_del_session(
1647 self,
1648 addr,
1649 port,
1650 protocol,
1651 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001652 is_in=1,
1653 ext_host_address=None,
1654 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001655 """Delete NAT44 session
1656
1657 :param addr: IPv4 address
1658 :param por: port number
1659 :param protocol: IP protocol number
1660 :param vrf_id: VRF ID
1661 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001662 :param ext_host_address: external host IPv4 address
1663 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001664 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001665 if ext_host_address is None:
1666 return self.api(
1667 self.papi.nat44_del_session,
1668 {'address': addr,
1669 'port': port,
1670 'protocol': protocol,
1671 'vrf_id': vrf_id,
1672 'is_in': is_in})
1673 else:
1674 return self.api(
1675 self.papi.nat44_del_session,
1676 {'address': addr,
1677 'port': port,
1678 'protocol': protocol,
1679 'vrf_id': vrf_id,
1680 'is_in': is_in,
1681 'ext_host_valid': 1,
1682 'ext_host_address': ext_host_address,
1683 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001684
Juraj Sloboda7b929792017-11-23 13:20:48 +01001685 def nat44_forwarding_enable_disable(
1686 self,
1687 enable):
1688 """Enable/disable forwarding for NAT44
1689
1690 :param enable: 1 for enable, 0 for disable
1691 """
1692 return self.api(
1693 self.papi.nat44_forwarding_enable_disable,
1694 {'enable': enable})
1695
Matus Fabianefcd1e92017-08-15 06:59:19 -07001696 def nat_set_reass(
1697 self,
1698 timeout=2,
1699 max_reass=1024,
1700 max_frag=5,
1701 drop_frag=0,
1702 is_ip6=0):
1703 """Set NAT virtual fragmentation reassembly
1704
1705 :param timeout: reassembly timeout (Default 2sec)
1706 :param max_reass: maximum concurrent reassemblies (Default 1024)
1707 :param max_frag: maximum fragmets per reassembly (Default 5)
1708 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1709 :param is_ip6: 1 if IPv6, 0 if IPv4
1710 """
1711 return self.api(
1712 self.papi.nat_set_reass,
1713 {'timeout': timeout,
1714 'max_reass': max_reass,
1715 'max_frag': max_frag,
1716 'drop_frag': drop_frag,
1717 'is_ip6': is_ip6})
1718
1719 def nat_get_reass(self):
1720 """Get NAT virtual fragmentation reassembly configuration
1721
1722 :return: NAT virtual fragmentation reassembly configuration
1723 """
1724 return self.api(self.papi.nat_get_reass, {})
1725
1726 def nat_reass_dump(self):
1727 """Dump NAT virtual fragmentation reassemblies
1728
1729 :return: Dictionary of NAT virtual fragmentation reassemblies
1730 """
1731 return self.api(self.papi.nat_reass_dump, {})
1732
Matus Fabian2ba92e32017-08-21 07:05:03 -07001733 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001734 self,
1735 in_addr,
1736 in_plen,
1737 out_addr,
1738 out_plen,
1739 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001740 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001741
1742 :param is_add - 1 if add, 0 if delete
1743 :param in_addr - inside IP address
1744 :param in_plen - inside IP address prefix length
1745 :param out_addr - outside IP address
1746 :param out_plen - outside IP address prefix length
1747 """
1748 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001749 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001750 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001751 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001752 'in_addr': in_addr,
1753 'in_plen': in_plen,
1754 'out_addr': out_addr,
1755 'out_plen': out_plen})
1756
Matus Fabian2ba92e32017-08-21 07:05:03 -07001757 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001758 self,
1759 in_addr):
1760 """Get outside address and port range from inside address
1761
1762 :param in_addr - inside IP address
1763 """
1764 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001765 self.papi.nat_det_forward,
1766 {'in_addr': in_addr,
1767 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001768
Matus Fabian2ba92e32017-08-21 07:05:03 -07001769 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001770 self,
1771 out_addr,
1772 out_port):
1773 """Get inside address from outside address and port
1774
1775 :param out_addr - outside IP address
1776 :param out_port - outside port
1777 """
1778 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001779 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001780 {'out_addr': out_addr,
1781 'out_port': out_port})
1782
Matus Fabian2ba92e32017-08-21 07:05:03 -07001783 def nat_det_map_dump(self):
1784 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001785
Matus Fabian2ba92e32017-08-21 07:05:03 -07001786 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001787 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001788 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001789
Matus Fabian878c6462018-08-23 00:33:35 -07001790 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001791 self,
1792 udp=300,
1793 tcp_established=7440,
1794 tcp_transitory=240,
1795 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001796 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001797
1798 :param udp - UDP timeout (Default value = 300)
1799 :param tcp_established - TCP established timeout (Default value = 7440)
1800 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1801 :param icmp - ICMP timeout (Default value = 60)
1802 """
1803 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001804 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001805 {'udp': udp,
1806 'tcp_established': tcp_established,
1807 'tcp_transitory': tcp_transitory,
1808 'icmp': icmp})
1809
Matus Fabian878c6462018-08-23 00:33:35 -07001810 def nat_get_timeouts(self):
1811 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001812
Matus Fabian878c6462018-08-23 00:33:35 -07001813 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001814 """
Matus Fabian878c6462018-08-23 00:33:35 -07001815 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001816
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001817 def nat_set_addr_and_port_alloc_alg(
1818 self,
1819 alg=0,
1820 psid_offset=0,
1821 psid_length=0,
1822 psid=0,
1823 start_port=0,
1824 end_port=0):
1825 """Set address and port assignment algorithm
1826
1827 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1828 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1829 :param psid_length: length of PSID (valid only for MAP-E alg)
1830 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1831 :param start_port: beginning of the port range
1832 :param end_port: end of the port range
1833 """
1834 return self.api(
1835 self.papi.nat_set_addr_and_port_alloc_alg,
1836 {'alg': alg,
1837 'psid_offset': psid_offset,
1838 'psid_length': psid_length,
1839 'psid': psid,
1840 'start_port': start_port,
1841 'end_port': end_port})
1842
1843 def nat_get_addr_and_port_alloc_alg(self):
1844 """Get address and port assignment algorithm"""
1845 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1846
Matus Fabianbb4e0222018-09-13 02:36:25 -07001847 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1848 """Set TCP MSS rewriting configuration
1849
1850 :param enable: disable(0)/enable(1) MSS rewriting feature
1851 :param mss_value: MSS value to be used for MSS rewriting
1852 """
1853 return self.api(
1854 self.papi.nat_set_mss_clamping,
1855 {'enable': enable, 'mss_value': mss_value})
1856
1857 def nat_get_mss_clamping(self):
1858 """Get TCP MSS rewriting configuration"""
1859 return self.api(self.papi.nat_get_mss_clamping, {})
1860
Matus Fabian2ba92e32017-08-21 07:05:03 -07001861 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001862 self,
1863 out_addr,
1864 out_port,
1865 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001866 ext_port):
1867 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001868
1869 :param out_addr - outside IP address
1870 :param out_port - outside port
1871 :param ext_addr - external host IP address
1872 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001873 """
1874 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001875 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001876 {'out_addr': out_addr,
1877 'out_port': out_port,
1878 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001879 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001880
Matus Fabian2ba92e32017-08-21 07:05:03 -07001881 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001882 self,
1883 in_addr,
1884 in_port,
1885 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001886 ext_port):
1887 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001888
1889 :param in_addr - inside IP address
1890 :param in_port - inside port
1891 :param ext_addr - external host IP address
1892 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001893 """
1894 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001895 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001896 {'in_addr': in_addr,
1897 'in_port': in_port,
1898 'ext_addr': ext_addr,
1899 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001900 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001901
Matus Fabian2ba92e32017-08-21 07:05:03 -07001902 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001903 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001904 user_addr):
1905 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001906
1907 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001908 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001909 """
1910 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001911 self.papi.nat_det_session_dump,
1912 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001913 'user_addr': user_addr})
1914
Matus Fabian06596c52017-06-06 04:53:28 -07001915 def nat64_add_del_pool_addr_range(
1916 self,
1917 start_addr,
1918 end_addr,
1919 vrf_id=0xFFFFFFFF,
1920 is_add=1):
1921 """Add/del address range to NAT64 pool
1922
1923 :param start_addr: First IP address
1924 :param end_addr: Last IP address
1925 :param vrf_id: VRF id for the address range
1926 :param is_add: 1 if add, 0 if delete (Default value = 1)
1927 """
1928 return self.api(
1929 self.papi.nat64_add_del_pool_addr_range,
1930 {'start_addr': start_addr,
1931 'end_addr': end_addr,
1932 'vrf_id': vrf_id,
1933 'is_add': is_add})
1934
1935 def nat64_pool_addr_dump(self):
1936 """Dump NAT64 pool addresses
1937 :return: Dictionary of NAT64 pool addresses
1938 """
1939 return self.api(self.papi.nat64_pool_addr_dump, {})
1940
1941 def nat64_add_del_interface(
1942 self,
1943 sw_if_index,
1944 is_inside=1,
1945 is_add=1):
1946 """Enable/disable NAT64 feature on the interface
1947 :param sw_if_index: Index of the interface
1948 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1949 :param is_add: 1 if add, 0 if delete (Default value = 1)
1950 """
1951 return self.api(
1952 self.papi.nat64_add_del_interface,
1953 {'sw_if_index': sw_if_index,
1954 'is_inside': is_inside,
1955 'is_add': is_add})
1956
1957 def nat64_interface_dump(self):
1958 """Dump interfaces with NAT64 feature
1959 :return: Dictionary of interfaces with NAT64 feature
1960 """
1961 return self.api(self.papi.nat64_interface_dump, {})
1962
1963 def nat64_add_del_static_bib(
1964 self,
1965 in_ip,
1966 out_ip,
1967 in_port,
1968 out_port,
1969 protocol,
1970 vrf_id=0,
1971 is_add=1):
1972 """Add/delete S-NAT static BIB entry
1973
1974 :param in_ip: Inside IPv6 address
1975 :param out_ip: Outside IPv4 address
1976 :param in_port: Inside port number
1977 :param out_port: Outside port number
1978 :param protocol: IP protocol
1979 :param vrf_id: VRF ID (Default value = 0)
1980 :param is_add: 1 if add, 0 if delete (Default value = 1)
1981 """
1982 return self.api(
1983 self.papi.nat64_add_del_static_bib,
1984 {'i_addr': in_ip,
1985 'o_addr': out_ip,
1986 'i_port': in_port,
1987 'o_port': out_port,
1988 'vrf_id': vrf_id,
1989 'proto': protocol,
1990 'is_add': is_add})
1991
Matus Fabianab9a59c2017-08-16 05:37:36 -07001992 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001993 """Dump NAT64 BIB
1994
Matus Fabianab9a59c2017-08-16 05:37:36 -07001995 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001996 :returns: Dictionary of NAT64 BIB entries
1997 """
1998 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1999
2000 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2001 tcp_incoming_syn=6):
2002 """Set values of timeouts for NAT64 (in seconds)
2003
Matus Fabian428dc912017-06-21 06:15:18 -07002004 :param udpi: UDP timeout (Default value = 300)
2005 :param icmp: ICMP timeout (Default value = 60)
2006 :param tcp_trans: TCP transitory timeout (Default value = 240)
2007 :param tcp_est: TCP established timeout (Default value = 7440)
2008 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002009 """
2010 return self.api(
2011 self.papi.nat64_set_timeouts,
2012 {'udp': udp,
2013 'icmp': icmp,
2014 'tcp_trans': tcp_trans,
2015 'tcp_est': tcp_est,
2016 'tcp_incoming_syn': tcp_incoming_syn})
2017
2018 def nat64_get_timeouts(self):
2019 """Get values of timeouts for NAT64
2020
2021 :return: Timeouts for NAT64 (in seconds)
2022 """
2023 return self.api(self.papi.nat64_get_timeouts, {})
2024
Matus Fabianab9a59c2017-08-16 05:37:36 -07002025 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002026 """Dump NAT64 session table
2027
Matus Fabianab9a59c2017-08-16 05:37:36 -07002028 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002029 :returns: Dictionary of NAT64 sesstion table entries
2030 """
2031 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2032
Matus Fabian428dc912017-06-21 06:15:18 -07002033 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2034 """Add/del NAT64 prefix
2035
2036 :param prefix: NAT64 prefix
2037 :param plen: NAT64 prefix length
2038 :param vrf_id: VRF id of tenant (Default 0)
2039 :param is_add: 1 if add, 0 if delete (Default value = 1)
2040 """
2041 return self.api(
2042 self.papi.nat64_add_del_prefix,
2043 {'prefix': prefix,
2044 'prefix_len': plen,
2045 'vrf_id': vrf_id,
2046 'is_add': is_add})
2047
2048 def nat64_prefix_dump(self):
2049 """Dump NAT64 prefix
2050
2051 :returns: Dictionary of NAT64 prefixes
2052 """
2053 return self.api(self.papi.nat64_prefix_dump, {})
2054
Matus Fabian0938dcf2017-11-08 01:59:38 -08002055 def nat64_add_interface_addr(
2056 self,
2057 sw_if_index,
2058 is_add=1):
2059 """Add/del NAT64 address from interface
2060
2061 :param sw_if_index: Software index of the interface
2062 :param is_add: 1 if add, 0 if delete (Default value = 1)
2063 """
2064 return self.api(self.papi.nat64_add_del_interface_addr,
2065 {'is_add': is_add, 'sw_if_index': sw_if_index})
2066
Matus Fabian8ebe6252017-11-06 05:04:53 -08002067 def dslite_set_aftr_addr(self, ip6, ip4):
2068 """Set DS-Lite AFTR addresses
2069
2070 :param ip4: IPv4 address
2071 :param ip6: IPv6 address
2072 """
2073 return self.api(
2074 self.papi.dslite_set_aftr_addr,
2075 {'ip4_addr': ip4,
2076 'ip6_addr': ip6})
2077
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002078 def dslite_set_b4_addr(self, ip6, ip4):
2079 """Set DS-Lite B4 IPv6 address
2080
2081 :param ip4: IPv4 address
2082 :param ip6: IPv6 address
2083 """
2084 return self.api(
2085 self.papi.dslite_set_b4_addr,
2086 {'ip4_addr': ip4,
2087 'ip6_addr': ip6})
2088
Matus Fabian8ebe6252017-11-06 05:04:53 -08002089 def dslite_add_del_pool_addr_range(
2090 self,
2091 start_addr,
2092 end_addr,
2093 is_add=1):
2094 """Add/del address range to DS-Lite pool
2095
2096 :param start_addr: First IP address
2097 :param end_addr: Last IP address
2098 :param is_add: 1 if add, 0 if delete (Default value = 1)
2099 """
2100 return self.api(
2101 self.papi.dslite_add_del_pool_addr_range,
2102 {'start_addr': start_addr,
2103 'end_addr': end_addr,
2104 'is_add': is_add})
2105
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002106 def nat66_add_del_interface(
2107 self,
2108 sw_if_index,
2109 is_inside=1,
2110 is_add=1):
2111 """Enable/disable NAT66 feature on the interface
2112 :param sw_if_index: Index of the interface
2113 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2114 :param is_add: 1 if add, 0 if delete (Default value = 1)
2115 """
2116 return self.api(
2117 self.papi.nat66_add_del_interface,
2118 {'sw_if_index': sw_if_index,
2119 'is_inside': is_inside,
2120 'is_add': is_add})
2121
2122 def nat66_add_del_static_mapping(
2123 self,
2124 in_ip,
2125 out_ip,
2126 vrf_id=0,
2127 is_add=1):
2128 """Add/delete NAT66 static mapping
2129
2130 :param in_ip: Inside IPv6 address
2131 :param out_ip: Outside IPv6 address
2132 :param vrf_id: VRF ID (Default value = 0)
2133 :param is_add: 1 if add, 0 if delete (Default value = 1)
2134 """
2135 return self.api(
2136 self.papi.nat66_add_del_static_mapping,
2137 {'local_ip_address': in_ip,
2138 'external_ip_address': out_ip,
2139 'vrf_id': vrf_id,
2140 'is_add': is_add})
2141
2142 def nat66_interface_dump(self):
2143 """Dump interfaces with NAT66 feature
2144 :return: Dictionary of interfaces with NAT66 feature
2145 """
2146 return self.api(self.papi.nat66_interface_dump, {})
2147
2148 def nat66_static_mapping_dump(self):
2149 """Dump NAT66 static mappings
2150 :return: Dictionary of NAT66 static mappings
2151 """
2152 return self.api(self.papi.nat66_static_mapping_dump, {})
2153
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002154 def control_ping(self):
2155 self.api(self.papi.control_ping)
2156
2157 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002158 detect_mult, local_addr, peer_addr, is_ipv6=0,
2159 bfd_key_id=None, conf_key_id=None):
2160 if bfd_key_id is None:
2161 return self.api(self.papi.bfd_udp_add,
2162 {
2163 'sw_if_index': sw_if_index,
2164 'desired_min_tx': desired_min_tx,
2165 'required_min_rx': required_min_rx,
2166 'local_addr': local_addr,
2167 'peer_addr': peer_addr,
2168 'is_ipv6': is_ipv6,
2169 'detect_mult': detect_mult,
2170 })
2171 else:
2172 return self.api(self.papi.bfd_udp_add,
2173 {
2174 'sw_if_index': sw_if_index,
2175 'desired_min_tx': desired_min_tx,
2176 'required_min_rx': required_min_rx,
2177 'local_addr': local_addr,
2178 'peer_addr': peer_addr,
2179 'is_ipv6': is_ipv6,
2180 'detect_mult': detect_mult,
2181 'is_authenticated': 1,
2182 'bfd_key_id': bfd_key_id,
2183 'conf_key_id': conf_key_id,
2184 })
2185
Klement Sekeraa57a9702017-02-02 06:58:07 +01002186 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2187 detect_mult, local_addr, peer_addr, is_ipv6=0):
2188 return self.api(self.papi.bfd_udp_mod,
2189 {
2190 'sw_if_index': sw_if_index,
2191 'desired_min_tx': desired_min_tx,
2192 'required_min_rx': required_min_rx,
2193 'local_addr': local_addr,
2194 'peer_addr': peer_addr,
2195 'is_ipv6': is_ipv6,
2196 'detect_mult': detect_mult,
2197 })
2198
Klement Sekerab17dd962017-01-09 07:43:48 +01002199 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2200 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2201 is_delayed=False):
2202 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002203 {
2204 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002205 'local_addr': local_addr,
2206 'peer_addr': peer_addr,
2207 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002208 'is_delayed': 1 if is_delayed else 0,
2209 'bfd_key_id': bfd_key_id,
2210 'conf_key_id': conf_key_id,
2211 })
2212
2213 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2214 is_ipv6=0, is_delayed=False):
2215 return self.api(self.papi.bfd_udp_auth_deactivate,
2216 {
2217 'sw_if_index': sw_if_index,
2218 'local_addr': local_addr,
2219 'peer_addr': peer_addr,
2220 'is_ipv6': is_ipv6,
2221 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002222 })
2223
2224 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2225 return self.api(self.papi.bfd_udp_del,
2226 {
2227 'sw_if_index': sw_if_index,
2228 'local_addr': local_addr,
2229 'peer_addr': peer_addr,
2230 'is_ipv6': is_ipv6,
2231 })
2232
2233 def bfd_udp_session_dump(self):
2234 return self.api(self.papi.bfd_udp_session_dump, {})
2235
Klement Sekerab17dd962017-01-09 07:43:48 +01002236 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2237 peer_addr, is_ipv6=0):
2238 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002239 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002240 'sw_if_index': sw_if_index,
2241 'local_addr': local_addr,
2242 'peer_addr': peer_addr,
2243 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002244 })
2245
2246 def want_bfd_events(self, enable_disable=1):
2247 return self.api(self.papi.want_bfd_events, {
2248 'enable_disable': enable_disable,
2249 'pid': os.getpid(),
2250 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002251
Klement Sekerab17dd962017-01-09 07:43:48 +01002252 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2253 return self.api(self.papi.bfd_auth_set_key, {
2254 'conf_key_id': conf_key_id,
2255 'auth_type': auth_type,
2256 'key': key,
2257 'key_len': len(key),
2258 })
2259
2260 def bfd_auth_del_key(self, conf_key_id):
2261 return self.api(self.papi.bfd_auth_del_key, {
2262 'conf_key_id': conf_key_id,
2263 })
2264
2265 def bfd_auth_keys_dump(self):
2266 return self.api(self.papi.bfd_auth_keys_dump, {})
2267
Klement Sekera239790f2017-02-16 10:53:53 +01002268 def bfd_udp_set_echo_source(self, sw_if_index):
2269 return self.api(self.papi.bfd_udp_set_echo_source,
2270 {'sw_if_index': sw_if_index})
2271
Klement Sekera73884482017-02-23 09:26:30 +01002272 def bfd_udp_del_echo_source(self):
2273 return self.api(self.papi.bfd_udp_del_echo_source, {})
2274
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002275 def bfd_udp_get_echo_source(self):
2276 return self.api(self.papi.bfd_udp_get_echo_source, {})
2277
Steve Shin7957d6e2016-12-19 09:24:50 -08002278 def classify_add_del_table(
2279 self,
2280 is_add,
2281 mask,
2282 match_n_vectors=1,
2283 table_index=0xFFFFFFFF,
2284 nbuckets=2,
2285 memory_size=2097152,
2286 skip_n_vectors=0,
2287 next_table_index=0xFFFFFFFF,
2288 miss_next_index=0xFFFFFFFF,
2289 current_data_flag=0,
2290 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002291 """
2292 :param is_add:
2293 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002294 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002295 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002296 :param nbuckets: (Default value = 2)
2297 :param memory_size: (Default value = 2097152)
2298 :param skip_n_vectors: (Default value = 0)
2299 :param next_table_index: (Default value = 0xFFFFFFFF)
2300 :param miss_next_index: (Default value = 0xFFFFFFFF)
2301 :param current_data_flag: (Default value = 0)
2302 :param current_data_offset: (Default value = 0)
2303 """
2304
Juraj Sloboda75282452018-06-12 14:20:49 +02002305 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2306 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002307 return self.api(
2308 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002309 {'is_add': is_add,
2310 'table_index': table_index,
2311 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002312 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002313 'skip_n_vectors': skip_n_vectors,
2314 'match_n_vectors': match_n_vectors,
2315 'next_table_index': next_table_index,
2316 'miss_next_index': miss_next_index,
2317 'current_data_flag': current_data_flag,
2318 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002319 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002320 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002321
2322 def classify_add_del_session(
2323 self,
2324 is_add,
2325 table_index,
2326 match,
2327 opaque_index=0xFFFFFFFF,
2328 hit_next_index=0xFFFFFFFF,
2329 advance=0,
2330 action=0,
2331 metadata=0):
2332 """
2333 :param is_add:
2334 :param table_index:
2335 :param match:
2336 :param opaque_index: (Default value = 0xFFFFFFFF)
2337 :param hit_next_index: (Default value = 0xFFFFFFFF)
2338 :param advance: (Default value = 0)
2339 :param action: (Default value = 0)
2340 :param metadata: (Default value = 0)
2341 """
2342
Juraj Sloboda75282452018-06-12 14:20:49 +02002343 match_len = ((len(match) - 1) / 16 + 1) * 16
2344 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002345 return self.api(
2346 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002347 {'is_add': is_add,
2348 'table_index': table_index,
2349 'hit_next_index': hit_next_index,
2350 'opaque_index': opaque_index,
2351 'advance': advance,
2352 'action': action,
2353 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002354 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002355 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002356
2357 def input_acl_set_interface(
2358 self,
2359 is_add,
2360 sw_if_index,
2361 ip4_table_index=0xFFFFFFFF,
2362 ip6_table_index=0xFFFFFFFF,
2363 l2_table_index=0xFFFFFFFF):
2364 """
2365 :param is_add:
2366 :param sw_if_index:
2367 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2368 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2369 :param l2_table_index: (Default value = 0xFFFFFFFF)
2370 """
2371
2372 return self.api(
2373 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002374 {'sw_if_index': sw_if_index,
2375 'ip4_table_index': ip4_table_index,
2376 'ip6_table_index': ip6_table_index,
2377 'l2_table_index': l2_table_index,
2378 'is_add': is_add})
2379
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002380 def output_acl_set_interface(
2381 self,
2382 is_add,
2383 sw_if_index,
2384 ip4_table_index=0xFFFFFFFF,
2385 ip6_table_index=0xFFFFFFFF,
2386 l2_table_index=0xFFFFFFFF):
2387 """
2388 :param is_add:
2389 :param sw_if_index:
2390 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2391 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2392 :param l2_table_index: (Default value = 0xFFFFFFFF)
2393 """
2394
2395 return self.api(
2396 self.papi.output_acl_set_interface,
2397 {'sw_if_index': sw_if_index,
2398 'ip4_table_index': ip4_table_index,
2399 'ip6_table_index': ip6_table_index,
2400 'l2_table_index': l2_table_index,
2401 'is_add': is_add})
2402
Klement Sekera77fabdb2017-01-02 07:46:14 +01002403 def set_ipfix_exporter(
2404 self,
2405 collector_address,
2406 src_address,
2407 path_mtu,
2408 template_interval,
2409 vrf_id=0,
2410 collector_port=4739,
2411 udp_checksum=0):
2412 return self.api(
2413 self.papi.set_ipfix_exporter,
2414 {
2415 'collector_address': collector_address,
2416 'collector_port': collector_port,
2417 'src_address': src_address,
2418 'vrf_id': vrf_id,
2419 'path_mtu': path_mtu,
2420 'template_interval': template_interval,
2421 'udp_checksum': udp_checksum,
2422 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002423
2424 def dhcp_proxy_config(self,
2425 dhcp_server,
2426 dhcp_src_address,
2427 rx_table_id=0,
2428 server_table_id=0,
2429 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002430 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002431 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002432 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002433 {
2434 'rx_vrf_id': rx_table_id,
2435 'server_vrf_id': server_table_id,
2436 'is_ipv6': is_ipv6,
2437 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002438 'dhcp_server': dhcp_server,
2439 'dhcp_src_address': dhcp_src_address,
2440 })
2441
2442 def dhcp_proxy_set_vss(self,
2443 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002444 vss_type=255,
2445 vpn_ascii_id="",
2446 oui=0,
2447 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002448 is_add=1,
2449 is_ip6=0):
2450 return self.api(
2451 self.papi.dhcp_proxy_set_vss,
2452 {
2453 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002454 'vss_type': vss_type,
2455 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002456 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002457 'vpn_index': vpn_index,
2458 'is_add': is_add,
2459 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002460 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002461
Neale Rannsdaff1782018-05-16 04:12:18 -07002462 def dhcp_client_dump(self):
2463 return self.api(self.papi.dhcp_client_dump, {})
2464
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002465 def dhcp_client(self,
2466 sw_if_index,
2467 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002468 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002469 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002470 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002471 want_dhcp_events=0):
2472 return self.api(
2473 self.papi.dhcp_client_config,
2474 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002475 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002476 'client': {
2477 'sw_if_index': sw_if_index,
2478 'hostname': hostname,
2479 'id': client_id,
2480 'want_dhcp_event': want_dhcp_events,
2481 'set_broadcast_flag': set_broadcast_flag,
2482 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002483 })
2484
Neale Ranns32e1c012016-11-22 17:07:28 +00002485 def ip_mroute_add_del(self,
2486 src_address,
2487 grp_address,
2488 grp_address_length,
2489 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002490 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002491 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002492 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002493 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002494 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002495 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002496 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002497 is_add=1,
2498 is_ipv6=0,
2499 is_local=0):
2500 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002501 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002502 """
2503 return self.api(
2504 self.papi.ip_mroute_add_del,
2505 {'next_hop_sw_if_index': next_hop_sw_if_index,
2506 'entry_flags': e_flags,
2507 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002508 'table_id': table_id,
2509 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002510 'is_add': is_add,
2511 'is_ipv6': is_ipv6,
2512 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002513 'bier_imp': bier_imp,
2514 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002515 'grp_address_length': grp_address_length,
2516 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002517 'src_address': src_address,
2518 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002519
2520 def mfib_signal_dump(self):
2521 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002522
2523 def ip_mfib_dump(self):
2524 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002525
Neale Rannsd792d9c2017-10-21 10:53:20 -07002526 def ip6_mfib_dump(self):
2527 return self.api(self.papi.ip6_mfib_dump, {})
2528
Filip Tehlar770e89e2017-01-31 10:39:16 +01002529 def lisp_enable_disable(self, is_enabled):
2530 return self.api(
2531 self.papi.lisp_enable_disable,
2532 {
2533 'is_en': is_enabled,
2534 })
2535
2536 def lisp_locator_set(self,
2537 ls_name,
2538 is_add=1):
2539 return self.api(
2540 self.papi.lisp_add_del_locator_set,
2541 {
2542 'is_add': is_add,
2543 'locator_set_name': ls_name
2544 })
2545
2546 def lisp_locator_set_dump(self):
2547 return self.api(self.papi.lisp_locator_set_dump, {})
2548
2549 def lisp_locator(self,
2550 ls_name,
2551 sw_if_index,
2552 priority=1,
2553 weight=1,
2554 is_add=1):
2555 return self.api(
2556 self.papi.lisp_add_del_locator,
2557 {
2558 'is_add': is_add,
2559 'locator_set_name': ls_name,
2560 'sw_if_index': sw_if_index,
2561 'priority': priority,
2562 'weight': weight
2563 })
2564
2565 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2566 return self.api(
2567 self.papi.lisp_locator_dump,
2568 {
2569 'is_index_set': is_index_set,
2570 'ls_name': ls_name,
2571 'ls_index': ls_index,
2572 })
2573
2574 def lisp_local_mapping(self,
2575 ls_name,
2576 eid_type,
2577 eid,
2578 prefix_len,
2579 vni=0,
2580 key_id=0,
2581 key="",
2582 is_add=1):
2583 return self.api(
2584 self.papi.lisp_add_del_local_eid,
2585 {
2586 'locator_set_name': ls_name,
2587 'is_add': is_add,
2588 'eid_type': eid_type,
2589 'eid': eid,
2590 'prefix_len': prefix_len,
2591 'vni': vni,
2592 'key_id': key_id,
2593 'key': key
2594 })
2595
2596 def lisp_eid_table_dump(self,
2597 eid_set=0,
2598 prefix_length=0,
2599 vni=0,
2600 eid_type=0,
2601 eid=None,
2602 filter_opt=0):
2603 return self.api(
2604 self.papi.lisp_eid_table_dump,
2605 {
2606 'eid_set': eid_set,
2607 'prefix_length': prefix_length,
2608 'vni': vni,
2609 'eid_type': eid_type,
2610 'eid': eid,
2611 'filter': filter_opt,
2612 })
2613
2614 def lisp_remote_mapping(self,
2615 eid_type,
2616 eid,
2617 eid_prefix_len=0,
2618 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002619 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002620 rlocs_num=0,
2621 is_src_dst=0,
2622 is_add=1):
2623 return self.api(
2624 self.papi.lisp_add_del_remote_mapping,
2625 {
2626 'is_add': is_add,
2627 'eid_type': eid_type,
2628 'eid': eid,
2629 'eid_len': eid_prefix_len,
2630 'rloc_num': rlocs_num,
2631 'rlocs': rlocs,
2632 'vni': vni,
2633 'is_src_dst': is_src_dst,
2634 })
2635
2636 def lisp_adjacency(self,
2637 leid,
2638 reid,
2639 leid_len,
2640 reid_len,
2641 eid_type,
2642 is_add=1,
2643 vni=0):
2644 return self.api(
2645 self.papi.lisp_add_del_adjacency,
2646 {
2647 'is_add': is_add,
2648 'vni': vni,
2649 'eid_type': eid_type,
2650 'leid': leid,
2651 'reid': reid,
2652 'leid_len': leid_len,
2653 'reid_len': reid_len,
2654 })
2655
2656 def lisp_adjacencies_get(self, vni=0):
2657 return self.api(
2658 self.papi.lisp_adjacencies_get,
2659 {
2660 'vni': vni
2661 })
Neale Ranns80823802017-02-20 18:23:41 -08002662
2663 def map_add_domain(self,
2664 ip6_prefix,
2665 ip6_prefix_len,
2666 ip6_src,
2667 ip6_src_prefix_len,
2668 ip4_prefix,
2669 ip4_prefix_len,
2670 ea_bits_len=0,
2671 psid_offset=0,
2672 psid_length=0,
2673 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002674 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002675 mtu=1280):
2676 return self.api(
2677 self.papi.map_add_domain,
2678 {
2679 'ip6_prefix': ip6_prefix,
2680 'ip6_prefix_len': ip6_prefix_len,
2681 'ip4_prefix': ip4_prefix,
2682 'ip4_prefix_len': ip4_prefix_len,
2683 'ip6_src': ip6_src,
2684 'ip6_src_prefix_len': ip6_src_prefix_len,
2685 'ea_bits_len': ea_bits_len,
2686 'psid_offset': psid_offset,
2687 'psid_length': psid_length,
2688 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002689 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002690 'mtu': mtu
2691 })
Hongjun Nief486b12017-04-12 19:21:16 +08002692
2693 def gtpu_add_del_tunnel(
2694 self,
2695 src_addr,
2696 dst_addr,
2697 is_add=1,
2698 is_ipv6=0,
2699 mcast_sw_if_index=0xFFFFFFFF,
2700 encap_vrf_id=0,
2701 decap_next_index=0xFFFFFFFF,
2702 teid=0):
2703 """
2704
2705 :param is_add: (Default value = 1)
2706 :param is_ipv6: (Default value = 0)
2707 :param src_addr:
2708 :param dst_addr:
2709 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2710 :param encap_vrf_id: (Default value = 0)
2711 :param decap_next_index: (Default value = 0xFFFFFFFF)
2712 :param teid: (Default value = 0)
2713
2714 """
2715 return self.api(self.papi.gtpu_add_del_tunnel,
2716 {'is_add': is_add,
2717 'is_ipv6': is_ipv6,
2718 'src_address': src_addr,
2719 'dst_address': dst_addr,
2720 'mcast_sw_if_index': mcast_sw_if_index,
2721 'encap_vrf_id': encap_vrf_id,
2722 'decap_next_index': decap_next_index,
2723 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002724
2725 def vxlan_gpe_add_del_tunnel(
2726 self,
2727 src_addr,
2728 dst_addr,
2729 mcast_sw_if_index=0xFFFFFFFF,
2730 is_add=1,
2731 is_ipv6=0,
2732 encap_vrf_id=0,
2733 decap_vrf_id=0,
2734 protocol=3,
2735 vni=0):
2736 """
2737
2738 :param local:
2739 :param remote:
2740 :param is_add: (Default value = 1)
2741 :param is_ipv6: (Default value = 0)
2742 :param encap_vrf_id: (Default value = 0)
2743 :param decap_vrf_id: (Default value = 0)
2744 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2745 :param protocol: (Default value = 3)
2746 :param vni: (Default value = 0)
2747
2748 """
2749 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2750 {'is_add': is_add,
2751 'is_ipv6': is_ipv6,
2752 'local': src_addr,
2753 'remote': dst_addr,
2754 'mcast_sw_if_index': mcast_sw_if_index,
2755 'encap_vrf_id': encap_vrf_id,
2756 'decap_vrf_id': decap_vrf_id,
2757 'protocol': protocol,
2758 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002759
Neale Ranns79a05f52018-09-11 07:39:43 -07002760 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002761 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002762 src,
2763 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002764 mcast_sw_if_index=0xFFFFFFFF,
2765 is_add=1,
2766 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002767 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002768 decap_next_index=0xFFFFFFFF,
2769 vni=0,
2770 instance=0xFFFFFFFF):
2771 """
2772
2773 :param dst_addr:
2774 :param src_addr:
2775 :param is_add: (Default value = 1)
2776 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002777 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002778 :param decap_next_index: (Default value = 0xFFFFFFFF)
2779 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2780 :param vni: (Default value = 0)
2781 :param instance: (Default value = 0xFFFFFFFF)
2782
2783 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002784 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002785 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002786 'tunnel': {
2787 'src': src,
2788 'dst': dst,
2789 'mcast_sw_if_index': mcast_sw_if_index,
2790 'encap_table_id': encap_table_id,
2791 'decap_next_index': decap_next_index,
2792 'vni': vni,
2793 'instance': instance}})
2794
2795 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2796 return self.api(self.papi.vxlan_gbp_tunnel_dump,
2797 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002798
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002799 def pppoe_add_del_session(
2800 self,
2801 client_ip,
2802 client_mac,
2803 session_id=0,
2804 is_add=1,
2805 is_ipv6=0,
2806 decap_vrf_id=0):
2807 """
2808
2809 :param is_add: (Default value = 1)
2810 :param is_ipv6: (Default value = 0)
2811 :param client_ip:
2812 :param session_id: (Default value = 0)
2813 :param client_mac:
2814 :param decap_vrf_id: (Default value = 0)
2815
2816 """
2817 return self.api(self.papi.pppoe_add_del_session,
2818 {'is_add': is_add,
2819 'is_ipv6': is_ipv6,
2820 'session_id': session_id,
2821 'client_ip': client_ip,
2822 'decap_vrf_id': decap_vrf_id,
2823 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002824
Neale Ranns7c922dc2018-08-30 06:12:27 -07002825 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2826 return self.api(self.papi.sr_mpls_policy_add,
2827 {'bsid': bsid,
2828 'weight': weight,
2829 'type': type,
2830 'n_segments': len(segments),
2831 'segments': segments})
2832
2833 def sr_mpls_policy_del(self, bsid):
2834 return self.api(self.papi.sr_mpls_policy_del,
2835 {'bsid': bsid})
2836
Kris Michielsen91074432017-06-22 13:00:20 +02002837 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002838 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002839 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002840 nh_addr4,
2841 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002842 is_del=0,
2843 end_psp=0,
2844 sw_if_index=0xFFFFFFFF,
2845 vlan_index=0,
2846 fib_table=0,
2847 ):
2848 """ Add/del IPv6 SR local-SID.
2849
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002850 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002851 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2852 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002853 :param nh_addr4:
2854 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002855 :param is_del: (Default value = 0)
2856 :param end_psp: (Default value = 0)
2857 :param sw_if_index: (Default value = 0xFFFFFFFF)
2858 :param vlan_index: (Default value = 0)
2859 :param fib_table: (Default value = 0)
2860 """
2861 return self.api(
2862 self.papi.sr_localsid_add_del,
2863 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002864 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002865 'end_psp': end_psp,
2866 'behavior': behavior,
2867 'sw_if_index': sw_if_index,
2868 'vlan_index': vlan_index,
2869 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002870 'nh_addr4': nh_addr4,
2871 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002872 }
2873 )
2874
2875 def sr_policy_add(
2876 self,
2877 bsid_addr,
2878 weight=1,
2879 is_encap=1,
2880 type=0,
2881 fib_table=0,
2882 n_segments=0,
2883 segments=[]):
2884 """
2885 :param bsid_addr: bindingSID of the SR Policy
2886 :param weight: weight of the sid list. optional. (default: 1)
2887 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2888 (default: Encap)
2889 :param type: type/behavior of the SR policy. (default or spray) \
2890 (default: default)
2891 :param fib_table: VRF where to install the FIB entry for the BSID \
2892 (default: 0)
2893 :param n_segments: number of segments \
2894 (default: 0)
2895 :param segments: a vector of IPv6 address composing the segment list \
2896 (default: [])
2897 """
2898 return self.api(
2899 self.papi.sr_policy_add,
2900 {'bsid_addr': bsid_addr,
2901 'weight': weight,
2902 'is_encap': is_encap,
2903 'type': type,
2904 'fib_table': fib_table,
2905 'n_segments': n_segments,
2906 'segments': segments
2907 }
2908 )
2909
2910 def sr_policy_del(
2911 self,
2912 bsid_addr,
2913 sr_policy_index=0):
2914 """
2915 :param bsid: bindingSID of the SR Policy
2916 :param sr_policy_index: index of the sr policy (default: 0)
2917 """
2918 return self.api(
2919 self.papi.sr_policy_del,
2920 {'bsid_addr': bsid_addr,
2921 'sr_policy_index': sr_policy_index
2922 })
2923
2924 def sr_steering_add_del(
2925 self,
2926 is_del,
2927 bsid_addr,
2928 sr_policy_index,
2929 table_id,
2930 prefix_addr,
2931 mask_width,
2932 sw_if_index,
2933 traffic_type):
2934 """
2935 Steer traffic L2 and L3 traffic through a given SR policy
2936
2937 :param is_del: delete or add
2938 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2939 :param sr_policy: is the index of the SR Policy (alt to bsid)
2940 :param table_id: is the VRF where to install the FIB entry for the BSID
2941 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2942 :param mask_width: is the mask for L3 traffic type
2943 :param sw_if_index: is the incoming interface for L2 traffic
2944 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2945 """
2946 return self.api(
2947 self.papi.sr_steering_add_del,
2948 {'is_del': is_del,
2949 'bsid_addr': bsid_addr,
2950 'sr_policy_index': sr_policy_index,
2951 'table_id': table_id,
2952 'prefix_addr': prefix_addr,
2953 'mask_width': mask_width,
2954 'sw_if_index': sw_if_index,
2955 'traffic_type': traffic_type
2956 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002957
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002958 def acl_add_replace(self, acl_index, r, tag='',
2959 expected_retval=0):
2960 """Add/replace an ACL
2961 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2962 :param acl_rule r: ACL rules array.
2963 :param str tag: symbolic tag (description) for this ACL.
2964 :param int count: number of rules.
2965 """
2966 return self.api(self.papi.acl_add_replace,
2967 {'acl_index': acl_index,
2968 'r': r,
2969 'count': len(r),
2970 'tag': tag},
2971 expected_retval=expected_retval)
2972
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002973 def acl_del(self, acl_index, expected_retval=0):
2974 """
2975
2976 :param acl_index:
2977 :return:
2978 """
2979 return self.api(self.papi.acl_del,
2980 {'acl_index': acl_index},
2981 expected_retval=expected_retval)
2982
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002983 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2984 expected_retval=0):
2985 return self.api(self.papi.acl_interface_set_acl_list,
2986 {'sw_if_index': sw_if_index,
2987 'count': len(acls),
2988 'n_input': n_input,
2989 'acls': acls},
2990 expected_retval=expected_retval)
2991
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002992 def acl_interface_set_etype_whitelist(self, sw_if_index,
2993 n_input, whitelist,
2994 expected_retval=0):
2995 return self.api(self.papi.acl_interface_set_etype_whitelist,
2996 {'sw_if_index': sw_if_index,
2997 'count': len(whitelist),
2998 'n_input': n_input,
2999 'whitelist': whitelist},
3000 expected_retval=expected_retval)
3001
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003002 def acl_interface_add_del(self,
3003 sw_if_index,
3004 acl_index,
3005 is_add=1):
3006 """ Add/Delete ACL to/from interface
3007
3008 :param sw_if_index:
3009 :param acl_index:
3010 :param is_add: (Default value = 1)
3011 """
3012
3013 return self.api(self.papi.acl_interface_add_del,
3014 {'is_add': is_add,
3015 'is_input': 1,
3016 'sw_if_index': sw_if_index,
3017 'acl_index': acl_index})
3018
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003019 def acl_dump(self, acl_index, expected_retval=0):
3020 return self.api(self.papi.acl_dump,
3021 {'acl_index': acl_index},
3022 expected_retval=expected_retval)
3023
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003024 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3025 expected_retval=0):
3026 return self.api(self.papi.acl_interface_list_dump,
3027 {'sw_if_index': sw_if_index},
3028 expected_retval=expected_retval)
3029
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003030 def macip_acl_add(self, rules, tag=""):
3031 """ Add MACIP acl
3032
3033 :param rules: list of rules for given acl
3034 :param tag: acl tag
3035 """
3036
3037 return self.api(self.papi.macip_acl_add,
3038 {'r': rules,
3039 'count': len(rules),
3040 'tag': tag})
3041
Pavel Kotucek932f7412017-09-07 14:44:52 +02003042 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3043 """ Add MACIP acl
3044
3045 :param rules: list of rules for given acl
3046 :param tag: acl tag
3047 """
3048
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003049 return self.api(self.papi.macip_acl_add_replace,
3050 {'acl_index': acl_index,
3051 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003052 'count': len(rules),
3053 'tag': tag})
3054
3055 def macip_acl_del(self, acl_index):
3056 """
3057
3058 :param acl_index:
3059 :return:
3060 """
3061 return self.api(self.papi.macip_acl_del,
3062 {'acl_index': acl_index})
3063
3064 def macip_acl_interface_add_del(self,
3065 sw_if_index,
3066 acl_index,
3067 is_add=1):
3068 """ Add MACIP acl to interface
3069
3070 :param sw_if_index:
3071 :param acl_index:
3072 :param is_add: (Default value = 1)
3073 """
3074
3075 return self.api(self.papi.macip_acl_interface_add_del,
3076 {'is_add': is_add,
3077 'sw_if_index': sw_if_index,
3078 'acl_index': acl_index})
3079
3080 def macip_acl_interface_get(self):
3081 """ Return interface acls dump
3082 """
3083 return self.api(
3084 self.papi.macip_acl_interface_get, {})
3085
3086 def macip_acl_dump(self, acl_index=4294967295):
3087 """ Return MACIP acl dump
3088 """
3089
3090 return self.api(
3091 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003092
3093 def policer_add_del(self,
3094 name,
3095 cir,
3096 eir,
3097 cb,
3098 eb,
3099 is_add=1,
3100 rate_type=0,
3101 round_type=0,
3102 ptype=0,
3103 color_aware=0,
3104 conform_action_type=1,
3105 conform_dscp=0,
3106 exceed_action_type=0,
3107 exceed_dscp=0,
3108 violate_action_type=0,
3109 violate_dscp=0):
3110 return self.api(self.papi.policer_add_del,
3111 {'name': name,
3112 'cir': cir,
3113 'eir': eir,
3114 'cb': cb,
3115 'eb': eb,
3116 'is_add': is_add,
3117 'rate_type': rate_type,
3118 'round_type': round_type,
3119 'type': ptype,
3120 'color_aware': color_aware,
3121 'conform_action_type': conform_action_type,
3122 'conform_dscp': conform_dscp,
3123 'exceed_action_type': exceed_action_type,
3124 'exceed_dscp': exceed_dscp,
3125 'violate_action_type': violate_action_type,
3126 'violate_dscp': violate_dscp})
3127
3128 def ip_punt_police(self,
3129 policer_index,
3130 is_ip6=0,
3131 is_add=1):
3132 return self.api(self.papi.ip_punt_police,
3133 {'policer_index': policer_index,
3134 'is_add': is_add,
3135 'is_ip6': is_ip6})
3136
3137 def ip_punt_redirect(self,
3138 rx_sw_if_index,
3139 tx_sw_if_index,
3140 nh,
3141 is_ip6=0,
3142 is_add=1):
3143 return self.api(self.papi.ip_punt_redirect,
3144 {'rx_sw_if_index': rx_sw_if_index,
3145 'tx_sw_if_index': tx_sw_if_index,
3146 'nh': nh,
3147 'is_add': is_add,
3148 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003149
3150 def bier_table_add_del(self,
3151 bti,
3152 mpls_label,
3153 is_add=1):
3154 """ BIER Table add/del """
3155 return self.api(
3156 self.papi.bier_table_add_del,
3157 {'bt_tbl_id': {"bt_set": bti.set_id,
3158 "bt_sub_domain": bti.sub_domain_id,
3159 "bt_hdr_len_id": bti.hdr_len_id},
3160 'bt_label': mpls_label,
3161 'bt_is_add': is_add})
3162
3163 def bier_table_dump(self):
3164 return self.api(self.papi.bier_table_dump, {})
3165
3166 def bier_route_add_del(self,
3167 bti,
3168 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003169 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003170 is_add=1,
3171 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003172 """ BIER Route add/del """
3173 return self.api(
3174 self.papi.bier_route_add_del,
3175 {'br_tbl_id': {"bt_set": bti.set_id,
3176 "bt_sub_domain": bti.sub_domain_id,
3177 "bt_hdr_len_id": bti.hdr_len_id},
3178 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003179 'br_n_paths': len(paths),
3180 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003181 'br_is_add': is_add,
3182 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003183
3184 def bier_route_dump(self, bti):
3185 return self.api(
3186 self.papi.bier_route_dump,
3187 {'br_tbl_id': {"bt_set": bti.set_id,
3188 "bt_sub_domain": bti.sub_domain_id,
3189 "bt_hdr_len_id": bti.hdr_len_id}})
3190
3191 def bier_imp_add(self,
3192 bti,
3193 src,
3194 ibytes,
3195 is_add=1):
3196 """ BIER Imposition Add """
3197 return self.api(
3198 self.papi.bier_imp_add,
3199 {'bi_tbl_id': {"bt_set": bti.set_id,
3200 "bt_sub_domain": bti.sub_domain_id,
3201 "bt_hdr_len_id": bti.hdr_len_id},
3202 'bi_src': src,
3203 'bi_n_bytes': len(ibytes),
3204 'bi_bytes': ibytes})
3205
3206 def bier_imp_del(self, bi_index):
3207 """ BIER Imposition del """
3208 return self.api(
3209 self.papi.bier_imp_del,
3210 {'bi_index': bi_index})
3211
3212 def bier_imp_dump(self):
3213 return self.api(self.papi.bier_imp_dump, {})
3214
3215 def bier_disp_table_add_del(self,
3216 bdti,
3217 is_add=1):
3218 """ BIER Disposition Table add/del """
3219 return self.api(
3220 self.papi.bier_disp_table_add_del,
3221 {'bdt_tbl_id': bdti,
3222 'bdt_is_add': is_add})
3223
3224 def bier_disp_table_dump(self):
3225 return self.api(self.papi.bier_disp_table_dump, {})
3226
3227 def bier_disp_entry_add_del(self,
3228 bdti,
3229 bp,
3230 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003231 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003232 next_hop,
3233 next_hop_tbl_id=0,
3234 next_hop_rpf_id=~0,
3235 next_hop_is_ip4=1,
3236 is_add=1):
3237 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003238 lstack = []
3239 while (len(lstack) < 16):
3240 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003241 return self.api(
3242 self.papi.bier_disp_entry_add_del,
3243 {'bde_tbl_id': bdti,
3244 'bde_bp': bp,
3245 'bde_payload_proto': payload_proto,
3246 'bde_n_paths': 1,
3247 'bde_paths': [{'next_hop': next_hop,
3248 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003249 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003250 'rpf_id': next_hop_rpf_id,
3251 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003252 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003253 'bde_is_add': is_add})
3254
3255 def bier_disp_entry_dump(self, bdti):
3256 return self.api(
3257 self.papi.bier_disp_entry_dump,
3258 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003259
3260 def add_node_next(self, node_name, next_name):
3261 """ Set the next node for a given node request
3262
3263 :param node_name:
3264 :param next_name:
3265 """
3266 return self.api(self.papi.add_node_next,
3267 {'node_name': node_name,
3268 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003269
3270 def session_enable_disable(self, is_enabled):
3271 return self.api(
3272 self.papi.session_enable_disable,
3273 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003274
3275 def ipsec_spd_add_del(self, spd_id, is_add=1):
3276 """ SPD add/del - Wrapper to add or del ipsec SPD
3277 Sample CLI : 'ipsec spd add 1'
3278
3279 :param spd_id - SPD ID to be created in the vpp . mandatory
3280 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3281 optional
3282 :returns: reply from the API
3283 """
3284 return self.api(
3285 self.papi.ipsec_spd_add_del, {
3286 'spd_id': spd_id, 'is_add': is_add})
3287
3288 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3289 """ IPSEC interface SPD add/del - \
3290 Wrapper to associate/disassociate SPD to interface in VPP
3291 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3292
3293 :param spd_id - SPD ID to associate with the interface . mandatory
3294 :param sw_if_index - Interface Index which needs to ipsec \
3295 association mandatory
3296 :param is_add - add(1) or del(0) association with interface \
3297 (Default 1 - add) . optional
3298 :returns: reply from the API
3299 """
3300 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003301 self.papi.ipsec_interface_add_del_spd,
3302 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003303
3304 def ipsec_sad_add_del_entry(self,
3305 sad_id,
3306 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003307 integrity_algorithm,
3308 integrity_key,
3309 crypto_algorithm,
3310 crypto_key,
3311 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003312 tunnel_src_address='',
3313 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003314 is_tunnel=1,
Klement Sekera31da2e32018-06-24 22:49:55 +02003315 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003316 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003317 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003318 :param sad_id: security association ID
3319 :param spi: security param index of the SA in decimal
3320 :param integrity_algorithm:
3321 :param integrity_key:
3322 :param crypto_algorithm:
3323 :param crypto_key:
3324 :param protocol: AH(0) or ESP(1) protocol
3325 :param tunnel_src_address: tunnel mode outer src address
3326 :param tunnel_dst_address: tunnel mode outer dst address
3327 :param is_add:
3328 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003329 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3330 crypto and ipsec algorithms
3331 """
3332 return self.api(
3333 self.papi.ipsec_sad_add_del_entry,
3334 {'sad_id': sad_id,
3335 'spi': spi,
3336 'tunnel_src_address': tunnel_src_address,
3337 'tunnel_dst_address': tunnel_dst_address,
3338 'protocol': protocol,
3339 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003340 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003341 'integrity_key': integrity_key,
3342 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003343 'crypto_key_length': len(crypto_key) if crypto_key is not None
3344 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003345 'crypto_key': crypto_key,
3346 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003347 'is_tunnel': is_tunnel,
3348 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003349
3350 def ipsec_spd_add_del_entry(self,
3351 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003352 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003353 local_address_start,
3354 local_address_stop,
3355 remote_address_start,
3356 remote_address_stop,
3357 local_port_start=0,
3358 local_port_stop=65535,
3359 remote_port_start=0,
3360 remote_port_stop=65535,
3361 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003362 policy=0,
3363 priority=100,
3364 is_outbound=1,
3365 is_add=1,
3366 is_ip_any=0):
3367 """ IPSEC policy SPD add/del -
3368 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003369 :param spd_id: SPD ID for the policy
3370 :param local_address_start: local-ip-range start address
3371 :param local_address_stop : local-ip-range stop address
3372 :param remote_address_start: remote-ip-range start address
3373 :param remote_address_stop : remote-ip-range stop address
3374 :param local_port_start: (Default value = 0)
3375 :param local_port_stop: (Default value = 65535)
3376 :param remote_port_start: (Default value = 0)
3377 :param remote_port_stop: (Default value = 65535)
3378 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3379 :param sa_id: Security Association ID for mapping it to SPD
3380 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3381 (Default value = 0)
3382 :param priority: value for the spd action (Default value = 100)
3383 :param is_outbound: flag for inbound(0) or outbound(1)
3384 (Default value = 1)
3385 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003386 """
3387 return self.api(
3388 self.papi.ipsec_spd_add_del_entry,
3389 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003390 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003391 'local_address_start': local_address_start,
3392 'local_address_stop': local_address_stop,
3393 'remote_address_start': remote_address_start,
3394 'remote_address_stop': remote_address_stop,
3395 'local_port_start': local_port_start,
3396 'local_port_stop': local_port_stop,
3397 'remote_port_start': remote_port_start,
3398 'remote_port_stop': remote_port_stop,
3399 'is_add': is_add,
3400 'protocol': protocol,
3401 'policy': policy,
3402 'priority': priority,
3403 'is_outbound': is_outbound,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003404 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003405
Klement Sekera31da2e32018-06-24 22:49:55 +02003406 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3407 remote_spi, crypto_alg, local_crypto_key,
3408 remote_crypto_key, integ_alg, local_integ_key,
3409 remote_integ_key, is_add=1, esn=0,
3410 anti_replay=1, renumber=0, show_instance=0):
3411 return self.api(
3412 self.papi.ipsec_tunnel_if_add_del,
3413 {'local_ip': local_ip, 'remote_ip': remote_ip,
3414 'local_spi': local_spi, 'remote_spi': remote_spi,
3415 'crypto_alg': crypto_alg,
3416 'local_crypto_key_len': len(local_crypto_key),
3417 'local_crypto_key': local_crypto_key,
3418 'remote_crypto_key_len': len(remote_crypto_key),
3419 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3420 'local_integ_key_len': len(local_integ_key),
3421 'local_integ_key': local_integ_key,
3422 'remote_integ_key_len': len(remote_integ_key),
3423 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3424 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3425 'show_instance': show_instance
3426 })
3427
Florin Corasb795bd02017-12-14 11:30:48 -08003428 def app_namespace_add(self,
3429 namespace_id,
3430 ip4_fib_id=0,
3431 ip6_fib_id=0,
3432 sw_if_index=0xFFFFFFFF,
3433 secret=0):
3434 return self.api(
3435 self.papi.app_namespace_add_del,
3436 {'secret': secret,
3437 'sw_if_index': sw_if_index,
3438 'ip4_fib_id': ip4_fib_id,
3439 'ip6_fib_id': ip6_fib_id,
3440 'namespace_id': namespace_id,
3441 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003442
3443 def punt_socket_register(self, l4_port, pathname, header_version=1,
3444 is_ip4=1, l4_protocol=0x11):
3445 """ Punt to socket """
3446 return self.api(self.papi.punt_socket_register,
3447 {'is_ip4': is_ip4,
3448 'l4_protocol': l4_protocol,
3449 'l4_port': l4_port,
3450 'pathname': pathname,
3451 'header_version': header_version})
3452
3453 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3454 expire_walk_interval_ms, is_ip6=0):
3455 """ Set IP reassembly parameters """
3456 return self.api(self.papi.ip_reassembly_set,
3457 {'is_ip6': is_ip6,
3458 'timeout_ms': timeout_ms,
3459 'expire_walk_interval_ms': expire_walk_interval_ms,
3460 'max_reassemblies': max_reassemblies})
3461
3462 def ip_reassembly_get(self, is_ip6=0):
3463 """ Get IP reassembly parameters """
3464 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003465
Klement Sekera4c533132018-02-22 11:41:12 +01003466 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3467 enable_ip6=False):
3468 """ Enable/disable IP reassembly """
3469 return self.api(self.papi.ip_reassembly_enable_disable,
3470 {'sw_if_index': sw_if_index,
3471 'enable_ip4': 1 if enable_ip4 else 0,
3472 'enable_ip6': 1 if enable_ip6 else 0,
3473 })
3474
Neale Rannsc0a93142018-09-05 15:42:26 -07003475 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg):
3476 """ GBP endpoint Add """
3477 return self.api(self.papi.gbp_endpoint_add,
3478 {'endpoint': {
3479 'sw_if_index': sw_if_index,
3480 'ips': ips,
3481 'n_ips': len(ips),
3482 'mac': mac,
3483 'epg_id': epg}})
3484
3485 def gbp_endpoint_del(self, handle):
3486 """ GBP endpoint Del """
3487 return self.api(self.papi.gbp_endpoint_del,
3488 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003489
3490 def gbp_endpoint_dump(self):
3491 """ GBP endpoint Dump """
3492 return self.api(self.papi.gbp_endpoint_dump, {})
3493
Neale Ranns25b04942018-04-04 09:34:50 -07003494 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3495 ip4_rd,
3496 ip6_rd,
3497 uplink_sw_if_index):
3498 """ GBP endpoint group Add/Del """
3499 return self.api(self.papi.gbp_endpoint_group_add_del,
3500 {'is_add': is_add,
3501 'epg': {
3502 'uplink_sw_if_index': uplink_sw_if_index,
3503 'bd_id': bd,
3504 'ip4_table_id': ip4_rd,
3505 'ip6_table_id': ip6_rd,
3506 'epg_id': epg}})
3507
3508 def gbp_endpoint_group_dump(self):
3509 """ GBP endpoint group Dump """
3510 return self.api(self.papi.gbp_endpoint_group_dump, {})
3511
3512 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3513 """ GBP recirc Add/Del """
3514 return self.api(self.papi.gbp_recirc_add_del,
3515 {'is_add': is_add,
3516 'recirc': {
3517 'is_ext': is_ext,
3518 'sw_if_index': sw_if_index,
3519 'epg_id': epg}})
3520
3521 def gbp_recirc_dump(self):
3522 """ GBP recirc Dump """
3523 return self.api(self.papi.gbp_recirc_dump, {})
3524
3525 def gbp_subnet_add_del(self, is_add, table_id,
3526 is_internal,
Neale Rannsc0a93142018-09-05 15:42:26 -07003527 prefix,
Neale Ranns25b04942018-04-04 09:34:50 -07003528 sw_if_index=0xffffffff,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02003529 epg_id=0xffff,
Neale Ranns25b04942018-04-04 09:34:50 -07003530 is_ip6=False):
3531 """ GBP Subnet Add/Del """
3532 return self.api(self.papi.gbp_subnet_add_del,
3533 {'is_add': is_add,
3534 'subnet': {
3535 'is_internal': is_internal,
3536 'is_ip6': is_ip6,
3537 'sw_if_index': sw_if_index,
3538 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003539 'prefix': prefix,
Neale Ranns25b04942018-04-04 09:34:50 -07003540 'table_id': table_id}})
3541
3542 def gbp_subnet_dump(self):
3543 """ GBP Subnet Dump """
3544 return self.api(self.papi.gbp_subnet_dump, {})
3545
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003546 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3547 """ GBP contract Add/Del """
3548 return self.api(self.papi.gbp_contract_add_del,
3549 {'is_add': is_add,
3550 'contract': {
3551 'acl_index': acl_index,
3552 'src_epg': src_epg,
3553 'dst_epg': dst_epg}})
3554
3555 def gbp_contract_dump(self):
3556 """ GBP contract Dump """
3557 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003558
Neale Ranns61502112018-08-22 00:21:14 -07003559 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3560 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003561 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003562 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003563 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003564 {'ip4_table_id': ip4_table_id,
3565 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003566 'ip6_prefix': ip6_prefix,
3567 'ip6_prefix_len': ip6_prefix_len,
3568 'ip4_prefix': ip4_prefix,
3569 'ip4_prefix_len': ip4_prefix_len,
3570 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003571 'security_check': security_check})
3572
Ole Troan298c6952018-03-08 12:30:43 +01003573 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003574 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003575 return self.api(self.papi.ipip_6rd_del_tunnel,
3576 {'sw_if_index': sw_if_index})
3577
3578 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003579 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003580 """ IPIP tunnel Add/Del """
3581 return self.api(self.papi.ipip_add_tunnel,
3582 {'is_ipv6': is_ipv6,
3583 'instance': instance,
3584 'src_address': src_address,
3585 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003586 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003587 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003588
3589 def ipip_del_tunnel(self, sw_if_index):
3590 """ IPIP tunnel Delete """
3591 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003592 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003593
3594 def qos_egress_map_update(self, id, outputs):
3595 """ QOS egress map update """
3596 return self.api(self.papi.qos_egress_map_update,
3597 {'map_id': id,
3598 'rows': outputs})
3599
3600 def qos_egress_map_delete(self, id):
3601 """ QOS egress map delete """
3602 return self.api(self.papi.qos_egress_map_delete,
3603 {'map_id': id})
3604
3605 def qos_mark_enable_disable(self, sw_if_index,
3606 output_source,
3607 map_id,
3608 enable):
3609 """ QOS Mark Enable/Disable """
3610 return self.api(self.papi.qos_mark_enable_disable,
3611 {'map_id': map_id,
3612 'sw_if_index': sw_if_index,
3613 'output_source': output_source,
3614 'enable': enable})
3615
3616 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3617 """ IP QoS recording Enble/Disable """
3618 return self.api(self.papi.qos_record_enable_disable,
3619 {'sw_if_index': sw_if_index,
3620 'input_source': input_source,
3621 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003622
Neale Ranns947ea622018-06-07 23:48:20 -07003623 def igmp_enable_disable(self, sw_if_index, enable, host):
3624 """ Enable/disable IGMP on a given interface """
3625 return self.api(self.papi.igmp_enable_disable,
3626 {'enable': enable,
3627 'mode': host,
3628 'sw_if_index': sw_if_index})
3629
3630 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003631 """ Listen for new (S,G) on specified interface
3632
3633 :param enable: add/del
3634 :param sw_if_index: interface sw index
3635 :param saddr: source ip4 addr
3636 :param gaddr: group ip4 addr
3637 """
3638 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003639 {
3640 'group':
3641 {
3642 'filter': filter,
3643 'sw_if_index': sw_if_index,
3644 'n_srcs': len(saddrs),
3645 'saddrs': saddrs,
3646 'gaddr':
3647 {
3648 'address': gaddr
3649 }
3650 }
3651 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003652
3653 def igmp_dump(self, sw_if_index=None):
3654 """ Dump all (S,G) interface configurations """
3655 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003656 sw_if_index = 0xffffffff
3657 return self.api(self.papi.igmp_dump,
3658 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003659
3660 def igmp_clear_interface(self, sw_if_index):
3661 """ Remove all (S,G)s from specified interface
3662 doesn't send IGMP report!
3663 """
3664 return self.api(
3665 self.papi.igmp_clear_interface, {
3666 'sw_if_index': sw_if_index})
3667
3668 def want_igmp_events(self, enable=1):
3669 return self.api(self.papi.want_igmp_events, {'enable': enable,
3670 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003671
3672 def bond_create(
3673 self,
3674 mode,
3675 lb,
3676 use_custom_mac,
3677 mac_address=''):
3678 """
3679 :param mode: mode
3680 :param lb: load balance
3681 :param use_custom_mac: use custom mac
3682 :param mac_address: mac address
3683 """
3684 return self.api(
3685 self.papi.bond_create,
3686 {'mode': mode,
3687 'lb': lb,
3688 'use_custom_mac': use_custom_mac,
3689 'mac_address': mac_address
3690 })
3691
3692 def bond_delete(
3693 self,
3694 sw_if_index):
3695 """
3696 :param sw_if_index: interface the operation is applied to
3697 """
3698 return self.api(self.papi.bond_delete,
3699 {'sw_if_index': sw_if_index})
3700
3701 def bond_enslave(
3702 self,
3703 sw_if_index,
3704 bond_sw_if_index,
3705 is_passive,
3706 is_long_timeout):
3707 """
3708 :param sw_if_index: slave sw_if_index
3709 :param bond_sw_if_index: bond sw_if_index
3710 :param is_passive: is passive lacp speaker
3711 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3712 """
3713 return self.api(
3714 self.papi.bond_enslave,
3715 {'sw_if_index': sw_if_index,
3716 'bond_sw_if_index': bond_sw_if_index,
3717 'is_passive': is_passive,
3718 'is_long_timeout': is_long_timeout
3719 })
3720
3721 def bond_detach_slave(
3722 self,
3723 sw_if_index):
3724 """
3725 :param sw_if_index: slave interface the operation is applied to
3726 """
3727 return self.api(self.papi.bond_detach_slave,
3728 {'sw_if_index': sw_if_index})
3729
3730 def sw_interface_slave_dump(
3731 self,
3732 sw_if_index):
3733 """
3734 :param sw_if_index: bond sw_if_index
3735 """
3736 return self.api(self.papi.sw_interface_slave_dump,
3737 {'sw_if_index': sw_if_index})
3738
3739 def sw_interface_bond_dump(
3740 self):
3741 """
3742
3743 """
3744 return self.api(self.papi.sw_interface_bond_dump,
3745 {})
Stevene8fa6202017-08-30 14:36:45 -07003746
3747 def create_vhost_user_if(
3748 self,
3749 is_server,
3750 sock_filename,
3751 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003752 disable_mrg_rxbuf,
3753 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003754 custom_dev_instance,
3755 use_custom_mac,
3756 mac_address,
3757 tag=''):
3758 """
3759 :param is_server: is server
3760 :param sock_filename: socket name
3761 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003762 :param disable_mrg_rxbuf: disable mergable rx buffers
3763 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003764 :param custom_dev_instance: custom dev instance
3765 :param use_custom_mac: use custom mac
3766 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003767 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003768 """
3769 return self.api(
3770 self.papi.create_vhost_user_if,
3771 {'is_server': is_server,
3772 'sock_filename': sock_filename,
3773 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003774 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3775 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003776 'custom_dev_instance': custom_dev_instance,
3777 'use_custom_mac': use_custom_mac,
3778 'mac_address': mac_address,
3779 'tag': tag
3780 })
3781
3782 def delete_vhost_user_if(
3783 self,
3784 sw_if_index):
3785 """
3786 :param sw_if_index: interface the operation is applied to
3787 """
3788 return self.api(self.papi.delete_vhost_user_if,
3789 {'sw_if_index': sw_if_index, })
3790
3791 def sw_interface_vhost_user_dump(
3792 self):
3793 """
3794
3795 """
3796 return self.api(self.papi.sw_interface_vhost_user_dump,
3797 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003798
3799 def abf_policy_add_del(self, is_add, policy):
3800 return self.api(
3801 self.papi.abf_policy_add_del,
3802 {'is_add': is_add,
3803 'policy': policy})
3804
3805 def abf_itf_attach_add_del(self, is_add, attach):
3806 return self.api(
3807 self.papi.abf_itf_attach_add_del,
3808 {'is_add': is_add,
3809 'attach': attach})
3810
3811 def abf_policy_dump(self):
3812 return self.api(
3813 self.papi.abf_policy_dump, {})
3814
3815 def abf_itf_attach_dump(self):
3816 return self.api(
3817 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003818
3819 def pipe_create(self, is_specified, user_instance):
3820 return self.api(self.papi.pipe_create,
3821 {'is_specified': is_specified,
3822 'user_instance': user_instance})
3823
3824 def pipe_delete(self, parent_sw_if_index):
3825 return self.api(self.papi.pipe_delete,
3826 {'parent_sw_if_index': parent_sw_if_index})
3827
3828 def pipe_dump(self):
3829 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003830
3831 def memif_create(
3832 self,
3833 role,
3834 mode,
3835 rx_queues=None,
3836 tx_queues=None,
3837 _id=None,
3838 socket_id=None,
3839 secret=None,
3840 ring_size=None,
3841 buffer_size=None,
3842 hw_addr=None):
3843 return self.api(self.papi.memif_create,
3844 {'role': role,
3845 'mode': mode,
3846 'rx_queues': rx_queues,
3847 'tx_queues': tx_queues,
3848 'id': _id,
3849 'socket_id': socket_id,
3850 'secret': secret,
3851 'ring_size': ring_size,
3852 'buffer_size': buffer_size,
3853 'hw_addr': hw_addr})
3854
3855 def memif_delete(self, sw_if_index):
3856 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
3857
3858 def memif_dump(self):
3859 return self.api(self.papi.memif_dump, {})
3860
3861 def memif_socket_filename_add_del(
3862 self, is_add, socket_id, socket_filename):
3863 return self.api(
3864 self.papi.memif_socket_filename_add_del,
3865 {'is_add': is_add,
3866 'socket_id': socket_id,
3867 'socket_filename': socket_filename})
3868
3869 def memif_socket_filename_dump(self):
3870 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07003871
3872 def svs_table_add_del(self, af, table_id, is_add=1):
3873 return self.api(self.papi.svs_table_add_del,
3874 {
3875 'table_id': table_id,
3876 'is_add': is_add,
3877 'af': af,
3878 })
3879
3880 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
3881 return self.api(self.papi.svs_route_add_del,
3882 {
3883 'table_id': table_id,
3884 'source_table_id': src_table_id,
3885 'prefix': prefix,
3886 'is_add': is_add,
3887 })
3888
3889 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
3890 return self.api(self.papi.svs_enable_disable,
3891 {
3892 'af': af,
3893 'table_id': table_id,
3894 'sw_if_index': sw_if_index,
3895 'is_enable': is_enable,
3896 })
3897
3898 def svs_dump(self):
3899 return self.api(self.papi.svs_dump, {})