blob: c7e875f04817f247a15fdb2fb9966a3b10e173ad [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
Klement Sekera7112c542017-03-01 09:53:19 +010058 self.vpp = VPP(jsonfiles)
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:
155 msg = "API call failed, expected zero return value instead "\
156 "of %d in %s" % (expected_retval, repr(reply))
157 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100158 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100159 else:
160 raise Exception("Internal error, unexpected value for "
161 "self._expect_api_retval %s" %
162 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200163 self.hook.after_api(api_fn.__name__, api_args)
164 return reply
165
166 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100167 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200168
169 :param cli: CLI to execute
170 :returns: CLI output
171
172 """
173 self.hook.before_cli(cli)
174 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100175 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200176 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200177 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100178 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200179
Jan49c0fca2016-10-26 15:44:27 +0200180 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100181 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200182
183 :param cli: CLI to execute
184 :returns: CLI output
185 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600186 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200187
Jan4af521d2016-11-15 17:05:00 +0100188 def _convert_mac(self, mac):
189 return int(mac.replace(":", ""), 16) << 16
190
Klement Sekeraf62ae122016-10-11 11:47:09 +0200191 def show_version(self):
192 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100193 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194
195 def pg_create_interface(self, pg_index):
196 """
197
198 :param pg_index:
199
200 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100201 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200202 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203
204 def sw_interface_dump(self, filter=None):
205 """
206
207 :param filter: (Default value = None)
208
209 """
210 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200211 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100213 args = {}
214 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200215
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000216 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100217 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000218
219 :param sw_if_index:
220 :param is_ipv6:
221 :param table_id:
222
223 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100224 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200225 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
226 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000227
Klement Sekeraf62ae122016-10-11 11:47:09 +0200228 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
229 is_ipv6=0, is_add=1, del_all=0):
230 """
231
232 :param addr: param is_ipv6: (Default value = 0)
233 :param sw_if_index:
234 :param addr_len:
235 :param is_ipv6: (Default value = 0)
236 :param is_add: (Default value = 1)
237 :param del_all: (Default value = 0)
238
239 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100240 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200241 {'sw_if_index': sw_if_index,
242 'is_add': is_add,
243 'is_ipv6': is_ipv6,
244 'del_all': del_all,
245 'address_length': addr_len,
246 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200247
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800248 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
249 is_add=1):
250 """ Set the Interface to be unnumbered
251
252 :param is_add: (Default value = 1)
253 :param sw_if_index - interface That will be unnumbered
254 :param ip_sw_if_index - interface with an IP addres
255
256 """
257 return self.api(self.papi.sw_interface_set_unnumbered,
258 {'sw_if_index': ip_sw_if_index,
259 'unnumbered_sw_if_index': sw_if_index,
260 'is_add': is_add})
261
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000262 def sw_interface_enable_disable_mpls(self, sw_if_index,
263 is_enable=1):
264 """
265 Enable/Disable MPLS on the interface
266 :param sw_if_index:
267 :param is_enable: (Default value = 1)
268
269 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100270 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200271 {'sw_if_index': sw_if_index,
272 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000273
Jan Gelety057bb8c2016-12-20 17:32:45 +0100274 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100275 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100276 {'sw_if_index': sw_if_index,
277 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200278
Neale Ranns75152282017-01-09 01:00:45 -0800279 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000280 no,
Neale Ranns75152282017-01-09 01:00:45 -0800281 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000282 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800283 return self.api(self.papi.sw_interface_ip6nd_ra_config,
284 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000285 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100286 'suppress': suppress,
287 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800288
Neale Ranns87df12d2017-02-18 08:16:41 -0800289 def ip6_sw_interface_ra_prefix(self,
290 sw_if_index,
291 address,
292 address_length,
293 use_default=0,
294 no_advertise=0,
295 off_link=0,
296 no_autoconfig=0,
297 no_onlink=0,
298 is_no=0,
299 val_lifetime=0xffffffff,
300 pref_lifetime=0xffffffff):
301 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
302 {'sw_if_index': sw_if_index,
303 'address': address,
304 'address_length': address_length,
305 'use_default': use_default,
306 'no_advertise': no_advertise,
307 'off_link': off_link,
308 'no_autoconfig': no_autoconfig,
309 'no_onlink': no_onlink,
310 'is_no': is_no,
311 'val_lifetime': val_lifetime,
312 'pref_lifetime': pref_lifetime})
313
Neale Ranns75152282017-01-09 01:00:45 -0800314 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
315 """
316 Enable/Disable An interface for IPv6
317 """
318 return self.api(self.papi.sw_interface_ip6_enable_disable,
319 {'sw_if_index': sw_if_index,
320 'enable': enable})
321
Klement Sekeraf62ae122016-10-11 11:47:09 +0200322 def vxlan_add_del_tunnel(
323 self,
324 src_addr,
325 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200326 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200327 is_add=1,
328 is_ipv6=0,
329 encap_vrf_id=0,
330 decap_next_index=0xFFFFFFFF,
331 vni=0):
332 """
333
334 :param dst_addr:
335 :param src_addr:
336 :param is_add: (Default value = 1)
337 :param is_ipv6: (Default value = 0)
338 :param encap_vrf_id: (Default value = 0)
339 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200340 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200341 :param vni: (Default value = 0)
342
343 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100344 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200345 {'is_add': is_add,
346 'is_ipv6': is_ipv6,
347 'src_address': src_addr,
348 'dst_address': dst_addr,
349 'mcast_sw_if_index': mcast_sw_if_index,
350 'encap_vrf_id': encap_vrf_id,
351 'decap_next_index': decap_next_index,
352 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200353
Jan4af521d2016-11-15 17:05:00 +0100354 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
355 learn=1, arp_term=0, is_add=1):
356 """Create/delete bridge domain.
357
358 :param int bd_id: Bridge domain index.
359 :param int flood: Enable/disable bcast/mcast flooding in the BD.
360 (Default value = 1)
361 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
362 (Default value = 1)
363 :param int forward: Enable/disable forwarding on all interfaces in
364 the BD. (Default value = 1)
365 :param int learn: Enable/disable learning on all interfaces in the BD.
366 (Default value = 1)
367 :param int arp_term: Enable/disable arp termination in the BD.
368 (Default value = 1)
369 :param int is_add: Add or delete flag. (Default value = 1)
370 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100371 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200372 {'bd_id': bd_id,
373 'flood': flood,
374 'uu_flood': uu_flood,
375 'forward': forward,
376 'learn': learn,
377 'arp_term': arp_term,
378 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100379
380 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
381 filter_mac=0, bvi_mac=0):
382 """Create/delete L2 FIB entry.
383
384 :param str mac: MAC address to create FIB entry for.
385 :param int bd_id: Bridge domain index.
386 :param int sw_if_index: Software interface index of the interface.
387 :param int is_add: Add or delete flag. (Default value = 1)
388 :param int static_mac: Set to 1 to create static MAC entry.
389 (Default value = 0)
390 :param int filter_mac: Set to 1 to drop packet that's source or
391 destination MAC address contains defined MAC address.
392 (Default value = 0)
393 :param int bvi_mac: Set to 1 to create entry that points to BVI
394 interface. (Default value = 0)
395 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100396 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200397 {'mac': self._convert_mac(mac),
398 'bd_id': bd_id,
399 'sw_if_index': sw_if_index,
400 'is_add': is_add,
401 'static_mac': static_mac,
402 'filter_mac': filter_mac,
403 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100404
Klement Sekeraf62ae122016-10-11 11:47:09 +0200405 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
406 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100407 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200408
Jan4af521d2016-11-15 17:05:00 +0100409 :param int sw_if_index: Software interface index of the interface.
410 :param int bd_id: Bridge domain index.
411 :param int shg: Split-horizon group index. (Default value = 0)
412 :param int bvi: Set interface as a bridge group virtual interface.
413 (Default value = 0)
414 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200415 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100416 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200417 {'rx_sw_if_index': sw_if_index,
418 'bd_id': bd_id,
419 'shg': shg,
420 'bvi': bvi,
421 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200422
Jan00dad122016-11-29 10:04:53 +0100423 def bridge_flags(self, bd_id, is_set, feature_bitmap):
424 """Enable/disable required feature of the bridge domain with defined ID.
425
426 :param int bd_id: Bridge domain ID.
427 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
428 :param int feature_bitmap: Bitmap value of the feature to be set:
429 - learn (1 << 0),
430 - forward (1 << 1),
431 - flood (1 << 2),
432 - uu-flood (1 << 3) or
433 - arp-term (1 << 4).
434 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100435 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200436 {'bd_id': bd_id,
437 'is_set': is_set,
438 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100439
440 def bridge_domain_dump(self, bd_id=0):
441 """
442
443 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
444 existing bridge domains returned)
445 :return: Dictionary of bridge domain(s) data.
446 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100447 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200448 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100449
Klement Sekeraf62ae122016-10-11 11:47:09 +0200450 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
451 enable):
452 """Create or delete unidirectional cross-connect from Tx interface to
453 Rx interface.
454
Jan4af521d2016-11-15 17:05:00 +0100455 :param int rx_sw_if_index: Software interface index of Rx interface.
456 :param int tx_sw_if_index: Software interface index of Tx interface.
457 :param int enable: Create cross-connect if equal to 1, delete
458 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200459
460 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100461 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200462 {'rx_sw_if_index': rx_sw_if_index,
463 'tx_sw_if_index': tx_sw_if_index,
464 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200465
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200466 def sw_interface_set_l2_tag_rewrite(
467 self,
468 sw_if_index,
469 vtr_oper,
470 push=0,
471 tag1=0,
472 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000473 """L2 interface vlan tag rewrite configure request
474 :param client_index - opaque cookie to identify the sender
475 :param context - sender context, to match reply w/ request
476 :param sw_if_index - interface the operation is applied to
477 :param vtr_op - Choose from l2_vtr_op_t enum values
478 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
479 :param tag1 - Needed for any push or translate vtr op
480 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
481
482 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100483 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200484 {'sw_if_index': sw_if_index,
485 'vtr_op': vtr_oper,
486 'push_dot1q': push,
487 'tag1': tag1,
488 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000489
Klement Sekeraf62ae122016-10-11 11:47:09 +0200490 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
491 link_up_down=0, deleted=0):
492 """
493
494 :param admin_up_down:
495 :param sw_if_index:
496 :param link_up_down: (Default value = 0)
497 :param deleted: (Default value = 0)
498
499 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100500 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200501 {'sw_if_index': sw_if_index,
502 'admin_up_down': admin_up_down,
503 'link_up_down': link_up_down,
504 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200505
506 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
507 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
508 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
509 """Create subinterface
510 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
511
512 :param sub_id: param inner_vlan:
513 :param sw_if_index:
514 :param outer_vlan:
515 :param inner_vlan:
516 :param no_tags: (Default value = 0)
517 :param one_tag: (Default value = 0)
518 :param two_tags: (Default value = 0)
519 :param dot1ad: (Default value = 0)
520 :param exact_match: (Default value = 0)
521 :param default_sub: (Default value = 0)
522 :param outer_vlan_id_any: (Default value = 0)
523 :param inner_vlan_id_any: (Default value = 0)
524
525 """
526 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100527 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200528 {'sw_if_index': sw_if_index,
529 'sub_id': sub_id,
530 'no_tags': no_tags,
531 'one_tag': one_tag,
532 'two_tags': two_tags,
533 'dot1ad': dot1ad,
534 'exact_match': exact_match,
535 'default_sub': default_sub,
536 'outer_vlan_id_any': outer_vlan_id_any,
537 'inner_vlan_id_any': inner_vlan_id_any,
538 'outer_vlan_id': outer_vlan,
539 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200540
Neale Ranns177bbdc2016-11-15 09:46:51 +0000541 def delete_subif(self, sw_if_index):
542 """Delete subinterface
543
544 :param sw_if_index:
545 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100546 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200547 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000548
Klement Sekeraf62ae122016-10-11 11:47:09 +0200549 def create_vlan_subif(self, sw_if_index, vlan):
550 """
551
552 :param vlan:
553 :param sw_if_index:
554
555 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100556 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200557 {'sw_if_index': sw_if_index,
558 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200559
Matej Klotton0178d522016-11-04 11:11:44 +0100560 def create_loopback(self, mac=''):
561 """
562
563 :param mac: (Optional)
564 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100565 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200566 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100567
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100568 def delete_loopback(self, sw_if_index):
569 return self.api(self.papi.delete_loopback,
570 {'sw_if_index': sw_if_index, })
571
Klement Sekeraf62ae122016-10-11 11:47:09 +0200572 def ip_add_del_route(
573 self,
574 dst_address,
575 dst_address_length,
576 next_hop_address,
577 next_hop_sw_if_index=0xFFFFFFFF,
578 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200579 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000580 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200581 next_hop_n_out_labels=0,
582 next_hop_out_label_stack=[],
583 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200584 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000585 is_resolve_host=0,
586 is_resolve_attached=0,
587 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200588 is_add=1,
589 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200590 is_unreach=0,
591 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200592 is_ipv6=0,
593 is_local=0,
594 is_classify=0,
595 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000596 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200597 """
598
599 :param dst_address_length:
600 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
601 :param dst_address:
602 :param next_hop_address:
603 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
604 :param vrf_id: (Default value = 0)
605 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200606 :param classify_table_index: (Default value = 0xFFFFFFFF)
607 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200608 :param is_add: (Default value = 1)
609 :param is_drop: (Default value = 0)
610 :param is_ipv6: (Default value = 0)
611 :param is_local: (Default value = 0)
612 :param is_classify: (Default value = 0)
613 :param is_multipath: (Default value = 0)
614 :param is_resolve_host: (Default value = 0)
615 :param is_resolve_attached: (Default value = 0)
616 :param not_last: (Default value = 0)
617 :param next_hop_weight: (Default value = 1)
618
619 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000620
Klement Sekeraf62ae122016-10-11 11:47:09 +0200621 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100622 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200623 {'next_hop_sw_if_index': next_hop_sw_if_index,
624 'table_id': table_id,
625 'classify_table_index': classify_table_index,
626 'next_hop_table_id': next_hop_table_id,
627 'create_vrf_if_needed': create_vrf_if_needed,
628 'is_add': is_add,
629 'is_drop': is_drop,
630 'is_unreach': is_unreach,
631 'is_prohibit': is_prohibit,
632 'is_ipv6': is_ipv6,
633 'is_local': is_local,
634 'is_classify': is_classify,
635 'is_multipath': is_multipath,
636 'is_resolve_host': is_resolve_host,
637 'is_resolve_attached': is_resolve_attached,
638 'not_last': not_last,
639 'next_hop_weight': next_hop_weight,
640 'dst_address_length': dst_address_length,
641 'dst_address': dst_address,
642 'next_hop_address': next_hop_address,
643 'next_hop_n_out_labels': next_hop_n_out_labels,
644 'next_hop_via_label': next_hop_via_label,
645 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100646
Matej Klotton16a14cd2016-12-07 15:09:13 +0100647 def ip_fib_dump(self):
648 return self.api(self.papi.ip_fib_dump, {})
649
Jan Gelety057bb8c2016-12-20 17:32:45 +0100650 def ip6_fib_dump(self):
651 return self.api(self.papi.ip6_fib_dump, {})
652
Matej Klotton0178d522016-11-04 11:11:44 +0100653 def ip_neighbor_add_del(self,
654 sw_if_index,
655 mac_address,
656 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100657 is_add=1,
658 is_ipv6=0,
659 is_static=0,
660 ):
661 """ Add neighbor MAC to IPv4 or IPv6 address.
662
663 :param sw_if_index:
664 :param mac_address:
665 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100666 :param is_add: (Default value = 1)
667 :param is_ipv6: (Default value = 0)
668 :param is_static: (Default value = 0)
669 """
670
671 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100672 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800673 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200674 'is_add': is_add,
675 'is_ipv6': is_ipv6,
676 'is_static': is_static,
677 'mac_address': mac_address,
678 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100679 }
Matej Klotton0178d522016-11-04 11:11:44 +0100680 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100681
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800682 def ip_neighbor_dump(self,
683 sw_if_index,
684 is_ipv6=0):
685 """ Return IP neighbor dump.
686
687 :param sw_if_index:
688 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
689 """
690
691 return self.api(
692 self.papi.ip_neighbor_dump,
693 {'is_ipv6': is_ipv6,
694 'sw_if_index': sw_if_index
695 }
696 )
697
698 def proxy_arp_add_del(self,
699 low_address,
700 hi_address,
701 vrf_id=0,
702 is_add=1):
703 """ Config Proxy Arp Range.
704
705 :param low_address: Start address in the rnage to Proxy for
706 :param hi_address: End address in the rnage to Proxy for
707 :param vrf_id: The VRF/table in which to proxy
708 """
709
710 return self.api(
711 self.papi.proxy_arp_add_del,
712 {'vrf_id': vrf_id,
713 'is_add': is_add,
714 'low_address': low_address,
715 'hi_address': hi_address,
716 }
717 )
718
719 def proxy_arp_intfc_enable_disable(self,
720 sw_if_index,
721 is_enable=1):
722 """ Enable/Disable an interface for proxy ARP requests
723
724 :param sw_if_index: Interface
725 :param enable_disable: Enable/Disable
726 """
727
728 return self.api(
729 self.papi.proxy_arp_intfc_enable_disable,
730 {'sw_if_index': sw_if_index,
731 'enable_disable': is_enable
732 }
733 )
734
Jane546d3b2016-12-08 13:10:03 +0100735 def reset_vrf(self,
736 vrf_id,
737 is_ipv6=0,
738 ):
739 """ Reset VRF (remove all routes etc.) request.
740
741 :param int vrf_id: ID of the FIB table / VRF to reset.
742 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
743 """
744
745 return self.api(
746 self.papi.reset_vrf,
747 {'vrf_id': vrf_id,
748 'is_ipv6': is_ipv6,
749 }
750 )
751
752 def reset_fib(self,
753 vrf_id,
754 is_ipv6=0,
755 ):
756 """ Reset VRF (remove all routes etc.) request.
757
758 :param int vrf_id: ID of the FIB table / VRF to reset.
759 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
760 """
761
762 return self.api(
763 self.papi.reset_fib,
764 {'vrf_id': vrf_id,
765 'is_ipv6': is_ipv6,
766 }
767 )
768
769 def ip_dump(self,
770 is_ipv6=0,
771 ):
772 """ Return IP dump.
773
774 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
775 """
776
777 return self.api(
778 self.papi.ip_dump,
779 {'is_ipv6': is_ipv6,
780 }
781 )
782
Klement Sekera7bb873a2016-11-18 07:38:42 +0100783 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100784 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100785 """
786
787 :param sw_if_index_from:
788 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100789 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100790 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100791 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200792 {'sw_if_index_from': sw_if_index_from,
793 'sw_if_index_to': sw_if_index_to,
794 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000795
796 def gre_tunnel_add_del(self,
797 src_address,
798 dst_address,
799 outer_fib_id=0,
800 is_teb=0,
801 is_add=1,
802 is_ip6=0):
803 """ Add a GRE tunnel
804
805 :param src_address:
806 :param dst_address:
807 :param outer_fib_id: (Default value = 0)
808 :param is_add: (Default value = 1)
809 :param is_ipv6: (Default value = 0)
810 :param is_teb: (Default value = 0)
811 """
812
813 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100814 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200815 {'is_add': is_add,
816 'is_ipv6': is_ip6,
817 'teb': is_teb,
818 'src_address': src_address,
819 'dst_address': dst_address,
820 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000821 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000822
Neale Ranns5a8123b2017-01-26 01:18:23 -0800823 def mpls_fib_dump(self):
824 return self.api(self.papi.mpls_fib_dump, {})
825
Neale Rannsad422ed2016-11-02 14:20:04 +0000826 def mpls_route_add_del(
827 self,
828 label,
829 eos,
830 next_hop_proto_is_ip4,
831 next_hop_address,
832 next_hop_sw_if_index=0xFFFFFFFF,
833 table_id=0,
834 next_hop_table_id=0,
835 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200836 next_hop_n_out_labels=0,
837 next_hop_out_label_stack=[],
838 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000839 create_vrf_if_needed=0,
840 is_resolve_host=0,
841 is_resolve_attached=0,
842 is_add=1,
843 is_drop=0,
844 is_multipath=0,
845 classify_table_index=0xFFFFFFFF,
846 is_classify=0,
847 not_last=0):
848 """
849
850 :param dst_address_length:
851 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
852 :param dst_address:
853 :param next_hop_address:
854 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
855 :param vrf_id: (Default value = 0)
856 :param lookup_in_vrf: (Default value = 0)
857 :param classify_table_index: (Default value = 0xFFFFFFFF)
858 :param create_vrf_if_needed: (Default value = 0)
859 :param is_add: (Default value = 1)
860 :param is_drop: (Default value = 0)
861 :param is_ipv6: (Default value = 0)
862 :param is_local: (Default value = 0)
863 :param is_classify: (Default value = 0)
864 :param is_multipath: (Default value = 0)
865 :param is_resolve_host: (Default value = 0)
866 :param is_resolve_attached: (Default value = 0)
867 :param not_last: (Default value = 0)
868 :param next_hop_weight: (Default value = 1)
869
870 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000871
872 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100873 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200874 {'mr_label': label,
875 'mr_eos': eos,
876 'mr_table_id': table_id,
877 'mr_classify_table_index': classify_table_index,
878 'mr_create_table_if_needed': create_vrf_if_needed,
879 'mr_is_add': is_add,
880 'mr_is_classify': is_classify,
881 'mr_is_multipath': is_multipath,
882 'mr_is_resolve_host': is_resolve_host,
883 'mr_is_resolve_attached': is_resolve_attached,
884 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
885 'mr_next_hop_weight': next_hop_weight,
886 'mr_next_hop': next_hop_address,
887 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
888 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
889 'mr_next_hop_table_id': next_hop_table_id,
890 'mr_next_hop_via_label': next_hop_via_label,
891 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000892
893 def mpls_ip_bind_unbind(
894 self,
895 label,
896 dst_address,
897 dst_address_length,
898 table_id=0,
899 ip_table_id=0,
900 is_ip4=1,
901 create_vrf_if_needed=0,
902 is_bind=1):
903 """
904 """
905 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100906 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200907 {'mb_mpls_table_id': table_id,
908 'mb_label': label,
909 'mb_ip_table_id': ip_table_id,
910 'mb_create_table_if_needed': create_vrf_if_needed,
911 'mb_is_bind': is_bind,
912 'mb_is_ip4': is_ip4,
913 'mb_address_length': dst_address_length,
914 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000915
916 def mpls_tunnel_add_del(
917 self,
918 tun_sw_if_index,
919 next_hop_proto_is_ip4,
920 next_hop_address,
921 next_hop_sw_if_index=0xFFFFFFFF,
922 next_hop_table_id=0,
923 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200924 next_hop_n_out_labels=0,
925 next_hop_out_label_stack=[],
926 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000927 create_vrf_if_needed=0,
928 is_add=1,
929 l2_only=0):
930 """
931
932 :param dst_address_length:
933 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
934 :param dst_address:
935 :param next_hop_address:
936 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
937 :param vrf_id: (Default value = 0)
938 :param lookup_in_vrf: (Default value = 0)
939 :param classify_table_index: (Default value = 0xFFFFFFFF)
940 :param create_vrf_if_needed: (Default value = 0)
941 :param is_add: (Default value = 1)
942 :param is_drop: (Default value = 0)
943 :param is_ipv6: (Default value = 0)
944 :param is_local: (Default value = 0)
945 :param is_classify: (Default value = 0)
946 :param is_multipath: (Default value = 0)
947 :param is_resolve_host: (Default value = 0)
948 :param is_resolve_attached: (Default value = 0)
949 :param not_last: (Default value = 0)
950 :param next_hop_weight: (Default value = 1)
951
952 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000953 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100954 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200955 {'mt_sw_if_index': tun_sw_if_index,
956 'mt_is_add': is_add,
957 'mt_l2_only': l2_only,
958 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
959 'mt_next_hop_weight': next_hop_weight,
960 'mt_next_hop': next_hop_address,
961 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
962 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
963 'mt_next_hop_table_id': next_hop_table_id,
964 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800965
966 def snat_interface_add_del_feature(
967 self,
968 sw_if_index,
969 is_inside=1,
970 is_add=1):
971 """Enable/disable S-NAT feature on the interface
972
973 :param sw_if_index: Software index of the interface
974 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
975 :param is_add: 1 if add, 0 if delete (Default value = 1)
976 """
977 return self.api(
978 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200979 {'is_add': is_add,
980 'is_inside': is_inside,
981 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800982
983 def snat_add_static_mapping(
984 self,
985 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800986 external_ip=0,
987 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800988 local_port=0,
989 external_port=0,
990 addr_only=1,
991 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800992 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -0800993 is_add=1,
994 is_ip4=1):
995 """Add/delete S-NAT static mapping
996
997 :param local_ip: Local IP address
998 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800999 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001000 :param local_port: Local port number (Default value = 0)
1001 :param external_port: External port number (Default value = 0)
1002 :param addr_only: 1 if address only mapping, 0 if address and port
1003 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001004 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -08001005 :param is_add: 1 if add, 0 if delete (Default value = 1)
1006 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1007 """
1008 return self.api(
1009 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001010 {'is_add': is_add,
1011 'is_ip4': is_ip4,
1012 'addr_only': addr_only,
1013 'local_ip_address': local_ip,
1014 'external_ip_address': external_ip,
1015 'local_port': local_port,
1016 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001017 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001018 'vrf_id': vrf_id,
1019 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -08001020
1021 def snat_add_address_range(
1022 self,
1023 first_ip_address,
1024 last_ip_address,
1025 is_add=1,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001026 is_ip4=1,
1027 vrf_id=0xFFFFFFFF):
Matus Fabiande886752016-12-07 03:38:19 -08001028 """Add/del S-NAT address range
1029
1030 :param first_ip_address: First IP address
1031 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001032 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -08001033 :param is_add: 1 if add, 0 if delete (Default value = 1)
1034 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1035 """
1036 return self.api(
1037 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001038 {'is_ip4': is_ip4,
1039 'first_ip_address': first_ip_address,
1040 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001041 'vrf_id': vrf_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001042 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001043
1044 def snat_address_dump(self):
1045 """Dump S-NAT addresses
1046 :return: Dictionary of S-NAT addresses
1047 """
1048 return self.api(self.papi.snat_address_dump, {})
1049
1050 def snat_interface_dump(self):
1051 """Dump interfaces with S-NAT feature
1052 :return: Dictionary of interfaces with S-NAT feature
1053 """
1054 return self.api(self.papi.snat_interface_dump, {})
1055
1056 def snat_static_mapping_dump(self):
1057 """Dump S-NAT static mappings
1058 :return: Dictionary of S-NAT static mappings
1059 """
1060 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001061
Matus Fabian9902fcd2016-12-21 23:58:46 -08001062 def snat_show_config(self):
1063 """Show S-NAT config
1064 :return: S-NAT config parameters
1065 """
1066 return self.api(self.papi.snat_show_config, {})
1067
Matus Fabian8bf68e82017-01-12 04:24:35 -08001068 def snat_add_interface_addr(
1069 self,
1070 sw_if_index,
1071 is_add=1):
1072 """Add/del S-NAT address from interface
1073
1074 :param sw_if_index: Software index of the interface
1075 :param is_add: 1 if add, 0 if delete (Default value = 1)
1076 """
1077 return self.api(self.papi.snat_add_del_interface_addr,
1078 {'is_add': is_add, 'sw_if_index': sw_if_index})
1079
1080 def snat_interface_addr_dump(self):
1081 """Dump S-NAT addresses interfaces
1082 :return: Dictionary of S-NAT addresses interfaces
1083 """
1084 return self.api(self.papi.snat_interface_addr_dump, {})
1085
Matus Fabianeea28d72017-01-13 04:15:54 -08001086 def snat_ipfix(
1087 self,
1088 domain_id=1,
1089 src_port=4739,
1090 enable=1):
1091 """Enable/disable S-NAT IPFIX logging
1092
1093 :param domain_id: Observation domain ID (Default value = 1)
1094 :param src_port: Source port number (Default value = 4739)
1095 :param enable: 1 if enable, 0 if disable (Default value = 1)
1096 """
1097 return self.api(
1098 self.papi.snat_ipfix_enable_disable,
1099 {'domain_id': domain_id,
1100 'src_port': src_port,
1101 'enable': enable})
1102
magalik23caa882017-02-08 23:25:45 -08001103 def snat_user_session_dump(
1104 self,
1105 ip_address,
1106 vrf_id):
1107 """Dump S-NAT user's sessions
1108
1109 :param ip_address: ip adress of the user to be dumped
1110 :param cpu_index: cpu_index on which the user is
1111 :param vrf_id: VRF ID
1112 :return: Dictionary of S-NAT sessions
1113 """
1114 return self.api(
1115 self.papi.snat_user_session_dump,
1116 {'ip_address': ip_address,
1117 'vrf_id': vrf_id})
1118
1119 def snat_user_dump(self):
1120 """Dump S-NAT users
1121
1122 :return: Dictionary of S-NAT users
1123 """
1124 return self.api(self.papi.snat_user_dump, {})
1125
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001126 def control_ping(self):
1127 self.api(self.papi.control_ping)
1128
1129 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001130 detect_mult, local_addr, peer_addr, is_ipv6=0,
1131 bfd_key_id=None, conf_key_id=None):
1132 if bfd_key_id is None:
1133 return self.api(self.papi.bfd_udp_add,
1134 {
1135 'sw_if_index': sw_if_index,
1136 'desired_min_tx': desired_min_tx,
1137 'required_min_rx': required_min_rx,
1138 'local_addr': local_addr,
1139 'peer_addr': peer_addr,
1140 'is_ipv6': is_ipv6,
1141 'detect_mult': detect_mult,
1142 })
1143 else:
1144 return self.api(self.papi.bfd_udp_add,
1145 {
1146 'sw_if_index': sw_if_index,
1147 'desired_min_tx': desired_min_tx,
1148 'required_min_rx': required_min_rx,
1149 'local_addr': local_addr,
1150 'peer_addr': peer_addr,
1151 'is_ipv6': is_ipv6,
1152 'detect_mult': detect_mult,
1153 'is_authenticated': 1,
1154 'bfd_key_id': bfd_key_id,
1155 'conf_key_id': conf_key_id,
1156 })
1157
Klement Sekeraa57a9702017-02-02 06:58:07 +01001158 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1159 detect_mult, local_addr, peer_addr, is_ipv6=0):
1160 return self.api(self.papi.bfd_udp_mod,
1161 {
1162 'sw_if_index': sw_if_index,
1163 'desired_min_tx': desired_min_tx,
1164 'required_min_rx': required_min_rx,
1165 'local_addr': local_addr,
1166 'peer_addr': peer_addr,
1167 'is_ipv6': is_ipv6,
1168 'detect_mult': detect_mult,
1169 })
1170
Klement Sekerab17dd962017-01-09 07:43:48 +01001171 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1172 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1173 is_delayed=False):
1174 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001175 {
1176 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001177 'local_addr': local_addr,
1178 'peer_addr': peer_addr,
1179 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001180 'is_delayed': 1 if is_delayed else 0,
1181 'bfd_key_id': bfd_key_id,
1182 'conf_key_id': conf_key_id,
1183 })
1184
1185 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1186 is_ipv6=0, is_delayed=False):
1187 return self.api(self.papi.bfd_udp_auth_deactivate,
1188 {
1189 'sw_if_index': sw_if_index,
1190 'local_addr': local_addr,
1191 'peer_addr': peer_addr,
1192 'is_ipv6': is_ipv6,
1193 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001194 })
1195
1196 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1197 return self.api(self.papi.bfd_udp_del,
1198 {
1199 'sw_if_index': sw_if_index,
1200 'local_addr': local_addr,
1201 'peer_addr': peer_addr,
1202 'is_ipv6': is_ipv6,
1203 })
1204
1205 def bfd_udp_session_dump(self):
1206 return self.api(self.papi.bfd_udp_session_dump, {})
1207
Klement Sekerab17dd962017-01-09 07:43:48 +01001208 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1209 peer_addr, is_ipv6=0):
1210 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001211 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001212 'sw_if_index': sw_if_index,
1213 'local_addr': local_addr,
1214 'peer_addr': peer_addr,
1215 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001216 })
1217
1218 def want_bfd_events(self, enable_disable=1):
1219 return self.api(self.papi.want_bfd_events, {
1220 'enable_disable': enable_disable,
1221 'pid': os.getpid(),
1222 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001223
Klement Sekerab17dd962017-01-09 07:43:48 +01001224 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1225 return self.api(self.papi.bfd_auth_set_key, {
1226 'conf_key_id': conf_key_id,
1227 'auth_type': auth_type,
1228 'key': key,
1229 'key_len': len(key),
1230 })
1231
1232 def bfd_auth_del_key(self, conf_key_id):
1233 return self.api(self.papi.bfd_auth_del_key, {
1234 'conf_key_id': conf_key_id,
1235 })
1236
1237 def bfd_auth_keys_dump(self):
1238 return self.api(self.papi.bfd_auth_keys_dump, {})
1239
Klement Sekera239790f2017-02-16 10:53:53 +01001240 def bfd_udp_set_echo_source(self, sw_if_index):
1241 return self.api(self.papi.bfd_udp_set_echo_source,
1242 {'sw_if_index': sw_if_index})
1243
Klement Sekera73884482017-02-23 09:26:30 +01001244 def bfd_udp_del_echo_source(self):
1245 return self.api(self.papi.bfd_udp_del_echo_source, {})
1246
Steve Shin7957d6e2016-12-19 09:24:50 -08001247 def classify_add_del_table(
1248 self,
1249 is_add,
1250 mask,
1251 match_n_vectors=1,
1252 table_index=0xFFFFFFFF,
1253 nbuckets=2,
1254 memory_size=2097152,
1255 skip_n_vectors=0,
1256 next_table_index=0xFFFFFFFF,
1257 miss_next_index=0xFFFFFFFF,
1258 current_data_flag=0,
1259 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001260 """
1261 :param is_add:
1262 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001263 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001264 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001265 :param nbuckets: (Default value = 2)
1266 :param memory_size: (Default value = 2097152)
1267 :param skip_n_vectors: (Default value = 0)
1268 :param next_table_index: (Default value = 0xFFFFFFFF)
1269 :param miss_next_index: (Default value = 0xFFFFFFFF)
1270 :param current_data_flag: (Default value = 0)
1271 :param current_data_offset: (Default value = 0)
1272 """
1273
1274 return self.api(
1275 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001276 {'is_add': is_add,
1277 'table_index': table_index,
1278 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001279 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001280 'skip_n_vectors': skip_n_vectors,
1281 'match_n_vectors': match_n_vectors,
1282 'next_table_index': next_table_index,
1283 'miss_next_index': miss_next_index,
1284 'current_data_flag': current_data_flag,
1285 'current_data_offset': current_data_offset,
1286 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001287
1288 def classify_add_del_session(
1289 self,
1290 is_add,
1291 table_index,
1292 match,
1293 opaque_index=0xFFFFFFFF,
1294 hit_next_index=0xFFFFFFFF,
1295 advance=0,
1296 action=0,
1297 metadata=0):
1298 """
1299 :param is_add:
1300 :param table_index:
1301 :param match:
1302 :param opaque_index: (Default value = 0xFFFFFFFF)
1303 :param hit_next_index: (Default value = 0xFFFFFFFF)
1304 :param advance: (Default value = 0)
1305 :param action: (Default value = 0)
1306 :param metadata: (Default value = 0)
1307 """
1308
1309 return self.api(
1310 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001311 {'is_add': is_add,
1312 'table_index': table_index,
1313 'hit_next_index': hit_next_index,
1314 'opaque_index': opaque_index,
1315 'advance': advance,
1316 'action': action,
1317 'metadata': metadata,
1318 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001319
1320 def input_acl_set_interface(
1321 self,
1322 is_add,
1323 sw_if_index,
1324 ip4_table_index=0xFFFFFFFF,
1325 ip6_table_index=0xFFFFFFFF,
1326 l2_table_index=0xFFFFFFFF):
1327 """
1328 :param is_add:
1329 :param sw_if_index:
1330 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1331 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1332 :param l2_table_index: (Default value = 0xFFFFFFFF)
1333 """
1334
1335 return self.api(
1336 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001337 {'sw_if_index': sw_if_index,
1338 'ip4_table_index': ip4_table_index,
1339 'ip6_table_index': ip6_table_index,
1340 'l2_table_index': l2_table_index,
1341 'is_add': is_add})
1342
1343 def set_ipfix_exporter(
1344 self,
1345 collector_address,
1346 src_address,
1347 path_mtu,
1348 template_interval,
1349 vrf_id=0,
1350 collector_port=4739,
1351 udp_checksum=0):
1352 return self.api(
1353 self.papi.set_ipfix_exporter,
1354 {
1355 'collector_address': collector_address,
1356 'collector_port': collector_port,
1357 'src_address': src_address,
1358 'vrf_id': vrf_id,
1359 'path_mtu': path_mtu,
1360 'template_interval': template_interval,
1361 'udp_checksum': udp_checksum,
1362 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001363
1364 def dhcp_proxy_config(self,
1365 dhcp_server,
1366 dhcp_src_address,
1367 rx_table_id=0,
1368 server_table_id=0,
1369 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001370 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001371 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001372 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001373 {
1374 'rx_vrf_id': rx_table_id,
1375 'server_vrf_id': server_table_id,
1376 'is_ipv6': is_ipv6,
1377 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001378 'dhcp_server': dhcp_server,
1379 'dhcp_src_address': dhcp_src_address,
1380 })
1381
1382 def dhcp_proxy_set_vss(self,
1383 table_id,
1384 fib_id,
1385 oui,
1386 is_add=1,
1387 is_ip6=0):
1388 return self.api(
1389 self.papi.dhcp_proxy_set_vss,
1390 {
1391 'tbl_id': table_id,
1392 'fib_id': fib_id,
1393 'is_ipv6': is_ip6,
1394 'is_add': is_add,
1395 'oui': oui,
1396 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001397
1398 def ip_mroute_add_del(self,
1399 src_address,
1400 grp_address,
1401 grp_address_length,
1402 e_flags,
1403 next_hop_sw_if_index,
1404 i_flags,
1405 table_id=0,
1406 create_vrf_if_needed=0,
1407 is_add=1,
1408 is_ipv6=0,
1409 is_local=0):
1410 """
1411 """
1412 return self.api(
1413 self.papi.ip_mroute_add_del,
1414 {'next_hop_sw_if_index': next_hop_sw_if_index,
1415 'entry_flags': e_flags,
1416 'itf_flags': i_flags,
1417 'create_vrf_if_needed': create_vrf_if_needed,
1418 'is_add': is_add,
1419 'is_ipv6': is_ipv6,
1420 'is_local': is_local,
1421 'grp_address_length': grp_address_length,
1422 'grp_address': grp_address,
1423 'src_address': src_address})
1424
1425 def mfib_signal_dump(self):
1426 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001427
1428 def ip_mfib_dump(self):
1429 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001430
1431 def lisp_enable_disable(self, is_enabled):
1432 return self.api(
1433 self.papi.lisp_enable_disable,
1434 {
1435 'is_en': is_enabled,
1436 })
1437
1438 def lisp_locator_set(self,
1439 ls_name,
1440 is_add=1):
1441 return self.api(
1442 self.papi.lisp_add_del_locator_set,
1443 {
1444 'is_add': is_add,
1445 'locator_set_name': ls_name
1446 })
1447
1448 def lisp_locator_set_dump(self):
1449 return self.api(self.papi.lisp_locator_set_dump, {})
1450
1451 def lisp_locator(self,
1452 ls_name,
1453 sw_if_index,
1454 priority=1,
1455 weight=1,
1456 is_add=1):
1457 return self.api(
1458 self.papi.lisp_add_del_locator,
1459 {
1460 'is_add': is_add,
1461 'locator_set_name': ls_name,
1462 'sw_if_index': sw_if_index,
1463 'priority': priority,
1464 'weight': weight
1465 })
1466
1467 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1468 return self.api(
1469 self.papi.lisp_locator_dump,
1470 {
1471 'is_index_set': is_index_set,
1472 'ls_name': ls_name,
1473 'ls_index': ls_index,
1474 })
1475
1476 def lisp_local_mapping(self,
1477 ls_name,
1478 eid_type,
1479 eid,
1480 prefix_len,
1481 vni=0,
1482 key_id=0,
1483 key="",
1484 is_add=1):
1485 return self.api(
1486 self.papi.lisp_add_del_local_eid,
1487 {
1488 'locator_set_name': ls_name,
1489 'is_add': is_add,
1490 'eid_type': eid_type,
1491 'eid': eid,
1492 'prefix_len': prefix_len,
1493 'vni': vni,
1494 'key_id': key_id,
1495 'key': key
1496 })
1497
1498 def lisp_eid_table_dump(self,
1499 eid_set=0,
1500 prefix_length=0,
1501 vni=0,
1502 eid_type=0,
1503 eid=None,
1504 filter_opt=0):
1505 return self.api(
1506 self.papi.lisp_eid_table_dump,
1507 {
1508 'eid_set': eid_set,
1509 'prefix_length': prefix_length,
1510 'vni': vni,
1511 'eid_type': eid_type,
1512 'eid': eid,
1513 'filter': filter_opt,
1514 })
1515
1516 def lisp_remote_mapping(self,
1517 eid_type,
1518 eid,
1519 eid_prefix_len=0,
1520 vni=0,
1521 rlocs=None,
1522 rlocs_num=0,
1523 is_src_dst=0,
1524 is_add=1):
1525 return self.api(
1526 self.papi.lisp_add_del_remote_mapping,
1527 {
1528 'is_add': is_add,
1529 'eid_type': eid_type,
1530 'eid': eid,
1531 'eid_len': eid_prefix_len,
1532 'rloc_num': rlocs_num,
1533 'rlocs': rlocs,
1534 'vni': vni,
1535 'is_src_dst': is_src_dst,
1536 })
1537
1538 def lisp_adjacency(self,
1539 leid,
1540 reid,
1541 leid_len,
1542 reid_len,
1543 eid_type,
1544 is_add=1,
1545 vni=0):
1546 return self.api(
1547 self.papi.lisp_add_del_adjacency,
1548 {
1549 'is_add': is_add,
1550 'vni': vni,
1551 'eid_type': eid_type,
1552 'leid': leid,
1553 'reid': reid,
1554 'leid_len': leid_len,
1555 'reid_len': reid_len,
1556 })
1557
1558 def lisp_adjacencies_get(self, vni=0):
1559 return self.api(
1560 self.papi.lisp_adjacencies_get,
1561 {
1562 'vni': vni
1563 })