blob: 83c4a83b8c9031b5f4053e7c70ea7bbe6dd65d32 [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:
28 L2_POP_1 = 3
29
Klement Sekera0e3c0de2016-09-29 14:43:44 +020030
Klement Sekera73884482017-02-23 09:26:30 +010031class UnexpectedApiReturnValueError(Exception):
32 """ exception raised when the API return value is unexpected """
33 pass
34
35
Klement Sekeraf62ae122016-10-11 11:47:09 +020036class VppPapiProvider(object):
37 """VPP-api provider using vpp-papi
38
39 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020040 """
41
Klement Sekerae0545ef2017-01-25 08:00:40 +010042 _zero, _negative = range(2)
43
Klement Sekera7bb873a2016-11-18 07:38:42 +010044 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020045 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020046 self.name = name
47 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010048 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010049 self._expect_api_retval = self._zero
50 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010051 jsonfiles = []
52
Klement Sekera0e3c0de2016-09-29 14:43:44 +020053 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010054 for root, dirnames, filenames in os.walk(install_dir):
55 for filename in fnmatch.filter(filenames, '*.api.json'):
56 jsonfiles.append(os.path.join(root, filename))
57
Ole Troan3cc49712017-03-08 12:02:24 +010058 self.vpp = VPP(jsonfiles, logger=test_class.logger)
Klement Sekerae4504c62016-12-08 10:16:41 +010059 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020060
Klement Sekerae0545ef2017-01-25 08:00:40 +010061 def __enter__(self):
62 return self
63
64 def expect_negative_api_retval(self):
65 """ Expect API failure """
66 self._expect_stack.append(self._expect_api_retval)
67 self._expect_api_retval = self._negative
68 return self
69
70 def expect_zero_api_retval(self):
71 """ Expect API success """
72 self._expect_stack.append(self._expect_api_retval)
73 self._expect_api_retval = self._zero
74 return self
75
76 def __exit__(self, exc_type, exc_value, traceback):
77 self._expect_api_retval = self._expect_stack.pop()
78
Klement Sekeraf62ae122016-10-11 11:47:09 +020079 def register_hook(self, hook):
80 """Replace hook registration with new hook
81
82 :param hook:
83
84 """
85 self.hook = hook
86
Klement Sekera0e3c0de2016-09-29 14:43:44 +020087 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +010088 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +020089 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +010090 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +020091 return e
92
93 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +010094 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +010095 if name:
96 self.test_class.logger.debug("Expecting event within %ss",
97 timeout)
98 else:
99 self.test_class.logger.debug("Expecting event '%s' within %ss",
100 name, timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100101 if self._events:
102 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200103 limit = time.time() + timeout
104 while time.time() < limit:
105 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100106 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200107 if name and type(e).__name__ != name:
108 raise Exception(
109 "Unexpected event received: %s, expected: %s" %
110 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100111 self.test_class.logger.debug("Returning event %s:%s" %
112 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200113 return e
114 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200115 raise Exception("Event did not occur within timeout")
116
117 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100118 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200119 # FIXME use the name instead of relying on type(e).__name__ ?
120 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100121 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200122 self._events.append(event)
123
Klement Sekeraf62ae122016-10-11 11:47:09 +0200124 def connect(self):
125 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100126 self.vpp.connect(self.name, self.shm_prefix)
127 self.papi = self.vpp.api
128 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200129
130 def disconnect(self):
131 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100132 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200133
134 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100135 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200136 Call the appropriate hooks before and after the API call
137
138 :param api_fn: API function to call
139 :param api_args: tuple of API function arguments
140 :param expected_retval: Expected return value (Default value = 0)
141 :returns: reply from the API
142
143 """
144 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100145 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100146 if self._expect_api_retval == self._negative:
147 if hasattr(reply, 'retval') and reply.retval >= 0:
148 msg = "API call passed unexpectedly: expected negative "\
149 "return value instead of %d in %s" % \
150 (reply.retval, repr(reply))
151 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100152 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100153 elif self._expect_api_retval == self._zero:
154 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700155 msg = "API call failed, expected %d return value instead "\
156 "of %d in %s" % (expected_retval, reply.retval,
157 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100158 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100159 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100160 else:
161 raise Exception("Internal error, unexpected value for "
162 "self._expect_api_retval %s" %
163 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200164 self.hook.after_api(api_fn.__name__, api_args)
165 return reply
166
167 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100168 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200169
170 :param cli: CLI to execute
171 :returns: CLI output
172
173 """
174 self.hook.before_cli(cli)
175 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100176 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200177 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200178 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100179 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200180
Jan49c0fca2016-10-26 15:44:27 +0200181 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100182 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200183
184 :param cli: CLI to execute
185 :returns: CLI output
186 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600187 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200188
Jan4af521d2016-11-15 17:05:00 +0100189 def _convert_mac(self, mac):
190 return int(mac.replace(":", ""), 16) << 16
191
Klement Sekeraf62ae122016-10-11 11:47:09 +0200192 def show_version(self):
193 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100194 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195
196 def pg_create_interface(self, pg_index):
197 """
198
199 :param pg_index:
200
201 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100202 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200203 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200204
205 def sw_interface_dump(self, filter=None):
206 """
207
208 :param filter: (Default value = None)
209
210 """
211 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200212 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200213 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100214 args = {}
215 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200216
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000217 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100218 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000219
220 :param sw_if_index:
221 :param is_ipv6:
222 :param table_id:
223
224 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100225 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200226 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
227 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000228
Klement Sekeraf62ae122016-10-11 11:47:09 +0200229 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
230 is_ipv6=0, is_add=1, del_all=0):
231 """
232
233 :param addr: param is_ipv6: (Default value = 0)
234 :param sw_if_index:
235 :param addr_len:
236 :param is_ipv6: (Default value = 0)
237 :param is_add: (Default value = 1)
238 :param del_all: (Default value = 0)
239
240 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100241 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200242 {'sw_if_index': sw_if_index,
243 'is_add': is_add,
244 'is_ipv6': is_ipv6,
245 'del_all': del_all,
246 'address_length': addr_len,
247 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200248
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800249 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
250 is_add=1):
251 """ Set the Interface to be unnumbered
252
253 :param is_add: (Default value = 1)
254 :param sw_if_index - interface That will be unnumbered
255 :param ip_sw_if_index - interface with an IP addres
256
257 """
258 return self.api(self.papi.sw_interface_set_unnumbered,
259 {'sw_if_index': ip_sw_if_index,
260 'unnumbered_sw_if_index': sw_if_index,
261 'is_add': is_add})
262
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000263 def sw_interface_enable_disable_mpls(self, sw_if_index,
264 is_enable=1):
265 """
266 Enable/Disable MPLS on the interface
267 :param sw_if_index:
268 :param is_enable: (Default value = 1)
269
270 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100271 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200272 {'sw_if_index': sw_if_index,
273 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000274
Jan Gelety057bb8c2016-12-20 17:32:45 +0100275 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100276 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100277 {'sw_if_index': sw_if_index,
278 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200279
Neale Ranns227038a2017-04-21 01:07:59 -0700280 def set_ip_flow_hash(self,
281 table_id,
282 src=1,
283 dst=1,
284 sport=1,
285 dport=1,
286 proto=1,
287 reverse=0,
288 is_ip6=0):
289 return self.api(self.papi.set_ip_flow_hash,
290 {'vrf_id': table_id,
291 'src': src,
292 'dst': dst,
293 'dport': dport,
294 'sport': sport,
295 'proto': proto,
296 'reverse': reverse,
297 'is_ipv6': is_ip6})
298
Neale Ranns3f844d02017-02-18 00:03:54 -0800299 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
300 return self.api(self.papi.ip6nd_proxy_add_del,
301 {'address': address,
302 'sw_if_index': sw_if_index,
303 'is_del': is_del})
304
Neale Ranns75152282017-01-09 01:00:45 -0800305 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000306 no,
Neale Ranns75152282017-01-09 01:00:45 -0800307 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000308 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800309 return self.api(self.papi.sw_interface_ip6nd_ra_config,
310 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000311 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100312 'suppress': suppress,
313 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800314
Neale Ranns87df12d2017-02-18 08:16:41 -0800315 def ip6_sw_interface_ra_prefix(self,
316 sw_if_index,
317 address,
318 address_length,
319 use_default=0,
320 no_advertise=0,
321 off_link=0,
322 no_autoconfig=0,
323 no_onlink=0,
324 is_no=0,
325 val_lifetime=0xffffffff,
326 pref_lifetime=0xffffffff):
327 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
328 {'sw_if_index': sw_if_index,
329 'address': address,
330 'address_length': address_length,
331 'use_default': use_default,
332 'no_advertise': no_advertise,
333 'off_link': off_link,
334 'no_autoconfig': no_autoconfig,
335 'no_onlink': no_onlink,
336 'is_no': is_no,
337 'val_lifetime': val_lifetime,
338 'pref_lifetime': pref_lifetime})
339
Neale Ranns75152282017-01-09 01:00:45 -0800340 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
341 """
342 Enable/Disable An interface for IPv6
343 """
344 return self.api(self.papi.sw_interface_ip6_enable_disable,
345 {'sw_if_index': sw_if_index,
346 'enable': enable})
347
Klement Sekeraf62ae122016-10-11 11:47:09 +0200348 def vxlan_add_del_tunnel(
349 self,
350 src_addr,
351 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200352 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200353 is_add=1,
354 is_ipv6=0,
355 encap_vrf_id=0,
356 decap_next_index=0xFFFFFFFF,
357 vni=0):
358 """
359
360 :param dst_addr:
361 :param src_addr:
362 :param is_add: (Default value = 1)
363 :param is_ipv6: (Default value = 0)
364 :param encap_vrf_id: (Default value = 0)
365 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200366 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200367 :param vni: (Default value = 0)
368
369 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100370 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200371 {'is_add': is_add,
372 'is_ipv6': is_ipv6,
373 'src_address': src_addr,
374 'dst_address': dst_addr,
375 'mcast_sw_if_index': mcast_sw_if_index,
376 'encap_vrf_id': encap_vrf_id,
377 'decap_next_index': decap_next_index,
378 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200379
Jan4af521d2016-11-15 17:05:00 +0100380 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
381 learn=1, arp_term=0, is_add=1):
382 """Create/delete bridge domain.
383
384 :param int bd_id: Bridge domain index.
385 :param int flood: Enable/disable bcast/mcast flooding in the BD.
386 (Default value = 1)
387 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
388 (Default value = 1)
389 :param int forward: Enable/disable forwarding on all interfaces in
390 the BD. (Default value = 1)
391 :param int learn: Enable/disable learning on all interfaces in the BD.
392 (Default value = 1)
393 :param int arp_term: Enable/disable arp termination in the BD.
394 (Default value = 1)
395 :param int is_add: Add or delete flag. (Default value = 1)
396 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100397 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200398 {'bd_id': bd_id,
399 'flood': flood,
400 'uu_flood': uu_flood,
401 'forward': forward,
402 'learn': learn,
403 'arp_term': arp_term,
404 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100405
406 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
407 filter_mac=0, bvi_mac=0):
408 """Create/delete L2 FIB entry.
409
410 :param str mac: MAC address to create FIB entry for.
411 :param int bd_id: Bridge domain index.
412 :param int sw_if_index: Software interface index of the interface.
413 :param int is_add: Add or delete flag. (Default value = 1)
414 :param int static_mac: Set to 1 to create static MAC entry.
415 (Default value = 0)
416 :param int filter_mac: Set to 1 to drop packet that's source or
417 destination MAC address contains defined MAC address.
418 (Default value = 0)
419 :param int bvi_mac: Set to 1 to create entry that points to BVI
420 interface. (Default value = 0)
421 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100422 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200423 {'mac': self._convert_mac(mac),
424 'bd_id': bd_id,
425 'sw_if_index': sw_if_index,
426 'is_add': is_add,
427 'static_mac': static_mac,
428 'filter_mac': filter_mac,
429 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100430
Klement Sekeraf62ae122016-10-11 11:47:09 +0200431 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
432 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100433 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200434
Jan4af521d2016-11-15 17:05:00 +0100435 :param int sw_if_index: Software interface index of the interface.
436 :param int bd_id: Bridge domain index.
437 :param int shg: Split-horizon group index. (Default value = 0)
438 :param int bvi: Set interface as a bridge group virtual interface.
439 (Default value = 0)
440 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200441 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100442 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200443 {'rx_sw_if_index': sw_if_index,
444 'bd_id': bd_id,
445 'shg': shg,
446 'bvi': bvi,
447 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200448
Jan00dad122016-11-29 10:04:53 +0100449 def bridge_flags(self, bd_id, is_set, feature_bitmap):
450 """Enable/disable required feature of the bridge domain with defined ID.
451
452 :param int bd_id: Bridge domain ID.
453 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
454 :param int feature_bitmap: Bitmap value of the feature to be set:
455 - learn (1 << 0),
456 - forward (1 << 1),
457 - flood (1 << 2),
458 - uu-flood (1 << 3) or
459 - arp-term (1 << 4).
460 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100461 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200462 {'bd_id': bd_id,
463 'is_set': is_set,
464 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100465
466 def bridge_domain_dump(self, bd_id=0):
467 """
468
469 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
470 existing bridge domains returned)
471 :return: Dictionary of bridge domain(s) data.
472 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100473 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200474 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100475
Klement Sekeraf62ae122016-10-11 11:47:09 +0200476 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
477 enable):
478 """Create or delete unidirectional cross-connect from Tx interface to
479 Rx interface.
480
Jan4af521d2016-11-15 17:05:00 +0100481 :param int rx_sw_if_index: Software interface index of Rx interface.
482 :param int tx_sw_if_index: Software interface index of Tx interface.
483 :param int enable: Create cross-connect if equal to 1, delete
484 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200485
486 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100487 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200488 {'rx_sw_if_index': rx_sw_if_index,
489 'tx_sw_if_index': tx_sw_if_index,
490 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200491
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200492 def sw_interface_set_l2_tag_rewrite(
493 self,
494 sw_if_index,
495 vtr_oper,
496 push=0,
497 tag1=0,
498 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000499 """L2 interface vlan tag rewrite configure request
500 :param client_index - opaque cookie to identify the sender
501 :param context - sender context, to match reply w/ request
502 :param sw_if_index - interface the operation is applied to
503 :param vtr_op - Choose from l2_vtr_op_t enum values
504 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
505 :param tag1 - Needed for any push or translate vtr op
506 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
507
508 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100509 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200510 {'sw_if_index': sw_if_index,
511 'vtr_op': vtr_oper,
512 'push_dot1q': push,
513 'tag1': tag1,
514 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000515
Klement Sekeraf62ae122016-10-11 11:47:09 +0200516 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
517 link_up_down=0, deleted=0):
518 """
519
520 :param admin_up_down:
521 :param sw_if_index:
522 :param link_up_down: (Default value = 0)
523 :param deleted: (Default value = 0)
524
525 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100526 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200527 {'sw_if_index': sw_if_index,
528 'admin_up_down': admin_up_down,
529 'link_up_down': link_up_down,
530 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200531
532 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
533 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
534 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
535 """Create subinterface
536 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
537
538 :param sub_id: param inner_vlan:
539 :param sw_if_index:
540 :param outer_vlan:
541 :param inner_vlan:
542 :param no_tags: (Default value = 0)
543 :param one_tag: (Default value = 0)
544 :param two_tags: (Default value = 0)
545 :param dot1ad: (Default value = 0)
546 :param exact_match: (Default value = 0)
547 :param default_sub: (Default value = 0)
548 :param outer_vlan_id_any: (Default value = 0)
549 :param inner_vlan_id_any: (Default value = 0)
550
551 """
552 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100553 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200554 {'sw_if_index': sw_if_index,
555 'sub_id': sub_id,
556 'no_tags': no_tags,
557 'one_tag': one_tag,
558 'two_tags': two_tags,
559 'dot1ad': dot1ad,
560 'exact_match': exact_match,
561 'default_sub': default_sub,
562 'outer_vlan_id_any': outer_vlan_id_any,
563 'inner_vlan_id_any': inner_vlan_id_any,
564 'outer_vlan_id': outer_vlan,
565 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200566
Neale Ranns177bbdc2016-11-15 09:46:51 +0000567 def delete_subif(self, sw_if_index):
568 """Delete subinterface
569
570 :param sw_if_index:
571 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100572 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200573 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000574
Klement Sekeraf62ae122016-10-11 11:47:09 +0200575 def create_vlan_subif(self, sw_if_index, vlan):
576 """
577
578 :param vlan:
579 :param sw_if_index:
580
581 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100582 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200583 {'sw_if_index': sw_if_index,
584 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200585
Matej Klotton0178d522016-11-04 11:11:44 +0100586 def create_loopback(self, mac=''):
587 """
588
589 :param mac: (Optional)
590 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100591 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200592 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100593
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100594 def delete_loopback(self, sw_if_index):
595 return self.api(self.papi.delete_loopback,
596 {'sw_if_index': sw_if_index, })
597
Klement Sekeraf62ae122016-10-11 11:47:09 +0200598 def ip_add_del_route(
599 self,
600 dst_address,
601 dst_address_length,
602 next_hop_address,
603 next_hop_sw_if_index=0xFFFFFFFF,
604 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200605 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000606 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200607 next_hop_n_out_labels=0,
608 next_hop_out_label_stack=[],
609 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200610 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000611 is_resolve_host=0,
612 is_resolve_attached=0,
613 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200614 is_add=1,
615 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200616 is_unreach=0,
617 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200618 is_ipv6=0,
619 is_local=0,
620 is_classify=0,
621 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000622 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200623 """
624
625 :param dst_address_length:
626 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
627 :param dst_address:
628 :param next_hop_address:
629 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
630 :param vrf_id: (Default value = 0)
631 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200632 :param classify_table_index: (Default value = 0xFFFFFFFF)
633 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200634 :param is_add: (Default value = 1)
635 :param is_drop: (Default value = 0)
636 :param is_ipv6: (Default value = 0)
637 :param is_local: (Default value = 0)
638 :param is_classify: (Default value = 0)
639 :param is_multipath: (Default value = 0)
640 :param is_resolve_host: (Default value = 0)
641 :param is_resolve_attached: (Default value = 0)
642 :param not_last: (Default value = 0)
643 :param next_hop_weight: (Default value = 1)
644
645 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000646
Klement Sekeraf62ae122016-10-11 11:47:09 +0200647 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100648 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200649 {'next_hop_sw_if_index': next_hop_sw_if_index,
650 'table_id': table_id,
651 'classify_table_index': classify_table_index,
652 'next_hop_table_id': next_hop_table_id,
653 'create_vrf_if_needed': create_vrf_if_needed,
654 'is_add': is_add,
655 'is_drop': is_drop,
656 'is_unreach': is_unreach,
657 'is_prohibit': is_prohibit,
658 'is_ipv6': is_ipv6,
659 'is_local': is_local,
660 'is_classify': is_classify,
661 'is_multipath': is_multipath,
662 'is_resolve_host': is_resolve_host,
663 'is_resolve_attached': is_resolve_attached,
664 'not_last': not_last,
665 'next_hop_weight': next_hop_weight,
666 'dst_address_length': dst_address_length,
667 'dst_address': dst_address,
668 'next_hop_address': next_hop_address,
669 'next_hop_n_out_labels': next_hop_n_out_labels,
670 'next_hop_via_label': next_hop_via_label,
671 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100672
Matej Klotton16a14cd2016-12-07 15:09:13 +0100673 def ip_fib_dump(self):
674 return self.api(self.papi.ip_fib_dump, {})
675
Jan Gelety057bb8c2016-12-20 17:32:45 +0100676 def ip6_fib_dump(self):
677 return self.api(self.papi.ip6_fib_dump, {})
678
Matej Klotton0178d522016-11-04 11:11:44 +0100679 def ip_neighbor_add_del(self,
680 sw_if_index,
681 mac_address,
682 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100683 is_add=1,
684 is_ipv6=0,
685 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800686 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100687 ):
688 """ Add neighbor MAC to IPv4 or IPv6 address.
689
690 :param sw_if_index:
691 :param mac_address:
692 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100693 :param is_add: (Default value = 1)
694 :param is_ipv6: (Default value = 0)
695 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800696 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100697 """
698
699 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100700 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800701 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200702 'is_add': is_add,
703 'is_ipv6': is_ipv6,
704 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800705 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200706 'mac_address': mac_address,
707 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100708 }
Matej Klotton0178d522016-11-04 11:11:44 +0100709 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100710
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800711 def ip_neighbor_dump(self,
712 sw_if_index,
713 is_ipv6=0):
714 """ Return IP neighbor dump.
715
716 :param sw_if_index:
717 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
718 """
719
720 return self.api(
721 self.papi.ip_neighbor_dump,
722 {'is_ipv6': is_ipv6,
723 'sw_if_index': sw_if_index
724 }
725 )
726
727 def proxy_arp_add_del(self,
728 low_address,
729 hi_address,
730 vrf_id=0,
731 is_add=1):
732 """ Config Proxy Arp Range.
733
734 :param low_address: Start address in the rnage to Proxy for
735 :param hi_address: End address in the rnage to Proxy for
736 :param vrf_id: The VRF/table in which to proxy
737 """
738
739 return self.api(
740 self.papi.proxy_arp_add_del,
741 {'vrf_id': vrf_id,
742 'is_add': is_add,
743 'low_address': low_address,
744 'hi_address': hi_address,
745 }
746 )
747
748 def proxy_arp_intfc_enable_disable(self,
749 sw_if_index,
750 is_enable=1):
751 """ Enable/Disable an interface for proxy ARP requests
752
753 :param sw_if_index: Interface
754 :param enable_disable: Enable/Disable
755 """
756
757 return self.api(
758 self.papi.proxy_arp_intfc_enable_disable,
759 {'sw_if_index': sw_if_index,
760 'enable_disable': is_enable
761 }
762 )
763
Jane546d3b2016-12-08 13:10:03 +0100764 def reset_vrf(self,
765 vrf_id,
766 is_ipv6=0,
767 ):
768 """ Reset VRF (remove all routes etc.) request.
769
770 :param int vrf_id: ID of the FIB table / VRF to reset.
771 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
772 """
773
774 return self.api(
775 self.papi.reset_vrf,
776 {'vrf_id': vrf_id,
777 'is_ipv6': is_ipv6,
778 }
779 )
780
781 def reset_fib(self,
782 vrf_id,
783 is_ipv6=0,
784 ):
785 """ Reset VRF (remove all routes etc.) request.
786
787 :param int vrf_id: ID of the FIB table / VRF to reset.
788 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
789 """
790
791 return self.api(
792 self.papi.reset_fib,
793 {'vrf_id': vrf_id,
794 'is_ipv6': is_ipv6,
795 }
796 )
797
798 def ip_dump(self,
799 is_ipv6=0,
800 ):
801 """ Return IP dump.
802
803 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
804 """
805
806 return self.api(
807 self.papi.ip_dump,
808 {'is_ipv6': is_ipv6,
809 }
810 )
811
Klement Sekera7bb873a2016-11-18 07:38:42 +0100812 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100813 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100814 """
815
816 :param sw_if_index_from:
817 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100818 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100819 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100820 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200821 {'sw_if_index_from': sw_if_index_from,
822 'sw_if_index_to': sw_if_index_to,
823 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000824
825 def gre_tunnel_add_del(self,
826 src_address,
827 dst_address,
828 outer_fib_id=0,
829 is_teb=0,
830 is_add=1,
831 is_ip6=0):
832 """ Add a GRE tunnel
833
834 :param src_address:
835 :param dst_address:
836 :param outer_fib_id: (Default value = 0)
837 :param is_add: (Default value = 1)
838 :param is_ipv6: (Default value = 0)
839 :param is_teb: (Default value = 0)
840 """
841
842 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100843 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200844 {'is_add': is_add,
845 'is_ipv6': is_ip6,
846 'teb': is_teb,
847 'src_address': src_address,
848 'dst_address': dst_address,
849 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000850 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000851
Neale Ranns5a8123b2017-01-26 01:18:23 -0800852 def mpls_fib_dump(self):
853 return self.api(self.papi.mpls_fib_dump, {})
854
Neale Rannsad422ed2016-11-02 14:20:04 +0000855 def mpls_route_add_del(
856 self,
857 label,
858 eos,
859 next_hop_proto_is_ip4,
860 next_hop_address,
861 next_hop_sw_if_index=0xFFFFFFFF,
862 table_id=0,
863 next_hop_table_id=0,
864 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200865 next_hop_n_out_labels=0,
866 next_hop_out_label_stack=[],
867 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000868 create_vrf_if_needed=0,
869 is_resolve_host=0,
870 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800871 is_interface_rx=0,
872 is_rpf_id=0,
873 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000874 is_add=1,
875 is_drop=0,
876 is_multipath=0,
877 classify_table_index=0xFFFFFFFF,
878 is_classify=0,
879 not_last=0):
880 """
881
882 :param dst_address_length:
883 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
884 :param dst_address:
885 :param next_hop_address:
886 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
887 :param vrf_id: (Default value = 0)
888 :param lookup_in_vrf: (Default value = 0)
889 :param classify_table_index: (Default value = 0xFFFFFFFF)
890 :param create_vrf_if_needed: (Default value = 0)
891 :param is_add: (Default value = 1)
892 :param is_drop: (Default value = 0)
893 :param is_ipv6: (Default value = 0)
894 :param is_local: (Default value = 0)
895 :param is_classify: (Default value = 0)
896 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800897 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000898 :param is_resolve_host: (Default value = 0)
899 :param is_resolve_attached: (Default value = 0)
900 :param not_last: (Default value = 0)
901 :param next_hop_weight: (Default value = 1)
902
903 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000904
905 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100906 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200907 {'mr_label': label,
908 'mr_eos': eos,
909 'mr_table_id': table_id,
910 'mr_classify_table_index': classify_table_index,
911 'mr_create_table_if_needed': create_vrf_if_needed,
912 'mr_is_add': is_add,
913 'mr_is_classify': is_classify,
914 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800915 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200916 'mr_is_resolve_host': is_resolve_host,
917 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800918 'mr_is_interface_rx': is_interface_rx,
919 'mr_is_rpf_id': is_rpf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200920 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
921 'mr_next_hop_weight': next_hop_weight,
922 'mr_next_hop': next_hop_address,
923 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
924 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
925 'mr_next_hop_table_id': next_hop_table_id,
926 'mr_next_hop_via_label': next_hop_via_label,
927 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000928
929 def mpls_ip_bind_unbind(
930 self,
931 label,
932 dst_address,
933 dst_address_length,
934 table_id=0,
935 ip_table_id=0,
936 is_ip4=1,
937 create_vrf_if_needed=0,
938 is_bind=1):
939 """
940 """
941 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100942 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200943 {'mb_mpls_table_id': table_id,
944 'mb_label': label,
945 'mb_ip_table_id': ip_table_id,
946 'mb_create_table_if_needed': create_vrf_if_needed,
947 'mb_is_bind': is_bind,
948 'mb_is_ip4': is_ip4,
949 'mb_address_length': dst_address_length,
950 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000951
952 def mpls_tunnel_add_del(
953 self,
954 tun_sw_if_index,
955 next_hop_proto_is_ip4,
956 next_hop_address,
957 next_hop_sw_if_index=0xFFFFFFFF,
958 next_hop_table_id=0,
959 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200960 next_hop_n_out_labels=0,
961 next_hop_out_label_stack=[],
962 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000963 create_vrf_if_needed=0,
964 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800965 l2_only=0,
966 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000967 """
968
969 :param dst_address_length:
970 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
971 :param dst_address:
972 :param next_hop_address:
973 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
974 :param vrf_id: (Default value = 0)
975 :param lookup_in_vrf: (Default value = 0)
976 :param classify_table_index: (Default value = 0xFFFFFFFF)
977 :param create_vrf_if_needed: (Default value = 0)
978 :param is_add: (Default value = 1)
979 :param is_drop: (Default value = 0)
980 :param is_ipv6: (Default value = 0)
981 :param is_local: (Default value = 0)
982 :param is_classify: (Default value = 0)
983 :param is_multipath: (Default value = 0)
984 :param is_resolve_host: (Default value = 0)
985 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000986 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800987 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000988
989 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000990 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100991 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200992 {'mt_sw_if_index': tun_sw_if_index,
993 'mt_is_add': is_add,
994 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800995 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200996 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
997 'mt_next_hop_weight': next_hop_weight,
998 'mt_next_hop': next_hop_address,
999 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1000 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1001 'mt_next_hop_table_id': next_hop_table_id,
1002 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001003
1004 def snat_interface_add_del_feature(
1005 self,
1006 sw_if_index,
1007 is_inside=1,
1008 is_add=1):
1009 """Enable/disable S-NAT feature on the interface
1010
1011 :param sw_if_index: Software index of the interface
1012 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1013 :param is_add: 1 if add, 0 if delete (Default value = 1)
1014 """
1015 return self.api(
1016 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001017 {'is_add': is_add,
1018 'is_inside': is_inside,
1019 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001020
1021 def snat_add_static_mapping(
1022 self,
1023 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001024 external_ip=0,
1025 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001026 local_port=0,
1027 external_port=0,
1028 addr_only=1,
1029 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001030 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -08001031 is_add=1,
1032 is_ip4=1):
1033 """Add/delete S-NAT static mapping
1034
1035 :param local_ip: Local IP address
1036 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001037 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001038 :param local_port: Local port number (Default value = 0)
1039 :param external_port: External port number (Default value = 0)
1040 :param addr_only: 1 if address only mapping, 0 if address and port
1041 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001042 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001043 :param is_add: 1 if add, 0 if delete (Default value = 1)
1044 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1045 """
1046 return self.api(
1047 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001048 {'is_add': is_add,
1049 'is_ip4': is_ip4,
1050 'addr_only': addr_only,
1051 'local_ip_address': local_ip,
1052 'external_ip_address': external_ip,
1053 'local_port': local_port,
1054 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001055 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001056 'vrf_id': vrf_id,
1057 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001058
1059 def snat_add_address_range(
1060 self,
1061 first_ip_address,
1062 last_ip_address,
1063 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001064 is_ip4=1,
1065 vrf_id=0xFFFFFFFF):
Matus Fabiande886752016-12-07 03:38:19 -08001066 """Add/del S-NAT address range
1067
1068 :param first_ip_address: First IP address
1069 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001070 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001071 :param is_add: 1 if add, 0 if delete (Default value = 1)
1072 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1073 """
1074 return self.api(
1075 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001076 {'is_ip4': is_ip4,
1077 'first_ip_address': first_ip_address,
1078 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001079 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001080 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001081
1082 def snat_address_dump(self):
1083 """Dump S-NAT addresses
1084 :return: Dictionary of S-NAT addresses
1085 """
1086 return self.api(self.papi.snat_address_dump, {})
1087
1088 def snat_interface_dump(self):
1089 """Dump interfaces with S-NAT feature
1090 :return: Dictionary of interfaces with S-NAT feature
1091 """
1092 return self.api(self.papi.snat_interface_dump, {})
1093
1094 def snat_static_mapping_dump(self):
1095 """Dump S-NAT static mappings
1096 :return: Dictionary of S-NAT static mappings
1097 """
1098 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001099
Matus Fabian9902fcd2016-12-21 23:58:46 -08001100 def snat_show_config(self):
1101 """Show S-NAT config
1102 :return: S-NAT config parameters
1103 """
1104 return self.api(self.papi.snat_show_config, {})
1105
Matus Fabian8bf68e82017-01-12 04:24:35 -08001106 def snat_add_interface_addr(
1107 self,
1108 sw_if_index,
1109 is_add=1):
1110 """Add/del S-NAT address from interface
1111
1112 :param sw_if_index: Software index of the interface
1113 :param is_add: 1 if add, 0 if delete (Default value = 1)
1114 """
1115 return self.api(self.papi.snat_add_del_interface_addr,
1116 {'is_add': is_add, 'sw_if_index': sw_if_index})
1117
1118 def snat_interface_addr_dump(self):
1119 """Dump S-NAT addresses interfaces
1120 :return: Dictionary of S-NAT addresses interfaces
1121 """
1122 return self.api(self.papi.snat_interface_addr_dump, {})
1123
Matus Fabianeea28d72017-01-13 04:15:54 -08001124 def snat_ipfix(
1125 self,
1126 domain_id=1,
1127 src_port=4739,
1128 enable=1):
1129 """Enable/disable S-NAT IPFIX logging
1130
1131 :param domain_id: Observation domain ID (Default value = 1)
1132 :param src_port: Source port number (Default value = 4739)
1133 :param enable: 1 if enable, 0 if disable (Default value = 1)
1134 """
1135 return self.api(
1136 self.papi.snat_ipfix_enable_disable,
1137 {'domain_id': domain_id,
1138 'src_port': src_port,
1139 'enable': enable})
1140
magalik23caa882017-02-08 23:25:45 -08001141 def snat_user_session_dump(
1142 self,
1143 ip_address,
Martin6b7fcda2017-03-08 03:31:02 -08001144 vrf_id,
1145 is_ip4=1):
magalik23caa882017-02-08 23:25:45 -08001146 """Dump S-NAT user's sessions
1147
1148 :param ip_address: ip adress of the user to be dumped
1149 :param cpu_index: cpu_index on which the user is
1150 :param vrf_id: VRF ID
1151 :return: Dictionary of S-NAT sessions
1152 """
1153 return self.api(
1154 self.papi.snat_user_session_dump,
1155 {'ip_address': ip_address,
Martin6b7fcda2017-03-08 03:31:02 -08001156 'vrf_id': vrf_id,
1157 'is_ip4': is_ip4})
magalik23caa882017-02-08 23:25:45 -08001158
1159 def snat_user_dump(self):
1160 """Dump S-NAT users
1161
1162 :return: Dictionary of S-NAT users
1163 """
1164 return self.api(self.papi.snat_user_dump, {})
1165
Matus Fabian066f0342017-02-10 03:48:01 -08001166 def snat_add_det_map(
1167 self,
1168 in_addr,
1169 in_plen,
1170 out_addr,
1171 out_plen,
1172 is_add=1):
1173 """Add/delete S-NAT deterministic mapping
1174
1175 :param is_add - 1 if add, 0 if delete
1176 :param in_addr - inside IP address
1177 :param in_plen - inside IP address prefix length
1178 :param out_addr - outside IP address
1179 :param out_plen - outside IP address prefix length
1180 """
1181 return self.api(
1182 self.papi.snat_add_det_map,
1183 {'is_add': is_add,
1184 'in_addr': in_addr,
1185 'in_plen': in_plen,
1186 'out_addr': out_addr,
1187 'out_plen': out_plen})
1188
1189 def snat_det_forward(
1190 self,
1191 in_addr):
1192 """Get outside address and port range from inside address
1193
1194 :param in_addr - inside IP address
1195 """
1196 return self.api(
1197 self.papi.snat_det_forward,
1198 {'in_addr': in_addr})
1199
1200 def snat_det_reverse(
1201 self,
1202 out_addr,
1203 out_port):
1204 """Get inside address from outside address and port
1205
1206 :param out_addr - outside IP address
1207 :param out_port - outside port
1208 """
1209 return self.api(
1210 self.papi.snat_det_reverse,
1211 {'out_addr': out_addr,
1212 'out_port': out_port})
1213
Martin17a75cb2017-03-08 05:53:20 -08001214 def snat_det_map_dump(self):
1215 """Dump S-NAT deterministic mappings
1216
1217 :return: Dictionary of S-NAT deterministic mappings
1218 """
1219 return self.api(self.papi.snat_det_map_dump, {})
1220
Matus Fabian6a0946f2017-04-12 03:36:13 -07001221 def snat_det_set_timeouts(
1222 self,
1223 udp=300,
1224 tcp_established=7440,
1225 tcp_transitory=240,
1226 icmp=60):
1227 """Set values of timeouts for deterministic NAT (in seconds)
1228
1229 :param udp - UDP timeout (Default value = 300)
1230 :param tcp_established - TCP established timeout (Default value = 7440)
1231 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1232 :param icmp - ICMP timeout (Default value = 60)
1233 """
1234 return self.api(
1235 self.papi.snat_det_set_timeouts,
1236 {'udp': udp,
1237 'tcp_established': tcp_established,
1238 'tcp_transitory': tcp_transitory,
1239 'icmp': icmp})
1240
1241 def snat_det_get_timeouts(self):
1242 """Get values of timeouts for deterministic NAT
1243
1244 :return: Timeouts for deterministic NAT (in seconds)
1245 """
1246 return self.api(self.papi.snat_det_get_timeouts, {})
1247
Martin Gálik6bc8c642017-04-19 01:12:27 -07001248 def snat_det_close_session_out(
1249 self,
1250 out_addr,
1251 out_port,
1252 ext_addr,
1253 ext_port,
1254 is_ip4=1):
1255 """Close CGN session using outside address and port
1256
1257 :param out_addr - outside IP address
1258 :param out_port - outside port
1259 :param ext_addr - external host IP address
1260 :param ext_port - external host port
1261 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1262 """
1263 return self.api(
1264 self.papi.snat_det_close_session_out,
1265 {'out_addr': out_addr,
1266 'out_port': out_port,
1267 'ext_addr': ext_addr,
1268 'ext_port': ext_port,
1269 'is_ip4': is_ip4})
1270
1271 def snat_det_close_session_in(
1272 self,
1273 in_addr,
1274 in_port,
1275 ext_addr,
1276 ext_port,
1277 is_ip4=1):
1278 """Close CGN session using inside address and port
1279
1280 :param in_addr - inside IP address
1281 :param in_port - inside port
1282 :param ext_addr - external host IP address
1283 :param ext_port - external host port
1284 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1285 """
1286 return self.api(
1287 self.papi.snat_det_close_session_in,
1288 {'in_addr': in_addr,
1289 'in_port': in_port,
1290 'ext_addr': ext_addr,
1291 'ext_port': ext_port,
1292 'is_ip4': is_ip4})
1293
Martin Gálik9806eae2017-04-25 01:25:08 -07001294 def snat_det_session_dump(
1295 self,
1296 user_addr,
1297 is_ip4=1):
1298 """Dump S-NAT deterministic sessions belonging to a user
1299
1300 :param user_addr - inside IP address of the user
1301 :param is_ip4: - 1 if address type is IPv4 (Default value = 1)
1302 :return: Dictionary of S-NAT deterministic sessions
1303 """
1304 return self.api(
1305 self.papi.snat_det_session_dump,
1306 {'is_ip4': is_ip4,
1307 'user_addr': user_addr})
1308
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001309 def control_ping(self):
1310 self.api(self.papi.control_ping)
1311
1312 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001313 detect_mult, local_addr, peer_addr, is_ipv6=0,
1314 bfd_key_id=None, conf_key_id=None):
1315 if bfd_key_id is None:
1316 return self.api(self.papi.bfd_udp_add,
1317 {
1318 'sw_if_index': sw_if_index,
1319 'desired_min_tx': desired_min_tx,
1320 'required_min_rx': required_min_rx,
1321 'local_addr': local_addr,
1322 'peer_addr': peer_addr,
1323 'is_ipv6': is_ipv6,
1324 'detect_mult': detect_mult,
1325 })
1326 else:
1327 return self.api(self.papi.bfd_udp_add,
1328 {
1329 'sw_if_index': sw_if_index,
1330 'desired_min_tx': desired_min_tx,
1331 'required_min_rx': required_min_rx,
1332 'local_addr': local_addr,
1333 'peer_addr': peer_addr,
1334 'is_ipv6': is_ipv6,
1335 'detect_mult': detect_mult,
1336 'is_authenticated': 1,
1337 'bfd_key_id': bfd_key_id,
1338 'conf_key_id': conf_key_id,
1339 })
1340
Klement Sekeraa57a9702017-02-02 06:58:07 +01001341 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1342 detect_mult, local_addr, peer_addr, is_ipv6=0):
1343 return self.api(self.papi.bfd_udp_mod,
1344 {
1345 'sw_if_index': sw_if_index,
1346 'desired_min_tx': desired_min_tx,
1347 'required_min_rx': required_min_rx,
1348 'local_addr': local_addr,
1349 'peer_addr': peer_addr,
1350 'is_ipv6': is_ipv6,
1351 'detect_mult': detect_mult,
1352 })
1353
Klement Sekerab17dd962017-01-09 07:43:48 +01001354 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1355 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1356 is_delayed=False):
1357 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001358 {
1359 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001360 'local_addr': local_addr,
1361 'peer_addr': peer_addr,
1362 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001363 'is_delayed': 1 if is_delayed else 0,
1364 'bfd_key_id': bfd_key_id,
1365 'conf_key_id': conf_key_id,
1366 })
1367
1368 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1369 is_ipv6=0, is_delayed=False):
1370 return self.api(self.papi.bfd_udp_auth_deactivate,
1371 {
1372 'sw_if_index': sw_if_index,
1373 'local_addr': local_addr,
1374 'peer_addr': peer_addr,
1375 'is_ipv6': is_ipv6,
1376 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001377 })
1378
1379 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1380 return self.api(self.papi.bfd_udp_del,
1381 {
1382 'sw_if_index': sw_if_index,
1383 'local_addr': local_addr,
1384 'peer_addr': peer_addr,
1385 'is_ipv6': is_ipv6,
1386 })
1387
1388 def bfd_udp_session_dump(self):
1389 return self.api(self.papi.bfd_udp_session_dump, {})
1390
Klement Sekerab17dd962017-01-09 07:43:48 +01001391 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1392 peer_addr, is_ipv6=0):
1393 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001394 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001395 'sw_if_index': sw_if_index,
1396 'local_addr': local_addr,
1397 'peer_addr': peer_addr,
1398 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001399 })
1400
1401 def want_bfd_events(self, enable_disable=1):
1402 return self.api(self.papi.want_bfd_events, {
1403 'enable_disable': enable_disable,
1404 'pid': os.getpid(),
1405 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001406
Klement Sekerab17dd962017-01-09 07:43:48 +01001407 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1408 return self.api(self.papi.bfd_auth_set_key, {
1409 'conf_key_id': conf_key_id,
1410 'auth_type': auth_type,
1411 'key': key,
1412 'key_len': len(key),
1413 })
1414
1415 def bfd_auth_del_key(self, conf_key_id):
1416 return self.api(self.papi.bfd_auth_del_key, {
1417 'conf_key_id': conf_key_id,
1418 })
1419
1420 def bfd_auth_keys_dump(self):
1421 return self.api(self.papi.bfd_auth_keys_dump, {})
1422
Klement Sekera239790f2017-02-16 10:53:53 +01001423 def bfd_udp_set_echo_source(self, sw_if_index):
1424 return self.api(self.papi.bfd_udp_set_echo_source,
1425 {'sw_if_index': sw_if_index})
1426
Klement Sekera73884482017-02-23 09:26:30 +01001427 def bfd_udp_del_echo_source(self):
1428 return self.api(self.papi.bfd_udp_del_echo_source, {})
1429
Steve Shin7957d6e2016-12-19 09:24:50 -08001430 def classify_add_del_table(
1431 self,
1432 is_add,
1433 mask,
1434 match_n_vectors=1,
1435 table_index=0xFFFFFFFF,
1436 nbuckets=2,
1437 memory_size=2097152,
1438 skip_n_vectors=0,
1439 next_table_index=0xFFFFFFFF,
1440 miss_next_index=0xFFFFFFFF,
1441 current_data_flag=0,
1442 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001443 """
1444 :param is_add:
1445 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001446 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001447 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001448 :param nbuckets: (Default value = 2)
1449 :param memory_size: (Default value = 2097152)
1450 :param skip_n_vectors: (Default value = 0)
1451 :param next_table_index: (Default value = 0xFFFFFFFF)
1452 :param miss_next_index: (Default value = 0xFFFFFFFF)
1453 :param current_data_flag: (Default value = 0)
1454 :param current_data_offset: (Default value = 0)
1455 """
1456
1457 return self.api(
1458 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001459 {'is_add': is_add,
1460 'table_index': table_index,
1461 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001462 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001463 'skip_n_vectors': skip_n_vectors,
1464 'match_n_vectors': match_n_vectors,
1465 'next_table_index': next_table_index,
1466 'miss_next_index': miss_next_index,
1467 'current_data_flag': current_data_flag,
1468 'current_data_offset': current_data_offset,
1469 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001470
1471 def classify_add_del_session(
1472 self,
1473 is_add,
1474 table_index,
1475 match,
1476 opaque_index=0xFFFFFFFF,
1477 hit_next_index=0xFFFFFFFF,
1478 advance=0,
1479 action=0,
1480 metadata=0):
1481 """
1482 :param is_add:
1483 :param table_index:
1484 :param match:
1485 :param opaque_index: (Default value = 0xFFFFFFFF)
1486 :param hit_next_index: (Default value = 0xFFFFFFFF)
1487 :param advance: (Default value = 0)
1488 :param action: (Default value = 0)
1489 :param metadata: (Default value = 0)
1490 """
1491
1492 return self.api(
1493 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001494 {'is_add': is_add,
1495 'table_index': table_index,
1496 'hit_next_index': hit_next_index,
1497 'opaque_index': opaque_index,
1498 'advance': advance,
1499 'action': action,
1500 'metadata': metadata,
1501 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001502
1503 def input_acl_set_interface(
1504 self,
1505 is_add,
1506 sw_if_index,
1507 ip4_table_index=0xFFFFFFFF,
1508 ip6_table_index=0xFFFFFFFF,
1509 l2_table_index=0xFFFFFFFF):
1510 """
1511 :param is_add:
1512 :param sw_if_index:
1513 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1514 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1515 :param l2_table_index: (Default value = 0xFFFFFFFF)
1516 """
1517
1518 return self.api(
1519 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001520 {'sw_if_index': sw_if_index,
1521 'ip4_table_index': ip4_table_index,
1522 'ip6_table_index': ip6_table_index,
1523 'l2_table_index': l2_table_index,
1524 'is_add': is_add})
1525
1526 def set_ipfix_exporter(
1527 self,
1528 collector_address,
1529 src_address,
1530 path_mtu,
1531 template_interval,
1532 vrf_id=0,
1533 collector_port=4739,
1534 udp_checksum=0):
1535 return self.api(
1536 self.papi.set_ipfix_exporter,
1537 {
1538 'collector_address': collector_address,
1539 'collector_port': collector_port,
1540 'src_address': src_address,
1541 'vrf_id': vrf_id,
1542 'path_mtu': path_mtu,
1543 'template_interval': template_interval,
1544 'udp_checksum': udp_checksum,
1545 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001546
1547 def dhcp_proxy_config(self,
1548 dhcp_server,
1549 dhcp_src_address,
1550 rx_table_id=0,
1551 server_table_id=0,
1552 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001553 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001554 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001555 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001556 {
1557 'rx_vrf_id': rx_table_id,
1558 'server_vrf_id': server_table_id,
1559 'is_ipv6': is_ipv6,
1560 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001561 'dhcp_server': dhcp_server,
1562 'dhcp_src_address': dhcp_src_address,
1563 })
1564
1565 def dhcp_proxy_set_vss(self,
1566 table_id,
1567 fib_id,
1568 oui,
1569 is_add=1,
1570 is_ip6=0):
1571 return self.api(
1572 self.papi.dhcp_proxy_set_vss,
1573 {
1574 'tbl_id': table_id,
1575 'fib_id': fib_id,
1576 'is_ipv6': is_ip6,
1577 'is_add': is_add,
1578 'oui': oui,
1579 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001580
1581 def ip_mroute_add_del(self,
1582 src_address,
1583 grp_address,
1584 grp_address_length,
1585 e_flags,
1586 next_hop_sw_if_index,
1587 i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001588 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001589 table_id=0,
1590 create_vrf_if_needed=0,
1591 is_add=1,
1592 is_ipv6=0,
1593 is_local=0):
1594 """
1595 """
1596 return self.api(
1597 self.papi.ip_mroute_add_del,
1598 {'next_hop_sw_if_index': next_hop_sw_if_index,
1599 'entry_flags': e_flags,
1600 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001601 'table_id': table_id,
1602 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001603 'create_vrf_if_needed': create_vrf_if_needed,
1604 'is_add': is_add,
1605 'is_ipv6': is_ipv6,
1606 'is_local': is_local,
1607 'grp_address_length': grp_address_length,
1608 'grp_address': grp_address,
1609 'src_address': src_address})
1610
1611 def mfib_signal_dump(self):
1612 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001613
1614 def ip_mfib_dump(self):
1615 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001616
1617 def lisp_enable_disable(self, is_enabled):
1618 return self.api(
1619 self.papi.lisp_enable_disable,
1620 {
1621 'is_en': is_enabled,
1622 })
1623
1624 def lisp_locator_set(self,
1625 ls_name,
1626 is_add=1):
1627 return self.api(
1628 self.papi.lisp_add_del_locator_set,
1629 {
1630 'is_add': is_add,
1631 'locator_set_name': ls_name
1632 })
1633
1634 def lisp_locator_set_dump(self):
1635 return self.api(self.papi.lisp_locator_set_dump, {})
1636
1637 def lisp_locator(self,
1638 ls_name,
1639 sw_if_index,
1640 priority=1,
1641 weight=1,
1642 is_add=1):
1643 return self.api(
1644 self.papi.lisp_add_del_locator,
1645 {
1646 'is_add': is_add,
1647 'locator_set_name': ls_name,
1648 'sw_if_index': sw_if_index,
1649 'priority': priority,
1650 'weight': weight
1651 })
1652
1653 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1654 return self.api(
1655 self.papi.lisp_locator_dump,
1656 {
1657 'is_index_set': is_index_set,
1658 'ls_name': ls_name,
1659 'ls_index': ls_index,
1660 })
1661
1662 def lisp_local_mapping(self,
1663 ls_name,
1664 eid_type,
1665 eid,
1666 prefix_len,
1667 vni=0,
1668 key_id=0,
1669 key="",
1670 is_add=1):
1671 return self.api(
1672 self.papi.lisp_add_del_local_eid,
1673 {
1674 'locator_set_name': ls_name,
1675 'is_add': is_add,
1676 'eid_type': eid_type,
1677 'eid': eid,
1678 'prefix_len': prefix_len,
1679 'vni': vni,
1680 'key_id': key_id,
1681 'key': key
1682 })
1683
1684 def lisp_eid_table_dump(self,
1685 eid_set=0,
1686 prefix_length=0,
1687 vni=0,
1688 eid_type=0,
1689 eid=None,
1690 filter_opt=0):
1691 return self.api(
1692 self.papi.lisp_eid_table_dump,
1693 {
1694 'eid_set': eid_set,
1695 'prefix_length': prefix_length,
1696 'vni': vni,
1697 'eid_type': eid_type,
1698 'eid': eid,
1699 'filter': filter_opt,
1700 })
1701
1702 def lisp_remote_mapping(self,
1703 eid_type,
1704 eid,
1705 eid_prefix_len=0,
1706 vni=0,
1707 rlocs=None,
1708 rlocs_num=0,
1709 is_src_dst=0,
1710 is_add=1):
1711 return self.api(
1712 self.papi.lisp_add_del_remote_mapping,
1713 {
1714 'is_add': is_add,
1715 'eid_type': eid_type,
1716 'eid': eid,
1717 'eid_len': eid_prefix_len,
1718 'rloc_num': rlocs_num,
1719 'rlocs': rlocs,
1720 'vni': vni,
1721 'is_src_dst': is_src_dst,
1722 })
1723
1724 def lisp_adjacency(self,
1725 leid,
1726 reid,
1727 leid_len,
1728 reid_len,
1729 eid_type,
1730 is_add=1,
1731 vni=0):
1732 return self.api(
1733 self.papi.lisp_add_del_adjacency,
1734 {
1735 'is_add': is_add,
1736 'vni': vni,
1737 'eid_type': eid_type,
1738 'leid': leid,
1739 'reid': reid,
1740 'leid_len': leid_len,
1741 'reid_len': reid_len,
1742 })
1743
1744 def lisp_adjacencies_get(self, vni=0):
1745 return self.api(
1746 self.papi.lisp_adjacencies_get,
1747 {
1748 'vni': vni
1749 })
Neale Ranns80823802017-02-20 18:23:41 -08001750
1751 def map_add_domain(self,
1752 ip6_prefix,
1753 ip6_prefix_len,
1754 ip6_src,
1755 ip6_src_prefix_len,
1756 ip4_prefix,
1757 ip4_prefix_len,
1758 ea_bits_len=0,
1759 psid_offset=0,
1760 psid_length=0,
1761 is_translation=0,
1762 mtu=1280):
1763 return self.api(
1764 self.papi.map_add_domain,
1765 {
1766 'ip6_prefix': ip6_prefix,
1767 'ip6_prefix_len': ip6_prefix_len,
1768 'ip4_prefix': ip4_prefix,
1769 'ip4_prefix_len': ip4_prefix_len,
1770 'ip6_src': ip6_src,
1771 'ip6_src_prefix_len': ip6_src_prefix_len,
1772 'ea_bits_len': ea_bits_len,
1773 'psid_offset': psid_offset,
1774 'psid_length': psid_length,
1775 'is_translation': is_translation,
1776 'mtu': mtu
1777 })