blob: 842c21b810b0cfe7d25ed46012be1972c0a22401 [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 Sekeraf62ae122016-10-11 11:47:09 +020031class VppPapiProvider(object):
32 """VPP-api provider using vpp-papi
33
34 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020035 """
36
Klement Sekerae0545ef2017-01-25 08:00:40 +010037 _zero, _negative = range(2)
38
Klement Sekera7bb873a2016-11-18 07:38:42 +010039 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020040 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020041 self.name = name
42 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010043 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010044 self._expect_api_retval = self._zero
45 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010046 jsonfiles = []
47
Klement Sekera0e3c0de2016-09-29 14:43:44 +020048 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010049 for root, dirnames, filenames in os.walk(install_dir):
50 for filename in fnmatch.filter(filenames, '*.api.json'):
51 jsonfiles.append(os.path.join(root, filename))
52
53 self.papi = VPP(jsonfiles)
Klement Sekerae4504c62016-12-08 10:16:41 +010054 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020055
Klement Sekerae0545ef2017-01-25 08:00:40 +010056 def __enter__(self):
57 return self
58
59 def expect_negative_api_retval(self):
60 """ Expect API failure """
61 self._expect_stack.append(self._expect_api_retval)
62 self._expect_api_retval = self._negative
63 return self
64
65 def expect_zero_api_retval(self):
66 """ Expect API success """
67 self._expect_stack.append(self._expect_api_retval)
68 self._expect_api_retval = self._zero
69 return self
70
71 def __exit__(self, exc_type, exc_value, traceback):
72 self._expect_api_retval = self._expect_stack.pop()
73
Klement Sekeraf62ae122016-10-11 11:47:09 +020074 def register_hook(self, hook):
75 """Replace hook registration with new hook
76
77 :param hook:
78
79 """
80 self.hook = hook
81
Klement Sekera0e3c0de2016-09-29 14:43:44 +020082 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +010083 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +020084 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +010085 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +020086 return e
87
88 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +010089 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +010090 if name:
91 self.test_class.logger.debug("Expecting event within %ss",
92 timeout)
93 else:
94 self.test_class.logger.debug("Expecting event '%s' within %ss",
95 name, timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010096 if self._events:
97 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +020098 limit = time.time() + timeout
99 while time.time() < limit:
100 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100101 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200102 if name and type(e).__name__ != name:
103 raise Exception(
104 "Unexpected event received: %s, expected: %s" %
105 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100106 self.test_class.logger.debug("Returning event %s:%s" %
107 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200108 return e
109 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200110 raise Exception("Event did not occur within timeout")
111
112 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100113 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200114 # FIXME use the name instead of relying on type(e).__name__ ?
115 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100116 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200117 self._events.append(event)
118
Klement Sekeraf62ae122016-10-11 11:47:09 +0200119 def connect(self):
120 """Connect the API to VPP"""
Ole Troan7e3a8752016-12-05 10:27:09 +0100121 self.papi.connect(self.name, self.shm_prefix)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200122 self.papi.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200123
124 def disconnect(self):
125 """Disconnect the API from VPP"""
Ole Troan7e3a8752016-12-05 10:27:09 +0100126 self.papi.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200127
128 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100129 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200130 Call the appropriate hooks before and after the API call
131
132 :param api_fn: API function to call
133 :param api_args: tuple of API function arguments
134 :param expected_retval: Expected return value (Default value = 0)
135 :returns: reply from the API
136
137 """
138 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100139 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100140 if self._expect_api_retval == self._negative:
141 if hasattr(reply, 'retval') and reply.retval >= 0:
142 msg = "API call passed unexpectedly: expected negative "\
143 "return value instead of %d in %s" % \
144 (reply.retval, repr(reply))
145 self.test_class.logger.info(msg)
146 raise Exception(msg)
147 elif self._expect_api_retval == self._zero:
148 if hasattr(reply, 'retval') and reply.retval != expected_retval:
149 msg = "API call failed, expected zero return value instead "\
150 "of %d in %s" % (expected_retval, repr(reply))
151 self.test_class.logger.info(msg)
152 raise Exception(msg)
153 else:
154 raise Exception("Internal error, unexpected value for "
155 "self._expect_api_retval %s" %
156 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200157 self.hook.after_api(api_fn.__name__, api_args)
158 return reply
159
160 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100161 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200162
163 :param cli: CLI to execute
164 :returns: CLI output
165
166 """
167 self.hook.before_cli(cli)
168 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100169 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200170 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200171 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100172 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200173
Jan49c0fca2016-10-26 15:44:27 +0200174 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100175 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200176
177 :param cli: CLI to execute
178 :returns: CLI output
179 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600180 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200181
Jan4af521d2016-11-15 17:05:00 +0100182 def _convert_mac(self, mac):
183 return int(mac.replace(":", ""), 16) << 16
184
Klement Sekeraf62ae122016-10-11 11:47:09 +0200185 def show_version(self):
186 """ """
Ole Troan7e3a8752016-12-05 10:27:09 +0100187 return self.papi.show_version()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188
189 def pg_create_interface(self, pg_index):
190 """
191
192 :param pg_index:
193
194 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100195 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200196 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200197
198 def sw_interface_dump(self, filter=None):
199 """
200
201 :param filter: (Default value = None)
202
203 """
204 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200205 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100207 args = {}
208 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200209
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000210 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100211 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000212
213 :param sw_if_index:
214 :param is_ipv6:
215 :param table_id:
216
217 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100218 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200219 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
220 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000221
Klement Sekeraf62ae122016-10-11 11:47:09 +0200222 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
223 is_ipv6=0, is_add=1, del_all=0):
224 """
225
226 :param addr: param is_ipv6: (Default value = 0)
227 :param sw_if_index:
228 :param addr_len:
229 :param is_ipv6: (Default value = 0)
230 :param is_add: (Default value = 1)
231 :param del_all: (Default value = 0)
232
233 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100234 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200235 {'sw_if_index': sw_if_index,
236 'is_add': is_add,
237 'is_ipv6': is_ipv6,
238 'del_all': del_all,
239 'address_length': addr_len,
240 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200241
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000242 def sw_interface_enable_disable_mpls(self, sw_if_index,
243 is_enable=1):
244 """
245 Enable/Disable MPLS on the interface
246 :param sw_if_index:
247 :param is_enable: (Default value = 1)
248
249 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100250 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200251 {'sw_if_index': sw_if_index,
252 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000253
Jan Gelety057bb8c2016-12-20 17:32:45 +0100254 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100255 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100256 {'sw_if_index': sw_if_index,
257 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200258
Neale Ranns75152282017-01-09 01:00:45 -0800259 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000260 no,
Neale Ranns75152282017-01-09 01:00:45 -0800261 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000262 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800263 return self.api(self.papi.sw_interface_ip6nd_ra_config,
264 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000265 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100266 'suppress': suppress,
267 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800268
269 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
270 """
271 Enable/Disable An interface for IPv6
272 """
273 return self.api(self.papi.sw_interface_ip6_enable_disable,
274 {'sw_if_index': sw_if_index,
275 'enable': enable})
276
Klement Sekeraf62ae122016-10-11 11:47:09 +0200277 def vxlan_add_del_tunnel(
278 self,
279 src_addr,
280 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200281 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200282 is_add=1,
283 is_ipv6=0,
284 encap_vrf_id=0,
285 decap_next_index=0xFFFFFFFF,
286 vni=0):
287 """
288
289 :param dst_addr:
290 :param src_addr:
291 :param is_add: (Default value = 1)
292 :param is_ipv6: (Default value = 0)
293 :param encap_vrf_id: (Default value = 0)
294 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200295 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200296 :param vni: (Default value = 0)
297
298 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100299 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200300 {'is_add': is_add,
301 'is_ipv6': is_ipv6,
302 'src_address': src_addr,
303 'dst_address': dst_addr,
304 'mcast_sw_if_index': mcast_sw_if_index,
305 'encap_vrf_id': encap_vrf_id,
306 'decap_next_index': decap_next_index,
307 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200308
Jan4af521d2016-11-15 17:05:00 +0100309 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
310 learn=1, arp_term=0, is_add=1):
311 """Create/delete bridge domain.
312
313 :param int bd_id: Bridge domain index.
314 :param int flood: Enable/disable bcast/mcast flooding in the BD.
315 (Default value = 1)
316 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
317 (Default value = 1)
318 :param int forward: Enable/disable forwarding on all interfaces in
319 the BD. (Default value = 1)
320 :param int learn: Enable/disable learning on all interfaces in the BD.
321 (Default value = 1)
322 :param int arp_term: Enable/disable arp termination in the BD.
323 (Default value = 1)
324 :param int is_add: Add or delete flag. (Default value = 1)
325 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100326 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200327 {'bd_id': bd_id,
328 'flood': flood,
329 'uu_flood': uu_flood,
330 'forward': forward,
331 'learn': learn,
332 'arp_term': arp_term,
333 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100334
335 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
336 filter_mac=0, bvi_mac=0):
337 """Create/delete L2 FIB entry.
338
339 :param str mac: MAC address to create FIB entry for.
340 :param int bd_id: Bridge domain index.
341 :param int sw_if_index: Software interface index of the interface.
342 :param int is_add: Add or delete flag. (Default value = 1)
343 :param int static_mac: Set to 1 to create static MAC entry.
344 (Default value = 0)
345 :param int filter_mac: Set to 1 to drop packet that's source or
346 destination MAC address contains defined MAC address.
347 (Default value = 0)
348 :param int bvi_mac: Set to 1 to create entry that points to BVI
349 interface. (Default value = 0)
350 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100351 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200352 {'mac': self._convert_mac(mac),
353 'bd_id': bd_id,
354 'sw_if_index': sw_if_index,
355 'is_add': is_add,
356 'static_mac': static_mac,
357 'filter_mac': filter_mac,
358 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100359
Klement Sekeraf62ae122016-10-11 11:47:09 +0200360 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
361 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100362 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200363
Jan4af521d2016-11-15 17:05:00 +0100364 :param int sw_if_index: Software interface index of the interface.
365 :param int bd_id: Bridge domain index.
366 :param int shg: Split-horizon group index. (Default value = 0)
367 :param int bvi: Set interface as a bridge group virtual interface.
368 (Default value = 0)
369 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200370 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100371 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200372 {'rx_sw_if_index': sw_if_index,
373 'bd_id': bd_id,
374 'shg': shg,
375 'bvi': bvi,
376 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200377
Jan00dad122016-11-29 10:04:53 +0100378 def bridge_flags(self, bd_id, is_set, feature_bitmap):
379 """Enable/disable required feature of the bridge domain with defined ID.
380
381 :param int bd_id: Bridge domain ID.
382 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
383 :param int feature_bitmap: Bitmap value of the feature to be set:
384 - learn (1 << 0),
385 - forward (1 << 1),
386 - flood (1 << 2),
387 - uu-flood (1 << 3) or
388 - arp-term (1 << 4).
389 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100390 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200391 {'bd_id': bd_id,
392 'is_set': is_set,
393 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100394
395 def bridge_domain_dump(self, bd_id=0):
396 """
397
398 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
399 existing bridge domains returned)
400 :return: Dictionary of bridge domain(s) data.
401 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100402 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200403 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100404
Klement Sekeraf62ae122016-10-11 11:47:09 +0200405 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
406 enable):
407 """Create or delete unidirectional cross-connect from Tx interface to
408 Rx interface.
409
Jan4af521d2016-11-15 17:05:00 +0100410 :param int rx_sw_if_index: Software interface index of Rx interface.
411 :param int tx_sw_if_index: Software interface index of Tx interface.
412 :param int enable: Create cross-connect if equal to 1, delete
413 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200414
415 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100416 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200417 {'rx_sw_if_index': rx_sw_if_index,
418 'tx_sw_if_index': tx_sw_if_index,
419 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200420
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200421 def sw_interface_set_l2_tag_rewrite(
422 self,
423 sw_if_index,
424 vtr_oper,
425 push=0,
426 tag1=0,
427 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000428 """L2 interface vlan tag rewrite configure request
429 :param client_index - opaque cookie to identify the sender
430 :param context - sender context, to match reply w/ request
431 :param sw_if_index - interface the operation is applied to
432 :param vtr_op - Choose from l2_vtr_op_t enum values
433 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
434 :param tag1 - Needed for any push or translate vtr op
435 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
436
437 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100438 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200439 {'sw_if_index': sw_if_index,
440 'vtr_op': vtr_oper,
441 'push_dot1q': push,
442 'tag1': tag1,
443 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000444
Klement Sekeraf62ae122016-10-11 11:47:09 +0200445 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
446 link_up_down=0, deleted=0):
447 """
448
449 :param admin_up_down:
450 :param sw_if_index:
451 :param link_up_down: (Default value = 0)
452 :param deleted: (Default value = 0)
453
454 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100455 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200456 {'sw_if_index': sw_if_index,
457 'admin_up_down': admin_up_down,
458 'link_up_down': link_up_down,
459 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200460
461 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
462 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
463 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
464 """Create subinterface
465 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
466
467 :param sub_id: param inner_vlan:
468 :param sw_if_index:
469 :param outer_vlan:
470 :param inner_vlan:
471 :param no_tags: (Default value = 0)
472 :param one_tag: (Default value = 0)
473 :param two_tags: (Default value = 0)
474 :param dot1ad: (Default value = 0)
475 :param exact_match: (Default value = 0)
476 :param default_sub: (Default value = 0)
477 :param outer_vlan_id_any: (Default value = 0)
478 :param inner_vlan_id_any: (Default value = 0)
479
480 """
481 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100482 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200483 {'sw_if_index': sw_if_index,
484 'sub_id': sub_id,
485 'no_tags': no_tags,
486 'one_tag': one_tag,
487 'two_tags': two_tags,
488 'dot1ad': dot1ad,
489 'exact_match': exact_match,
490 'default_sub': default_sub,
491 'outer_vlan_id_any': outer_vlan_id_any,
492 'inner_vlan_id_any': inner_vlan_id_any,
493 'outer_vlan_id': outer_vlan,
494 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200495
Neale Ranns177bbdc2016-11-15 09:46:51 +0000496 def delete_subif(self, sw_if_index):
497 """Delete subinterface
498
499 :param sw_if_index:
500 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100501 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200502 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000503
Klement Sekeraf62ae122016-10-11 11:47:09 +0200504 def create_vlan_subif(self, sw_if_index, vlan):
505 """
506
507 :param vlan:
508 :param sw_if_index:
509
510 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100511 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200512 {'sw_if_index': sw_if_index,
513 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200514
Matej Klotton0178d522016-11-04 11:11:44 +0100515 def create_loopback(self, mac=''):
516 """
517
518 :param mac: (Optional)
519 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100520 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200521 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100522
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100523 def delete_loopback(self, sw_if_index):
524 return self.api(self.papi.delete_loopback,
525 {'sw_if_index': sw_if_index, })
526
Klement Sekeraf62ae122016-10-11 11:47:09 +0200527 def ip_add_del_route(
528 self,
529 dst_address,
530 dst_address_length,
531 next_hop_address,
532 next_hop_sw_if_index=0xFFFFFFFF,
533 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200534 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000535 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200536 next_hop_n_out_labels=0,
537 next_hop_out_label_stack=[],
538 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200539 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000540 is_resolve_host=0,
541 is_resolve_attached=0,
542 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200543 is_add=1,
544 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200545 is_unreach=0,
546 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200547 is_ipv6=0,
548 is_local=0,
549 is_classify=0,
550 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000551 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200552 """
553
554 :param dst_address_length:
555 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
556 :param dst_address:
557 :param next_hop_address:
558 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
559 :param vrf_id: (Default value = 0)
560 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200561 :param classify_table_index: (Default value = 0xFFFFFFFF)
562 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200563 :param is_add: (Default value = 1)
564 :param is_drop: (Default value = 0)
565 :param is_ipv6: (Default value = 0)
566 :param is_local: (Default value = 0)
567 :param is_classify: (Default value = 0)
568 :param is_multipath: (Default value = 0)
569 :param is_resolve_host: (Default value = 0)
570 :param is_resolve_attached: (Default value = 0)
571 :param not_last: (Default value = 0)
572 :param next_hop_weight: (Default value = 1)
573
574 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000575
Klement Sekeraf62ae122016-10-11 11:47:09 +0200576 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100577 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200578 {'next_hop_sw_if_index': next_hop_sw_if_index,
579 'table_id': table_id,
580 'classify_table_index': classify_table_index,
581 'next_hop_table_id': next_hop_table_id,
582 'create_vrf_if_needed': create_vrf_if_needed,
583 'is_add': is_add,
584 'is_drop': is_drop,
585 'is_unreach': is_unreach,
586 'is_prohibit': is_prohibit,
587 'is_ipv6': is_ipv6,
588 'is_local': is_local,
589 'is_classify': is_classify,
590 'is_multipath': is_multipath,
591 'is_resolve_host': is_resolve_host,
592 'is_resolve_attached': is_resolve_attached,
593 'not_last': not_last,
594 'next_hop_weight': next_hop_weight,
595 'dst_address_length': dst_address_length,
596 'dst_address': dst_address,
597 'next_hop_address': next_hop_address,
598 'next_hop_n_out_labels': next_hop_n_out_labels,
599 'next_hop_via_label': next_hop_via_label,
600 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100601
Matej Klotton16a14cd2016-12-07 15:09:13 +0100602 def ip_fib_dump(self):
603 return self.api(self.papi.ip_fib_dump, {})
604
Jan Gelety057bb8c2016-12-20 17:32:45 +0100605 def ip6_fib_dump(self):
606 return self.api(self.papi.ip6_fib_dump, {})
607
Matej Klotton0178d522016-11-04 11:11:44 +0100608 def ip_neighbor_add_del(self,
609 sw_if_index,
610 mac_address,
611 dst_address,
612 vrf_id=0,
613 is_add=1,
614 is_ipv6=0,
615 is_static=0,
616 ):
617 """ Add neighbor MAC to IPv4 or IPv6 address.
618
619 :param sw_if_index:
620 :param mac_address:
621 :param dst_address:
622 :param vrf_id: (Default value = 0)
623 :param is_add: (Default value = 1)
624 :param is_ipv6: (Default value = 0)
625 :param is_static: (Default value = 0)
626 """
627
628 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100629 self.papi.ip_neighbor_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200630 {'vrf_id': vrf_id,
631 'sw_if_index': sw_if_index,
632 'is_add': is_add,
633 'is_ipv6': is_ipv6,
634 'is_static': is_static,
635 'mac_address': mac_address,
636 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100637 }
Matej Klotton0178d522016-11-04 11:11:44 +0100638 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100639
Jane546d3b2016-12-08 13:10:03 +0100640 def reset_vrf(self,
641 vrf_id,
642 is_ipv6=0,
643 ):
644 """ Reset VRF (remove all routes etc.) request.
645
646 :param int vrf_id: ID of the FIB table / VRF to reset.
647 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
648 """
649
650 return self.api(
651 self.papi.reset_vrf,
652 {'vrf_id': vrf_id,
653 'is_ipv6': is_ipv6,
654 }
655 )
656
657 def reset_fib(self,
658 vrf_id,
659 is_ipv6=0,
660 ):
661 """ Reset VRF (remove all routes etc.) request.
662
663 :param int vrf_id: ID of the FIB table / VRF to reset.
664 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
665 """
666
667 return self.api(
668 self.papi.reset_fib,
669 {'vrf_id': vrf_id,
670 'is_ipv6': is_ipv6,
671 }
672 )
673
674 def ip_dump(self,
675 is_ipv6=0,
676 ):
677 """ Return IP dump.
678
679 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
680 """
681
682 return self.api(
683 self.papi.ip_dump,
684 {'is_ipv6': is_ipv6,
685 }
686 )
687
Klement Sekera7bb873a2016-11-18 07:38:42 +0100688 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100689 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100690 """
691
692 :param sw_if_index_from:
693 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100694 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100695 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100696 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200697 {'sw_if_index_from': sw_if_index_from,
698 'sw_if_index_to': sw_if_index_to,
699 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000700
701 def gre_tunnel_add_del(self,
702 src_address,
703 dst_address,
704 outer_fib_id=0,
705 is_teb=0,
706 is_add=1,
707 is_ip6=0):
708 """ Add a GRE tunnel
709
710 :param src_address:
711 :param dst_address:
712 :param outer_fib_id: (Default value = 0)
713 :param is_add: (Default value = 1)
714 :param is_ipv6: (Default value = 0)
715 :param is_teb: (Default value = 0)
716 """
717
718 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100719 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200720 {'is_add': is_add,
721 'is_ipv6': is_ip6,
722 'teb': is_teb,
723 'src_address': src_address,
724 'dst_address': dst_address,
725 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000726 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000727
Neale Ranns5a8123b2017-01-26 01:18:23 -0800728 def mpls_fib_dump(self):
729 return self.api(self.papi.mpls_fib_dump, {})
730
Neale Rannsad422ed2016-11-02 14:20:04 +0000731 def mpls_route_add_del(
732 self,
733 label,
734 eos,
735 next_hop_proto_is_ip4,
736 next_hop_address,
737 next_hop_sw_if_index=0xFFFFFFFF,
738 table_id=0,
739 next_hop_table_id=0,
740 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200741 next_hop_n_out_labels=0,
742 next_hop_out_label_stack=[],
743 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000744 create_vrf_if_needed=0,
745 is_resolve_host=0,
746 is_resolve_attached=0,
747 is_add=1,
748 is_drop=0,
749 is_multipath=0,
750 classify_table_index=0xFFFFFFFF,
751 is_classify=0,
752 not_last=0):
753 """
754
755 :param dst_address_length:
756 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
757 :param dst_address:
758 :param next_hop_address:
759 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
760 :param vrf_id: (Default value = 0)
761 :param lookup_in_vrf: (Default value = 0)
762 :param classify_table_index: (Default value = 0xFFFFFFFF)
763 :param create_vrf_if_needed: (Default value = 0)
764 :param is_add: (Default value = 1)
765 :param is_drop: (Default value = 0)
766 :param is_ipv6: (Default value = 0)
767 :param is_local: (Default value = 0)
768 :param is_classify: (Default value = 0)
769 :param is_multipath: (Default value = 0)
770 :param is_resolve_host: (Default value = 0)
771 :param is_resolve_attached: (Default value = 0)
772 :param not_last: (Default value = 0)
773 :param next_hop_weight: (Default value = 1)
774
775 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000776
777 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100778 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200779 {'mr_label': label,
780 'mr_eos': eos,
781 'mr_table_id': table_id,
782 'mr_classify_table_index': classify_table_index,
783 'mr_create_table_if_needed': create_vrf_if_needed,
784 'mr_is_add': is_add,
785 'mr_is_classify': is_classify,
786 'mr_is_multipath': is_multipath,
787 'mr_is_resolve_host': is_resolve_host,
788 'mr_is_resolve_attached': is_resolve_attached,
789 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
790 'mr_next_hop_weight': next_hop_weight,
791 'mr_next_hop': next_hop_address,
792 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
793 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
794 'mr_next_hop_table_id': next_hop_table_id,
795 'mr_next_hop_via_label': next_hop_via_label,
796 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000797
798 def mpls_ip_bind_unbind(
799 self,
800 label,
801 dst_address,
802 dst_address_length,
803 table_id=0,
804 ip_table_id=0,
805 is_ip4=1,
806 create_vrf_if_needed=0,
807 is_bind=1):
808 """
809 """
810 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100811 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200812 {'mb_mpls_table_id': table_id,
813 'mb_label': label,
814 'mb_ip_table_id': ip_table_id,
815 'mb_create_table_if_needed': create_vrf_if_needed,
816 'mb_is_bind': is_bind,
817 'mb_is_ip4': is_ip4,
818 'mb_address_length': dst_address_length,
819 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000820
821 def mpls_tunnel_add_del(
822 self,
823 tun_sw_if_index,
824 next_hop_proto_is_ip4,
825 next_hop_address,
826 next_hop_sw_if_index=0xFFFFFFFF,
827 next_hop_table_id=0,
828 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200829 next_hop_n_out_labels=0,
830 next_hop_out_label_stack=[],
831 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000832 create_vrf_if_needed=0,
833 is_add=1,
834 l2_only=0):
835 """
836
837 :param dst_address_length:
838 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
839 :param dst_address:
840 :param next_hop_address:
841 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
842 :param vrf_id: (Default value = 0)
843 :param lookup_in_vrf: (Default value = 0)
844 :param classify_table_index: (Default value = 0xFFFFFFFF)
845 :param create_vrf_if_needed: (Default value = 0)
846 :param is_add: (Default value = 1)
847 :param is_drop: (Default value = 0)
848 :param is_ipv6: (Default value = 0)
849 :param is_local: (Default value = 0)
850 :param is_classify: (Default value = 0)
851 :param is_multipath: (Default value = 0)
852 :param is_resolve_host: (Default value = 0)
853 :param is_resolve_attached: (Default value = 0)
854 :param not_last: (Default value = 0)
855 :param next_hop_weight: (Default value = 1)
856
857 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000858 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100859 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200860 {'mt_sw_if_index': tun_sw_if_index,
861 'mt_is_add': is_add,
862 'mt_l2_only': l2_only,
863 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
864 'mt_next_hop_weight': next_hop_weight,
865 'mt_next_hop': next_hop_address,
866 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
867 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
868 'mt_next_hop_table_id': next_hop_table_id,
869 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800870
871 def snat_interface_add_del_feature(
872 self,
873 sw_if_index,
874 is_inside=1,
875 is_add=1):
876 """Enable/disable S-NAT feature on the interface
877
878 :param sw_if_index: Software index of the interface
879 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
880 :param is_add: 1 if add, 0 if delete (Default value = 1)
881 """
882 return self.api(
883 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200884 {'is_add': is_add,
885 'is_inside': is_inside,
886 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800887
888 def snat_add_static_mapping(
889 self,
890 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800891 external_ip=0,
892 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800893 local_port=0,
894 external_port=0,
895 addr_only=1,
896 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800897 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -0800898 is_add=1,
899 is_ip4=1):
900 """Add/delete S-NAT static mapping
901
902 :param local_ip: Local IP address
903 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800904 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800905 :param local_port: Local port number (Default value = 0)
906 :param external_port: External port number (Default value = 0)
907 :param addr_only: 1 if address only mapping, 0 if address and port
908 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800909 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -0800910 :param is_add: 1 if add, 0 if delete (Default value = 1)
911 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
912 """
913 return self.api(
914 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200915 {'is_add': is_add,
916 'is_ip4': is_ip4,
917 'addr_only': addr_only,
918 'local_ip_address': local_ip,
919 'external_ip_address': external_ip,
920 'local_port': local_port,
921 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800922 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800923 'vrf_id': vrf_id,
924 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -0800925
926 def snat_add_address_range(
927 self,
928 first_ip_address,
929 last_ip_address,
930 is_add=1,
931 is_ip4=1):
932 """Add/del S-NAT address range
933
934 :param first_ip_address: First IP address
935 :param last_ip_address: Last IP address
936 :param is_add: 1 if add, 0 if delete (Default value = 1)
937 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
938 """
939 return self.api(
940 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200941 {'is_ip4': is_ip4,
942 'first_ip_address': first_ip_address,
943 'last_ip_address': last_ip_address,
944 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -0800945
946 def snat_address_dump(self):
947 """Dump S-NAT addresses
948 :return: Dictionary of S-NAT addresses
949 """
950 return self.api(self.papi.snat_address_dump, {})
951
952 def snat_interface_dump(self):
953 """Dump interfaces with S-NAT feature
954 :return: Dictionary of interfaces with S-NAT feature
955 """
956 return self.api(self.papi.snat_interface_dump, {})
957
958 def snat_static_mapping_dump(self):
959 """Dump S-NAT static mappings
960 :return: Dictionary of S-NAT static mappings
961 """
962 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200963
Matus Fabian9902fcd2016-12-21 23:58:46 -0800964 def snat_show_config(self):
965 """Show S-NAT config
966 :return: S-NAT config parameters
967 """
968 return self.api(self.papi.snat_show_config, {})
969
Matus Fabian8bf68e82017-01-12 04:24:35 -0800970 def snat_add_interface_addr(
971 self,
972 sw_if_index,
973 is_add=1):
974 """Add/del S-NAT address from interface
975
976 :param sw_if_index: Software index of the interface
977 :param is_add: 1 if add, 0 if delete (Default value = 1)
978 """
979 return self.api(self.papi.snat_add_del_interface_addr,
980 {'is_add': is_add, 'sw_if_index': sw_if_index})
981
982 def snat_interface_addr_dump(self):
983 """Dump S-NAT addresses interfaces
984 :return: Dictionary of S-NAT addresses interfaces
985 """
986 return self.api(self.papi.snat_interface_addr_dump, {})
987
Matus Fabianeea28d72017-01-13 04:15:54 -0800988 def snat_ipfix(
989 self,
990 domain_id=1,
991 src_port=4739,
992 enable=1):
993 """Enable/disable S-NAT IPFIX logging
994
995 :param domain_id: Observation domain ID (Default value = 1)
996 :param src_port: Source port number (Default value = 4739)
997 :param enable: 1 if enable, 0 if disable (Default value = 1)
998 """
999 return self.api(
1000 self.papi.snat_ipfix_enable_disable,
1001 {'domain_id': domain_id,
1002 'src_port': src_port,
1003 'enable': enable})
1004
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001005 def control_ping(self):
1006 self.api(self.papi.control_ping)
1007
1008 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001009 detect_mult, local_addr, peer_addr, is_ipv6=0,
1010 bfd_key_id=None, conf_key_id=None):
1011 if bfd_key_id is None:
1012 return self.api(self.papi.bfd_udp_add,
1013 {
1014 'sw_if_index': sw_if_index,
1015 'desired_min_tx': desired_min_tx,
1016 'required_min_rx': required_min_rx,
1017 'local_addr': local_addr,
1018 'peer_addr': peer_addr,
1019 'is_ipv6': is_ipv6,
1020 'detect_mult': detect_mult,
1021 })
1022 else:
1023 return self.api(self.papi.bfd_udp_add,
1024 {
1025 'sw_if_index': sw_if_index,
1026 'desired_min_tx': desired_min_tx,
1027 'required_min_rx': required_min_rx,
1028 'local_addr': local_addr,
1029 'peer_addr': peer_addr,
1030 'is_ipv6': is_ipv6,
1031 'detect_mult': detect_mult,
1032 'is_authenticated': 1,
1033 'bfd_key_id': bfd_key_id,
1034 'conf_key_id': conf_key_id,
1035 })
1036
Klement Sekeraa57a9702017-02-02 06:58:07 +01001037 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1038 detect_mult, local_addr, peer_addr, is_ipv6=0):
1039 return self.api(self.papi.bfd_udp_mod,
1040 {
1041 'sw_if_index': sw_if_index,
1042 'desired_min_tx': desired_min_tx,
1043 'required_min_rx': required_min_rx,
1044 'local_addr': local_addr,
1045 'peer_addr': peer_addr,
1046 'is_ipv6': is_ipv6,
1047 'detect_mult': detect_mult,
1048 })
1049
Klement Sekerab17dd962017-01-09 07:43:48 +01001050 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1051 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1052 is_delayed=False):
1053 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001054 {
1055 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001056 'local_addr': local_addr,
1057 'peer_addr': peer_addr,
1058 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001059 'is_delayed': 1 if is_delayed else 0,
1060 'bfd_key_id': bfd_key_id,
1061 'conf_key_id': conf_key_id,
1062 })
1063
1064 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1065 is_ipv6=0, is_delayed=False):
1066 return self.api(self.papi.bfd_udp_auth_deactivate,
1067 {
1068 'sw_if_index': sw_if_index,
1069 'local_addr': local_addr,
1070 'peer_addr': peer_addr,
1071 'is_ipv6': is_ipv6,
1072 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001073 })
1074
1075 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1076 return self.api(self.papi.bfd_udp_del,
1077 {
1078 'sw_if_index': sw_if_index,
1079 'local_addr': local_addr,
1080 'peer_addr': peer_addr,
1081 'is_ipv6': is_ipv6,
1082 })
1083
1084 def bfd_udp_session_dump(self):
1085 return self.api(self.papi.bfd_udp_session_dump, {})
1086
Klement Sekerab17dd962017-01-09 07:43:48 +01001087 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1088 peer_addr, is_ipv6=0):
1089 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001090 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001091 'sw_if_index': sw_if_index,
1092 'local_addr': local_addr,
1093 'peer_addr': peer_addr,
1094 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001095 })
1096
1097 def want_bfd_events(self, enable_disable=1):
1098 return self.api(self.papi.want_bfd_events, {
1099 'enable_disable': enable_disable,
1100 'pid': os.getpid(),
1101 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001102
Klement Sekerab17dd962017-01-09 07:43:48 +01001103 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1104 return self.api(self.papi.bfd_auth_set_key, {
1105 'conf_key_id': conf_key_id,
1106 'auth_type': auth_type,
1107 'key': key,
1108 'key_len': len(key),
1109 })
1110
1111 def bfd_auth_del_key(self, conf_key_id):
1112 return self.api(self.papi.bfd_auth_del_key, {
1113 'conf_key_id': conf_key_id,
1114 })
1115
1116 def bfd_auth_keys_dump(self):
1117 return self.api(self.papi.bfd_auth_keys_dump, {})
1118
Steve Shin7957d6e2016-12-19 09:24:50 -08001119 def classify_add_del_table(
1120 self,
1121 is_add,
1122 mask,
1123 match_n_vectors=1,
1124 table_index=0xFFFFFFFF,
1125 nbuckets=2,
1126 memory_size=2097152,
1127 skip_n_vectors=0,
1128 next_table_index=0xFFFFFFFF,
1129 miss_next_index=0xFFFFFFFF,
1130 current_data_flag=0,
1131 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001132 """
1133 :param is_add:
1134 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001135 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001136 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001137 :param nbuckets: (Default value = 2)
1138 :param memory_size: (Default value = 2097152)
1139 :param skip_n_vectors: (Default value = 0)
1140 :param next_table_index: (Default value = 0xFFFFFFFF)
1141 :param miss_next_index: (Default value = 0xFFFFFFFF)
1142 :param current_data_flag: (Default value = 0)
1143 :param current_data_offset: (Default value = 0)
1144 """
1145
1146 return self.api(
1147 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001148 {'is_add': is_add,
1149 'table_index': table_index,
1150 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001151 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001152 'skip_n_vectors': skip_n_vectors,
1153 'match_n_vectors': match_n_vectors,
1154 'next_table_index': next_table_index,
1155 'miss_next_index': miss_next_index,
1156 'current_data_flag': current_data_flag,
1157 'current_data_offset': current_data_offset,
1158 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001159
1160 def classify_add_del_session(
1161 self,
1162 is_add,
1163 table_index,
1164 match,
1165 opaque_index=0xFFFFFFFF,
1166 hit_next_index=0xFFFFFFFF,
1167 advance=0,
1168 action=0,
1169 metadata=0):
1170 """
1171 :param is_add:
1172 :param table_index:
1173 :param match:
1174 :param opaque_index: (Default value = 0xFFFFFFFF)
1175 :param hit_next_index: (Default value = 0xFFFFFFFF)
1176 :param advance: (Default value = 0)
1177 :param action: (Default value = 0)
1178 :param metadata: (Default value = 0)
1179 """
1180
1181 return self.api(
1182 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001183 {'is_add': is_add,
1184 'table_index': table_index,
1185 'hit_next_index': hit_next_index,
1186 'opaque_index': opaque_index,
1187 'advance': advance,
1188 'action': action,
1189 'metadata': metadata,
1190 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001191
1192 def input_acl_set_interface(
1193 self,
1194 is_add,
1195 sw_if_index,
1196 ip4_table_index=0xFFFFFFFF,
1197 ip6_table_index=0xFFFFFFFF,
1198 l2_table_index=0xFFFFFFFF):
1199 """
1200 :param is_add:
1201 :param sw_if_index:
1202 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1203 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1204 :param l2_table_index: (Default value = 0xFFFFFFFF)
1205 """
1206
1207 return self.api(
1208 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001209 {'sw_if_index': sw_if_index,
1210 'ip4_table_index': ip4_table_index,
1211 'ip6_table_index': ip6_table_index,
1212 'l2_table_index': l2_table_index,
1213 'is_add': is_add})
1214
1215 def set_ipfix_exporter(
1216 self,
1217 collector_address,
1218 src_address,
1219 path_mtu,
1220 template_interval,
1221 vrf_id=0,
1222 collector_port=4739,
1223 udp_checksum=0):
1224 return self.api(
1225 self.papi.set_ipfix_exporter,
1226 {
1227 'collector_address': collector_address,
1228 'collector_port': collector_port,
1229 'src_address': src_address,
1230 'vrf_id': vrf_id,
1231 'path_mtu': path_mtu,
1232 'template_interval': template_interval,
1233 'udp_checksum': udp_checksum,
1234 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001235
1236 def dhcp_proxy_config(self,
1237 dhcp_server,
1238 dhcp_src_address,
1239 rx_table_id=0,
1240 server_table_id=0,
1241 is_add=1,
1242 is_ipv6=0,
1243 insert_circuit_id=0):
1244 return self.api(
1245 self.papi.dhcp_proxy_config_2,
1246 {
1247 'rx_vrf_id': rx_table_id,
1248 'server_vrf_id': server_table_id,
1249 'is_ipv6': is_ipv6,
1250 'is_add': is_add,
1251 'insert_circuit_id': insert_circuit_id,
1252 'dhcp_server': dhcp_server,
1253 'dhcp_src_address': dhcp_src_address,
1254 })
1255
1256 def dhcp_proxy_set_vss(self,
1257 table_id,
1258 fib_id,
1259 oui,
1260 is_add=1,
1261 is_ip6=0):
1262 return self.api(
1263 self.papi.dhcp_proxy_set_vss,
1264 {
1265 'tbl_id': table_id,
1266 'fib_id': fib_id,
1267 'is_ipv6': is_ip6,
1268 'is_add': is_add,
1269 'oui': oui,
1270 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001271
1272 def ip_mroute_add_del(self,
1273 src_address,
1274 grp_address,
1275 grp_address_length,
1276 e_flags,
1277 next_hop_sw_if_index,
1278 i_flags,
1279 table_id=0,
1280 create_vrf_if_needed=0,
1281 is_add=1,
1282 is_ipv6=0,
1283 is_local=0):
1284 """
1285 """
1286 return self.api(
1287 self.papi.ip_mroute_add_del,
1288 {'next_hop_sw_if_index': next_hop_sw_if_index,
1289 'entry_flags': e_flags,
1290 'itf_flags': i_flags,
1291 'create_vrf_if_needed': create_vrf_if_needed,
1292 'is_add': is_add,
1293 'is_ipv6': is_ipv6,
1294 'is_local': is_local,
1295 'grp_address_length': grp_address_length,
1296 'grp_address': grp_address,
1297 'src_address': src_address})
1298
1299 def mfib_signal_dump(self):
1300 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08001301
1302 def ip_mfib_dump(self):
1303 return self.api(self.papi.ip_mfib_dump, {})