blob: 90c954dc0b354e9313c43c007891ffd4fd0c2bb5 [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. """
90 if self._events:
91 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +020092 limit = time.time() + timeout
93 while time.time() < limit:
94 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +010095 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +020096 if name and type(e).__name__ != name:
97 raise Exception(
98 "Unexpected event received: %s, expected: %s" %
99 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100100 self.test_class.logger.debug("Returning event %s:%s" %
101 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200102 return e
103 time.sleep(0) # yield
104 if name is not None:
105 raise Exception("Event %s did not occur within timeout" % name)
106 raise Exception("Event did not occur within timeout")
107
108 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100109 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200110 # FIXME use the name instead of relying on type(e).__name__ ?
111 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100112 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200113 self._events.append(event)
114
Klement Sekeraf62ae122016-10-11 11:47:09 +0200115 def connect(self):
116 """Connect the API to VPP"""
Ole Troan7e3a8752016-12-05 10:27:09 +0100117 self.papi.connect(self.name, self.shm_prefix)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200118 self.papi.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200119
120 def disconnect(self):
121 """Disconnect the API from VPP"""
Ole Troan7e3a8752016-12-05 10:27:09 +0100122 self.papi.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200123
124 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100125 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200126 Call the appropriate hooks before and after the API call
127
128 :param api_fn: API function to call
129 :param api_args: tuple of API function arguments
130 :param expected_retval: Expected return value (Default value = 0)
131 :returns: reply from the API
132
133 """
134 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100135 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100136 if self._expect_api_retval == self._negative:
137 if hasattr(reply, 'retval') and reply.retval >= 0:
138 msg = "API call passed unexpectedly: expected negative "\
139 "return value instead of %d in %s" % \
140 (reply.retval, repr(reply))
141 self.test_class.logger.info(msg)
142 raise Exception(msg)
143 elif self._expect_api_retval == self._zero:
144 if hasattr(reply, 'retval') and reply.retval != expected_retval:
145 msg = "API call failed, expected zero return value instead "\
146 "of %d in %s" % (expected_retval, repr(reply))
147 self.test_class.logger.info(msg)
148 raise Exception(msg)
149 else:
150 raise Exception("Internal error, unexpected value for "
151 "self._expect_api_retval %s" %
152 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200153 self.hook.after_api(api_fn.__name__, api_args)
154 return reply
155
156 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100157 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200158
159 :param cli: CLI to execute
160 :returns: CLI output
161
162 """
163 self.hook.before_cli(cli)
164 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100165 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200167 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100168 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200169
Jan49c0fca2016-10-26 15:44:27 +0200170 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100171 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200172
173 :param cli: CLI to execute
174 :returns: CLI output
175 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600176 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200177
Jan4af521d2016-11-15 17:05:00 +0100178 def _convert_mac(self, mac):
179 return int(mac.replace(":", ""), 16) << 16
180
Klement Sekeraf62ae122016-10-11 11:47:09 +0200181 def show_version(self):
182 """ """
Ole Troan7e3a8752016-12-05 10:27:09 +0100183 return self.papi.show_version()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200184
185 def pg_create_interface(self, pg_index):
186 """
187
188 :param pg_index:
189
190 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100191 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200192 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200193
194 def sw_interface_dump(self, filter=None):
195 """
196
197 :param filter: (Default value = None)
198
199 """
200 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200201 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200202 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100203 args = {}
204 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200205
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000206 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100207 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000208
209 :param sw_if_index:
210 :param is_ipv6:
211 :param table_id:
212
213 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100214 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200215 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
216 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000217
Klement Sekeraf62ae122016-10-11 11:47:09 +0200218 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
219 is_ipv6=0, is_add=1, del_all=0):
220 """
221
222 :param addr: param is_ipv6: (Default value = 0)
223 :param sw_if_index:
224 :param addr_len:
225 :param is_ipv6: (Default value = 0)
226 :param is_add: (Default value = 1)
227 :param del_all: (Default value = 0)
228
229 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100230 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200231 {'sw_if_index': sw_if_index,
232 'is_add': is_add,
233 'is_ipv6': is_ipv6,
234 'del_all': del_all,
235 'address_length': addr_len,
236 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200237
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000238 def sw_interface_enable_disable_mpls(self, sw_if_index,
239 is_enable=1):
240 """
241 Enable/Disable MPLS on the interface
242 :param sw_if_index:
243 :param is_enable: (Default value = 1)
244
245 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100246 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200247 {'sw_if_index': sw_if_index,
248 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000249
Klement Sekeraf62ae122016-10-11 11:47:09 +0200250 def sw_interface_ra_suppress(self, sw_if_index):
Ole Troan7e3a8752016-12-05 10:27:09 +0100251 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200252 {'sw_if_index': sw_if_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200253
Neale Ranns75152282017-01-09 01:00:45 -0800254 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000255 no,
Neale Ranns75152282017-01-09 01:00:45 -0800256 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000257 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800258 return self.api(self.papi.sw_interface_ip6nd_ra_config,
259 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000260 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100261 'suppress': suppress,
262 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800263
264 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
265 """
266 Enable/Disable An interface for IPv6
267 """
268 return self.api(self.papi.sw_interface_ip6_enable_disable,
269 {'sw_if_index': sw_if_index,
270 'enable': enable})
271
Klement Sekeraf62ae122016-10-11 11:47:09 +0200272 def vxlan_add_del_tunnel(
273 self,
274 src_addr,
275 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200276 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200277 is_add=1,
278 is_ipv6=0,
279 encap_vrf_id=0,
280 decap_next_index=0xFFFFFFFF,
281 vni=0):
282 """
283
284 :param dst_addr:
285 :param src_addr:
286 :param is_add: (Default value = 1)
287 :param is_ipv6: (Default value = 0)
288 :param encap_vrf_id: (Default value = 0)
289 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200290 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200291 :param vni: (Default value = 0)
292
293 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100294 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200295 {'is_add': is_add,
296 'is_ipv6': is_ipv6,
297 'src_address': src_addr,
298 'dst_address': dst_addr,
299 'mcast_sw_if_index': mcast_sw_if_index,
300 'encap_vrf_id': encap_vrf_id,
301 'decap_next_index': decap_next_index,
302 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200303
Jan4af521d2016-11-15 17:05:00 +0100304 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
305 learn=1, arp_term=0, is_add=1):
306 """Create/delete bridge domain.
307
308 :param int bd_id: Bridge domain index.
309 :param int flood: Enable/disable bcast/mcast flooding in the BD.
310 (Default value = 1)
311 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
312 (Default value = 1)
313 :param int forward: Enable/disable forwarding on all interfaces in
314 the BD. (Default value = 1)
315 :param int learn: Enable/disable learning on all interfaces in the BD.
316 (Default value = 1)
317 :param int arp_term: Enable/disable arp termination in the BD.
318 (Default value = 1)
319 :param int is_add: Add or delete flag. (Default value = 1)
320 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100321 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200322 {'bd_id': bd_id,
323 'flood': flood,
324 'uu_flood': uu_flood,
325 'forward': forward,
326 'learn': learn,
327 'arp_term': arp_term,
328 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100329
330 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
331 filter_mac=0, bvi_mac=0):
332 """Create/delete L2 FIB entry.
333
334 :param str mac: MAC address to create FIB entry for.
335 :param int bd_id: Bridge domain index.
336 :param int sw_if_index: Software interface index of the interface.
337 :param int is_add: Add or delete flag. (Default value = 1)
338 :param int static_mac: Set to 1 to create static MAC entry.
339 (Default value = 0)
340 :param int filter_mac: Set to 1 to drop packet that's source or
341 destination MAC address contains defined MAC address.
342 (Default value = 0)
343 :param int bvi_mac: Set to 1 to create entry that points to BVI
344 interface. (Default value = 0)
345 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100346 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200347 {'mac': self._convert_mac(mac),
348 'bd_id': bd_id,
349 'sw_if_index': sw_if_index,
350 'is_add': is_add,
351 'static_mac': static_mac,
352 'filter_mac': filter_mac,
353 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100354
Klement Sekeraf62ae122016-10-11 11:47:09 +0200355 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
356 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100357 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200358
Jan4af521d2016-11-15 17:05:00 +0100359 :param int sw_if_index: Software interface index of the interface.
360 :param int bd_id: Bridge domain index.
361 :param int shg: Split-horizon group index. (Default value = 0)
362 :param int bvi: Set interface as a bridge group virtual interface.
363 (Default value = 0)
364 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200365 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100366 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200367 {'rx_sw_if_index': sw_if_index,
368 'bd_id': bd_id,
369 'shg': shg,
370 'bvi': bvi,
371 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200372
Jan00dad122016-11-29 10:04:53 +0100373 def bridge_flags(self, bd_id, is_set, feature_bitmap):
374 """Enable/disable required feature of the bridge domain with defined ID.
375
376 :param int bd_id: Bridge domain ID.
377 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
378 :param int feature_bitmap: Bitmap value of the feature to be set:
379 - learn (1 << 0),
380 - forward (1 << 1),
381 - flood (1 << 2),
382 - uu-flood (1 << 3) or
383 - arp-term (1 << 4).
384 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100385 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200386 {'bd_id': bd_id,
387 'is_set': is_set,
388 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100389
390 def bridge_domain_dump(self, bd_id=0):
391 """
392
393 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
394 existing bridge domains returned)
395 :return: Dictionary of bridge domain(s) data.
396 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100397 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200398 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100399
Klement Sekeraf62ae122016-10-11 11:47:09 +0200400 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
401 enable):
402 """Create or delete unidirectional cross-connect from Tx interface to
403 Rx interface.
404
Jan4af521d2016-11-15 17:05:00 +0100405 :param int rx_sw_if_index: Software interface index of Rx interface.
406 :param int tx_sw_if_index: Software interface index of Tx interface.
407 :param int enable: Create cross-connect if equal to 1, delete
408 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200409
410 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100411 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200412 {'rx_sw_if_index': rx_sw_if_index,
413 'tx_sw_if_index': tx_sw_if_index,
414 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200415
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200416 def sw_interface_set_l2_tag_rewrite(
417 self,
418 sw_if_index,
419 vtr_oper,
420 push=0,
421 tag1=0,
422 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000423 """L2 interface vlan tag rewrite configure request
424 :param client_index - opaque cookie to identify the sender
425 :param context - sender context, to match reply w/ request
426 :param sw_if_index - interface the operation is applied to
427 :param vtr_op - Choose from l2_vtr_op_t enum values
428 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
429 :param tag1 - Needed for any push or translate vtr op
430 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
431
432 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100433 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200434 {'sw_if_index': sw_if_index,
435 'vtr_op': vtr_oper,
436 'push_dot1q': push,
437 'tag1': tag1,
438 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000439
Klement Sekeraf62ae122016-10-11 11:47:09 +0200440 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
441 link_up_down=0, deleted=0):
442 """
443
444 :param admin_up_down:
445 :param sw_if_index:
446 :param link_up_down: (Default value = 0)
447 :param deleted: (Default value = 0)
448
449 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100450 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200451 {'sw_if_index': sw_if_index,
452 'admin_up_down': admin_up_down,
453 'link_up_down': link_up_down,
454 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200455
456 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
457 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
458 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
459 """Create subinterface
460 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
461
462 :param sub_id: param inner_vlan:
463 :param sw_if_index:
464 :param outer_vlan:
465 :param inner_vlan:
466 :param no_tags: (Default value = 0)
467 :param one_tag: (Default value = 0)
468 :param two_tags: (Default value = 0)
469 :param dot1ad: (Default value = 0)
470 :param exact_match: (Default value = 0)
471 :param default_sub: (Default value = 0)
472 :param outer_vlan_id_any: (Default value = 0)
473 :param inner_vlan_id_any: (Default value = 0)
474
475 """
476 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100477 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200478 {'sw_if_index': sw_if_index,
479 'sub_id': sub_id,
480 'no_tags': no_tags,
481 'one_tag': one_tag,
482 'two_tags': two_tags,
483 'dot1ad': dot1ad,
484 'exact_match': exact_match,
485 'default_sub': default_sub,
486 'outer_vlan_id_any': outer_vlan_id_any,
487 'inner_vlan_id_any': inner_vlan_id_any,
488 'outer_vlan_id': outer_vlan,
489 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200490
Neale Ranns177bbdc2016-11-15 09:46:51 +0000491 def delete_subif(self, sw_if_index):
492 """Delete subinterface
493
494 :param sw_if_index:
495 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100496 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200497 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000498
Klement Sekeraf62ae122016-10-11 11:47:09 +0200499 def create_vlan_subif(self, sw_if_index, vlan):
500 """
501
502 :param vlan:
503 :param sw_if_index:
504
505 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100506 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200507 {'sw_if_index': sw_if_index,
508 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200509
Matej Klotton0178d522016-11-04 11:11:44 +0100510 def create_loopback(self, mac=''):
511 """
512
513 :param mac: (Optional)
514 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100515 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200516 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100517
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100518 def delete_loopback(self, sw_if_index):
519 return self.api(self.papi.delete_loopback,
520 {'sw_if_index': sw_if_index, })
521
Klement Sekeraf62ae122016-10-11 11:47:09 +0200522 def ip_add_del_route(
523 self,
524 dst_address,
525 dst_address_length,
526 next_hop_address,
527 next_hop_sw_if_index=0xFFFFFFFF,
528 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200529 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000530 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200531 next_hop_n_out_labels=0,
532 next_hop_out_label_stack=[],
533 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200534 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000535 is_resolve_host=0,
536 is_resolve_attached=0,
537 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200538 is_add=1,
539 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200540 is_unreach=0,
541 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200542 is_ipv6=0,
543 is_local=0,
544 is_classify=0,
545 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000546 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200547 """
548
549 :param dst_address_length:
550 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
551 :param dst_address:
552 :param next_hop_address:
553 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
554 :param vrf_id: (Default value = 0)
555 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200556 :param classify_table_index: (Default value = 0xFFFFFFFF)
557 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200558 :param is_add: (Default value = 1)
559 :param is_drop: (Default value = 0)
560 :param is_ipv6: (Default value = 0)
561 :param is_local: (Default value = 0)
562 :param is_classify: (Default value = 0)
563 :param is_multipath: (Default value = 0)
564 :param is_resolve_host: (Default value = 0)
565 :param is_resolve_attached: (Default value = 0)
566 :param not_last: (Default value = 0)
567 :param next_hop_weight: (Default value = 1)
568
569 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000570
Klement Sekeraf62ae122016-10-11 11:47:09 +0200571 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100572 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200573 {'next_hop_sw_if_index': next_hop_sw_if_index,
574 'table_id': table_id,
575 'classify_table_index': classify_table_index,
576 'next_hop_table_id': next_hop_table_id,
577 'create_vrf_if_needed': create_vrf_if_needed,
578 'is_add': is_add,
579 'is_drop': is_drop,
580 'is_unreach': is_unreach,
581 'is_prohibit': is_prohibit,
582 'is_ipv6': is_ipv6,
583 'is_local': is_local,
584 'is_classify': is_classify,
585 'is_multipath': is_multipath,
586 'is_resolve_host': is_resolve_host,
587 'is_resolve_attached': is_resolve_attached,
588 'not_last': not_last,
589 'next_hop_weight': next_hop_weight,
590 'dst_address_length': dst_address_length,
591 'dst_address': dst_address,
592 'next_hop_address': next_hop_address,
593 'next_hop_n_out_labels': next_hop_n_out_labels,
594 'next_hop_via_label': next_hop_via_label,
595 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100596
Matej Klotton16a14cd2016-12-07 15:09:13 +0100597 def ip_fib_dump(self):
598 return self.api(self.papi.ip_fib_dump, {})
599
Matej Klotton0178d522016-11-04 11:11:44 +0100600 def ip_neighbor_add_del(self,
601 sw_if_index,
602 mac_address,
603 dst_address,
604 vrf_id=0,
605 is_add=1,
606 is_ipv6=0,
607 is_static=0,
608 ):
609 """ Add neighbor MAC to IPv4 or IPv6 address.
610
611 :param sw_if_index:
612 :param mac_address:
613 :param dst_address:
614 :param vrf_id: (Default value = 0)
615 :param is_add: (Default value = 1)
616 :param is_ipv6: (Default value = 0)
617 :param is_static: (Default value = 0)
618 """
619
620 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100621 self.papi.ip_neighbor_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200622 {'vrf_id': vrf_id,
623 'sw_if_index': sw_if_index,
624 'is_add': is_add,
625 'is_ipv6': is_ipv6,
626 'is_static': is_static,
627 'mac_address': mac_address,
628 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100629 }
Matej Klotton0178d522016-11-04 11:11:44 +0100630 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100631
Jane546d3b2016-12-08 13:10:03 +0100632 def reset_vrf(self,
633 vrf_id,
634 is_ipv6=0,
635 ):
636 """ Reset VRF (remove all routes etc.) request.
637
638 :param int vrf_id: ID of the FIB table / VRF to reset.
639 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
640 """
641
642 return self.api(
643 self.papi.reset_vrf,
644 {'vrf_id': vrf_id,
645 'is_ipv6': is_ipv6,
646 }
647 )
648
649 def reset_fib(self,
650 vrf_id,
651 is_ipv6=0,
652 ):
653 """ Reset VRF (remove all routes etc.) request.
654
655 :param int vrf_id: ID of the FIB table / VRF to reset.
656 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
657 """
658
659 return self.api(
660 self.papi.reset_fib,
661 {'vrf_id': vrf_id,
662 'is_ipv6': is_ipv6,
663 }
664 )
665
666 def ip_dump(self,
667 is_ipv6=0,
668 ):
669 """ Return IP dump.
670
671 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
672 """
673
674 return self.api(
675 self.papi.ip_dump,
676 {'is_ipv6': is_ipv6,
677 }
678 )
679
Klement Sekera7bb873a2016-11-18 07:38:42 +0100680 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100681 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100682 """
683
684 :param sw_if_index_from:
685 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100686 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100687 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100688 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200689 {'sw_if_index_from': sw_if_index_from,
690 'sw_if_index_to': sw_if_index_to,
691 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000692
693 def gre_tunnel_add_del(self,
694 src_address,
695 dst_address,
696 outer_fib_id=0,
697 is_teb=0,
698 is_add=1,
699 is_ip6=0):
700 """ Add a GRE tunnel
701
702 :param src_address:
703 :param dst_address:
704 :param outer_fib_id: (Default value = 0)
705 :param is_add: (Default value = 1)
706 :param is_ipv6: (Default value = 0)
707 :param is_teb: (Default value = 0)
708 """
709
710 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100711 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200712 {'is_add': is_add,
713 'is_ipv6': is_ip6,
714 'teb': is_teb,
715 'src_address': src_address,
716 'dst_address': dst_address,
717 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000718 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000719
720 def mpls_route_add_del(
721 self,
722 label,
723 eos,
724 next_hop_proto_is_ip4,
725 next_hop_address,
726 next_hop_sw_if_index=0xFFFFFFFF,
727 table_id=0,
728 next_hop_table_id=0,
729 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200730 next_hop_n_out_labels=0,
731 next_hop_out_label_stack=[],
732 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000733 create_vrf_if_needed=0,
734 is_resolve_host=0,
735 is_resolve_attached=0,
736 is_add=1,
737 is_drop=0,
738 is_multipath=0,
739 classify_table_index=0xFFFFFFFF,
740 is_classify=0,
741 not_last=0):
742 """
743
744 :param dst_address_length:
745 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
746 :param dst_address:
747 :param next_hop_address:
748 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
749 :param vrf_id: (Default value = 0)
750 :param lookup_in_vrf: (Default value = 0)
751 :param classify_table_index: (Default value = 0xFFFFFFFF)
752 :param create_vrf_if_needed: (Default value = 0)
753 :param is_add: (Default value = 1)
754 :param is_drop: (Default value = 0)
755 :param is_ipv6: (Default value = 0)
756 :param is_local: (Default value = 0)
757 :param is_classify: (Default value = 0)
758 :param is_multipath: (Default value = 0)
759 :param is_resolve_host: (Default value = 0)
760 :param is_resolve_attached: (Default value = 0)
761 :param not_last: (Default value = 0)
762 :param next_hop_weight: (Default value = 1)
763
764 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000765
766 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100767 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200768 {'mr_label': label,
769 'mr_eos': eos,
770 'mr_table_id': table_id,
771 'mr_classify_table_index': classify_table_index,
772 'mr_create_table_if_needed': create_vrf_if_needed,
773 'mr_is_add': is_add,
774 'mr_is_classify': is_classify,
775 'mr_is_multipath': is_multipath,
776 'mr_is_resolve_host': is_resolve_host,
777 'mr_is_resolve_attached': is_resolve_attached,
778 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
779 'mr_next_hop_weight': next_hop_weight,
780 'mr_next_hop': next_hop_address,
781 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
782 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
783 'mr_next_hop_table_id': next_hop_table_id,
784 'mr_next_hop_via_label': next_hop_via_label,
785 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000786
787 def mpls_ip_bind_unbind(
788 self,
789 label,
790 dst_address,
791 dst_address_length,
792 table_id=0,
793 ip_table_id=0,
794 is_ip4=1,
795 create_vrf_if_needed=0,
796 is_bind=1):
797 """
798 """
799 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100800 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200801 {'mb_mpls_table_id': table_id,
802 'mb_label': label,
803 'mb_ip_table_id': ip_table_id,
804 'mb_create_table_if_needed': create_vrf_if_needed,
805 'mb_is_bind': is_bind,
806 'mb_is_ip4': is_ip4,
807 'mb_address_length': dst_address_length,
808 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000809
810 def mpls_tunnel_add_del(
811 self,
812 tun_sw_if_index,
813 next_hop_proto_is_ip4,
814 next_hop_address,
815 next_hop_sw_if_index=0xFFFFFFFF,
816 next_hop_table_id=0,
817 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200818 next_hop_n_out_labels=0,
819 next_hop_out_label_stack=[],
820 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000821 create_vrf_if_needed=0,
822 is_add=1,
823 l2_only=0):
824 """
825
826 :param dst_address_length:
827 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
828 :param dst_address:
829 :param next_hop_address:
830 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
831 :param vrf_id: (Default value = 0)
832 :param lookup_in_vrf: (Default value = 0)
833 :param classify_table_index: (Default value = 0xFFFFFFFF)
834 :param create_vrf_if_needed: (Default value = 0)
835 :param is_add: (Default value = 1)
836 :param is_drop: (Default value = 0)
837 :param is_ipv6: (Default value = 0)
838 :param is_local: (Default value = 0)
839 :param is_classify: (Default value = 0)
840 :param is_multipath: (Default value = 0)
841 :param is_resolve_host: (Default value = 0)
842 :param is_resolve_attached: (Default value = 0)
843 :param not_last: (Default value = 0)
844 :param next_hop_weight: (Default value = 1)
845
846 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000847 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100848 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200849 {'mt_sw_if_index': tun_sw_if_index,
850 'mt_is_add': is_add,
851 'mt_l2_only': l2_only,
852 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
853 'mt_next_hop_weight': next_hop_weight,
854 'mt_next_hop': next_hop_address,
855 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
856 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
857 'mt_next_hop_table_id': next_hop_table_id,
858 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800859
860 def snat_interface_add_del_feature(
861 self,
862 sw_if_index,
863 is_inside=1,
864 is_add=1):
865 """Enable/disable S-NAT feature on the interface
866
867 :param sw_if_index: Software index of the interface
868 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
869 :param is_add: 1 if add, 0 if delete (Default value = 1)
870 """
871 return self.api(
872 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200873 {'is_add': is_add,
874 'is_inside': is_inside,
875 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800876
877 def snat_add_static_mapping(
878 self,
879 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800880 external_ip=0,
881 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800882 local_port=0,
883 external_port=0,
884 addr_only=1,
885 vrf_id=0,
886 is_add=1,
887 is_ip4=1):
888 """Add/delete S-NAT static mapping
889
890 :param local_ip: Local IP address
891 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800892 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800893 :param local_port: Local port number (Default value = 0)
894 :param external_port: External port number (Default value = 0)
895 :param addr_only: 1 if address only mapping, 0 if address and port
896 :param vrf_id: VRF ID
897 :param is_add: 1 if add, 0 if delete (Default value = 1)
898 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
899 """
900 return self.api(
901 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200902 {'is_add': is_add,
903 'is_ip4': is_ip4,
904 'addr_only': addr_only,
905 'local_ip_address': local_ip,
906 'external_ip_address': external_ip,
907 'local_port': local_port,
908 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800909 'external_sw_if_index': external_sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200910 'vrf_id': vrf_id})
Matus Fabiande886752016-12-07 03:38:19 -0800911
912 def snat_add_address_range(
913 self,
914 first_ip_address,
915 last_ip_address,
916 is_add=1,
917 is_ip4=1):
918 """Add/del S-NAT address range
919
920 :param first_ip_address: First IP address
921 :param last_ip_address: Last IP address
922 :param is_add: 1 if add, 0 if delete (Default value = 1)
923 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
924 """
925 return self.api(
926 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200927 {'is_ip4': is_ip4,
928 'first_ip_address': first_ip_address,
929 'last_ip_address': last_ip_address,
930 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -0800931
932 def snat_address_dump(self):
933 """Dump S-NAT addresses
934 :return: Dictionary of S-NAT addresses
935 """
936 return self.api(self.papi.snat_address_dump, {})
937
938 def snat_interface_dump(self):
939 """Dump interfaces with S-NAT feature
940 :return: Dictionary of interfaces with S-NAT feature
941 """
942 return self.api(self.papi.snat_interface_dump, {})
943
944 def snat_static_mapping_dump(self):
945 """Dump S-NAT static mappings
946 :return: Dictionary of S-NAT static mappings
947 """
948 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200949
Matus Fabian9902fcd2016-12-21 23:58:46 -0800950 def snat_show_config(self):
951 """Show S-NAT config
952 :return: S-NAT config parameters
953 """
954 return self.api(self.papi.snat_show_config, {})
955
Matus Fabian8bf68e82017-01-12 04:24:35 -0800956 def snat_add_interface_addr(
957 self,
958 sw_if_index,
959 is_add=1):
960 """Add/del S-NAT address from interface
961
962 :param sw_if_index: Software index of the interface
963 :param is_add: 1 if add, 0 if delete (Default value = 1)
964 """
965 return self.api(self.papi.snat_add_del_interface_addr,
966 {'is_add': is_add, 'sw_if_index': sw_if_index})
967
968 def snat_interface_addr_dump(self):
969 """Dump S-NAT addresses interfaces
970 :return: Dictionary of S-NAT addresses interfaces
971 """
972 return self.api(self.papi.snat_interface_addr_dump, {})
973
Matus Fabianeea28d72017-01-13 04:15:54 -0800974 def snat_ipfix(
975 self,
976 domain_id=1,
977 src_port=4739,
978 enable=1):
979 """Enable/disable S-NAT IPFIX logging
980
981 :param domain_id: Observation domain ID (Default value = 1)
982 :param src_port: Source port number (Default value = 4739)
983 :param enable: 1 if enable, 0 if disable (Default value = 1)
984 """
985 return self.api(
986 self.papi.snat_ipfix_enable_disable,
987 {'domain_id': domain_id,
988 'src_port': src_port,
989 'enable': enable})
990
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200991 def control_ping(self):
992 self.api(self.papi.control_ping)
993
994 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
995 detect_mult, local_addr, peer_addr, is_ipv6=0):
996 return self.api(self.papi.bfd_udp_add,
997 {
998 'sw_if_index': sw_if_index,
999 'desired_min_tx': desired_min_tx,
1000 'required_min_rx': required_min_rx,
1001 'local_addr': local_addr,
1002 'peer_addr': peer_addr,
1003 'is_ipv6': is_ipv6,
1004 'detect_mult': detect_mult,
1005 })
1006
1007 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1008 return self.api(self.papi.bfd_udp_del,
1009 {
1010 'sw_if_index': sw_if_index,
1011 'local_addr': local_addr,
1012 'peer_addr': peer_addr,
1013 'is_ipv6': is_ipv6,
1014 })
1015
1016 def bfd_udp_session_dump(self):
1017 return self.api(self.papi.bfd_udp_session_dump, {})
1018
1019 def bfd_session_set_flags(self, bs_idx, admin_up_down):
1020 return self.api(self.papi.bfd_session_set_flags, {
1021 'bs_index': bs_idx,
1022 'admin_up_down': admin_up_down,
1023 })
1024
1025 def want_bfd_events(self, enable_disable=1):
1026 return self.api(self.papi.want_bfd_events, {
1027 'enable_disable': enable_disable,
1028 'pid': os.getpid(),
1029 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001030
1031 def classify_add_del_table(
1032 self,
1033 is_add,
1034 mask,
1035 match_n_vectors=1,
1036 table_index=0xFFFFFFFF,
1037 nbuckets=2,
1038 memory_size=2097152,
1039 skip_n_vectors=0,
1040 next_table_index=0xFFFFFFFF,
1041 miss_next_index=0xFFFFFFFF,
1042 current_data_flag=0,
1043 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001044 """
1045 :param is_add:
1046 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001047 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001048 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001049 :param nbuckets: (Default value = 2)
1050 :param memory_size: (Default value = 2097152)
1051 :param skip_n_vectors: (Default value = 0)
1052 :param next_table_index: (Default value = 0xFFFFFFFF)
1053 :param miss_next_index: (Default value = 0xFFFFFFFF)
1054 :param current_data_flag: (Default value = 0)
1055 :param current_data_offset: (Default value = 0)
1056 """
1057
1058 return self.api(
1059 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001060 {'is_add': is_add,
1061 'table_index': table_index,
1062 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001063 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001064 'skip_n_vectors': skip_n_vectors,
1065 'match_n_vectors': match_n_vectors,
1066 'next_table_index': next_table_index,
1067 'miss_next_index': miss_next_index,
1068 'current_data_flag': current_data_flag,
1069 'current_data_offset': current_data_offset,
1070 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001071
1072 def classify_add_del_session(
1073 self,
1074 is_add,
1075 table_index,
1076 match,
1077 opaque_index=0xFFFFFFFF,
1078 hit_next_index=0xFFFFFFFF,
1079 advance=0,
1080 action=0,
1081 metadata=0):
1082 """
1083 :param is_add:
1084 :param table_index:
1085 :param match:
1086 :param opaque_index: (Default value = 0xFFFFFFFF)
1087 :param hit_next_index: (Default value = 0xFFFFFFFF)
1088 :param advance: (Default value = 0)
1089 :param action: (Default value = 0)
1090 :param metadata: (Default value = 0)
1091 """
1092
1093 return self.api(
1094 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001095 {'is_add': is_add,
1096 'table_index': table_index,
1097 'hit_next_index': hit_next_index,
1098 'opaque_index': opaque_index,
1099 'advance': advance,
1100 'action': action,
1101 'metadata': metadata,
1102 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001103
1104 def input_acl_set_interface(
1105 self,
1106 is_add,
1107 sw_if_index,
1108 ip4_table_index=0xFFFFFFFF,
1109 ip6_table_index=0xFFFFFFFF,
1110 l2_table_index=0xFFFFFFFF):
1111 """
1112 :param is_add:
1113 :param sw_if_index:
1114 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1115 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1116 :param l2_table_index: (Default value = 0xFFFFFFFF)
1117 """
1118
1119 return self.api(
1120 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001121 {'sw_if_index': sw_if_index,
1122 'ip4_table_index': ip4_table_index,
1123 'ip6_table_index': ip6_table_index,
1124 'l2_table_index': l2_table_index,
1125 'is_add': is_add})
1126
1127 def set_ipfix_exporter(
1128 self,
1129 collector_address,
1130 src_address,
1131 path_mtu,
1132 template_interval,
1133 vrf_id=0,
1134 collector_port=4739,
1135 udp_checksum=0):
1136 return self.api(
1137 self.papi.set_ipfix_exporter,
1138 {
1139 'collector_address': collector_address,
1140 'collector_port': collector_port,
1141 'src_address': src_address,
1142 'vrf_id': vrf_id,
1143 'path_mtu': path_mtu,
1144 'template_interval': template_interval,
1145 'udp_checksum': udp_checksum,
1146 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001147
1148 def dhcp_proxy_config(self,
1149 dhcp_server,
1150 dhcp_src_address,
1151 rx_table_id=0,
1152 server_table_id=0,
1153 is_add=1,
1154 is_ipv6=0,
1155 insert_circuit_id=0):
1156 return self.api(
1157 self.papi.dhcp_proxy_config_2,
1158 {
1159 'rx_vrf_id': rx_table_id,
1160 'server_vrf_id': server_table_id,
1161 'is_ipv6': is_ipv6,
1162 'is_add': is_add,
1163 'insert_circuit_id': insert_circuit_id,
1164 'dhcp_server': dhcp_server,
1165 'dhcp_src_address': dhcp_src_address,
1166 })
1167
1168 def dhcp_proxy_set_vss(self,
1169 table_id,
1170 fib_id,
1171 oui,
1172 is_add=1,
1173 is_ip6=0):
1174 return self.api(
1175 self.papi.dhcp_proxy_set_vss,
1176 {
1177 'tbl_id': table_id,
1178 'fib_id': fib_id,
1179 'is_ipv6': is_ip6,
1180 'is_add': is_add,
1181 'oui': oui,
1182 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001183
1184 def ip_mroute_add_del(self,
1185 src_address,
1186 grp_address,
1187 grp_address_length,
1188 e_flags,
1189 next_hop_sw_if_index,
1190 i_flags,
1191 table_id=0,
1192 create_vrf_if_needed=0,
1193 is_add=1,
1194 is_ipv6=0,
1195 is_local=0):
1196 """
1197 """
1198 return self.api(
1199 self.papi.ip_mroute_add_del,
1200 {'next_hop_sw_if_index': next_hop_sw_if_index,
1201 'entry_flags': e_flags,
1202 'itf_flags': i_flags,
1203 'create_vrf_if_needed': create_vrf_if_needed,
1204 'is_add': is_add,
1205 'is_ipv6': is_ipv6,
1206 'is_local': is_local,
1207 'grp_address_length': grp_address_length,
1208 'grp_address': grp_address,
1209 'src_address': src_address})
1210
1211 def mfib_signal_dump(self):
1212 return self.api(self.papi.mfib_signal_dump, {})