blob: b8a7a47004361b6528338bd4e5f996f36d8580a8 [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
Eyal Bari93b503e2017-05-15 10:13:15 +0300431 def l2fib_flush_int(self, sw_if_index):
432 """Flush L2 FIB entries for sw_if_index.
433
434 :param int sw_if_index: Software interface index of the interface.
435 """
436 return self.api(self.papi.l2fib_flush_int,
437 {'sw_if_index': sw_if_index})
438
439 def l2fib_flush_bd(self, bd_id):
440 """Flush L2 FIB entries for bd_id.
441
442 :param int sw_if_index: Bridge Domain id.
443 """
444 return self.api(self.papi.l2fib_flush_bd,
445 {'bd_id': bd_id})
446
447 def l2fib_flush_all(self):
448 """Flush all L2 FIB.
449 """
450 return self.api(self.papi.l2fib_flush_all, {})
451
Klement Sekeraf62ae122016-10-11 11:47:09 +0200452 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
453 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100454 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200455
Jan4af521d2016-11-15 17:05:00 +0100456 :param int sw_if_index: Software interface index of the interface.
457 :param int bd_id: Bridge domain index.
458 :param int shg: Split-horizon group index. (Default value = 0)
459 :param int bvi: Set interface as a bridge group virtual interface.
460 (Default value = 0)
461 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200462 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100463 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200464 {'rx_sw_if_index': sw_if_index,
465 'bd_id': bd_id,
466 'shg': shg,
467 'bvi': bvi,
468 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200469
Jan00dad122016-11-29 10:04:53 +0100470 def bridge_flags(self, bd_id, is_set, feature_bitmap):
471 """Enable/disable required feature of the bridge domain with defined ID.
472
473 :param int bd_id: Bridge domain ID.
474 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
475 :param int feature_bitmap: Bitmap value of the feature to be set:
476 - learn (1 << 0),
477 - forward (1 << 1),
478 - flood (1 << 2),
479 - uu-flood (1 << 3) or
480 - arp-term (1 << 4).
481 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100482 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200483 {'bd_id': bd_id,
484 'is_set': is_set,
485 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100486
487 def bridge_domain_dump(self, bd_id=0):
488 """
489
490 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
491 existing bridge domains returned)
492 :return: Dictionary of bridge domain(s) data.
493 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100494 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200495 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100496
Klement Sekeraf62ae122016-10-11 11:47:09 +0200497 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
498 enable):
499 """Create or delete unidirectional cross-connect from Tx interface to
500 Rx interface.
501
Jan4af521d2016-11-15 17:05:00 +0100502 :param int rx_sw_if_index: Software interface index of Rx interface.
503 :param int tx_sw_if_index: Software interface index of Tx interface.
504 :param int enable: Create cross-connect if equal to 1, delete
505 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200506
507 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100508 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200509 {'rx_sw_if_index': rx_sw_if_index,
510 'tx_sw_if_index': tx_sw_if_index,
511 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200512
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200513 def sw_interface_set_l2_tag_rewrite(
514 self,
515 sw_if_index,
516 vtr_oper,
517 push=0,
518 tag1=0,
519 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000520 """L2 interface vlan tag rewrite configure request
521 :param client_index - opaque cookie to identify the sender
522 :param context - sender context, to match reply w/ request
523 :param sw_if_index - interface the operation is applied to
524 :param vtr_op - Choose from l2_vtr_op_t enum values
525 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
526 :param tag1 - Needed for any push or translate vtr op
527 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
528
529 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100530 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200531 {'sw_if_index': sw_if_index,
532 'vtr_op': vtr_oper,
533 'push_dot1q': push,
534 'tag1': tag1,
535 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000536
Klement Sekeraf62ae122016-10-11 11:47:09 +0200537 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
538 link_up_down=0, deleted=0):
539 """
540
541 :param admin_up_down:
542 :param sw_if_index:
543 :param link_up_down: (Default value = 0)
544 :param deleted: (Default value = 0)
545
546 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100547 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200548 {'sw_if_index': sw_if_index,
549 'admin_up_down': admin_up_down,
550 'link_up_down': link_up_down,
551 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200552
553 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
554 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
555 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
556 """Create subinterface
557 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
558
559 :param sub_id: param inner_vlan:
560 :param sw_if_index:
561 :param outer_vlan:
562 :param inner_vlan:
563 :param no_tags: (Default value = 0)
564 :param one_tag: (Default value = 0)
565 :param two_tags: (Default value = 0)
566 :param dot1ad: (Default value = 0)
567 :param exact_match: (Default value = 0)
568 :param default_sub: (Default value = 0)
569 :param outer_vlan_id_any: (Default value = 0)
570 :param inner_vlan_id_any: (Default value = 0)
571
572 """
573 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100574 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200575 {'sw_if_index': sw_if_index,
576 'sub_id': sub_id,
577 'no_tags': no_tags,
578 'one_tag': one_tag,
579 'two_tags': two_tags,
580 'dot1ad': dot1ad,
581 'exact_match': exact_match,
582 'default_sub': default_sub,
583 'outer_vlan_id_any': outer_vlan_id_any,
584 'inner_vlan_id_any': inner_vlan_id_any,
585 'outer_vlan_id': outer_vlan,
586 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200587
Neale Ranns177bbdc2016-11-15 09:46:51 +0000588 def delete_subif(self, sw_if_index):
589 """Delete subinterface
590
591 :param sw_if_index:
592 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100593 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200594 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000595
Klement Sekeraf62ae122016-10-11 11:47:09 +0200596 def create_vlan_subif(self, sw_if_index, vlan):
597 """
598
599 :param vlan:
600 :param sw_if_index:
601
602 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100603 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200604 {'sw_if_index': sw_if_index,
605 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200606
Matej Klotton0178d522016-11-04 11:11:44 +0100607 def create_loopback(self, mac=''):
608 """
609
610 :param mac: (Optional)
611 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100612 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200613 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100614
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100615 def delete_loopback(self, sw_if_index):
616 return self.api(self.papi.delete_loopback,
617 {'sw_if_index': sw_if_index, })
618
Klement Sekeraf62ae122016-10-11 11:47:09 +0200619 def ip_add_del_route(
620 self,
621 dst_address,
622 dst_address_length,
623 next_hop_address,
624 next_hop_sw_if_index=0xFFFFFFFF,
625 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200626 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000627 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200628 next_hop_n_out_labels=0,
629 next_hop_out_label_stack=[],
630 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200631 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000632 is_resolve_host=0,
633 is_resolve_attached=0,
634 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200635 is_add=1,
636 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200637 is_unreach=0,
638 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200639 is_ipv6=0,
640 is_local=0,
641 is_classify=0,
642 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000643 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200644 """
645
646 :param dst_address_length:
647 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
648 :param dst_address:
649 :param next_hop_address:
650 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
651 :param vrf_id: (Default value = 0)
652 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200653 :param classify_table_index: (Default value = 0xFFFFFFFF)
654 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200655 :param is_add: (Default value = 1)
656 :param is_drop: (Default value = 0)
657 :param is_ipv6: (Default value = 0)
658 :param is_local: (Default value = 0)
659 :param is_classify: (Default value = 0)
660 :param is_multipath: (Default value = 0)
661 :param is_resolve_host: (Default value = 0)
662 :param is_resolve_attached: (Default value = 0)
663 :param not_last: (Default value = 0)
664 :param next_hop_weight: (Default value = 1)
665
666 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000667
Klement Sekeraf62ae122016-10-11 11:47:09 +0200668 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100669 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200670 {'next_hop_sw_if_index': next_hop_sw_if_index,
671 'table_id': table_id,
672 'classify_table_index': classify_table_index,
673 'next_hop_table_id': next_hop_table_id,
674 'create_vrf_if_needed': create_vrf_if_needed,
675 'is_add': is_add,
676 'is_drop': is_drop,
677 'is_unreach': is_unreach,
678 'is_prohibit': is_prohibit,
679 'is_ipv6': is_ipv6,
680 'is_local': is_local,
681 'is_classify': is_classify,
682 'is_multipath': is_multipath,
683 'is_resolve_host': is_resolve_host,
684 'is_resolve_attached': is_resolve_attached,
685 'not_last': not_last,
686 'next_hop_weight': next_hop_weight,
687 'dst_address_length': dst_address_length,
688 'dst_address': dst_address,
689 'next_hop_address': next_hop_address,
690 'next_hop_n_out_labels': next_hop_n_out_labels,
691 'next_hop_via_label': next_hop_via_label,
692 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100693
Matej Klotton16a14cd2016-12-07 15:09:13 +0100694 def ip_fib_dump(self):
695 return self.api(self.papi.ip_fib_dump, {})
696
Jan Gelety057bb8c2016-12-20 17:32:45 +0100697 def ip6_fib_dump(self):
698 return self.api(self.papi.ip6_fib_dump, {})
699
Matej Klotton0178d522016-11-04 11:11:44 +0100700 def ip_neighbor_add_del(self,
701 sw_if_index,
702 mac_address,
703 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100704 is_add=1,
705 is_ipv6=0,
706 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800707 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100708 ):
709 """ Add neighbor MAC to IPv4 or IPv6 address.
710
711 :param sw_if_index:
712 :param mac_address:
713 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100714 :param is_add: (Default value = 1)
715 :param is_ipv6: (Default value = 0)
716 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800717 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100718 """
719
720 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100721 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800722 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200723 'is_add': is_add,
724 'is_ipv6': is_ipv6,
725 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800726 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200727 'mac_address': mac_address,
728 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100729 }
Matej Klotton0178d522016-11-04 11:11:44 +0100730 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100731
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800732 def ip_neighbor_dump(self,
733 sw_if_index,
734 is_ipv6=0):
735 """ Return IP neighbor dump.
736
737 :param sw_if_index:
738 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
739 """
740
741 return self.api(
742 self.papi.ip_neighbor_dump,
743 {'is_ipv6': is_ipv6,
744 'sw_if_index': sw_if_index
745 }
746 )
747
748 def proxy_arp_add_del(self,
749 low_address,
750 hi_address,
751 vrf_id=0,
752 is_add=1):
753 """ Config Proxy Arp Range.
754
755 :param low_address: Start address in the rnage to Proxy for
756 :param hi_address: End address in the rnage to Proxy for
757 :param vrf_id: The VRF/table in which to proxy
758 """
759
760 return self.api(
761 self.papi.proxy_arp_add_del,
762 {'vrf_id': vrf_id,
763 'is_add': is_add,
764 'low_address': low_address,
765 'hi_address': hi_address,
766 }
767 )
768
769 def proxy_arp_intfc_enable_disable(self,
770 sw_if_index,
771 is_enable=1):
772 """ Enable/Disable an interface for proxy ARP requests
773
774 :param sw_if_index: Interface
775 :param enable_disable: Enable/Disable
776 """
777
778 return self.api(
779 self.papi.proxy_arp_intfc_enable_disable,
780 {'sw_if_index': sw_if_index,
781 'enable_disable': is_enable
782 }
783 )
784
Jane546d3b2016-12-08 13:10:03 +0100785 def reset_vrf(self,
786 vrf_id,
787 is_ipv6=0,
788 ):
789 """ Reset VRF (remove all routes etc.) request.
790
791 :param int vrf_id: ID of the FIB table / VRF to reset.
792 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
793 """
794
795 return self.api(
796 self.papi.reset_vrf,
797 {'vrf_id': vrf_id,
798 'is_ipv6': is_ipv6,
799 }
800 )
801
802 def reset_fib(self,
803 vrf_id,
804 is_ipv6=0,
805 ):
806 """ Reset VRF (remove all routes etc.) request.
807
808 :param int vrf_id: ID of the FIB table / VRF to reset.
809 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
810 """
811
812 return self.api(
813 self.papi.reset_fib,
814 {'vrf_id': vrf_id,
815 'is_ipv6': is_ipv6,
816 }
817 )
818
819 def ip_dump(self,
820 is_ipv6=0,
821 ):
822 """ Return IP dump.
823
824 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
825 """
826
827 return self.api(
828 self.papi.ip_dump,
829 {'is_ipv6': is_ipv6,
830 }
831 )
832
Klement Sekera7bb873a2016-11-18 07:38:42 +0100833 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100834 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100835 """
836
837 :param sw_if_index_from:
838 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100839 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100840 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100841 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200842 {'sw_if_index_from': sw_if_index_from,
843 'sw_if_index_to': sw_if_index_to,
844 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000845
846 def gre_tunnel_add_del(self,
847 src_address,
848 dst_address,
849 outer_fib_id=0,
850 is_teb=0,
851 is_add=1,
852 is_ip6=0):
853 """ Add a GRE tunnel
854
855 :param src_address:
856 :param dst_address:
857 :param outer_fib_id: (Default value = 0)
858 :param is_add: (Default value = 1)
859 :param is_ipv6: (Default value = 0)
860 :param is_teb: (Default value = 0)
861 """
862
863 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100864 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200865 {'is_add': is_add,
866 'is_ipv6': is_ip6,
867 'teb': is_teb,
868 'src_address': src_address,
869 'dst_address': dst_address,
870 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000871 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000872
Neale Ranns5a8123b2017-01-26 01:18:23 -0800873 def mpls_fib_dump(self):
874 return self.api(self.papi.mpls_fib_dump, {})
875
Neale Rannsad422ed2016-11-02 14:20:04 +0000876 def mpls_route_add_del(
877 self,
878 label,
879 eos,
880 next_hop_proto_is_ip4,
881 next_hop_address,
882 next_hop_sw_if_index=0xFFFFFFFF,
883 table_id=0,
884 next_hop_table_id=0,
885 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200886 next_hop_n_out_labels=0,
887 next_hop_out_label_stack=[],
888 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000889 create_vrf_if_needed=0,
890 is_resolve_host=0,
891 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800892 is_interface_rx=0,
893 is_rpf_id=0,
894 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000895 is_add=1,
896 is_drop=0,
897 is_multipath=0,
898 classify_table_index=0xFFFFFFFF,
899 is_classify=0,
900 not_last=0):
901 """
902
903 :param dst_address_length:
904 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
905 :param dst_address:
906 :param next_hop_address:
907 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
908 :param vrf_id: (Default value = 0)
909 :param lookup_in_vrf: (Default value = 0)
910 :param classify_table_index: (Default value = 0xFFFFFFFF)
911 :param create_vrf_if_needed: (Default value = 0)
912 :param is_add: (Default value = 1)
913 :param is_drop: (Default value = 0)
914 :param is_ipv6: (Default value = 0)
915 :param is_local: (Default value = 0)
916 :param is_classify: (Default value = 0)
917 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800918 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000919 :param is_resolve_host: (Default value = 0)
920 :param is_resolve_attached: (Default value = 0)
921 :param not_last: (Default value = 0)
922 :param next_hop_weight: (Default value = 1)
923
924 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000925
926 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100927 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200928 {'mr_label': label,
929 'mr_eos': eos,
930 'mr_table_id': table_id,
931 'mr_classify_table_index': classify_table_index,
932 'mr_create_table_if_needed': create_vrf_if_needed,
933 'mr_is_add': is_add,
934 'mr_is_classify': is_classify,
935 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800936 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200937 'mr_is_resolve_host': is_resolve_host,
938 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800939 'mr_is_interface_rx': is_interface_rx,
940 'mr_is_rpf_id': is_rpf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200941 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
942 'mr_next_hop_weight': next_hop_weight,
943 'mr_next_hop': next_hop_address,
944 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
945 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
946 'mr_next_hop_table_id': next_hop_table_id,
947 'mr_next_hop_via_label': next_hop_via_label,
948 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000949
950 def mpls_ip_bind_unbind(
951 self,
952 label,
953 dst_address,
954 dst_address_length,
955 table_id=0,
956 ip_table_id=0,
957 is_ip4=1,
958 create_vrf_if_needed=0,
959 is_bind=1):
960 """
961 """
962 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100963 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200964 {'mb_mpls_table_id': table_id,
965 'mb_label': label,
966 'mb_ip_table_id': ip_table_id,
967 'mb_create_table_if_needed': create_vrf_if_needed,
968 'mb_is_bind': is_bind,
969 'mb_is_ip4': is_ip4,
970 'mb_address_length': dst_address_length,
971 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000972
973 def mpls_tunnel_add_del(
974 self,
975 tun_sw_if_index,
976 next_hop_proto_is_ip4,
977 next_hop_address,
978 next_hop_sw_if_index=0xFFFFFFFF,
979 next_hop_table_id=0,
980 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200981 next_hop_n_out_labels=0,
982 next_hop_out_label_stack=[],
983 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000984 create_vrf_if_needed=0,
985 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800986 l2_only=0,
987 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000988 """
989
990 :param dst_address_length:
991 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
992 :param dst_address:
993 :param next_hop_address:
994 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
995 :param vrf_id: (Default value = 0)
996 :param lookup_in_vrf: (Default value = 0)
997 :param classify_table_index: (Default value = 0xFFFFFFFF)
998 :param create_vrf_if_needed: (Default value = 0)
999 :param is_add: (Default value = 1)
1000 :param is_drop: (Default value = 0)
1001 :param is_ipv6: (Default value = 0)
1002 :param is_local: (Default value = 0)
1003 :param is_classify: (Default value = 0)
1004 :param is_multipath: (Default value = 0)
1005 :param is_resolve_host: (Default value = 0)
1006 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001007 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001008 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001009
1010 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001011 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001012 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001013 {'mt_sw_if_index': tun_sw_if_index,
1014 'mt_is_add': is_add,
1015 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001016 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001017 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1018 'mt_next_hop_weight': next_hop_weight,
1019 'mt_next_hop': next_hop_address,
1020 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1021 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1022 'mt_next_hop_table_id': next_hop_table_id,
1023 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001024
1025 def snat_interface_add_del_feature(
1026 self,
1027 sw_if_index,
1028 is_inside=1,
1029 is_add=1):
1030 """Enable/disable S-NAT feature on the interface
1031
1032 :param sw_if_index: Software index of the interface
1033 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1034 :param is_add: 1 if add, 0 if delete (Default value = 1)
1035 """
1036 return self.api(
1037 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001038 {'is_add': is_add,
1039 'is_inside': is_inside,
1040 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001041
1042 def snat_add_static_mapping(
1043 self,
1044 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001045 external_ip=0,
1046 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001047 local_port=0,
1048 external_port=0,
1049 addr_only=1,
1050 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001051 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -08001052 is_add=1,
1053 is_ip4=1):
1054 """Add/delete S-NAT static mapping
1055
1056 :param local_ip: Local IP address
1057 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001058 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001059 :param local_port: Local port number (Default value = 0)
1060 :param external_port: External port number (Default value = 0)
1061 :param addr_only: 1 if address only mapping, 0 if address and port
1062 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001063 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001064 :param is_add: 1 if add, 0 if delete (Default value = 1)
1065 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1066 """
1067 return self.api(
1068 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001069 {'is_add': is_add,
1070 'is_ip4': is_ip4,
1071 'addr_only': addr_only,
1072 'local_ip_address': local_ip,
1073 'external_ip_address': external_ip,
1074 'local_port': local_port,
1075 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001076 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001077 'vrf_id': vrf_id,
1078 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001079
1080 def snat_add_address_range(
1081 self,
1082 first_ip_address,
1083 last_ip_address,
1084 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001085 is_ip4=1,
1086 vrf_id=0xFFFFFFFF):
Matus Fabiande886752016-12-07 03:38:19 -08001087 """Add/del S-NAT address range
1088
1089 :param first_ip_address: First IP address
1090 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001091 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001092 :param is_add: 1 if add, 0 if delete (Default value = 1)
1093 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1094 """
1095 return self.api(
1096 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001097 {'is_ip4': is_ip4,
1098 'first_ip_address': first_ip_address,
1099 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001100 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001101 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001102
1103 def snat_address_dump(self):
1104 """Dump S-NAT addresses
1105 :return: Dictionary of S-NAT addresses
1106 """
1107 return self.api(self.papi.snat_address_dump, {})
1108
1109 def snat_interface_dump(self):
1110 """Dump interfaces with S-NAT feature
1111 :return: Dictionary of interfaces with S-NAT feature
1112 """
1113 return self.api(self.papi.snat_interface_dump, {})
1114
1115 def snat_static_mapping_dump(self):
1116 """Dump S-NAT static mappings
1117 :return: Dictionary of S-NAT static mappings
1118 """
1119 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001120
Matus Fabian9902fcd2016-12-21 23:58:46 -08001121 def snat_show_config(self):
1122 """Show S-NAT config
1123 :return: S-NAT config parameters
1124 """
1125 return self.api(self.papi.snat_show_config, {})
1126
Matus Fabian8bf68e82017-01-12 04:24:35 -08001127 def snat_add_interface_addr(
1128 self,
1129 sw_if_index,
1130 is_add=1):
1131 """Add/del S-NAT address from interface
1132
1133 :param sw_if_index: Software index of the interface
1134 :param is_add: 1 if add, 0 if delete (Default value = 1)
1135 """
1136 return self.api(self.papi.snat_add_del_interface_addr,
1137 {'is_add': is_add, 'sw_if_index': sw_if_index})
1138
1139 def snat_interface_addr_dump(self):
1140 """Dump S-NAT addresses interfaces
1141 :return: Dictionary of S-NAT addresses interfaces
1142 """
1143 return self.api(self.papi.snat_interface_addr_dump, {})
1144
Matus Fabianeea28d72017-01-13 04:15:54 -08001145 def snat_ipfix(
1146 self,
1147 domain_id=1,
1148 src_port=4739,
1149 enable=1):
1150 """Enable/disable S-NAT IPFIX logging
1151
1152 :param domain_id: Observation domain ID (Default value = 1)
1153 :param src_port: Source port number (Default value = 4739)
1154 :param enable: 1 if enable, 0 if disable (Default value = 1)
1155 """
1156 return self.api(
1157 self.papi.snat_ipfix_enable_disable,
1158 {'domain_id': domain_id,
1159 'src_port': src_port,
1160 'enable': enable})
1161
magalik23caa882017-02-08 23:25:45 -08001162 def snat_user_session_dump(
1163 self,
1164 ip_address,
Martin6b7fcda2017-03-08 03:31:02 -08001165 vrf_id,
1166 is_ip4=1):
magalik23caa882017-02-08 23:25:45 -08001167 """Dump S-NAT user's sessions
1168
1169 :param ip_address: ip adress of the user to be dumped
1170 :param cpu_index: cpu_index on which the user is
1171 :param vrf_id: VRF ID
1172 :return: Dictionary of S-NAT sessions
1173 """
1174 return self.api(
1175 self.papi.snat_user_session_dump,
1176 {'ip_address': ip_address,
Martin6b7fcda2017-03-08 03:31:02 -08001177 'vrf_id': vrf_id,
1178 'is_ip4': is_ip4})
magalik23caa882017-02-08 23:25:45 -08001179
1180 def snat_user_dump(self):
1181 """Dump S-NAT users
1182
1183 :return: Dictionary of S-NAT users
1184 """
1185 return self.api(self.papi.snat_user_dump, {})
1186
Matus Fabian066f0342017-02-10 03:48:01 -08001187 def snat_add_det_map(
1188 self,
1189 in_addr,
1190 in_plen,
1191 out_addr,
1192 out_plen,
1193 is_add=1):
1194 """Add/delete S-NAT deterministic mapping
1195
1196 :param is_add - 1 if add, 0 if delete
1197 :param in_addr - inside IP address
1198 :param in_plen - inside IP address prefix length
1199 :param out_addr - outside IP address
1200 :param out_plen - outside IP address prefix length
1201 """
1202 return self.api(
1203 self.papi.snat_add_det_map,
1204 {'is_add': is_add,
1205 'in_addr': in_addr,
1206 'in_plen': in_plen,
1207 'out_addr': out_addr,
1208 'out_plen': out_plen})
1209
1210 def snat_det_forward(
1211 self,
1212 in_addr):
1213 """Get outside address and port range from inside address
1214
1215 :param in_addr - inside IP address
1216 """
1217 return self.api(
1218 self.papi.snat_det_forward,
1219 {'in_addr': in_addr})
1220
1221 def snat_det_reverse(
1222 self,
1223 out_addr,
1224 out_port):
1225 """Get inside address from outside address and port
1226
1227 :param out_addr - outside IP address
1228 :param out_port - outside port
1229 """
1230 return self.api(
1231 self.papi.snat_det_reverse,
1232 {'out_addr': out_addr,
1233 'out_port': out_port})
1234
Martin17a75cb2017-03-08 05:53:20 -08001235 def snat_det_map_dump(self):
1236 """Dump S-NAT deterministic mappings
1237
1238 :return: Dictionary of S-NAT deterministic mappings
1239 """
1240 return self.api(self.papi.snat_det_map_dump, {})
1241
Matus Fabian6a0946f2017-04-12 03:36:13 -07001242 def snat_det_set_timeouts(
1243 self,
1244 udp=300,
1245 tcp_established=7440,
1246 tcp_transitory=240,
1247 icmp=60):
1248 """Set values of timeouts for deterministic NAT (in seconds)
1249
1250 :param udp - UDP timeout (Default value = 300)
1251 :param tcp_established - TCP established timeout (Default value = 7440)
1252 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1253 :param icmp - ICMP timeout (Default value = 60)
1254 """
1255 return self.api(
1256 self.papi.snat_det_set_timeouts,
1257 {'udp': udp,
1258 'tcp_established': tcp_established,
1259 'tcp_transitory': tcp_transitory,
1260 'icmp': icmp})
1261
1262 def snat_det_get_timeouts(self):
1263 """Get values of timeouts for deterministic NAT
1264
1265 :return: Timeouts for deterministic NAT (in seconds)
1266 """
1267 return self.api(self.papi.snat_det_get_timeouts, {})
1268
Martin Gálik6bc8c642017-04-19 01:12:27 -07001269 def snat_det_close_session_out(
1270 self,
1271 out_addr,
1272 out_port,
1273 ext_addr,
1274 ext_port,
1275 is_ip4=1):
1276 """Close CGN session using outside address and port
1277
1278 :param out_addr - outside IP address
1279 :param out_port - outside port
1280 :param ext_addr - external host IP address
1281 :param ext_port - external host port
1282 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1283 """
1284 return self.api(
1285 self.papi.snat_det_close_session_out,
1286 {'out_addr': out_addr,
1287 'out_port': out_port,
1288 'ext_addr': ext_addr,
1289 'ext_port': ext_port,
1290 'is_ip4': is_ip4})
1291
1292 def snat_det_close_session_in(
1293 self,
1294 in_addr,
1295 in_port,
1296 ext_addr,
1297 ext_port,
1298 is_ip4=1):
1299 """Close CGN session using inside address and port
1300
1301 :param in_addr - inside IP address
1302 :param in_port - inside port
1303 :param ext_addr - external host IP address
1304 :param ext_port - external host port
1305 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1306 """
1307 return self.api(
1308 self.papi.snat_det_close_session_in,
1309 {'in_addr': in_addr,
1310 'in_port': in_port,
1311 'ext_addr': ext_addr,
1312 'ext_port': ext_port,
1313 'is_ip4': is_ip4})
1314
Martin Gálik9806eae2017-04-25 01:25:08 -07001315 def snat_det_session_dump(
1316 self,
1317 user_addr,
1318 is_ip4=1):
1319 """Dump S-NAT deterministic sessions belonging to a user
1320
1321 :param user_addr - inside IP address of the user
1322 :param is_ip4: - 1 if address type is IPv4 (Default value = 1)
1323 :return: Dictionary of S-NAT deterministic sessions
1324 """
1325 return self.api(
1326 self.papi.snat_det_session_dump,
1327 {'is_ip4': is_ip4,
1328 'user_addr': user_addr})
1329
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001330 def control_ping(self):
1331 self.api(self.papi.control_ping)
1332
1333 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001334 detect_mult, local_addr, peer_addr, is_ipv6=0,
1335 bfd_key_id=None, conf_key_id=None):
1336 if bfd_key_id is None:
1337 return self.api(self.papi.bfd_udp_add,
1338 {
1339 'sw_if_index': sw_if_index,
1340 'desired_min_tx': desired_min_tx,
1341 'required_min_rx': required_min_rx,
1342 'local_addr': local_addr,
1343 'peer_addr': peer_addr,
1344 'is_ipv6': is_ipv6,
1345 'detect_mult': detect_mult,
1346 })
1347 else:
1348 return self.api(self.papi.bfd_udp_add,
1349 {
1350 'sw_if_index': sw_if_index,
1351 'desired_min_tx': desired_min_tx,
1352 'required_min_rx': required_min_rx,
1353 'local_addr': local_addr,
1354 'peer_addr': peer_addr,
1355 'is_ipv6': is_ipv6,
1356 'detect_mult': detect_mult,
1357 'is_authenticated': 1,
1358 'bfd_key_id': bfd_key_id,
1359 'conf_key_id': conf_key_id,
1360 })
1361
Klement Sekeraa57a9702017-02-02 06:58:07 +01001362 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1363 detect_mult, local_addr, peer_addr, is_ipv6=0):
1364 return self.api(self.papi.bfd_udp_mod,
1365 {
1366 'sw_if_index': sw_if_index,
1367 'desired_min_tx': desired_min_tx,
1368 'required_min_rx': required_min_rx,
1369 'local_addr': local_addr,
1370 'peer_addr': peer_addr,
1371 'is_ipv6': is_ipv6,
1372 'detect_mult': detect_mult,
1373 })
1374
Klement Sekerab17dd962017-01-09 07:43:48 +01001375 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1376 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1377 is_delayed=False):
1378 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001379 {
1380 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001381 'local_addr': local_addr,
1382 'peer_addr': peer_addr,
1383 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001384 'is_delayed': 1 if is_delayed else 0,
1385 'bfd_key_id': bfd_key_id,
1386 'conf_key_id': conf_key_id,
1387 })
1388
1389 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1390 is_ipv6=0, is_delayed=False):
1391 return self.api(self.papi.bfd_udp_auth_deactivate,
1392 {
1393 'sw_if_index': sw_if_index,
1394 'local_addr': local_addr,
1395 'peer_addr': peer_addr,
1396 'is_ipv6': is_ipv6,
1397 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001398 })
1399
1400 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1401 return self.api(self.papi.bfd_udp_del,
1402 {
1403 'sw_if_index': sw_if_index,
1404 'local_addr': local_addr,
1405 'peer_addr': peer_addr,
1406 'is_ipv6': is_ipv6,
1407 })
1408
1409 def bfd_udp_session_dump(self):
1410 return self.api(self.papi.bfd_udp_session_dump, {})
1411
Klement Sekerab17dd962017-01-09 07:43:48 +01001412 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1413 peer_addr, is_ipv6=0):
1414 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001415 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001416 'sw_if_index': sw_if_index,
1417 'local_addr': local_addr,
1418 'peer_addr': peer_addr,
1419 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001420 })
1421
1422 def want_bfd_events(self, enable_disable=1):
1423 return self.api(self.papi.want_bfd_events, {
1424 'enable_disable': enable_disable,
1425 'pid': os.getpid(),
1426 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001427
Klement Sekerab17dd962017-01-09 07:43:48 +01001428 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1429 return self.api(self.papi.bfd_auth_set_key, {
1430 'conf_key_id': conf_key_id,
1431 'auth_type': auth_type,
1432 'key': key,
1433 'key_len': len(key),
1434 })
1435
1436 def bfd_auth_del_key(self, conf_key_id):
1437 return self.api(self.papi.bfd_auth_del_key, {
1438 'conf_key_id': conf_key_id,
1439 })
1440
1441 def bfd_auth_keys_dump(self):
1442 return self.api(self.papi.bfd_auth_keys_dump, {})
1443
Klement Sekera239790f2017-02-16 10:53:53 +01001444 def bfd_udp_set_echo_source(self, sw_if_index):
1445 return self.api(self.papi.bfd_udp_set_echo_source,
1446 {'sw_if_index': sw_if_index})
1447
Klement Sekera73884482017-02-23 09:26:30 +01001448 def bfd_udp_del_echo_source(self):
1449 return self.api(self.papi.bfd_udp_del_echo_source, {})
1450
Steve Shin7957d6e2016-12-19 09:24:50 -08001451 def classify_add_del_table(
1452 self,
1453 is_add,
1454 mask,
1455 match_n_vectors=1,
1456 table_index=0xFFFFFFFF,
1457 nbuckets=2,
1458 memory_size=2097152,
1459 skip_n_vectors=0,
1460 next_table_index=0xFFFFFFFF,
1461 miss_next_index=0xFFFFFFFF,
1462 current_data_flag=0,
1463 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001464 """
1465 :param is_add:
1466 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001467 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001468 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001469 :param nbuckets: (Default value = 2)
1470 :param memory_size: (Default value = 2097152)
1471 :param skip_n_vectors: (Default value = 0)
1472 :param next_table_index: (Default value = 0xFFFFFFFF)
1473 :param miss_next_index: (Default value = 0xFFFFFFFF)
1474 :param current_data_flag: (Default value = 0)
1475 :param current_data_offset: (Default value = 0)
1476 """
1477
1478 return self.api(
1479 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001480 {'is_add': is_add,
1481 'table_index': table_index,
1482 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001483 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001484 'skip_n_vectors': skip_n_vectors,
1485 'match_n_vectors': match_n_vectors,
1486 'next_table_index': next_table_index,
1487 'miss_next_index': miss_next_index,
1488 'current_data_flag': current_data_flag,
1489 'current_data_offset': current_data_offset,
1490 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001491
1492 def classify_add_del_session(
1493 self,
1494 is_add,
1495 table_index,
1496 match,
1497 opaque_index=0xFFFFFFFF,
1498 hit_next_index=0xFFFFFFFF,
1499 advance=0,
1500 action=0,
1501 metadata=0):
1502 """
1503 :param is_add:
1504 :param table_index:
1505 :param match:
1506 :param opaque_index: (Default value = 0xFFFFFFFF)
1507 :param hit_next_index: (Default value = 0xFFFFFFFF)
1508 :param advance: (Default value = 0)
1509 :param action: (Default value = 0)
1510 :param metadata: (Default value = 0)
1511 """
1512
1513 return self.api(
1514 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001515 {'is_add': is_add,
1516 'table_index': table_index,
1517 'hit_next_index': hit_next_index,
1518 'opaque_index': opaque_index,
1519 'advance': advance,
1520 'action': action,
1521 'metadata': metadata,
1522 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001523
1524 def input_acl_set_interface(
1525 self,
1526 is_add,
1527 sw_if_index,
1528 ip4_table_index=0xFFFFFFFF,
1529 ip6_table_index=0xFFFFFFFF,
1530 l2_table_index=0xFFFFFFFF):
1531 """
1532 :param is_add:
1533 :param sw_if_index:
1534 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1535 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1536 :param l2_table_index: (Default value = 0xFFFFFFFF)
1537 """
1538
1539 return self.api(
1540 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001541 {'sw_if_index': sw_if_index,
1542 'ip4_table_index': ip4_table_index,
1543 'ip6_table_index': ip6_table_index,
1544 'l2_table_index': l2_table_index,
1545 'is_add': is_add})
1546
1547 def set_ipfix_exporter(
1548 self,
1549 collector_address,
1550 src_address,
1551 path_mtu,
1552 template_interval,
1553 vrf_id=0,
1554 collector_port=4739,
1555 udp_checksum=0):
1556 return self.api(
1557 self.papi.set_ipfix_exporter,
1558 {
1559 'collector_address': collector_address,
1560 'collector_port': collector_port,
1561 'src_address': src_address,
1562 'vrf_id': vrf_id,
1563 'path_mtu': path_mtu,
1564 'template_interval': template_interval,
1565 'udp_checksum': udp_checksum,
1566 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001567
1568 def dhcp_proxy_config(self,
1569 dhcp_server,
1570 dhcp_src_address,
1571 rx_table_id=0,
1572 server_table_id=0,
1573 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001574 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001575 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001576 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001577 {
1578 'rx_vrf_id': rx_table_id,
1579 'server_vrf_id': server_table_id,
1580 'is_ipv6': is_ipv6,
1581 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001582 'dhcp_server': dhcp_server,
1583 'dhcp_src_address': dhcp_src_address,
1584 })
1585
1586 def dhcp_proxy_set_vss(self,
1587 table_id,
1588 fib_id,
1589 oui,
1590 is_add=1,
1591 is_ip6=0):
1592 return self.api(
1593 self.papi.dhcp_proxy_set_vss,
1594 {
1595 'tbl_id': table_id,
1596 'fib_id': fib_id,
1597 'is_ipv6': is_ip6,
1598 'is_add': is_add,
1599 'oui': oui,
1600 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001601
1602 def ip_mroute_add_del(self,
1603 src_address,
1604 grp_address,
1605 grp_address_length,
1606 e_flags,
1607 next_hop_sw_if_index,
1608 i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001609 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001610 table_id=0,
1611 create_vrf_if_needed=0,
1612 is_add=1,
1613 is_ipv6=0,
1614 is_local=0):
1615 """
1616 """
1617 return self.api(
1618 self.papi.ip_mroute_add_del,
1619 {'next_hop_sw_if_index': next_hop_sw_if_index,
1620 'entry_flags': e_flags,
1621 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001622 'table_id': table_id,
1623 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001624 'create_vrf_if_needed': create_vrf_if_needed,
1625 'is_add': is_add,
1626 'is_ipv6': is_ipv6,
1627 'is_local': is_local,
1628 'grp_address_length': grp_address_length,
1629 'grp_address': grp_address,
1630 'src_address': src_address})
1631
1632 def mfib_signal_dump(self):
1633 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001634
1635 def ip_mfib_dump(self):
1636 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001637
1638 def lisp_enable_disable(self, is_enabled):
1639 return self.api(
1640 self.papi.lisp_enable_disable,
1641 {
1642 'is_en': is_enabled,
1643 })
1644
1645 def lisp_locator_set(self,
1646 ls_name,
1647 is_add=1):
1648 return self.api(
1649 self.papi.lisp_add_del_locator_set,
1650 {
1651 'is_add': is_add,
1652 'locator_set_name': ls_name
1653 })
1654
1655 def lisp_locator_set_dump(self):
1656 return self.api(self.papi.lisp_locator_set_dump, {})
1657
1658 def lisp_locator(self,
1659 ls_name,
1660 sw_if_index,
1661 priority=1,
1662 weight=1,
1663 is_add=1):
1664 return self.api(
1665 self.papi.lisp_add_del_locator,
1666 {
1667 'is_add': is_add,
1668 'locator_set_name': ls_name,
1669 'sw_if_index': sw_if_index,
1670 'priority': priority,
1671 'weight': weight
1672 })
1673
1674 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1675 return self.api(
1676 self.papi.lisp_locator_dump,
1677 {
1678 'is_index_set': is_index_set,
1679 'ls_name': ls_name,
1680 'ls_index': ls_index,
1681 })
1682
1683 def lisp_local_mapping(self,
1684 ls_name,
1685 eid_type,
1686 eid,
1687 prefix_len,
1688 vni=0,
1689 key_id=0,
1690 key="",
1691 is_add=1):
1692 return self.api(
1693 self.papi.lisp_add_del_local_eid,
1694 {
1695 'locator_set_name': ls_name,
1696 'is_add': is_add,
1697 'eid_type': eid_type,
1698 'eid': eid,
1699 'prefix_len': prefix_len,
1700 'vni': vni,
1701 'key_id': key_id,
1702 'key': key
1703 })
1704
1705 def lisp_eid_table_dump(self,
1706 eid_set=0,
1707 prefix_length=0,
1708 vni=0,
1709 eid_type=0,
1710 eid=None,
1711 filter_opt=0):
1712 return self.api(
1713 self.papi.lisp_eid_table_dump,
1714 {
1715 'eid_set': eid_set,
1716 'prefix_length': prefix_length,
1717 'vni': vni,
1718 'eid_type': eid_type,
1719 'eid': eid,
1720 'filter': filter_opt,
1721 })
1722
1723 def lisp_remote_mapping(self,
1724 eid_type,
1725 eid,
1726 eid_prefix_len=0,
1727 vni=0,
1728 rlocs=None,
1729 rlocs_num=0,
1730 is_src_dst=0,
1731 is_add=1):
1732 return self.api(
1733 self.papi.lisp_add_del_remote_mapping,
1734 {
1735 'is_add': is_add,
1736 'eid_type': eid_type,
1737 'eid': eid,
1738 'eid_len': eid_prefix_len,
1739 'rloc_num': rlocs_num,
1740 'rlocs': rlocs,
1741 'vni': vni,
1742 'is_src_dst': is_src_dst,
1743 })
1744
1745 def lisp_adjacency(self,
1746 leid,
1747 reid,
1748 leid_len,
1749 reid_len,
1750 eid_type,
1751 is_add=1,
1752 vni=0):
1753 return self.api(
1754 self.papi.lisp_add_del_adjacency,
1755 {
1756 'is_add': is_add,
1757 'vni': vni,
1758 'eid_type': eid_type,
1759 'leid': leid,
1760 'reid': reid,
1761 'leid_len': leid_len,
1762 'reid_len': reid_len,
1763 })
1764
1765 def lisp_adjacencies_get(self, vni=0):
1766 return self.api(
1767 self.papi.lisp_adjacencies_get,
1768 {
1769 'vni': vni
1770 })
Neale Ranns80823802017-02-20 18:23:41 -08001771
1772 def map_add_domain(self,
1773 ip6_prefix,
1774 ip6_prefix_len,
1775 ip6_src,
1776 ip6_src_prefix_len,
1777 ip4_prefix,
1778 ip4_prefix_len,
1779 ea_bits_len=0,
1780 psid_offset=0,
1781 psid_length=0,
1782 is_translation=0,
1783 mtu=1280):
1784 return self.api(
1785 self.papi.map_add_domain,
1786 {
1787 'ip6_prefix': ip6_prefix,
1788 'ip6_prefix_len': ip6_prefix_len,
1789 'ip4_prefix': ip4_prefix,
1790 'ip4_prefix_len': ip4_prefix_len,
1791 'ip6_src': ip6_src,
1792 'ip6_src_prefix_len': ip6_src_prefix_len,
1793 'ea_bits_len': ea_bits_len,
1794 'psid_offset': psid_offset,
1795 'psid_length': psid_length,
1796 'is_translation': is_translation,
1797 'mtu': mtu
1798 })
Hongjun Nief486b12017-04-12 19:21:16 +08001799
1800 def gtpu_add_del_tunnel(
1801 self,
1802 src_addr,
1803 dst_addr,
1804 is_add=1,
1805 is_ipv6=0,
1806 mcast_sw_if_index=0xFFFFFFFF,
1807 encap_vrf_id=0,
1808 decap_next_index=0xFFFFFFFF,
1809 teid=0):
1810 """
1811
1812 :param is_add: (Default value = 1)
1813 :param is_ipv6: (Default value = 0)
1814 :param src_addr:
1815 :param dst_addr:
1816 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1817 :param encap_vrf_id: (Default value = 0)
1818 :param decap_next_index: (Default value = 0xFFFFFFFF)
1819 :param teid: (Default value = 0)
1820
1821 """
1822 return self.api(self.papi.gtpu_add_del_tunnel,
1823 {'is_add': is_add,
1824 'is_ipv6': is_ipv6,
1825 'src_address': src_addr,
1826 'dst_address': dst_addr,
1827 'mcast_sw_if_index': mcast_sw_if_index,
1828 'encap_vrf_id': encap_vrf_id,
1829 'decap_next_index': decap_next_index,
1830 'teid': teid})