blob: bebbe76dfd6c4e457c263a18680efd1a47ab7730 [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import os
Filip Tehlar770e89e2017-01-31 10:39:16 +01002import socket
Klement Sekera0e3c0de2016-09-29 14:43:44 +02003import fnmatch
4import time
Klement Sekeraf62ae122016-10-11 11:47:09 +02005from hook import Hook
Klement Sekerae4504c62016-12-08 10:16:41 +01006from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02007
Klement Sekera0e3c0de2016-09-29 14:43:44 +02008# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +01009# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
10# the vpp_papi_provider.py file to be importable without having to build
11# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020012do_import = True
13try:
14 no_vpp_papi = os.getenv("NO_VPP_PAPI")
15 if no_vpp_papi == "1":
16 do_import = False
17except:
18 pass
19
20if do_import:
Ole Troan7e3a8752016-12-05 10:27:09 +010021 from vpp_papi import VPP
Klement Sekera277b89c2016-10-28 13:20:27 +020022
Klement Sekeraf62ae122016-10-11 11:47:09 +020023# from vnet/vnet/mpls/mpls_types.h
24MPLS_IETF_MAX_LABEL = 0xfffff
25MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
26
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns177bbdc2016-11-15 09:46:51 +000028class L2_VTR_OP:
29 L2_POP_1 = 3
30
Klement Sekera0e3c0de2016-09-29 14:43:44 +020031
Klement Sekera73884482017-02-23 09:26:30 +010032class UnexpectedApiReturnValueError(Exception):
33 """ exception raised when the API return value is unexpected """
34 pass
35
36
Klement Sekeraf62ae122016-10-11 11:47:09 +020037class VppPapiProvider(object):
38 """VPP-api provider using vpp-papi
39
40 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020041 """
42
Klement Sekerae0545ef2017-01-25 08:00:40 +010043 _zero, _negative = range(2)
44
Klement Sekera7bb873a2016-11-18 07:38:42 +010045 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020046 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020047 self.name = name
48 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010049 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010050 self._expect_api_retval = self._zero
51 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010052 jsonfiles = []
53
Klement Sekera0e3c0de2016-09-29 14:43:44 +020054 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010055 for root, dirnames, filenames in os.walk(install_dir):
56 for filename in fnmatch.filter(filenames, '*.api.json'):
57 jsonfiles.append(os.path.join(root, filename))
58
59 self.papi = VPP(jsonfiles)
Klement Sekerae4504c62016-12-08 10:16:41 +010060 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020061
Klement Sekerae0545ef2017-01-25 08:00:40 +010062 def __enter__(self):
63 return self
64
65 def expect_negative_api_retval(self):
66 """ Expect API failure """
67 self._expect_stack.append(self._expect_api_retval)
68 self._expect_api_retval = self._negative
69 return self
70
71 def expect_zero_api_retval(self):
72 """ Expect API success """
73 self._expect_stack.append(self._expect_api_retval)
74 self._expect_api_retval = self._zero
75 return self
76
77 def __exit__(self, exc_type, exc_value, traceback):
78 self._expect_api_retval = self._expect_stack.pop()
79
Klement Sekeraf62ae122016-10-11 11:47:09 +020080 def register_hook(self, hook):
81 """Replace hook registration with new hook
82
83 :param hook:
84
85 """
86 self.hook = hook
87
Klement Sekera0e3c0de2016-09-29 14:43:44 +020088 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +010089 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +020090 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +010091 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +020092 return e
93
94 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +010095 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +010096 if name:
97 self.test_class.logger.debug("Expecting event within %ss",
98 timeout)
99 else:
100 self.test_class.logger.debug("Expecting event '%s' within %ss",
101 name, timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100102 if self._events:
103 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200104 limit = time.time() + timeout
105 while time.time() < limit:
106 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100107 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200108 if name and type(e).__name__ != name:
109 raise Exception(
110 "Unexpected event received: %s, expected: %s" %
111 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100112 self.test_class.logger.debug("Returning event %s:%s" %
113 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200114 return e
115 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200116 raise Exception("Event did not occur within timeout")
117
118 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100119 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200120 # FIXME use the name instead of relying on type(e).__name__ ?
121 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100122 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200123 self._events.append(event)
124
Klement Sekeraf62ae122016-10-11 11:47:09 +0200125 def connect(self):
126 """Connect the API to VPP"""
Ole Troan7e3a8752016-12-05 10:27:09 +0100127 self.papi.connect(self.name, self.shm_prefix)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200128 self.papi.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200129
130 def disconnect(self):
131 """Disconnect the API from VPP"""
Ole Troan7e3a8752016-12-05 10:27:09 +0100132 self.papi.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 """ """
Ole Troan7e3a8752016-12-05 10:27:09 +0100193 return 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
289 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
290 """
291 Enable/Disable An interface for IPv6
292 """
293 return self.api(self.papi.sw_interface_ip6_enable_disable,
294 {'sw_if_index': sw_if_index,
295 'enable': enable})
296
Klement Sekeraf62ae122016-10-11 11:47:09 +0200297 def vxlan_add_del_tunnel(
298 self,
299 src_addr,
300 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200301 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200302 is_add=1,
303 is_ipv6=0,
304 encap_vrf_id=0,
305 decap_next_index=0xFFFFFFFF,
306 vni=0):
307 """
308
309 :param dst_addr:
310 :param src_addr:
311 :param is_add: (Default value = 1)
312 :param is_ipv6: (Default value = 0)
313 :param encap_vrf_id: (Default value = 0)
314 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200315 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200316 :param vni: (Default value = 0)
317
318 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100319 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200320 {'is_add': is_add,
321 'is_ipv6': is_ipv6,
322 'src_address': src_addr,
323 'dst_address': dst_addr,
324 'mcast_sw_if_index': mcast_sw_if_index,
325 'encap_vrf_id': encap_vrf_id,
326 'decap_next_index': decap_next_index,
327 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200328
Jan4af521d2016-11-15 17:05:00 +0100329 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
330 learn=1, arp_term=0, is_add=1):
331 """Create/delete bridge domain.
332
333 :param int bd_id: Bridge domain index.
334 :param int flood: Enable/disable bcast/mcast flooding in the BD.
335 (Default value = 1)
336 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
337 (Default value = 1)
338 :param int forward: Enable/disable forwarding on all interfaces in
339 the BD. (Default value = 1)
340 :param int learn: Enable/disable learning on all interfaces in the BD.
341 (Default value = 1)
342 :param int arp_term: Enable/disable arp termination in the BD.
343 (Default value = 1)
344 :param int is_add: Add or delete flag. (Default value = 1)
345 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100346 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200347 {'bd_id': bd_id,
348 'flood': flood,
349 'uu_flood': uu_flood,
350 'forward': forward,
351 'learn': learn,
352 'arp_term': arp_term,
353 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100354
355 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
356 filter_mac=0, bvi_mac=0):
357 """Create/delete L2 FIB entry.
358
359 :param str mac: MAC address to create FIB entry for.
360 :param int bd_id: Bridge domain index.
361 :param int sw_if_index: Software interface index of the interface.
362 :param int is_add: Add or delete flag. (Default value = 1)
363 :param int static_mac: Set to 1 to create static MAC entry.
364 (Default value = 0)
365 :param int filter_mac: Set to 1 to drop packet that's source or
366 destination MAC address contains defined MAC address.
367 (Default value = 0)
368 :param int bvi_mac: Set to 1 to create entry that points to BVI
369 interface. (Default value = 0)
370 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100371 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200372 {'mac': self._convert_mac(mac),
373 'bd_id': bd_id,
374 'sw_if_index': sw_if_index,
375 'is_add': is_add,
376 'static_mac': static_mac,
377 'filter_mac': filter_mac,
378 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100379
Klement Sekeraf62ae122016-10-11 11:47:09 +0200380 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
381 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100382 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200383
Jan4af521d2016-11-15 17:05:00 +0100384 :param int sw_if_index: Software interface index of the interface.
385 :param int bd_id: Bridge domain index.
386 :param int shg: Split-horizon group index. (Default value = 0)
387 :param int bvi: Set interface as a bridge group virtual interface.
388 (Default value = 0)
389 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200390 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100391 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200392 {'rx_sw_if_index': sw_if_index,
393 'bd_id': bd_id,
394 'shg': shg,
395 'bvi': bvi,
396 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200397
Jan00dad122016-11-29 10:04:53 +0100398 def bridge_flags(self, bd_id, is_set, feature_bitmap):
399 """Enable/disable required feature of the bridge domain with defined ID.
400
401 :param int bd_id: Bridge domain ID.
402 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
403 :param int feature_bitmap: Bitmap value of the feature to be set:
404 - learn (1 << 0),
405 - forward (1 << 1),
406 - flood (1 << 2),
407 - uu-flood (1 << 3) or
408 - arp-term (1 << 4).
409 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100410 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200411 {'bd_id': bd_id,
412 'is_set': is_set,
413 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100414
415 def bridge_domain_dump(self, bd_id=0):
416 """
417
418 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
419 existing bridge domains returned)
420 :return: Dictionary of bridge domain(s) data.
421 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100422 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200423 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100424
Klement Sekeraf62ae122016-10-11 11:47:09 +0200425 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
426 enable):
427 """Create or delete unidirectional cross-connect from Tx interface to
428 Rx interface.
429
Jan4af521d2016-11-15 17:05:00 +0100430 :param int rx_sw_if_index: Software interface index of Rx interface.
431 :param int tx_sw_if_index: Software interface index of Tx interface.
432 :param int enable: Create cross-connect if equal to 1, delete
433 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200434
435 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100436 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200437 {'rx_sw_if_index': rx_sw_if_index,
438 'tx_sw_if_index': tx_sw_if_index,
439 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200440
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200441 def sw_interface_set_l2_tag_rewrite(
442 self,
443 sw_if_index,
444 vtr_oper,
445 push=0,
446 tag1=0,
447 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000448 """L2 interface vlan tag rewrite configure request
449 :param client_index - opaque cookie to identify the sender
450 :param context - sender context, to match reply w/ request
451 :param sw_if_index - interface the operation is applied to
452 :param vtr_op - Choose from l2_vtr_op_t enum values
453 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
454 :param tag1 - Needed for any push or translate vtr op
455 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
456
457 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100458 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200459 {'sw_if_index': sw_if_index,
460 'vtr_op': vtr_oper,
461 'push_dot1q': push,
462 'tag1': tag1,
463 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000464
Klement Sekeraf62ae122016-10-11 11:47:09 +0200465 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
466 link_up_down=0, deleted=0):
467 """
468
469 :param admin_up_down:
470 :param sw_if_index:
471 :param link_up_down: (Default value = 0)
472 :param deleted: (Default value = 0)
473
474 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100475 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200476 {'sw_if_index': sw_if_index,
477 'admin_up_down': admin_up_down,
478 'link_up_down': link_up_down,
479 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200480
481 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
482 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
483 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
484 """Create subinterface
485 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
486
487 :param sub_id: param inner_vlan:
488 :param sw_if_index:
489 :param outer_vlan:
490 :param inner_vlan:
491 :param no_tags: (Default value = 0)
492 :param one_tag: (Default value = 0)
493 :param two_tags: (Default value = 0)
494 :param dot1ad: (Default value = 0)
495 :param exact_match: (Default value = 0)
496 :param default_sub: (Default value = 0)
497 :param outer_vlan_id_any: (Default value = 0)
498 :param inner_vlan_id_any: (Default value = 0)
499
500 """
501 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100502 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200503 {'sw_if_index': sw_if_index,
504 'sub_id': sub_id,
505 'no_tags': no_tags,
506 'one_tag': one_tag,
507 'two_tags': two_tags,
508 'dot1ad': dot1ad,
509 'exact_match': exact_match,
510 'default_sub': default_sub,
511 'outer_vlan_id_any': outer_vlan_id_any,
512 'inner_vlan_id_any': inner_vlan_id_any,
513 'outer_vlan_id': outer_vlan,
514 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200515
Neale Ranns177bbdc2016-11-15 09:46:51 +0000516 def delete_subif(self, sw_if_index):
517 """Delete subinterface
518
519 :param sw_if_index:
520 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100521 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200522 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000523
Klement Sekeraf62ae122016-10-11 11:47:09 +0200524 def create_vlan_subif(self, sw_if_index, vlan):
525 """
526
527 :param vlan:
528 :param sw_if_index:
529
530 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100531 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200532 {'sw_if_index': sw_if_index,
533 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200534
Matej Klotton0178d522016-11-04 11:11:44 +0100535 def create_loopback(self, mac=''):
536 """
537
538 :param mac: (Optional)
539 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100540 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200541 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100542
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100543 def delete_loopback(self, sw_if_index):
544 return self.api(self.papi.delete_loopback,
545 {'sw_if_index': sw_if_index, })
546
Klement Sekeraf62ae122016-10-11 11:47:09 +0200547 def ip_add_del_route(
548 self,
549 dst_address,
550 dst_address_length,
551 next_hop_address,
552 next_hop_sw_if_index=0xFFFFFFFF,
553 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200554 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000555 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200556 next_hop_n_out_labels=0,
557 next_hop_out_label_stack=[],
558 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200559 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000560 is_resolve_host=0,
561 is_resolve_attached=0,
562 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200563 is_add=1,
564 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200565 is_unreach=0,
566 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200567 is_ipv6=0,
568 is_local=0,
569 is_classify=0,
570 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000571 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200572 """
573
574 :param dst_address_length:
575 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
576 :param dst_address:
577 :param next_hop_address:
578 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
579 :param vrf_id: (Default value = 0)
580 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200581 :param classify_table_index: (Default value = 0xFFFFFFFF)
582 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200583 :param is_add: (Default value = 1)
584 :param is_drop: (Default value = 0)
585 :param is_ipv6: (Default value = 0)
586 :param is_local: (Default value = 0)
587 :param is_classify: (Default value = 0)
588 :param is_multipath: (Default value = 0)
589 :param is_resolve_host: (Default value = 0)
590 :param is_resolve_attached: (Default value = 0)
591 :param not_last: (Default value = 0)
592 :param next_hop_weight: (Default value = 1)
593
594 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000595
Klement Sekeraf62ae122016-10-11 11:47:09 +0200596 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100597 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200598 {'next_hop_sw_if_index': next_hop_sw_if_index,
599 'table_id': table_id,
600 'classify_table_index': classify_table_index,
601 'next_hop_table_id': next_hop_table_id,
602 'create_vrf_if_needed': create_vrf_if_needed,
603 'is_add': is_add,
604 'is_drop': is_drop,
605 'is_unreach': is_unreach,
606 'is_prohibit': is_prohibit,
607 'is_ipv6': is_ipv6,
608 'is_local': is_local,
609 'is_classify': is_classify,
610 'is_multipath': is_multipath,
611 'is_resolve_host': is_resolve_host,
612 'is_resolve_attached': is_resolve_attached,
613 'not_last': not_last,
614 'next_hop_weight': next_hop_weight,
615 'dst_address_length': dst_address_length,
616 'dst_address': dst_address,
617 'next_hop_address': next_hop_address,
618 'next_hop_n_out_labels': next_hop_n_out_labels,
619 'next_hop_via_label': next_hop_via_label,
620 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100621
Matej Klotton16a14cd2016-12-07 15:09:13 +0100622 def ip_fib_dump(self):
623 return self.api(self.papi.ip_fib_dump, {})
624
Jan Gelety057bb8c2016-12-20 17:32:45 +0100625 def ip6_fib_dump(self):
626 return self.api(self.papi.ip6_fib_dump, {})
627
Matej Klotton0178d522016-11-04 11:11:44 +0100628 def ip_neighbor_add_del(self,
629 sw_if_index,
630 mac_address,
631 dst_address,
632 vrf_id=0,
633 is_add=1,
634 is_ipv6=0,
635 is_static=0,
636 ):
637 """ Add neighbor MAC to IPv4 or IPv6 address.
638
639 :param sw_if_index:
640 :param mac_address:
641 :param dst_address:
642 :param vrf_id: (Default value = 0)
643 :param is_add: (Default value = 1)
644 :param is_ipv6: (Default value = 0)
645 :param is_static: (Default value = 0)
646 """
647
648 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100649 self.papi.ip_neighbor_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200650 {'vrf_id': vrf_id,
651 'sw_if_index': sw_if_index,
652 'is_add': is_add,
653 'is_ipv6': is_ipv6,
654 'is_static': is_static,
655 'mac_address': mac_address,
656 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100657 }
Matej Klotton0178d522016-11-04 11:11:44 +0100658 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100659
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800660 def ip_neighbor_dump(self,
661 sw_if_index,
662 is_ipv6=0):
663 """ Return IP neighbor dump.
664
665 :param sw_if_index:
666 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
667 """
668
669 return self.api(
670 self.papi.ip_neighbor_dump,
671 {'is_ipv6': is_ipv6,
672 'sw_if_index': sw_if_index
673 }
674 )
675
676 def proxy_arp_add_del(self,
677 low_address,
678 hi_address,
679 vrf_id=0,
680 is_add=1):
681 """ Config Proxy Arp Range.
682
683 :param low_address: Start address in the rnage to Proxy for
684 :param hi_address: End address in the rnage to Proxy for
685 :param vrf_id: The VRF/table in which to proxy
686 """
687
688 return self.api(
689 self.papi.proxy_arp_add_del,
690 {'vrf_id': vrf_id,
691 'is_add': is_add,
692 'low_address': low_address,
693 'hi_address': hi_address,
694 }
695 )
696
697 def proxy_arp_intfc_enable_disable(self,
698 sw_if_index,
699 is_enable=1):
700 """ Enable/Disable an interface for proxy ARP requests
701
702 :param sw_if_index: Interface
703 :param enable_disable: Enable/Disable
704 """
705
706 return self.api(
707 self.papi.proxy_arp_intfc_enable_disable,
708 {'sw_if_index': sw_if_index,
709 'enable_disable': is_enable
710 }
711 )
712
Jane546d3b2016-12-08 13:10:03 +0100713 def reset_vrf(self,
714 vrf_id,
715 is_ipv6=0,
716 ):
717 """ Reset VRF (remove all routes etc.) request.
718
719 :param int vrf_id: ID of the FIB table / VRF to reset.
720 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
721 """
722
723 return self.api(
724 self.papi.reset_vrf,
725 {'vrf_id': vrf_id,
726 'is_ipv6': is_ipv6,
727 }
728 )
729
730 def reset_fib(self,
731 vrf_id,
732 is_ipv6=0,
733 ):
734 """ Reset VRF (remove all routes etc.) request.
735
736 :param int vrf_id: ID of the FIB table / VRF to reset.
737 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
738 """
739
740 return self.api(
741 self.papi.reset_fib,
742 {'vrf_id': vrf_id,
743 'is_ipv6': is_ipv6,
744 }
745 )
746
747 def ip_dump(self,
748 is_ipv6=0,
749 ):
750 """ Return IP dump.
751
752 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
753 """
754
755 return self.api(
756 self.papi.ip_dump,
757 {'is_ipv6': is_ipv6,
758 }
759 )
760
Klement Sekera7bb873a2016-11-18 07:38:42 +0100761 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100762 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100763 """
764
765 :param sw_if_index_from:
766 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100767 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100768 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100769 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200770 {'sw_if_index_from': sw_if_index_from,
771 'sw_if_index_to': sw_if_index_to,
772 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000773
774 def gre_tunnel_add_del(self,
775 src_address,
776 dst_address,
777 outer_fib_id=0,
778 is_teb=0,
779 is_add=1,
780 is_ip6=0):
781 """ Add a GRE tunnel
782
783 :param src_address:
784 :param dst_address:
785 :param outer_fib_id: (Default value = 0)
786 :param is_add: (Default value = 1)
787 :param is_ipv6: (Default value = 0)
788 :param is_teb: (Default value = 0)
789 """
790
791 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100792 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200793 {'is_add': is_add,
794 'is_ipv6': is_ip6,
795 'teb': is_teb,
796 'src_address': src_address,
797 'dst_address': dst_address,
798 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000799 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000800
Neale Ranns5a8123b2017-01-26 01:18:23 -0800801 def mpls_fib_dump(self):
802 return self.api(self.papi.mpls_fib_dump, {})
803
Neale Rannsad422ed2016-11-02 14:20:04 +0000804 def mpls_route_add_del(
805 self,
806 label,
807 eos,
808 next_hop_proto_is_ip4,
809 next_hop_address,
810 next_hop_sw_if_index=0xFFFFFFFF,
811 table_id=0,
812 next_hop_table_id=0,
813 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200814 next_hop_n_out_labels=0,
815 next_hop_out_label_stack=[],
816 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000817 create_vrf_if_needed=0,
818 is_resolve_host=0,
819 is_resolve_attached=0,
820 is_add=1,
821 is_drop=0,
822 is_multipath=0,
823 classify_table_index=0xFFFFFFFF,
824 is_classify=0,
825 not_last=0):
826 """
827
828 :param dst_address_length:
829 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
830 :param dst_address:
831 :param next_hop_address:
832 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
833 :param vrf_id: (Default value = 0)
834 :param lookup_in_vrf: (Default value = 0)
835 :param classify_table_index: (Default value = 0xFFFFFFFF)
836 :param create_vrf_if_needed: (Default value = 0)
837 :param is_add: (Default value = 1)
838 :param is_drop: (Default value = 0)
839 :param is_ipv6: (Default value = 0)
840 :param is_local: (Default value = 0)
841 :param is_classify: (Default value = 0)
842 :param is_multipath: (Default value = 0)
843 :param is_resolve_host: (Default value = 0)
844 :param is_resolve_attached: (Default value = 0)
845 :param not_last: (Default value = 0)
846 :param next_hop_weight: (Default value = 1)
847
848 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000849
850 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100851 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200852 {'mr_label': label,
853 'mr_eos': eos,
854 'mr_table_id': table_id,
855 'mr_classify_table_index': classify_table_index,
856 'mr_create_table_if_needed': create_vrf_if_needed,
857 'mr_is_add': is_add,
858 'mr_is_classify': is_classify,
859 'mr_is_multipath': is_multipath,
860 'mr_is_resolve_host': is_resolve_host,
861 'mr_is_resolve_attached': is_resolve_attached,
862 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
863 'mr_next_hop_weight': next_hop_weight,
864 'mr_next_hop': next_hop_address,
865 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
866 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
867 'mr_next_hop_table_id': next_hop_table_id,
868 'mr_next_hop_via_label': next_hop_via_label,
869 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000870
871 def mpls_ip_bind_unbind(
872 self,
873 label,
874 dst_address,
875 dst_address_length,
876 table_id=0,
877 ip_table_id=0,
878 is_ip4=1,
879 create_vrf_if_needed=0,
880 is_bind=1):
881 """
882 """
883 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100884 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200885 {'mb_mpls_table_id': table_id,
886 'mb_label': label,
887 'mb_ip_table_id': ip_table_id,
888 'mb_create_table_if_needed': create_vrf_if_needed,
889 'mb_is_bind': is_bind,
890 'mb_is_ip4': is_ip4,
891 'mb_address_length': dst_address_length,
892 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000893
894 def mpls_tunnel_add_del(
895 self,
896 tun_sw_if_index,
897 next_hop_proto_is_ip4,
898 next_hop_address,
899 next_hop_sw_if_index=0xFFFFFFFF,
900 next_hop_table_id=0,
901 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200902 next_hop_n_out_labels=0,
903 next_hop_out_label_stack=[],
904 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000905 create_vrf_if_needed=0,
906 is_add=1,
907 l2_only=0):
908 """
909
910 :param dst_address_length:
911 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
912 :param dst_address:
913 :param next_hop_address:
914 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
915 :param vrf_id: (Default value = 0)
916 :param lookup_in_vrf: (Default value = 0)
917 :param classify_table_index: (Default value = 0xFFFFFFFF)
918 :param create_vrf_if_needed: (Default value = 0)
919 :param is_add: (Default value = 1)
920 :param is_drop: (Default value = 0)
921 :param is_ipv6: (Default value = 0)
922 :param is_local: (Default value = 0)
923 :param is_classify: (Default value = 0)
924 :param is_multipath: (Default value = 0)
925 :param is_resolve_host: (Default value = 0)
926 :param is_resolve_attached: (Default value = 0)
927 :param not_last: (Default value = 0)
928 :param next_hop_weight: (Default value = 1)
929
930 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000931 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100932 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200933 {'mt_sw_if_index': tun_sw_if_index,
934 'mt_is_add': is_add,
935 'mt_l2_only': l2_only,
936 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
937 'mt_next_hop_weight': next_hop_weight,
938 'mt_next_hop': next_hop_address,
939 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
940 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
941 'mt_next_hop_table_id': next_hop_table_id,
942 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800943
944 def snat_interface_add_del_feature(
945 self,
946 sw_if_index,
947 is_inside=1,
948 is_add=1):
949 """Enable/disable S-NAT feature on the interface
950
951 :param sw_if_index: Software index of the interface
952 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
953 :param is_add: 1 if add, 0 if delete (Default value = 1)
954 """
955 return self.api(
956 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200957 {'is_add': is_add,
958 'is_inside': is_inside,
959 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800960
961 def snat_add_static_mapping(
962 self,
963 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800964 external_ip=0,
965 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800966 local_port=0,
967 external_port=0,
968 addr_only=1,
969 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800970 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -0800971 is_add=1,
972 is_ip4=1):
973 """Add/delete S-NAT static mapping
974
975 :param local_ip: Local IP address
976 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800977 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800978 :param local_port: Local port number (Default value = 0)
979 :param external_port: External port number (Default value = 0)
980 :param addr_only: 1 if address only mapping, 0 if address and port
981 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800982 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -0800983 :param is_add: 1 if add, 0 if delete (Default value = 1)
984 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
985 """
986 return self.api(
987 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200988 {'is_add': is_add,
989 'is_ip4': is_ip4,
990 'addr_only': addr_only,
991 'local_ip_address': local_ip,
992 'external_ip_address': external_ip,
993 'local_port': local_port,
994 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800995 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800996 'vrf_id': vrf_id,
997 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -0800998
999 def snat_add_address_range(
1000 self,
1001 first_ip_address,
1002 last_ip_address,
1003 is_add=1,
1004 is_ip4=1):
1005 """Add/del S-NAT address range
1006
1007 :param first_ip_address: First IP address
1008 :param last_ip_address: Last IP address
1009 :param is_add: 1 if add, 0 if delete (Default value = 1)
1010 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1011 """
1012 return self.api(
1013 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001014 {'is_ip4': is_ip4,
1015 'first_ip_address': first_ip_address,
1016 'last_ip_address': last_ip_address,
1017 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001018
1019 def snat_address_dump(self):
1020 """Dump S-NAT addresses
1021 :return: Dictionary of S-NAT addresses
1022 """
1023 return self.api(self.papi.snat_address_dump, {})
1024
1025 def snat_interface_dump(self):
1026 """Dump interfaces with S-NAT feature
1027 :return: Dictionary of interfaces with S-NAT feature
1028 """
1029 return self.api(self.papi.snat_interface_dump, {})
1030
1031 def snat_static_mapping_dump(self):
1032 """Dump S-NAT static mappings
1033 :return: Dictionary of S-NAT static mappings
1034 """
1035 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001036
Matus Fabian9902fcd2016-12-21 23:58:46 -08001037 def snat_show_config(self):
1038 """Show S-NAT config
1039 :return: S-NAT config parameters
1040 """
1041 return self.api(self.papi.snat_show_config, {})
1042
Matus Fabian8bf68e82017-01-12 04:24:35 -08001043 def snat_add_interface_addr(
1044 self,
1045 sw_if_index,
1046 is_add=1):
1047 """Add/del S-NAT address from interface
1048
1049 :param sw_if_index: Software index of the interface
1050 :param is_add: 1 if add, 0 if delete (Default value = 1)
1051 """
1052 return self.api(self.papi.snat_add_del_interface_addr,
1053 {'is_add': is_add, 'sw_if_index': sw_if_index})
1054
1055 def snat_interface_addr_dump(self):
1056 """Dump S-NAT addresses interfaces
1057 :return: Dictionary of S-NAT addresses interfaces
1058 """
1059 return self.api(self.papi.snat_interface_addr_dump, {})
1060
Matus Fabianeea28d72017-01-13 04:15:54 -08001061 def snat_ipfix(
1062 self,
1063 domain_id=1,
1064 src_port=4739,
1065 enable=1):
1066 """Enable/disable S-NAT IPFIX logging
1067
1068 :param domain_id: Observation domain ID (Default value = 1)
1069 :param src_port: Source port number (Default value = 4739)
1070 :param enable: 1 if enable, 0 if disable (Default value = 1)
1071 """
1072 return self.api(
1073 self.papi.snat_ipfix_enable_disable,
1074 {'domain_id': domain_id,
1075 'src_port': src_port,
1076 'enable': enable})
1077
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001078 def control_ping(self):
1079 self.api(self.papi.control_ping)
1080
1081 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001082 detect_mult, local_addr, peer_addr, is_ipv6=0,
1083 bfd_key_id=None, conf_key_id=None):
1084 if bfd_key_id is None:
1085 return self.api(self.papi.bfd_udp_add,
1086 {
1087 'sw_if_index': sw_if_index,
1088 'desired_min_tx': desired_min_tx,
1089 'required_min_rx': required_min_rx,
1090 'local_addr': local_addr,
1091 'peer_addr': peer_addr,
1092 'is_ipv6': is_ipv6,
1093 'detect_mult': detect_mult,
1094 })
1095 else:
1096 return self.api(self.papi.bfd_udp_add,
1097 {
1098 'sw_if_index': sw_if_index,
1099 'desired_min_tx': desired_min_tx,
1100 'required_min_rx': required_min_rx,
1101 'local_addr': local_addr,
1102 'peer_addr': peer_addr,
1103 'is_ipv6': is_ipv6,
1104 'detect_mult': detect_mult,
1105 'is_authenticated': 1,
1106 'bfd_key_id': bfd_key_id,
1107 'conf_key_id': conf_key_id,
1108 })
1109
Klement Sekeraa57a9702017-02-02 06:58:07 +01001110 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1111 detect_mult, local_addr, peer_addr, is_ipv6=0):
1112 return self.api(self.papi.bfd_udp_mod,
1113 {
1114 'sw_if_index': sw_if_index,
1115 'desired_min_tx': desired_min_tx,
1116 'required_min_rx': required_min_rx,
1117 'local_addr': local_addr,
1118 'peer_addr': peer_addr,
1119 'is_ipv6': is_ipv6,
1120 'detect_mult': detect_mult,
1121 })
1122
Klement Sekerab17dd962017-01-09 07:43:48 +01001123 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1124 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1125 is_delayed=False):
1126 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001127 {
1128 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001129 'local_addr': local_addr,
1130 'peer_addr': peer_addr,
1131 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001132 'is_delayed': 1 if is_delayed else 0,
1133 'bfd_key_id': bfd_key_id,
1134 'conf_key_id': conf_key_id,
1135 })
1136
1137 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1138 is_ipv6=0, is_delayed=False):
1139 return self.api(self.papi.bfd_udp_auth_deactivate,
1140 {
1141 'sw_if_index': sw_if_index,
1142 'local_addr': local_addr,
1143 'peer_addr': peer_addr,
1144 'is_ipv6': is_ipv6,
1145 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001146 })
1147
1148 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1149 return self.api(self.papi.bfd_udp_del,
1150 {
1151 'sw_if_index': sw_if_index,
1152 'local_addr': local_addr,
1153 'peer_addr': peer_addr,
1154 'is_ipv6': is_ipv6,
1155 })
1156
1157 def bfd_udp_session_dump(self):
1158 return self.api(self.papi.bfd_udp_session_dump, {})
1159
Klement Sekerab17dd962017-01-09 07:43:48 +01001160 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1161 peer_addr, is_ipv6=0):
1162 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001163 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001164 'sw_if_index': sw_if_index,
1165 'local_addr': local_addr,
1166 'peer_addr': peer_addr,
1167 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001168 })
1169
1170 def want_bfd_events(self, enable_disable=1):
1171 return self.api(self.papi.want_bfd_events, {
1172 'enable_disable': enable_disable,
1173 'pid': os.getpid(),
1174 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001175
Klement Sekerab17dd962017-01-09 07:43:48 +01001176 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1177 return self.api(self.papi.bfd_auth_set_key, {
1178 'conf_key_id': conf_key_id,
1179 'auth_type': auth_type,
1180 'key': key,
1181 'key_len': len(key),
1182 })
1183
1184 def bfd_auth_del_key(self, conf_key_id):
1185 return self.api(self.papi.bfd_auth_del_key, {
1186 'conf_key_id': conf_key_id,
1187 })
1188
1189 def bfd_auth_keys_dump(self):
1190 return self.api(self.papi.bfd_auth_keys_dump, {})
1191
Klement Sekera239790f2017-02-16 10:53:53 +01001192 def bfd_udp_set_echo_source(self, sw_if_index):
1193 return self.api(self.papi.bfd_udp_set_echo_source,
1194 {'sw_if_index': sw_if_index})
1195
Klement Sekera73884482017-02-23 09:26:30 +01001196 def bfd_udp_del_echo_source(self):
1197 return self.api(self.papi.bfd_udp_del_echo_source, {})
1198
Steve Shin7957d6e2016-12-19 09:24:50 -08001199 def classify_add_del_table(
1200 self,
1201 is_add,
1202 mask,
1203 match_n_vectors=1,
1204 table_index=0xFFFFFFFF,
1205 nbuckets=2,
1206 memory_size=2097152,
1207 skip_n_vectors=0,
1208 next_table_index=0xFFFFFFFF,
1209 miss_next_index=0xFFFFFFFF,
1210 current_data_flag=0,
1211 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001212 """
1213 :param is_add:
1214 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001215 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001216 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001217 :param nbuckets: (Default value = 2)
1218 :param memory_size: (Default value = 2097152)
1219 :param skip_n_vectors: (Default value = 0)
1220 :param next_table_index: (Default value = 0xFFFFFFFF)
1221 :param miss_next_index: (Default value = 0xFFFFFFFF)
1222 :param current_data_flag: (Default value = 0)
1223 :param current_data_offset: (Default value = 0)
1224 """
1225
1226 return self.api(
1227 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001228 {'is_add': is_add,
1229 'table_index': table_index,
1230 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001231 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001232 'skip_n_vectors': skip_n_vectors,
1233 'match_n_vectors': match_n_vectors,
1234 'next_table_index': next_table_index,
1235 'miss_next_index': miss_next_index,
1236 'current_data_flag': current_data_flag,
1237 'current_data_offset': current_data_offset,
1238 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001239
1240 def classify_add_del_session(
1241 self,
1242 is_add,
1243 table_index,
1244 match,
1245 opaque_index=0xFFFFFFFF,
1246 hit_next_index=0xFFFFFFFF,
1247 advance=0,
1248 action=0,
1249 metadata=0):
1250 """
1251 :param is_add:
1252 :param table_index:
1253 :param match:
1254 :param opaque_index: (Default value = 0xFFFFFFFF)
1255 :param hit_next_index: (Default value = 0xFFFFFFFF)
1256 :param advance: (Default value = 0)
1257 :param action: (Default value = 0)
1258 :param metadata: (Default value = 0)
1259 """
1260
1261 return self.api(
1262 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001263 {'is_add': is_add,
1264 'table_index': table_index,
1265 'hit_next_index': hit_next_index,
1266 'opaque_index': opaque_index,
1267 'advance': advance,
1268 'action': action,
1269 'metadata': metadata,
1270 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001271
1272 def input_acl_set_interface(
1273 self,
1274 is_add,
1275 sw_if_index,
1276 ip4_table_index=0xFFFFFFFF,
1277 ip6_table_index=0xFFFFFFFF,
1278 l2_table_index=0xFFFFFFFF):
1279 """
1280 :param is_add:
1281 :param sw_if_index:
1282 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1283 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1284 :param l2_table_index: (Default value = 0xFFFFFFFF)
1285 """
1286
1287 return self.api(
1288 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001289 {'sw_if_index': sw_if_index,
1290 'ip4_table_index': ip4_table_index,
1291 'ip6_table_index': ip6_table_index,
1292 'l2_table_index': l2_table_index,
1293 'is_add': is_add})
1294
1295 def set_ipfix_exporter(
1296 self,
1297 collector_address,
1298 src_address,
1299 path_mtu,
1300 template_interval,
1301 vrf_id=0,
1302 collector_port=4739,
1303 udp_checksum=0):
1304 return self.api(
1305 self.papi.set_ipfix_exporter,
1306 {
1307 'collector_address': collector_address,
1308 'collector_port': collector_port,
1309 'src_address': src_address,
1310 'vrf_id': vrf_id,
1311 'path_mtu': path_mtu,
1312 'template_interval': template_interval,
1313 'udp_checksum': udp_checksum,
1314 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001315
1316 def dhcp_proxy_config(self,
1317 dhcp_server,
1318 dhcp_src_address,
1319 rx_table_id=0,
1320 server_table_id=0,
1321 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001322 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001323 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001324 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001325 {
1326 'rx_vrf_id': rx_table_id,
1327 'server_vrf_id': server_table_id,
1328 'is_ipv6': is_ipv6,
1329 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001330 'dhcp_server': dhcp_server,
1331 'dhcp_src_address': dhcp_src_address,
1332 })
1333
1334 def dhcp_proxy_set_vss(self,
1335 table_id,
1336 fib_id,
1337 oui,
1338 is_add=1,
1339 is_ip6=0):
1340 return self.api(
1341 self.papi.dhcp_proxy_set_vss,
1342 {
1343 'tbl_id': table_id,
1344 'fib_id': fib_id,
1345 'is_ipv6': is_ip6,
1346 'is_add': is_add,
1347 'oui': oui,
1348 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001349
1350 def ip_mroute_add_del(self,
1351 src_address,
1352 grp_address,
1353 grp_address_length,
1354 e_flags,
1355 next_hop_sw_if_index,
1356 i_flags,
1357 table_id=0,
1358 create_vrf_if_needed=0,
1359 is_add=1,
1360 is_ipv6=0,
1361 is_local=0):
1362 """
1363 """
1364 return self.api(
1365 self.papi.ip_mroute_add_del,
1366 {'next_hop_sw_if_index': next_hop_sw_if_index,
1367 'entry_flags': e_flags,
1368 'itf_flags': i_flags,
1369 'create_vrf_if_needed': create_vrf_if_needed,
1370 'is_add': is_add,
1371 'is_ipv6': is_ipv6,
1372 'is_local': is_local,
1373 'grp_address_length': grp_address_length,
1374 'grp_address': grp_address,
1375 'src_address': src_address})
1376
1377 def mfib_signal_dump(self):
1378 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001379
1380 def ip_mfib_dump(self):
1381 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01001382
1383 def lisp_enable_disable(self, is_enabled):
1384 return self.api(
1385 self.papi.lisp_enable_disable,
1386 {
1387 'is_en': is_enabled,
1388 })
1389
1390 def lisp_locator_set(self,
1391 ls_name,
1392 is_add=1):
1393 return self.api(
1394 self.papi.lisp_add_del_locator_set,
1395 {
1396 'is_add': is_add,
1397 'locator_set_name': ls_name
1398 })
1399
1400 def lisp_locator_set_dump(self):
1401 return self.api(self.papi.lisp_locator_set_dump, {})
1402
1403 def lisp_locator(self,
1404 ls_name,
1405 sw_if_index,
1406 priority=1,
1407 weight=1,
1408 is_add=1):
1409 return self.api(
1410 self.papi.lisp_add_del_locator,
1411 {
1412 'is_add': is_add,
1413 'locator_set_name': ls_name,
1414 'sw_if_index': sw_if_index,
1415 'priority': priority,
1416 'weight': weight
1417 })
1418
1419 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1420 return self.api(
1421 self.papi.lisp_locator_dump,
1422 {
1423 'is_index_set': is_index_set,
1424 'ls_name': ls_name,
1425 'ls_index': ls_index,
1426 })
1427
1428 def lisp_local_mapping(self,
1429 ls_name,
1430 eid_type,
1431 eid,
1432 prefix_len,
1433 vni=0,
1434 key_id=0,
1435 key="",
1436 is_add=1):
1437 return self.api(
1438 self.papi.lisp_add_del_local_eid,
1439 {
1440 'locator_set_name': ls_name,
1441 'is_add': is_add,
1442 'eid_type': eid_type,
1443 'eid': eid,
1444 'prefix_len': prefix_len,
1445 'vni': vni,
1446 'key_id': key_id,
1447 'key': key
1448 })
1449
1450 def lisp_eid_table_dump(self,
1451 eid_set=0,
1452 prefix_length=0,
1453 vni=0,
1454 eid_type=0,
1455 eid=None,
1456 filter_opt=0):
1457 return self.api(
1458 self.papi.lisp_eid_table_dump,
1459 {
1460 'eid_set': eid_set,
1461 'prefix_length': prefix_length,
1462 'vni': vni,
1463 'eid_type': eid_type,
1464 'eid': eid,
1465 'filter': filter_opt,
1466 })
1467
1468 def lisp_remote_mapping(self,
1469 eid_type,
1470 eid,
1471 eid_prefix_len=0,
1472 vni=0,
1473 rlocs=None,
1474 rlocs_num=0,
1475 is_src_dst=0,
1476 is_add=1):
1477 return self.api(
1478 self.papi.lisp_add_del_remote_mapping,
1479 {
1480 'is_add': is_add,
1481 'eid_type': eid_type,
1482 'eid': eid,
1483 'eid_len': eid_prefix_len,
1484 'rloc_num': rlocs_num,
1485 'rlocs': rlocs,
1486 'vni': vni,
1487 'is_src_dst': is_src_dst,
1488 })
1489
1490 def lisp_adjacency(self,
1491 leid,
1492 reid,
1493 leid_len,
1494 reid_len,
1495 eid_type,
1496 is_add=1,
1497 vni=0):
1498 return self.api(
1499 self.papi.lisp_add_del_adjacency,
1500 {
1501 'is_add': is_add,
1502 'vni': vni,
1503 'eid_type': eid_type,
1504 'leid': leid,
1505 'reid': reid,
1506 'leid_len': leid_len,
1507 'reid_len': reid_len,
1508 })
1509
1510 def lisp_adjacencies_get(self, vni=0):
1511 return self.api(
1512 self.papi.lisp_adjacencies_get,
1513 {
1514 'vni': vni
1515 })