blob: 95de0be6f2cf6e138957761874a26426800d2c8e [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
Klement Sekera73884482017-02-23 09:26:30 +010039class UnexpectedApiReturnValueError(Exception):
40 """ exception raised when the API return value is unexpected """
41 pass
42
43
Klement Sekeraf62ae122016-10-11 11:47:09 +020044class VppPapiProvider(object):
45 """VPP-api provider using vpp-papi
46
47 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020048 """
49
Klement Sekerae0545ef2017-01-25 08:00:40 +010050 _zero, _negative = range(2)
51
Klement Sekera7bb873a2016-11-18 07:38:42 +010052 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020053 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020054 self.name = name
55 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010056 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010057 self._expect_api_retval = self._zero
58 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010059 jsonfiles = []
60
Klement Sekera0e3c0de2016-09-29 14:43:44 +020061 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010062 for root, dirnames, filenames in os.walk(install_dir):
63 for filename in fnmatch.filter(filenames, '*.api.json'):
64 jsonfiles.append(os.path.join(root, filename))
65
Ole Troan3cc49712017-03-08 12:02:24 +010066 self.vpp = VPP(jsonfiles, logger=test_class.logger)
Klement Sekerae4504c62016-12-08 10:16:41 +010067 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020068
Klement Sekerae0545ef2017-01-25 08:00:40 +010069 def __enter__(self):
70 return self
71
72 def expect_negative_api_retval(self):
73 """ Expect API failure """
74 self._expect_stack.append(self._expect_api_retval)
75 self._expect_api_retval = self._negative
76 return self
77
78 def expect_zero_api_retval(self):
79 """ Expect API success """
80 self._expect_stack.append(self._expect_api_retval)
81 self._expect_api_retval = self._zero
82 return self
83
84 def __exit__(self, exc_type, exc_value, traceback):
85 self._expect_api_retval = self._expect_stack.pop()
86
Klement Sekeraf62ae122016-10-11 11:47:09 +020087 def register_hook(self, hook):
88 """Replace hook registration with new hook
89
90 :param hook:
91
92 """
93 self.hook = hook
94
Klement Sekera0e3c0de2016-09-29 14:43:44 +020095 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +010096 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +020097 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +010098 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +020099 return e
100
101 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100102 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100103 if name:
104 self.test_class.logger.debug("Expecting event within %ss",
105 timeout)
106 else:
107 self.test_class.logger.debug("Expecting event '%s' within %ss",
108 name, timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100109 if self._events:
110 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200111 limit = time.time() + timeout
112 while time.time() < limit:
113 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100114 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200115 if name and type(e).__name__ != name:
116 raise Exception(
117 "Unexpected event received: %s, expected: %s" %
118 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100119 self.test_class.logger.debug("Returning event %s:%s" %
120 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200121 return e
122 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200123 raise Exception("Event did not occur within timeout")
124
125 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200127 # FIXME use the name instead of relying on type(e).__name__ ?
128 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100129 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200130 self._events.append(event)
131
Klement Sekeraf62ae122016-10-11 11:47:09 +0200132 def connect(self):
133 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100134 self.vpp.connect(self.name, self.shm_prefix)
135 self.papi = self.vpp.api
136 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200137
138 def disconnect(self):
139 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100140 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200141
142 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200144 Call the appropriate hooks before and after the API call
145
146 :param api_fn: API function to call
147 :param api_args: tuple of API function arguments
148 :param expected_retval: Expected return value (Default value = 0)
149 :returns: reply from the API
150
151 """
152 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100153 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100154 if self._expect_api_retval == self._negative:
155 if hasattr(reply, 'retval') and reply.retval >= 0:
156 msg = "API call passed unexpectedly: expected negative "\
157 "return value instead of %d in %s" % \
158 (reply.retval, repr(reply))
159 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100160 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100161 elif self._expect_api_retval == self._zero:
162 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700163 msg = "API call failed, expected %d return value instead "\
164 "of %d in %s" % (expected_retval, reply.retval,
165 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100166 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100167 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100168 else:
169 raise Exception("Internal error, unexpected value for "
170 "self._expect_api_retval %s" %
171 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200172 self.hook.after_api(api_fn.__name__, api_args)
173 return reply
174
175 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100176 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200177
178 :param cli: CLI to execute
179 :returns: CLI output
180
181 """
182 self.hook.before_cli(cli)
183 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100184 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200185 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200186 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100187 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188
Jan49c0fca2016-10-26 15:44:27 +0200189 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100190 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200191
192 :param cli: CLI to execute
193 :returns: CLI output
194 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600195 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200196
Jan4af521d2016-11-15 17:05:00 +0100197 def _convert_mac(self, mac):
198 return int(mac.replace(":", ""), 16) << 16
199
Klement Sekeraf62ae122016-10-11 11:47:09 +0200200 def show_version(self):
201 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100202 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203
204 def pg_create_interface(self, pg_index):
205 """
206
207 :param pg_index:
208
209 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100210 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200211 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212
213 def sw_interface_dump(self, filter=None):
214 """
215
216 :param filter: (Default value = None)
217
218 """
219 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100222 args = {}
223 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200224
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000225 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100226 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000227
228 :param sw_if_index:
229 :param is_ipv6:
230 :param table_id:
231
232 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100233 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
235 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000236
Klement Sekeraf62ae122016-10-11 11:47:09 +0200237 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
238 is_ipv6=0, is_add=1, del_all=0):
239 """
240
241 :param addr: param is_ipv6: (Default value = 0)
242 :param sw_if_index:
243 :param addr_len:
244 :param is_ipv6: (Default value = 0)
245 :param is_add: (Default value = 1)
246 :param del_all: (Default value = 0)
247
248 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100249 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200250 {'sw_if_index': sw_if_index,
251 'is_add': is_add,
252 'is_ipv6': is_ipv6,
253 'del_all': del_all,
254 'address_length': addr_len,
255 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200256
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800257 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
258 is_add=1):
259 """ Set the Interface to be unnumbered
260
261 :param is_add: (Default value = 1)
262 :param sw_if_index - interface That will be unnumbered
263 :param ip_sw_if_index - interface with an IP addres
264
265 """
266 return self.api(self.papi.sw_interface_set_unnumbered,
267 {'sw_if_index': ip_sw_if_index,
268 'unnumbered_sw_if_index': sw_if_index,
269 'is_add': is_add})
270
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000271 def sw_interface_enable_disable_mpls(self, sw_if_index,
272 is_enable=1):
273 """
274 Enable/Disable MPLS on the interface
275 :param sw_if_index:
276 :param is_enable: (Default value = 1)
277
278 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100279 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200280 {'sw_if_index': sw_if_index,
281 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000282
Jan Gelety057bb8c2016-12-20 17:32:45 +0100283 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100284 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100285 {'sw_if_index': sw_if_index,
286 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200287
Neale Ranns227038a2017-04-21 01:07:59 -0700288 def set_ip_flow_hash(self,
289 table_id,
290 src=1,
291 dst=1,
292 sport=1,
293 dport=1,
294 proto=1,
295 reverse=0,
296 is_ip6=0):
297 return self.api(self.papi.set_ip_flow_hash,
298 {'vrf_id': table_id,
299 'src': src,
300 'dst': dst,
301 'dport': dport,
302 'sport': sport,
303 'proto': proto,
304 'reverse': reverse,
305 'is_ipv6': is_ip6})
306
Neale Ranns3f844d02017-02-18 00:03:54 -0800307 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
308 return self.api(self.papi.ip6nd_proxy_add_del,
309 {'address': address,
310 'sw_if_index': sw_if_index,
311 'is_del': is_del})
312
Neale Ranns75152282017-01-09 01:00:45 -0800313 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000314 no,
Neale Ranns75152282017-01-09 01:00:45 -0800315 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000316 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800317 return self.api(self.papi.sw_interface_ip6nd_ra_config,
318 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000319 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100320 'suppress': suppress,
321 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800322
Neale Ranns87df12d2017-02-18 08:16:41 -0800323 def ip6_sw_interface_ra_prefix(self,
324 sw_if_index,
325 address,
326 address_length,
327 use_default=0,
328 no_advertise=0,
329 off_link=0,
330 no_autoconfig=0,
331 no_onlink=0,
332 is_no=0,
333 val_lifetime=0xffffffff,
334 pref_lifetime=0xffffffff):
335 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
336 {'sw_if_index': sw_if_index,
337 'address': address,
338 'address_length': address_length,
339 'use_default': use_default,
340 'no_advertise': no_advertise,
341 'off_link': off_link,
342 'no_autoconfig': no_autoconfig,
343 'no_onlink': no_onlink,
344 'is_no': is_no,
345 'val_lifetime': val_lifetime,
346 'pref_lifetime': pref_lifetime})
347
Neale Ranns75152282017-01-09 01:00:45 -0800348 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
349 """
350 Enable/Disable An interface for IPv6
351 """
352 return self.api(self.papi.sw_interface_ip6_enable_disable,
353 {'sw_if_index': sw_if_index,
354 'enable': enable})
355
Klement Sekeraf62ae122016-10-11 11:47:09 +0200356 def vxlan_add_del_tunnel(
357 self,
358 src_addr,
359 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200360 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200361 is_add=1,
362 is_ipv6=0,
363 encap_vrf_id=0,
364 decap_next_index=0xFFFFFFFF,
365 vni=0):
366 """
367
368 :param dst_addr:
369 :param src_addr:
370 :param is_add: (Default value = 1)
371 :param is_ipv6: (Default value = 0)
372 :param encap_vrf_id: (Default value = 0)
373 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200374 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200375 :param vni: (Default value = 0)
376
377 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100378 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200379 {'is_add': is_add,
380 'is_ipv6': is_ipv6,
381 'src_address': src_addr,
382 'dst_address': dst_addr,
383 'mcast_sw_if_index': mcast_sw_if_index,
384 'encap_vrf_id': encap_vrf_id,
385 'decap_next_index': decap_next_index,
386 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387
Jan4af521d2016-11-15 17:05:00 +0100388 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
389 learn=1, arp_term=0, is_add=1):
390 """Create/delete bridge domain.
391
392 :param int bd_id: Bridge domain index.
393 :param int flood: Enable/disable bcast/mcast flooding in the BD.
394 (Default value = 1)
395 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
396 (Default value = 1)
397 :param int forward: Enable/disable forwarding on all interfaces in
398 the BD. (Default value = 1)
399 :param int learn: Enable/disable learning on all interfaces in the BD.
400 (Default value = 1)
401 :param int arp_term: Enable/disable arp termination in the BD.
402 (Default value = 1)
403 :param int is_add: Add or delete flag. (Default value = 1)
404 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100405 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200406 {'bd_id': bd_id,
407 'flood': flood,
408 'uu_flood': uu_flood,
409 'forward': forward,
410 'learn': learn,
411 'arp_term': arp_term,
412 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100413
Eyal Baric86e5922017-07-02 18:33:16 +0300414 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
415 return self.api(self.papi.bd_ip_mac_add_del,
416 {'bd_id': bd_id,
417 'is_add': is_add,
418 'is_ipv6': is_ipv6,
419 'ip_address': ip,
420 'mac_address': mac})
421
Jan4af521d2016-11-15 17:05:00 +0100422 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
423 filter_mac=0, bvi_mac=0):
424 """Create/delete L2 FIB entry.
425
426 :param str mac: MAC address to create FIB entry for.
427 :param int bd_id: Bridge domain index.
428 :param int sw_if_index: Software interface index of the interface.
429 :param int is_add: Add or delete flag. (Default value = 1)
430 :param int static_mac: Set to 1 to create static MAC entry.
431 (Default value = 0)
432 :param int filter_mac: Set to 1 to drop packet that's source or
433 destination MAC address contains defined MAC address.
434 (Default value = 0)
435 :param int bvi_mac: Set to 1 to create entry that points to BVI
436 interface. (Default value = 0)
437 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100438 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200439 {'mac': self._convert_mac(mac),
440 'bd_id': bd_id,
441 'sw_if_index': sw_if_index,
442 'is_add': is_add,
443 'static_mac': static_mac,
444 'filter_mac': filter_mac,
445 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100446
Eyal Bari93b503e2017-05-15 10:13:15 +0300447 def l2fib_flush_int(self, sw_if_index):
448 """Flush L2 FIB entries for sw_if_index.
449
450 :param int sw_if_index: Software interface index of the interface.
451 """
452 return self.api(self.papi.l2fib_flush_int,
453 {'sw_if_index': sw_if_index})
454
455 def l2fib_flush_bd(self, bd_id):
456 """Flush L2 FIB entries for bd_id.
457
458 :param int sw_if_index: Bridge Domain id.
459 """
460 return self.api(self.papi.l2fib_flush_bd,
461 {'bd_id': bd_id})
462
463 def l2fib_flush_all(self):
464 """Flush all L2 FIB.
465 """
466 return self.api(self.papi.l2fib_flush_all, {})
467
Klement Sekeraf62ae122016-10-11 11:47:09 +0200468 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
469 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100470 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200471
Jan4af521d2016-11-15 17:05:00 +0100472 :param int sw_if_index: Software interface index of the interface.
473 :param int bd_id: Bridge domain index.
474 :param int shg: Split-horizon group index. (Default value = 0)
475 :param int bvi: Set interface as a bridge group virtual interface.
476 (Default value = 0)
477 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200478 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100479 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200480 {'rx_sw_if_index': sw_if_index,
481 'bd_id': bd_id,
482 'shg': shg,
483 'bvi': bvi,
484 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200485
Jan00dad122016-11-29 10:04:53 +0100486 def bridge_flags(self, bd_id, is_set, feature_bitmap):
487 """Enable/disable required feature of the bridge domain with defined ID.
488
489 :param int bd_id: Bridge domain ID.
490 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
491 :param int feature_bitmap: Bitmap value of the feature to be set:
492 - learn (1 << 0),
493 - forward (1 << 1),
494 - flood (1 << 2),
495 - uu-flood (1 << 3) or
496 - arp-term (1 << 4).
497 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100498 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200499 {'bd_id': bd_id,
500 'is_set': is_set,
501 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100502
503 def bridge_domain_dump(self, bd_id=0):
504 """
505
506 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
507 existing bridge domains returned)
508 :return: Dictionary of bridge domain(s) data.
509 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100510 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200511 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100512
Klement Sekeraf62ae122016-10-11 11:47:09 +0200513 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
514 enable):
515 """Create or delete unidirectional cross-connect from Tx interface to
516 Rx interface.
517
Jan4af521d2016-11-15 17:05:00 +0100518 :param int rx_sw_if_index: Software interface index of Rx interface.
519 :param int tx_sw_if_index: Software interface index of Tx interface.
520 :param int enable: Create cross-connect if equal to 1, delete
521 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200522
523 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100524 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200525 {'rx_sw_if_index': rx_sw_if_index,
526 'tx_sw_if_index': tx_sw_if_index,
527 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200528
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200529 def sw_interface_set_l2_tag_rewrite(
530 self,
531 sw_if_index,
532 vtr_oper,
533 push=0,
534 tag1=0,
535 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000536 """L2 interface vlan tag rewrite configure request
537 :param client_index - opaque cookie to identify the sender
538 :param context - sender context, to match reply w/ request
539 :param sw_if_index - interface the operation is applied to
540 :param vtr_op - Choose from l2_vtr_op_t enum values
541 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
542 :param tag1 - Needed for any push or translate vtr op
543 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
544
545 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100546 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200547 {'sw_if_index': sw_if_index,
548 'vtr_op': vtr_oper,
549 'push_dot1q': push,
550 'tag1': tag1,
551 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000552
Neale Rannsa07bd702017-08-07 07:53:49 -0700553 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200554 """
555
556 :param admin_up_down:
557 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200558
559 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100560 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200561 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700562 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200563
564 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
565 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
566 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
567 """Create subinterface
568 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
569
570 :param sub_id: param inner_vlan:
571 :param sw_if_index:
572 :param outer_vlan:
573 :param inner_vlan:
574 :param no_tags: (Default value = 0)
575 :param one_tag: (Default value = 0)
576 :param two_tags: (Default value = 0)
577 :param dot1ad: (Default value = 0)
578 :param exact_match: (Default value = 0)
579 :param default_sub: (Default value = 0)
580 :param outer_vlan_id_any: (Default value = 0)
581 :param inner_vlan_id_any: (Default value = 0)
582
583 """
584 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100585 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200586 {'sw_if_index': sw_if_index,
587 'sub_id': sub_id,
588 'no_tags': no_tags,
589 'one_tag': one_tag,
590 'two_tags': two_tags,
591 'dot1ad': dot1ad,
592 'exact_match': exact_match,
593 'default_sub': default_sub,
594 'outer_vlan_id_any': outer_vlan_id_any,
595 'inner_vlan_id_any': inner_vlan_id_any,
596 'outer_vlan_id': outer_vlan,
597 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200598
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200599 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
600 """Create p2p ethernet subinterface
601
602 :param sw_if_index: main (parent) interface
603 :param remote_mac: client (remote) mac address
604
605 """
606 return self.api(
607 self.papi.p2p_ethernet_add,
608 {'parent_if_index': sw_if_index,
609 'remote_mac': remote_mac,
610 'subif_id': subif_id})
611
Neale Ranns177bbdc2016-11-15 09:46:51 +0000612 def delete_subif(self, sw_if_index):
613 """Delete subinterface
614
615 :param sw_if_index:
616 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100617 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200618 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000619
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200620 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
621 """Delete p2p ethernet subinterface
622
623 :param sw_if_index: main (parent) interface
624 :param remote_mac: client (remote) mac address
625
626 """
627 return self.api(
628 self.papi.p2p_ethernet_del,
629 {'parent_if_index': sw_if_index,
630 'remote_mac': remote_mac})
631
Klement Sekeraf62ae122016-10-11 11:47:09 +0200632 def create_vlan_subif(self, sw_if_index, vlan):
633 """
634
635 :param vlan:
636 :param sw_if_index:
637
638 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100639 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200640 {'sw_if_index': sw_if_index,
641 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200642
Matej Klotton0178d522016-11-04 11:11:44 +0100643 def create_loopback(self, mac=''):
644 """
645
646 :param mac: (Optional)
647 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100648 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200649 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100650
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100651 def delete_loopback(self, sw_if_index):
652 return self.api(self.papi.delete_loopback,
653 {'sw_if_index': sw_if_index, })
654
Klement Sekeraf62ae122016-10-11 11:47:09 +0200655 def ip_add_del_route(
656 self,
657 dst_address,
658 dst_address_length,
659 next_hop_address,
660 next_hop_sw_if_index=0xFFFFFFFF,
661 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200662 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000663 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200664 next_hop_n_out_labels=0,
665 next_hop_out_label_stack=[],
666 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200667 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000668 is_resolve_host=0,
669 is_resolve_attached=0,
670 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200671 is_add=1,
672 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200673 is_unreach=0,
674 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200675 is_ipv6=0,
676 is_local=0,
677 is_classify=0,
678 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000679 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200680 """
681
682 :param dst_address_length:
683 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
684 :param dst_address:
685 :param next_hop_address:
686 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
687 :param vrf_id: (Default value = 0)
688 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200689 :param classify_table_index: (Default value = 0xFFFFFFFF)
690 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200691 :param is_add: (Default value = 1)
692 :param is_drop: (Default value = 0)
693 :param is_ipv6: (Default value = 0)
694 :param is_local: (Default value = 0)
695 :param is_classify: (Default value = 0)
696 :param is_multipath: (Default value = 0)
697 :param is_resolve_host: (Default value = 0)
698 :param is_resolve_attached: (Default value = 0)
699 :param not_last: (Default value = 0)
700 :param next_hop_weight: (Default value = 1)
701
702 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000703
Klement Sekeraf62ae122016-10-11 11:47:09 +0200704 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100705 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200706 {'next_hop_sw_if_index': next_hop_sw_if_index,
707 'table_id': table_id,
708 'classify_table_index': classify_table_index,
709 'next_hop_table_id': next_hop_table_id,
710 'create_vrf_if_needed': create_vrf_if_needed,
711 'is_add': is_add,
712 'is_drop': is_drop,
713 'is_unreach': is_unreach,
714 'is_prohibit': is_prohibit,
715 'is_ipv6': is_ipv6,
716 'is_local': is_local,
717 'is_classify': is_classify,
718 'is_multipath': is_multipath,
719 'is_resolve_host': is_resolve_host,
720 'is_resolve_attached': is_resolve_attached,
721 'not_last': not_last,
722 'next_hop_weight': next_hop_weight,
723 'dst_address_length': dst_address_length,
724 'dst_address': dst_address,
725 'next_hop_address': next_hop_address,
726 'next_hop_n_out_labels': next_hop_n_out_labels,
727 'next_hop_via_label': next_hop_via_label,
728 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100729
Matej Klotton16a14cd2016-12-07 15:09:13 +0100730 def ip_fib_dump(self):
731 return self.api(self.papi.ip_fib_dump, {})
732
Jan Gelety057bb8c2016-12-20 17:32:45 +0100733 def ip6_fib_dump(self):
734 return self.api(self.papi.ip6_fib_dump, {})
735
Matej Klotton0178d522016-11-04 11:11:44 +0100736 def ip_neighbor_add_del(self,
737 sw_if_index,
738 mac_address,
739 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100740 is_add=1,
741 is_ipv6=0,
742 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800743 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100744 ):
745 """ Add neighbor MAC to IPv4 or IPv6 address.
746
747 :param sw_if_index:
748 :param mac_address:
749 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100750 :param is_add: (Default value = 1)
751 :param is_ipv6: (Default value = 0)
752 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800753 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100754 """
755
756 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100757 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800758 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200759 'is_add': is_add,
760 'is_ipv6': is_ipv6,
761 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800762 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200763 'mac_address': mac_address,
764 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100765 }
Matej Klotton0178d522016-11-04 11:11:44 +0100766 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100767
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800768 def ip_neighbor_dump(self,
769 sw_if_index,
770 is_ipv6=0):
771 """ Return IP neighbor dump.
772
773 :param sw_if_index:
774 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
775 """
776
777 return self.api(
778 self.papi.ip_neighbor_dump,
779 {'is_ipv6': is_ipv6,
780 'sw_if_index': sw_if_index
781 }
782 )
783
784 def proxy_arp_add_del(self,
785 low_address,
786 hi_address,
787 vrf_id=0,
788 is_add=1):
789 """ Config Proxy Arp Range.
790
791 :param low_address: Start address in the rnage to Proxy for
792 :param hi_address: End address in the rnage to Proxy for
793 :param vrf_id: The VRF/table in which to proxy
794 """
795
796 return self.api(
797 self.papi.proxy_arp_add_del,
798 {'vrf_id': vrf_id,
799 'is_add': is_add,
800 'low_address': low_address,
801 'hi_address': hi_address,
802 }
803 )
804
805 def proxy_arp_intfc_enable_disable(self,
806 sw_if_index,
807 is_enable=1):
808 """ Enable/Disable an interface for proxy ARP requests
809
810 :param sw_if_index: Interface
811 :param enable_disable: Enable/Disable
812 """
813
814 return self.api(
815 self.papi.proxy_arp_intfc_enable_disable,
816 {'sw_if_index': sw_if_index,
817 'enable_disable': is_enable
818 }
819 )
820
Jane546d3b2016-12-08 13:10:03 +0100821 def reset_vrf(self,
822 vrf_id,
823 is_ipv6=0,
824 ):
825 """ Reset VRF (remove all routes etc.) request.
826
827 :param int vrf_id: ID of the FIB table / VRF to reset.
828 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
829 """
830
831 return self.api(
832 self.papi.reset_vrf,
833 {'vrf_id': vrf_id,
834 'is_ipv6': is_ipv6,
835 }
836 )
837
838 def reset_fib(self,
839 vrf_id,
840 is_ipv6=0,
841 ):
842 """ Reset VRF (remove all routes etc.) request.
843
844 :param int vrf_id: ID of the FIB table / VRF to reset.
845 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
846 """
847
848 return self.api(
849 self.papi.reset_fib,
850 {'vrf_id': vrf_id,
851 'is_ipv6': is_ipv6,
852 }
853 )
854
855 def ip_dump(self,
856 is_ipv6=0,
857 ):
858 """ Return IP dump.
859
860 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
861 """
862
863 return self.api(
864 self.papi.ip_dump,
865 {'is_ipv6': is_ipv6,
866 }
867 )
868
Klement Sekera7bb873a2016-11-18 07:38:42 +0100869 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +0300870 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100871 """
872
873 :param sw_if_index_from:
874 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100875 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +0300876 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100877 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100878 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200879 {'sw_if_index_from': sw_if_index_from,
880 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +0300881 'state': state,
882 'is_l2': is_l2,
883 })
Neale Ranns177bbdc2016-11-15 09:46:51 +0000884
885 def gre_tunnel_add_del(self,
886 src_address,
887 dst_address,
888 outer_fib_id=0,
889 is_teb=0,
890 is_add=1,
891 is_ip6=0):
892 """ Add a GRE tunnel
893
894 :param src_address:
895 :param dst_address:
896 :param outer_fib_id: (Default value = 0)
897 :param is_add: (Default value = 1)
898 :param is_ipv6: (Default value = 0)
899 :param is_teb: (Default value = 0)
900 """
901
902 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100903 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200904 {'is_add': is_add,
905 'is_ipv6': is_ip6,
906 'teb': is_teb,
907 'src_address': src_address,
908 'dst_address': dst_address,
909 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000910 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000911
Neale Ranns5a8123b2017-01-26 01:18:23 -0800912 def mpls_fib_dump(self):
913 return self.api(self.papi.mpls_fib_dump, {})
914
Neale Rannsad422ed2016-11-02 14:20:04 +0000915 def mpls_route_add_del(
916 self,
917 label,
918 eos,
Neale Rannsda78f952017-05-24 09:15:43 -0700919 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000920 next_hop_address,
921 next_hop_sw_if_index=0xFFFFFFFF,
922 table_id=0,
923 next_hop_table_id=0,
924 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200925 next_hop_n_out_labels=0,
926 next_hop_out_label_stack=[],
927 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000928 create_vrf_if_needed=0,
929 is_resolve_host=0,
930 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800931 is_interface_rx=0,
932 is_rpf_id=0,
933 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000934 is_add=1,
935 is_drop=0,
936 is_multipath=0,
937 classify_table_index=0xFFFFFFFF,
938 is_classify=0,
939 not_last=0):
940 """
941
942 :param dst_address_length:
943 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
944 :param dst_address:
945 :param next_hop_address:
946 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
947 :param vrf_id: (Default value = 0)
948 :param lookup_in_vrf: (Default value = 0)
949 :param classify_table_index: (Default value = 0xFFFFFFFF)
950 :param create_vrf_if_needed: (Default value = 0)
951 :param is_add: (Default value = 1)
952 :param is_drop: (Default value = 0)
953 :param is_ipv6: (Default value = 0)
954 :param is_local: (Default value = 0)
955 :param is_classify: (Default value = 0)
956 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800957 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000958 :param is_resolve_host: (Default value = 0)
959 :param is_resolve_attached: (Default value = 0)
960 :param not_last: (Default value = 0)
961 :param next_hop_weight: (Default value = 1)
962
963 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000964
965 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100966 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200967 {'mr_label': label,
968 'mr_eos': eos,
969 'mr_table_id': table_id,
970 'mr_classify_table_index': classify_table_index,
971 'mr_create_table_if_needed': create_vrf_if_needed,
972 'mr_is_add': is_add,
973 'mr_is_classify': is_classify,
974 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800975 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200976 'mr_is_resolve_host': is_resolve_host,
977 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800978 'mr_is_interface_rx': is_interface_rx,
979 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -0700980 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200981 'mr_next_hop_weight': next_hop_weight,
982 'mr_next_hop': next_hop_address,
983 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
984 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
985 'mr_next_hop_table_id': next_hop_table_id,
986 'mr_next_hop_via_label': next_hop_via_label,
987 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000988
989 def mpls_ip_bind_unbind(
990 self,
991 label,
992 dst_address,
993 dst_address_length,
994 table_id=0,
995 ip_table_id=0,
996 is_ip4=1,
997 create_vrf_if_needed=0,
998 is_bind=1):
999 """
1000 """
1001 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001002 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001003 {'mb_mpls_table_id': table_id,
1004 'mb_label': label,
1005 'mb_ip_table_id': ip_table_id,
1006 'mb_create_table_if_needed': create_vrf_if_needed,
1007 'mb_is_bind': is_bind,
1008 'mb_is_ip4': is_ip4,
1009 'mb_address_length': dst_address_length,
1010 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001011
1012 def mpls_tunnel_add_del(
1013 self,
1014 tun_sw_if_index,
1015 next_hop_proto_is_ip4,
1016 next_hop_address,
1017 next_hop_sw_if_index=0xFFFFFFFF,
1018 next_hop_table_id=0,
1019 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001020 next_hop_n_out_labels=0,
1021 next_hop_out_label_stack=[],
1022 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001023 create_vrf_if_needed=0,
1024 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001025 l2_only=0,
1026 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001027 """
1028
1029 :param dst_address_length:
1030 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1031 :param dst_address:
1032 :param next_hop_address:
1033 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1034 :param vrf_id: (Default value = 0)
1035 :param lookup_in_vrf: (Default value = 0)
1036 :param classify_table_index: (Default value = 0xFFFFFFFF)
1037 :param create_vrf_if_needed: (Default value = 0)
1038 :param is_add: (Default value = 1)
1039 :param is_drop: (Default value = 0)
1040 :param is_ipv6: (Default value = 0)
1041 :param is_local: (Default value = 0)
1042 :param is_classify: (Default value = 0)
1043 :param is_multipath: (Default value = 0)
1044 :param is_resolve_host: (Default value = 0)
1045 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001046 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001047 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001048
1049 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001050 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001051 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001052 {'mt_sw_if_index': tun_sw_if_index,
1053 'mt_is_add': is_add,
1054 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001055 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001056 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1057 'mt_next_hop_weight': next_hop_weight,
1058 'mt_next_hop': next_hop_address,
1059 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1060 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1061 'mt_next_hop_table_id': next_hop_table_id,
1062 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001063
1064 def snat_interface_add_del_feature(
1065 self,
1066 sw_if_index,
1067 is_inside=1,
1068 is_add=1):
1069 """Enable/disable S-NAT feature on the interface
1070
1071 :param sw_if_index: Software index of the interface
1072 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1073 :param is_add: 1 if add, 0 if delete (Default value = 1)
1074 """
1075 return self.api(
1076 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001077 {'is_add': is_add,
1078 'is_inside': is_inside,
1079 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001080
Matus Fabian93d84c92017-07-19 08:06:01 -07001081 def snat_interface_add_del_output_feature(
1082 self,
1083 sw_if_index,
1084 is_inside=1,
1085 is_add=1):
1086 """Enable/disable S-NAT output feature on the interface
1087
1088 :param sw_if_index: Software index of the interface
1089 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1090 :param is_add: 1 if add, 0 if delete (Default value = 1)
1091 """
1092 return self.api(
1093 self.papi.snat_interface_add_del_output_feature,
1094 {'is_add': is_add,
1095 'is_inside': is_inside,
1096 'sw_if_index': sw_if_index})
1097
Matus Fabiande886752016-12-07 03:38:19 -08001098 def snat_add_static_mapping(
1099 self,
1100 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001101 external_ip=0,
1102 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001103 local_port=0,
1104 external_port=0,
1105 addr_only=1,
1106 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001107 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -08001108 is_add=1,
1109 is_ip4=1):
1110 """Add/delete S-NAT static mapping
1111
1112 :param local_ip: Local IP address
1113 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001114 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001115 :param local_port: Local port number (Default value = 0)
1116 :param external_port: External port number (Default value = 0)
1117 :param addr_only: 1 if address only mapping, 0 if address and port
1118 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001119 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001120 :param is_add: 1 if add, 0 if delete (Default value = 1)
1121 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1122 """
1123 return self.api(
1124 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001125 {'is_add': is_add,
1126 'is_ip4': is_ip4,
1127 'addr_only': addr_only,
1128 'local_ip_address': local_ip,
1129 'external_ip_address': external_ip,
1130 'local_port': local_port,
1131 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001132 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001133 'vrf_id': vrf_id,
1134 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001135
1136 def snat_add_address_range(
1137 self,
1138 first_ip_address,
1139 last_ip_address,
1140 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001141 is_ip4=1,
1142 vrf_id=0xFFFFFFFF):
Matus Fabiande886752016-12-07 03:38:19 -08001143 """Add/del S-NAT address range
1144
1145 :param first_ip_address: First IP address
1146 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001147 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001148 :param is_add: 1 if add, 0 if delete (Default value = 1)
1149 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1150 """
1151 return self.api(
1152 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001153 {'is_ip4': is_ip4,
1154 'first_ip_address': first_ip_address,
1155 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001156 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001157 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001158
1159 def snat_address_dump(self):
1160 """Dump S-NAT addresses
1161 :return: Dictionary of S-NAT addresses
1162 """
1163 return self.api(self.papi.snat_address_dump, {})
1164
1165 def snat_interface_dump(self):
1166 """Dump interfaces with S-NAT feature
1167 :return: Dictionary of interfaces with S-NAT feature
1168 """
1169 return self.api(self.papi.snat_interface_dump, {})
1170
Matus Fabian93d84c92017-07-19 08:06:01 -07001171 def snat_interface_output_feature_dump(self):
1172 """Dump interfaces with S-NAT output feature
1173 :return: Dictionary of interfaces with S-NAT output feature
1174 """
1175 return self.api(self.papi.snat_interface_output_feature_dump, {})
1176
Matus Fabiande886752016-12-07 03:38:19 -08001177 def snat_static_mapping_dump(self):
1178 """Dump S-NAT static mappings
1179 :return: Dictionary of S-NAT static mappings
1180 """
1181 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001182
Matus Fabian9902fcd2016-12-21 23:58:46 -08001183 def snat_show_config(self):
1184 """Show S-NAT config
1185 :return: S-NAT config parameters
1186 """
1187 return self.api(self.papi.snat_show_config, {})
1188
Matus Fabian8bf68e82017-01-12 04:24:35 -08001189 def snat_add_interface_addr(
1190 self,
1191 sw_if_index,
1192 is_add=1):
1193 """Add/del S-NAT address from interface
1194
1195 :param sw_if_index: Software index of the interface
1196 :param is_add: 1 if add, 0 if delete (Default value = 1)
1197 """
1198 return self.api(self.papi.snat_add_del_interface_addr,
1199 {'is_add': is_add, 'sw_if_index': sw_if_index})
1200
1201 def snat_interface_addr_dump(self):
1202 """Dump S-NAT addresses interfaces
1203 :return: Dictionary of S-NAT addresses interfaces
1204 """
1205 return self.api(self.papi.snat_interface_addr_dump, {})
1206
Matus Fabianeea28d72017-01-13 04:15:54 -08001207 def snat_ipfix(
1208 self,
1209 domain_id=1,
1210 src_port=4739,
1211 enable=1):
1212 """Enable/disable S-NAT IPFIX logging
1213
1214 :param domain_id: Observation domain ID (Default value = 1)
1215 :param src_port: Source port number (Default value = 4739)
1216 :param enable: 1 if enable, 0 if disable (Default value = 1)
1217 """
1218 return self.api(
1219 self.papi.snat_ipfix_enable_disable,
1220 {'domain_id': domain_id,
1221 'src_port': src_port,
1222 'enable': enable})
1223
magalik23caa882017-02-08 23:25:45 -08001224 def snat_user_session_dump(
1225 self,
1226 ip_address,
Martin6b7fcda2017-03-08 03:31:02 -08001227 vrf_id,
1228 is_ip4=1):
magalik23caa882017-02-08 23:25:45 -08001229 """Dump S-NAT user's sessions
1230
1231 :param ip_address: ip adress of the user to be dumped
1232 :param cpu_index: cpu_index on which the user is
1233 :param vrf_id: VRF ID
1234 :return: Dictionary of S-NAT sessions
1235 """
1236 return self.api(
1237 self.papi.snat_user_session_dump,
1238 {'ip_address': ip_address,
Martin6b7fcda2017-03-08 03:31:02 -08001239 'vrf_id': vrf_id,
1240 'is_ip4': is_ip4})
magalik23caa882017-02-08 23:25:45 -08001241
1242 def snat_user_dump(self):
1243 """Dump S-NAT users
1244
1245 :return: Dictionary of S-NAT users
1246 """
1247 return self.api(self.papi.snat_user_dump, {})
1248
Matus Fabian066f0342017-02-10 03:48:01 -08001249 def snat_add_det_map(
1250 self,
1251 in_addr,
1252 in_plen,
1253 out_addr,
1254 out_plen,
1255 is_add=1):
1256 """Add/delete S-NAT deterministic mapping
1257
1258 :param is_add - 1 if add, 0 if delete
1259 :param in_addr - inside IP address
1260 :param in_plen - inside IP address prefix length
1261 :param out_addr - outside IP address
1262 :param out_plen - outside IP address prefix length
1263 """
1264 return self.api(
1265 self.papi.snat_add_det_map,
1266 {'is_add': is_add,
1267 'in_addr': in_addr,
1268 'in_plen': in_plen,
1269 'out_addr': out_addr,
1270 'out_plen': out_plen})
1271
1272 def snat_det_forward(
1273 self,
1274 in_addr):
1275 """Get outside address and port range from inside address
1276
1277 :param in_addr - inside IP address
1278 """
1279 return self.api(
1280 self.papi.snat_det_forward,
1281 {'in_addr': in_addr})
1282
1283 def snat_det_reverse(
1284 self,
1285 out_addr,
1286 out_port):
1287 """Get inside address from outside address and port
1288
1289 :param out_addr - outside IP address
1290 :param out_port - outside port
1291 """
1292 return self.api(
1293 self.papi.snat_det_reverse,
1294 {'out_addr': out_addr,
1295 'out_port': out_port})
1296
Martin17a75cb2017-03-08 05:53:20 -08001297 def snat_det_map_dump(self):
1298 """Dump S-NAT deterministic mappings
1299
1300 :return: Dictionary of S-NAT deterministic mappings
1301 """
1302 return self.api(self.papi.snat_det_map_dump, {})
1303
Matus Fabian6a0946f2017-04-12 03:36:13 -07001304 def snat_det_set_timeouts(
1305 self,
1306 udp=300,
1307 tcp_established=7440,
1308 tcp_transitory=240,
1309 icmp=60):
1310 """Set values of timeouts for deterministic NAT (in seconds)
1311
1312 :param udp - UDP timeout (Default value = 300)
1313 :param tcp_established - TCP established timeout (Default value = 7440)
1314 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1315 :param icmp - ICMP timeout (Default value = 60)
1316 """
1317 return self.api(
1318 self.papi.snat_det_set_timeouts,
1319 {'udp': udp,
1320 'tcp_established': tcp_established,
1321 'tcp_transitory': tcp_transitory,
1322 'icmp': icmp})
1323
1324 def snat_det_get_timeouts(self):
1325 """Get values of timeouts for deterministic NAT
1326
1327 :return: Timeouts for deterministic NAT (in seconds)
1328 """
1329 return self.api(self.papi.snat_det_get_timeouts, {})
1330
Martin Gálik6bc8c642017-04-19 01:12:27 -07001331 def snat_det_close_session_out(
1332 self,
1333 out_addr,
1334 out_port,
1335 ext_addr,
1336 ext_port,
1337 is_ip4=1):
1338 """Close CGN session using outside address and port
1339
1340 :param out_addr - outside IP address
1341 :param out_port - outside port
1342 :param ext_addr - external host IP address
1343 :param ext_port - external host port
1344 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1345 """
1346 return self.api(
1347 self.papi.snat_det_close_session_out,
1348 {'out_addr': out_addr,
1349 'out_port': out_port,
1350 'ext_addr': ext_addr,
1351 'ext_port': ext_port,
1352 'is_ip4': is_ip4})
1353
1354 def snat_det_close_session_in(
1355 self,
1356 in_addr,
1357 in_port,
1358 ext_addr,
1359 ext_port,
1360 is_ip4=1):
1361 """Close CGN session using inside address and port
1362
1363 :param in_addr - inside IP address
1364 :param in_port - inside port
1365 :param ext_addr - external host IP address
1366 :param ext_port - external host port
1367 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1368 """
1369 return self.api(
1370 self.papi.snat_det_close_session_in,
1371 {'in_addr': in_addr,
1372 'in_port': in_port,
1373 'ext_addr': ext_addr,
1374 'ext_port': ext_port,
1375 'is_ip4': is_ip4})
1376
Martin Gálik9806eae2017-04-25 01:25:08 -07001377 def snat_det_session_dump(
1378 self,
1379 user_addr,
1380 is_ip4=1):
1381 """Dump S-NAT deterministic sessions belonging to a user
1382
1383 :param user_addr - inside IP address of the user
1384 :param is_ip4: - 1 if address type is IPv4 (Default value = 1)
1385 :return: Dictionary of S-NAT deterministic sessions
1386 """
1387 return self.api(
1388 self.papi.snat_det_session_dump,
1389 {'is_ip4': is_ip4,
1390 'user_addr': user_addr})
1391
Matus Fabian06596c52017-06-06 04:53:28 -07001392 def nat64_add_del_pool_addr_range(
1393 self,
1394 start_addr,
1395 end_addr,
1396 vrf_id=0xFFFFFFFF,
1397 is_add=1):
1398 """Add/del address range to NAT64 pool
1399
1400 :param start_addr: First IP address
1401 :param end_addr: Last IP address
1402 :param vrf_id: VRF id for the address range
1403 :param is_add: 1 if add, 0 if delete (Default value = 1)
1404 """
1405 return self.api(
1406 self.papi.nat64_add_del_pool_addr_range,
1407 {'start_addr': start_addr,
1408 'end_addr': end_addr,
1409 'vrf_id': vrf_id,
1410 'is_add': is_add})
1411
1412 def nat64_pool_addr_dump(self):
1413 """Dump NAT64 pool addresses
1414 :return: Dictionary of NAT64 pool addresses
1415 """
1416 return self.api(self.papi.nat64_pool_addr_dump, {})
1417
1418 def nat64_add_del_interface(
1419 self,
1420 sw_if_index,
1421 is_inside=1,
1422 is_add=1):
1423 """Enable/disable NAT64 feature on the interface
1424 :param sw_if_index: Index of the interface
1425 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1426 :param is_add: 1 if add, 0 if delete (Default value = 1)
1427 """
1428 return self.api(
1429 self.papi.nat64_add_del_interface,
1430 {'sw_if_index': sw_if_index,
1431 'is_inside': is_inside,
1432 'is_add': is_add})
1433
1434 def nat64_interface_dump(self):
1435 """Dump interfaces with NAT64 feature
1436 :return: Dictionary of interfaces with NAT64 feature
1437 """
1438 return self.api(self.papi.nat64_interface_dump, {})
1439
1440 def nat64_add_del_static_bib(
1441 self,
1442 in_ip,
1443 out_ip,
1444 in_port,
1445 out_port,
1446 protocol,
1447 vrf_id=0,
1448 is_add=1):
1449 """Add/delete S-NAT static BIB entry
1450
1451 :param in_ip: Inside IPv6 address
1452 :param out_ip: Outside IPv4 address
1453 :param in_port: Inside port number
1454 :param out_port: Outside port number
1455 :param protocol: IP protocol
1456 :param vrf_id: VRF ID (Default value = 0)
1457 :param is_add: 1 if add, 0 if delete (Default value = 1)
1458 """
1459 return self.api(
1460 self.papi.nat64_add_del_static_bib,
1461 {'i_addr': in_ip,
1462 'o_addr': out_ip,
1463 'i_port': in_port,
1464 'o_port': out_port,
1465 'vrf_id': vrf_id,
1466 'proto': protocol,
1467 'is_add': is_add})
1468
Matus Fabianab9a59c2017-08-16 05:37:36 -07001469 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001470 """Dump NAT64 BIB
1471
Matus Fabianab9a59c2017-08-16 05:37:36 -07001472 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001473 :returns: Dictionary of NAT64 BIB entries
1474 """
1475 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1476
1477 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1478 tcp_incoming_syn=6):
1479 """Set values of timeouts for NAT64 (in seconds)
1480
Matus Fabian428dc912017-06-21 06:15:18 -07001481 :param udpi: UDP timeout (Default value = 300)
1482 :param icmp: ICMP timeout (Default value = 60)
1483 :param tcp_trans: TCP transitory timeout (Default value = 240)
1484 :param tcp_est: TCP established timeout (Default value = 7440)
1485 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001486 """
1487 return self.api(
1488 self.papi.nat64_set_timeouts,
1489 {'udp': udp,
1490 'icmp': icmp,
1491 'tcp_trans': tcp_trans,
1492 'tcp_est': tcp_est,
1493 'tcp_incoming_syn': tcp_incoming_syn})
1494
1495 def nat64_get_timeouts(self):
1496 """Get values of timeouts for NAT64
1497
1498 :return: Timeouts for NAT64 (in seconds)
1499 """
1500 return self.api(self.papi.nat64_get_timeouts, {})
1501
Matus Fabianab9a59c2017-08-16 05:37:36 -07001502 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001503 """Dump NAT64 session table
1504
Matus Fabianab9a59c2017-08-16 05:37:36 -07001505 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001506 :returns: Dictionary of NAT64 sesstion table entries
1507 """
1508 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1509
Matus Fabian428dc912017-06-21 06:15:18 -07001510 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1511 """Add/del NAT64 prefix
1512
1513 :param prefix: NAT64 prefix
1514 :param plen: NAT64 prefix length
1515 :param vrf_id: VRF id of tenant (Default 0)
1516 :param is_add: 1 if add, 0 if delete (Default value = 1)
1517 """
1518 return self.api(
1519 self.papi.nat64_add_del_prefix,
1520 {'prefix': prefix,
1521 'prefix_len': plen,
1522 'vrf_id': vrf_id,
1523 'is_add': is_add})
1524
1525 def nat64_prefix_dump(self):
1526 """Dump NAT64 prefix
1527
1528 :returns: Dictionary of NAT64 prefixes
1529 """
1530 return self.api(self.papi.nat64_prefix_dump, {})
1531
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001532 def control_ping(self):
1533 self.api(self.papi.control_ping)
1534
1535 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001536 detect_mult, local_addr, peer_addr, is_ipv6=0,
1537 bfd_key_id=None, conf_key_id=None):
1538 if bfd_key_id is None:
1539 return self.api(self.papi.bfd_udp_add,
1540 {
1541 'sw_if_index': sw_if_index,
1542 'desired_min_tx': desired_min_tx,
1543 'required_min_rx': required_min_rx,
1544 'local_addr': local_addr,
1545 'peer_addr': peer_addr,
1546 'is_ipv6': is_ipv6,
1547 'detect_mult': detect_mult,
1548 })
1549 else:
1550 return self.api(self.papi.bfd_udp_add,
1551 {
1552 'sw_if_index': sw_if_index,
1553 'desired_min_tx': desired_min_tx,
1554 'required_min_rx': required_min_rx,
1555 'local_addr': local_addr,
1556 'peer_addr': peer_addr,
1557 'is_ipv6': is_ipv6,
1558 'detect_mult': detect_mult,
1559 'is_authenticated': 1,
1560 'bfd_key_id': bfd_key_id,
1561 'conf_key_id': conf_key_id,
1562 })
1563
Klement Sekeraa57a9702017-02-02 06:58:07 +01001564 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1565 detect_mult, local_addr, peer_addr, is_ipv6=0):
1566 return self.api(self.papi.bfd_udp_mod,
1567 {
1568 'sw_if_index': sw_if_index,
1569 'desired_min_tx': desired_min_tx,
1570 'required_min_rx': required_min_rx,
1571 'local_addr': local_addr,
1572 'peer_addr': peer_addr,
1573 'is_ipv6': is_ipv6,
1574 'detect_mult': detect_mult,
1575 })
1576
Klement Sekerab17dd962017-01-09 07:43:48 +01001577 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1578 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1579 is_delayed=False):
1580 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001581 {
1582 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001583 'local_addr': local_addr,
1584 'peer_addr': peer_addr,
1585 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001586 'is_delayed': 1 if is_delayed else 0,
1587 'bfd_key_id': bfd_key_id,
1588 'conf_key_id': conf_key_id,
1589 })
1590
1591 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1592 is_ipv6=0, is_delayed=False):
1593 return self.api(self.papi.bfd_udp_auth_deactivate,
1594 {
1595 'sw_if_index': sw_if_index,
1596 'local_addr': local_addr,
1597 'peer_addr': peer_addr,
1598 'is_ipv6': is_ipv6,
1599 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001600 })
1601
1602 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1603 return self.api(self.papi.bfd_udp_del,
1604 {
1605 'sw_if_index': sw_if_index,
1606 'local_addr': local_addr,
1607 'peer_addr': peer_addr,
1608 'is_ipv6': is_ipv6,
1609 })
1610
1611 def bfd_udp_session_dump(self):
1612 return self.api(self.papi.bfd_udp_session_dump, {})
1613
Klement Sekerab17dd962017-01-09 07:43:48 +01001614 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1615 peer_addr, is_ipv6=0):
1616 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001617 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001618 'sw_if_index': sw_if_index,
1619 'local_addr': local_addr,
1620 'peer_addr': peer_addr,
1621 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001622 })
1623
1624 def want_bfd_events(self, enable_disable=1):
1625 return self.api(self.papi.want_bfd_events, {
1626 'enable_disable': enable_disable,
1627 'pid': os.getpid(),
1628 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001629
Klement Sekerab17dd962017-01-09 07:43:48 +01001630 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1631 return self.api(self.papi.bfd_auth_set_key, {
1632 'conf_key_id': conf_key_id,
1633 'auth_type': auth_type,
1634 'key': key,
1635 'key_len': len(key),
1636 })
1637
1638 def bfd_auth_del_key(self, conf_key_id):
1639 return self.api(self.papi.bfd_auth_del_key, {
1640 'conf_key_id': conf_key_id,
1641 })
1642
1643 def bfd_auth_keys_dump(self):
1644 return self.api(self.papi.bfd_auth_keys_dump, {})
1645
Klement Sekera239790f2017-02-16 10:53:53 +01001646 def bfd_udp_set_echo_source(self, sw_if_index):
1647 return self.api(self.papi.bfd_udp_set_echo_source,
1648 {'sw_if_index': sw_if_index})
1649
Klement Sekera73884482017-02-23 09:26:30 +01001650 def bfd_udp_del_echo_source(self):
1651 return self.api(self.papi.bfd_udp_del_echo_source, {})
1652
Steve Shin7957d6e2016-12-19 09:24:50 -08001653 def classify_add_del_table(
1654 self,
1655 is_add,
1656 mask,
1657 match_n_vectors=1,
1658 table_index=0xFFFFFFFF,
1659 nbuckets=2,
1660 memory_size=2097152,
1661 skip_n_vectors=0,
1662 next_table_index=0xFFFFFFFF,
1663 miss_next_index=0xFFFFFFFF,
1664 current_data_flag=0,
1665 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001666 """
1667 :param is_add:
1668 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001669 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001670 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001671 :param nbuckets: (Default value = 2)
1672 :param memory_size: (Default value = 2097152)
1673 :param skip_n_vectors: (Default value = 0)
1674 :param next_table_index: (Default value = 0xFFFFFFFF)
1675 :param miss_next_index: (Default value = 0xFFFFFFFF)
1676 :param current_data_flag: (Default value = 0)
1677 :param current_data_offset: (Default value = 0)
1678 """
1679
1680 return self.api(
1681 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001682 {'is_add': is_add,
1683 'table_index': table_index,
1684 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001685 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001686 'skip_n_vectors': skip_n_vectors,
1687 'match_n_vectors': match_n_vectors,
1688 'next_table_index': next_table_index,
1689 'miss_next_index': miss_next_index,
1690 'current_data_flag': current_data_flag,
1691 'current_data_offset': current_data_offset,
1692 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001693
1694 def classify_add_del_session(
1695 self,
1696 is_add,
1697 table_index,
1698 match,
1699 opaque_index=0xFFFFFFFF,
1700 hit_next_index=0xFFFFFFFF,
1701 advance=0,
1702 action=0,
1703 metadata=0):
1704 """
1705 :param is_add:
1706 :param table_index:
1707 :param match:
1708 :param opaque_index: (Default value = 0xFFFFFFFF)
1709 :param hit_next_index: (Default value = 0xFFFFFFFF)
1710 :param advance: (Default value = 0)
1711 :param action: (Default value = 0)
1712 :param metadata: (Default value = 0)
1713 """
1714
1715 return self.api(
1716 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001717 {'is_add': is_add,
1718 'table_index': table_index,
1719 'hit_next_index': hit_next_index,
1720 'opaque_index': opaque_index,
1721 'advance': advance,
1722 'action': action,
1723 'metadata': metadata,
1724 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001725
1726 def input_acl_set_interface(
1727 self,
1728 is_add,
1729 sw_if_index,
1730 ip4_table_index=0xFFFFFFFF,
1731 ip6_table_index=0xFFFFFFFF,
1732 l2_table_index=0xFFFFFFFF):
1733 """
1734 :param is_add:
1735 :param sw_if_index:
1736 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1737 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1738 :param l2_table_index: (Default value = 0xFFFFFFFF)
1739 """
1740
1741 return self.api(
1742 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001743 {'sw_if_index': sw_if_index,
1744 'ip4_table_index': ip4_table_index,
1745 'ip6_table_index': ip6_table_index,
1746 'l2_table_index': l2_table_index,
1747 'is_add': is_add})
1748
1749 def set_ipfix_exporter(
1750 self,
1751 collector_address,
1752 src_address,
1753 path_mtu,
1754 template_interval,
1755 vrf_id=0,
1756 collector_port=4739,
1757 udp_checksum=0):
1758 return self.api(
1759 self.papi.set_ipfix_exporter,
1760 {
1761 'collector_address': collector_address,
1762 'collector_port': collector_port,
1763 'src_address': src_address,
1764 'vrf_id': vrf_id,
1765 'path_mtu': path_mtu,
1766 'template_interval': template_interval,
1767 'udp_checksum': udp_checksum,
1768 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001769
1770 def dhcp_proxy_config(self,
1771 dhcp_server,
1772 dhcp_src_address,
1773 rx_table_id=0,
1774 server_table_id=0,
1775 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001776 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001777 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001778 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001779 {
1780 'rx_vrf_id': rx_table_id,
1781 'server_vrf_id': server_table_id,
1782 'is_ipv6': is_ipv6,
1783 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001784 'dhcp_server': dhcp_server,
1785 'dhcp_src_address': dhcp_src_address,
1786 })
1787
1788 def dhcp_proxy_set_vss(self,
1789 table_id,
1790 fib_id,
1791 oui,
1792 is_add=1,
1793 is_ip6=0):
1794 return self.api(
1795 self.papi.dhcp_proxy_set_vss,
1796 {
1797 'tbl_id': table_id,
1798 'fib_id': fib_id,
1799 'is_ipv6': is_ip6,
1800 'is_add': is_add,
1801 'oui': oui,
1802 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001803
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001804 def dhcp_client(self,
1805 sw_if_index,
1806 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001807 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001808 is_add=1,
1809 want_dhcp_events=0):
1810 return self.api(
1811 self.papi.dhcp_client_config,
1812 {
1813 'sw_if_index': sw_if_index,
1814 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07001815 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001816 'is_add': is_add,
1817 'want_dhcp_event': want_dhcp_events,
1818 'pid': os.getpid(),
1819 })
1820
Neale Ranns32e1c012016-11-22 17:07:28 +00001821 def ip_mroute_add_del(self,
1822 src_address,
1823 grp_address,
1824 grp_address_length,
1825 e_flags,
1826 next_hop_sw_if_index,
1827 i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001828 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001829 table_id=0,
1830 create_vrf_if_needed=0,
1831 is_add=1,
1832 is_ipv6=0,
1833 is_local=0):
1834 """
1835 """
1836 return self.api(
1837 self.papi.ip_mroute_add_del,
1838 {'next_hop_sw_if_index': next_hop_sw_if_index,
1839 'entry_flags': e_flags,
1840 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001841 'table_id': table_id,
1842 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001843 'create_vrf_if_needed': create_vrf_if_needed,
1844 'is_add': is_add,
1845 'is_ipv6': is_ipv6,
1846 'is_local': is_local,
1847 'grp_address_length': grp_address_length,
1848 'grp_address': grp_address,
1849 'src_address': src_address})
1850
1851 def mfib_signal_dump(self):
1852 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001853
1854 def ip_mfib_dump(self):
1855 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001856
1857 def lisp_enable_disable(self, is_enabled):
1858 return self.api(
1859 self.papi.lisp_enable_disable,
1860 {
1861 'is_en': is_enabled,
1862 })
1863
1864 def lisp_locator_set(self,
1865 ls_name,
1866 is_add=1):
1867 return self.api(
1868 self.papi.lisp_add_del_locator_set,
1869 {
1870 'is_add': is_add,
1871 'locator_set_name': ls_name
1872 })
1873
1874 def lisp_locator_set_dump(self):
1875 return self.api(self.papi.lisp_locator_set_dump, {})
1876
1877 def lisp_locator(self,
1878 ls_name,
1879 sw_if_index,
1880 priority=1,
1881 weight=1,
1882 is_add=1):
1883 return self.api(
1884 self.papi.lisp_add_del_locator,
1885 {
1886 'is_add': is_add,
1887 'locator_set_name': ls_name,
1888 'sw_if_index': sw_if_index,
1889 'priority': priority,
1890 'weight': weight
1891 })
1892
1893 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1894 return self.api(
1895 self.papi.lisp_locator_dump,
1896 {
1897 'is_index_set': is_index_set,
1898 'ls_name': ls_name,
1899 'ls_index': ls_index,
1900 })
1901
1902 def lisp_local_mapping(self,
1903 ls_name,
1904 eid_type,
1905 eid,
1906 prefix_len,
1907 vni=0,
1908 key_id=0,
1909 key="",
1910 is_add=1):
1911 return self.api(
1912 self.papi.lisp_add_del_local_eid,
1913 {
1914 'locator_set_name': ls_name,
1915 'is_add': is_add,
1916 'eid_type': eid_type,
1917 'eid': eid,
1918 'prefix_len': prefix_len,
1919 'vni': vni,
1920 'key_id': key_id,
1921 'key': key
1922 })
1923
1924 def lisp_eid_table_dump(self,
1925 eid_set=0,
1926 prefix_length=0,
1927 vni=0,
1928 eid_type=0,
1929 eid=None,
1930 filter_opt=0):
1931 return self.api(
1932 self.papi.lisp_eid_table_dump,
1933 {
1934 'eid_set': eid_set,
1935 'prefix_length': prefix_length,
1936 'vni': vni,
1937 'eid_type': eid_type,
1938 'eid': eid,
1939 'filter': filter_opt,
1940 })
1941
1942 def lisp_remote_mapping(self,
1943 eid_type,
1944 eid,
1945 eid_prefix_len=0,
1946 vni=0,
1947 rlocs=None,
1948 rlocs_num=0,
1949 is_src_dst=0,
1950 is_add=1):
1951 return self.api(
1952 self.papi.lisp_add_del_remote_mapping,
1953 {
1954 'is_add': is_add,
1955 'eid_type': eid_type,
1956 'eid': eid,
1957 'eid_len': eid_prefix_len,
1958 'rloc_num': rlocs_num,
1959 'rlocs': rlocs,
1960 'vni': vni,
1961 'is_src_dst': is_src_dst,
1962 })
1963
1964 def lisp_adjacency(self,
1965 leid,
1966 reid,
1967 leid_len,
1968 reid_len,
1969 eid_type,
1970 is_add=1,
1971 vni=0):
1972 return self.api(
1973 self.papi.lisp_add_del_adjacency,
1974 {
1975 'is_add': is_add,
1976 'vni': vni,
1977 'eid_type': eid_type,
1978 'leid': leid,
1979 'reid': reid,
1980 'leid_len': leid_len,
1981 'reid_len': reid_len,
1982 })
1983
1984 def lisp_adjacencies_get(self, vni=0):
1985 return self.api(
1986 self.papi.lisp_adjacencies_get,
1987 {
1988 'vni': vni
1989 })
Neale Ranns80823802017-02-20 18:23:41 -08001990
1991 def map_add_domain(self,
1992 ip6_prefix,
1993 ip6_prefix_len,
1994 ip6_src,
1995 ip6_src_prefix_len,
1996 ip4_prefix,
1997 ip4_prefix_len,
1998 ea_bits_len=0,
1999 psid_offset=0,
2000 psid_length=0,
2001 is_translation=0,
2002 mtu=1280):
2003 return self.api(
2004 self.papi.map_add_domain,
2005 {
2006 'ip6_prefix': ip6_prefix,
2007 'ip6_prefix_len': ip6_prefix_len,
2008 'ip4_prefix': ip4_prefix,
2009 'ip4_prefix_len': ip4_prefix_len,
2010 'ip6_src': ip6_src,
2011 'ip6_src_prefix_len': ip6_src_prefix_len,
2012 'ea_bits_len': ea_bits_len,
2013 'psid_offset': psid_offset,
2014 'psid_length': psid_length,
2015 'is_translation': is_translation,
2016 'mtu': mtu
2017 })
Hongjun Nief486b12017-04-12 19:21:16 +08002018
2019 def gtpu_add_del_tunnel(
2020 self,
2021 src_addr,
2022 dst_addr,
2023 is_add=1,
2024 is_ipv6=0,
2025 mcast_sw_if_index=0xFFFFFFFF,
2026 encap_vrf_id=0,
2027 decap_next_index=0xFFFFFFFF,
2028 teid=0):
2029 """
2030
2031 :param is_add: (Default value = 1)
2032 :param is_ipv6: (Default value = 0)
2033 :param src_addr:
2034 :param dst_addr:
2035 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2036 :param encap_vrf_id: (Default value = 0)
2037 :param decap_next_index: (Default value = 0xFFFFFFFF)
2038 :param teid: (Default value = 0)
2039
2040 """
2041 return self.api(self.papi.gtpu_add_del_tunnel,
2042 {'is_add': is_add,
2043 'is_ipv6': is_ipv6,
2044 'src_address': src_addr,
2045 'dst_address': dst_addr,
2046 'mcast_sw_if_index': mcast_sw_if_index,
2047 'encap_vrf_id': encap_vrf_id,
2048 'decap_next_index': decap_next_index,
2049 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002050
2051 def vxlan_gpe_add_del_tunnel(
2052 self,
2053 src_addr,
2054 dst_addr,
2055 mcast_sw_if_index=0xFFFFFFFF,
2056 is_add=1,
2057 is_ipv6=0,
2058 encap_vrf_id=0,
2059 decap_vrf_id=0,
2060 protocol=3,
2061 vni=0):
2062 """
2063
2064 :param local:
2065 :param remote:
2066 :param is_add: (Default value = 1)
2067 :param is_ipv6: (Default value = 0)
2068 :param encap_vrf_id: (Default value = 0)
2069 :param decap_vrf_id: (Default value = 0)
2070 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2071 :param protocol: (Default value = 3)
2072 :param vni: (Default value = 0)
2073
2074 """
2075 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2076 {'is_add': is_add,
2077 'is_ipv6': is_ipv6,
2078 'local': src_addr,
2079 'remote': dst_addr,
2080 'mcast_sw_if_index': mcast_sw_if_index,
2081 'encap_vrf_id': encap_vrf_id,
2082 'decap_vrf_id': decap_vrf_id,
2083 'protocol': protocol,
2084 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002085
2086 def pppoe_add_del_session(
2087 self,
2088 client_ip,
2089 client_mac,
2090 session_id=0,
2091 is_add=1,
2092 is_ipv6=0,
2093 decap_vrf_id=0):
2094 """
2095
2096 :param is_add: (Default value = 1)
2097 :param is_ipv6: (Default value = 0)
2098 :param client_ip:
2099 :param session_id: (Default value = 0)
2100 :param client_mac:
2101 :param decap_vrf_id: (Default value = 0)
2102
2103 """
2104 return self.api(self.papi.pppoe_add_del_session,
2105 {'is_add': is_add,
2106 'is_ipv6': is_ipv6,
2107 'session_id': session_id,
2108 'client_ip': client_ip,
2109 'decap_vrf_id': decap_vrf_id,
2110 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002111
2112 def sr_localsid_add_del(self,
2113 localsid_addr,
2114 behavior,
2115 nh_addr,
2116 is_del=0,
2117 end_psp=0,
2118 sw_if_index=0xFFFFFFFF,
2119 vlan_index=0,
2120 fib_table=0,
2121 ):
2122 """ Add/del IPv6 SR local-SID.
2123
2124 :param localsid_addr:
2125 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2126 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2127 :param nh_addr:
2128 :param is_del: (Default value = 0)
2129 :param end_psp: (Default value = 0)
2130 :param sw_if_index: (Default value = 0xFFFFFFFF)
2131 :param vlan_index: (Default value = 0)
2132 :param fib_table: (Default value = 0)
2133 """
2134 return self.api(
2135 self.papi.sr_localsid_add_del,
2136 {'is_del': is_del,
2137 'localsid_addr': localsid_addr,
2138 'end_psp': end_psp,
2139 'behavior': behavior,
2140 'sw_if_index': sw_if_index,
2141 'vlan_index': vlan_index,
2142 'fib_table': fib_table,
2143 'nh_addr': nh_addr
2144 }
2145 )
2146
2147 def sr_policy_add(
2148 self,
2149 bsid_addr,
2150 weight=1,
2151 is_encap=1,
2152 type=0,
2153 fib_table=0,
2154 n_segments=0,
2155 segments=[]):
2156 """
2157 :param bsid_addr: bindingSID of the SR Policy
2158 :param weight: weight of the sid list. optional. (default: 1)
2159 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2160 (default: Encap)
2161 :param type: type/behavior of the SR policy. (default or spray) \
2162 (default: default)
2163 :param fib_table: VRF where to install the FIB entry for the BSID \
2164 (default: 0)
2165 :param n_segments: number of segments \
2166 (default: 0)
2167 :param segments: a vector of IPv6 address composing the segment list \
2168 (default: [])
2169 """
2170 return self.api(
2171 self.papi.sr_policy_add,
2172 {'bsid_addr': bsid_addr,
2173 'weight': weight,
2174 'is_encap': is_encap,
2175 'type': type,
2176 'fib_table': fib_table,
2177 'n_segments': n_segments,
2178 'segments': segments
2179 }
2180 )
2181
2182 def sr_policy_del(
2183 self,
2184 bsid_addr,
2185 sr_policy_index=0):
2186 """
2187 :param bsid: bindingSID of the SR Policy
2188 :param sr_policy_index: index of the sr policy (default: 0)
2189 """
2190 return self.api(
2191 self.papi.sr_policy_del,
2192 {'bsid_addr': bsid_addr,
2193 'sr_policy_index': sr_policy_index
2194 })
2195
2196 def sr_steering_add_del(
2197 self,
2198 is_del,
2199 bsid_addr,
2200 sr_policy_index,
2201 table_id,
2202 prefix_addr,
2203 mask_width,
2204 sw_if_index,
2205 traffic_type):
2206 """
2207 Steer traffic L2 and L3 traffic through a given SR policy
2208
2209 :param is_del: delete or add
2210 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2211 :param sr_policy: is the index of the SR Policy (alt to bsid)
2212 :param table_id: is the VRF where to install the FIB entry for the BSID
2213 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2214 :param mask_width: is the mask for L3 traffic type
2215 :param sw_if_index: is the incoming interface for L2 traffic
2216 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2217 """
2218 return self.api(
2219 self.papi.sr_steering_add_del,
2220 {'is_del': is_del,
2221 'bsid_addr': bsid_addr,
2222 'sr_policy_index': sr_policy_index,
2223 'table_id': table_id,
2224 'prefix_addr': prefix_addr,
2225 'mask_width': mask_width,
2226 'sw_if_index': sw_if_index,
2227 'traffic_type': traffic_type
2228 })