blob: 7a508a44d3e1e34d328b8ffcc30169bcf2302cc1 [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
Klement Sekeraf62ae122016-10-11 11:47:09 +0200254 def sw_interface_ra_suppress(self, sw_if_index):
Ole Troan7e3a8752016-12-05 10:27:09 +0100255 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200256 {'sw_if_index': sw_if_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200257
Neale Ranns75152282017-01-09 01:00:45 -0800258 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000259 no,
Neale Ranns75152282017-01-09 01:00:45 -0800260 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000261 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800262 return self.api(self.papi.sw_interface_ip6nd_ra_config,
263 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000264 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100265 'suppress': suppress,
266 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800267
268 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
269 """
270 Enable/Disable An interface for IPv6
271 """
272 return self.api(self.papi.sw_interface_ip6_enable_disable,
273 {'sw_if_index': sw_if_index,
274 'enable': enable})
275
Klement Sekeraf62ae122016-10-11 11:47:09 +0200276 def vxlan_add_del_tunnel(
277 self,
278 src_addr,
279 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200280 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200281 is_add=1,
282 is_ipv6=0,
283 encap_vrf_id=0,
284 decap_next_index=0xFFFFFFFF,
285 vni=0):
286 """
287
288 :param dst_addr:
289 :param src_addr:
290 :param is_add: (Default value = 1)
291 :param is_ipv6: (Default value = 0)
292 :param encap_vrf_id: (Default value = 0)
293 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200294 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200295 :param vni: (Default value = 0)
296
297 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100298 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200299 {'is_add': is_add,
300 'is_ipv6': is_ipv6,
301 'src_address': src_addr,
302 'dst_address': dst_addr,
303 'mcast_sw_if_index': mcast_sw_if_index,
304 'encap_vrf_id': encap_vrf_id,
305 'decap_next_index': decap_next_index,
306 'vni': vni})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200307
Jan4af521d2016-11-15 17:05:00 +0100308 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
309 learn=1, arp_term=0, is_add=1):
310 """Create/delete bridge domain.
311
312 :param int bd_id: Bridge domain index.
313 :param int flood: Enable/disable bcast/mcast flooding in the BD.
314 (Default value = 1)
315 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
316 (Default value = 1)
317 :param int forward: Enable/disable forwarding on all interfaces in
318 the BD. (Default value = 1)
319 :param int learn: Enable/disable learning on all interfaces in the BD.
320 (Default value = 1)
321 :param int arp_term: Enable/disable arp termination in the BD.
322 (Default value = 1)
323 :param int is_add: Add or delete flag. (Default value = 1)
324 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100325 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200326 {'bd_id': bd_id,
327 'flood': flood,
328 'uu_flood': uu_flood,
329 'forward': forward,
330 'learn': learn,
331 'arp_term': arp_term,
332 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100333
334 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
335 filter_mac=0, bvi_mac=0):
336 """Create/delete L2 FIB entry.
337
338 :param str mac: MAC address to create FIB entry for.
339 :param int bd_id: Bridge domain index.
340 :param int sw_if_index: Software interface index of the interface.
341 :param int is_add: Add or delete flag. (Default value = 1)
342 :param int static_mac: Set to 1 to create static MAC entry.
343 (Default value = 0)
344 :param int filter_mac: Set to 1 to drop packet that's source or
345 destination MAC address contains defined MAC address.
346 (Default value = 0)
347 :param int bvi_mac: Set to 1 to create entry that points to BVI
348 interface. (Default value = 0)
349 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100350 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200351 {'mac': self._convert_mac(mac),
352 'bd_id': bd_id,
353 'sw_if_index': sw_if_index,
354 'is_add': is_add,
355 'static_mac': static_mac,
356 'filter_mac': filter_mac,
357 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100358
Klement Sekeraf62ae122016-10-11 11:47:09 +0200359 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
360 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100361 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200362
Jan4af521d2016-11-15 17:05:00 +0100363 :param int sw_if_index: Software interface index of the interface.
364 :param int bd_id: Bridge domain index.
365 :param int shg: Split-horizon group index. (Default value = 0)
366 :param int bvi: Set interface as a bridge group virtual interface.
367 (Default value = 0)
368 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200369 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100370 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200371 {'rx_sw_if_index': sw_if_index,
372 'bd_id': bd_id,
373 'shg': shg,
374 'bvi': bvi,
375 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200376
Jan00dad122016-11-29 10:04:53 +0100377 def bridge_flags(self, bd_id, is_set, feature_bitmap):
378 """Enable/disable required feature of the bridge domain with defined ID.
379
380 :param int bd_id: Bridge domain ID.
381 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
382 :param int feature_bitmap: Bitmap value of the feature to be set:
383 - learn (1 << 0),
384 - forward (1 << 1),
385 - flood (1 << 2),
386 - uu-flood (1 << 3) or
387 - arp-term (1 << 4).
388 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100389 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200390 {'bd_id': bd_id,
391 'is_set': is_set,
392 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100393
394 def bridge_domain_dump(self, bd_id=0):
395 """
396
397 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
398 existing bridge domains returned)
399 :return: Dictionary of bridge domain(s) data.
400 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100401 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200402 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100403
Klement Sekeraf62ae122016-10-11 11:47:09 +0200404 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
405 enable):
406 """Create or delete unidirectional cross-connect from Tx interface to
407 Rx interface.
408
Jan4af521d2016-11-15 17:05:00 +0100409 :param int rx_sw_if_index: Software interface index of Rx interface.
410 :param int tx_sw_if_index: Software interface index of Tx interface.
411 :param int enable: Create cross-connect if equal to 1, delete
412 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200413
414 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100415 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200416 {'rx_sw_if_index': rx_sw_if_index,
417 'tx_sw_if_index': tx_sw_if_index,
418 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200419
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200420 def sw_interface_set_l2_tag_rewrite(
421 self,
422 sw_if_index,
423 vtr_oper,
424 push=0,
425 tag1=0,
426 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000427 """L2 interface vlan tag rewrite configure request
428 :param client_index - opaque cookie to identify the sender
429 :param context - sender context, to match reply w/ request
430 :param sw_if_index - interface the operation is applied to
431 :param vtr_op - Choose from l2_vtr_op_t enum values
432 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
433 :param tag1 - Needed for any push or translate vtr op
434 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
435
436 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100437 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200438 {'sw_if_index': sw_if_index,
439 'vtr_op': vtr_oper,
440 'push_dot1q': push,
441 'tag1': tag1,
442 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000443
Klement Sekeraf62ae122016-10-11 11:47:09 +0200444 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
445 link_up_down=0, deleted=0):
446 """
447
448 :param admin_up_down:
449 :param sw_if_index:
450 :param link_up_down: (Default value = 0)
451 :param deleted: (Default value = 0)
452
453 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100454 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200455 {'sw_if_index': sw_if_index,
456 'admin_up_down': admin_up_down,
457 'link_up_down': link_up_down,
458 'deleted': deleted})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200459
460 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
461 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
462 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
463 """Create subinterface
464 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
465
466 :param sub_id: param inner_vlan:
467 :param sw_if_index:
468 :param outer_vlan:
469 :param inner_vlan:
470 :param no_tags: (Default value = 0)
471 :param one_tag: (Default value = 0)
472 :param two_tags: (Default value = 0)
473 :param dot1ad: (Default value = 0)
474 :param exact_match: (Default value = 0)
475 :param default_sub: (Default value = 0)
476 :param outer_vlan_id_any: (Default value = 0)
477 :param inner_vlan_id_any: (Default value = 0)
478
479 """
480 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100481 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200482 {'sw_if_index': sw_if_index,
483 'sub_id': sub_id,
484 'no_tags': no_tags,
485 'one_tag': one_tag,
486 'two_tags': two_tags,
487 'dot1ad': dot1ad,
488 'exact_match': exact_match,
489 'default_sub': default_sub,
490 'outer_vlan_id_any': outer_vlan_id_any,
491 'inner_vlan_id_any': inner_vlan_id_any,
492 'outer_vlan_id': outer_vlan,
493 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200494
Neale Ranns177bbdc2016-11-15 09:46:51 +0000495 def delete_subif(self, sw_if_index):
496 """Delete subinterface
497
498 :param sw_if_index:
499 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100500 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200501 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000502
Klement Sekeraf62ae122016-10-11 11:47:09 +0200503 def create_vlan_subif(self, sw_if_index, vlan):
504 """
505
506 :param vlan:
507 :param sw_if_index:
508
509 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100510 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200511 {'sw_if_index': sw_if_index,
512 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200513
Matej Klotton0178d522016-11-04 11:11:44 +0100514 def create_loopback(self, mac=''):
515 """
516
517 :param mac: (Optional)
518 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100519 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200520 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100521
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100522 def delete_loopback(self, sw_if_index):
523 return self.api(self.papi.delete_loopback,
524 {'sw_if_index': sw_if_index, })
525
Klement Sekeraf62ae122016-10-11 11:47:09 +0200526 def ip_add_del_route(
527 self,
528 dst_address,
529 dst_address_length,
530 next_hop_address,
531 next_hop_sw_if_index=0xFFFFFFFF,
532 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200533 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000534 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200535 next_hop_n_out_labels=0,
536 next_hop_out_label_stack=[],
537 next_hop_via_label=MPLS_LABEL_INVALID,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200538 create_vrf_if_needed=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000539 is_resolve_host=0,
540 is_resolve_attached=0,
541 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200542 is_add=1,
543 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200544 is_unreach=0,
545 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200546 is_ipv6=0,
547 is_local=0,
548 is_classify=0,
549 is_multipath=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000550 not_last=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200551 """
552
553 :param dst_address_length:
554 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
555 :param dst_address:
556 :param next_hop_address:
557 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
558 :param vrf_id: (Default value = 0)
559 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200560 :param classify_table_index: (Default value = 0xFFFFFFFF)
561 :param create_vrf_if_needed: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200562 :param is_add: (Default value = 1)
563 :param is_drop: (Default value = 0)
564 :param is_ipv6: (Default value = 0)
565 :param is_local: (Default value = 0)
566 :param is_classify: (Default value = 0)
567 :param is_multipath: (Default value = 0)
568 :param is_resolve_host: (Default value = 0)
569 :param is_resolve_attached: (Default value = 0)
570 :param not_last: (Default value = 0)
571 :param next_hop_weight: (Default value = 1)
572
573 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000574
Klement Sekeraf62ae122016-10-11 11:47:09 +0200575 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100576 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200577 {'next_hop_sw_if_index': next_hop_sw_if_index,
578 'table_id': table_id,
579 'classify_table_index': classify_table_index,
580 'next_hop_table_id': next_hop_table_id,
581 'create_vrf_if_needed': create_vrf_if_needed,
582 'is_add': is_add,
583 'is_drop': is_drop,
584 'is_unreach': is_unreach,
585 'is_prohibit': is_prohibit,
586 'is_ipv6': is_ipv6,
587 'is_local': is_local,
588 'is_classify': is_classify,
589 'is_multipath': is_multipath,
590 'is_resolve_host': is_resolve_host,
591 'is_resolve_attached': is_resolve_attached,
592 'not_last': not_last,
593 'next_hop_weight': next_hop_weight,
594 'dst_address_length': dst_address_length,
595 'dst_address': dst_address,
596 'next_hop_address': next_hop_address,
597 'next_hop_n_out_labels': next_hop_n_out_labels,
598 'next_hop_via_label': next_hop_via_label,
599 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100600
Matej Klotton16a14cd2016-12-07 15:09:13 +0100601 def ip_fib_dump(self):
602 return self.api(self.papi.ip_fib_dump, {})
603
Matej Klotton0178d522016-11-04 11:11:44 +0100604 def ip_neighbor_add_del(self,
605 sw_if_index,
606 mac_address,
607 dst_address,
608 vrf_id=0,
609 is_add=1,
610 is_ipv6=0,
611 is_static=0,
612 ):
613 """ Add neighbor MAC to IPv4 or IPv6 address.
614
615 :param sw_if_index:
616 :param mac_address:
617 :param dst_address:
618 :param vrf_id: (Default value = 0)
619 :param is_add: (Default value = 1)
620 :param is_ipv6: (Default value = 0)
621 :param is_static: (Default value = 0)
622 """
623
624 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100625 self.papi.ip_neighbor_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200626 {'vrf_id': vrf_id,
627 'sw_if_index': sw_if_index,
628 'is_add': is_add,
629 'is_ipv6': is_ipv6,
630 'is_static': is_static,
631 'mac_address': mac_address,
632 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100633 }
Matej Klotton0178d522016-11-04 11:11:44 +0100634 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100635
Jane546d3b2016-12-08 13:10:03 +0100636 def reset_vrf(self,
637 vrf_id,
638 is_ipv6=0,
639 ):
640 """ Reset VRF (remove all routes etc.) request.
641
642 :param int vrf_id: ID of the FIB table / VRF to reset.
643 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
644 """
645
646 return self.api(
647 self.papi.reset_vrf,
648 {'vrf_id': vrf_id,
649 'is_ipv6': is_ipv6,
650 }
651 )
652
653 def reset_fib(self,
654 vrf_id,
655 is_ipv6=0,
656 ):
657 """ Reset VRF (remove all routes etc.) request.
658
659 :param int vrf_id: ID of the FIB table / VRF to reset.
660 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
661 """
662
663 return self.api(
664 self.papi.reset_fib,
665 {'vrf_id': vrf_id,
666 'is_ipv6': is_ipv6,
667 }
668 )
669
670 def ip_dump(self,
671 is_ipv6=0,
672 ):
673 """ Return IP dump.
674
675 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
676 """
677
678 return self.api(
679 self.papi.ip_dump,
680 {'is_ipv6': is_ipv6,
681 }
682 )
683
Klement Sekera7bb873a2016-11-18 07:38:42 +0100684 def sw_interface_span_enable_disable(
Ole Troan399ca1c2016-12-06 23:00:38 +0100685 self, sw_if_index_from, sw_if_index_to, state=1):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100686 """
687
688 :param sw_if_index_from:
689 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +0100690 :param state:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100691 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100692 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200693 {'sw_if_index_from': sw_if_index_from,
694 'sw_if_index_to': sw_if_index_to,
695 'state': state})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000696
697 def gre_tunnel_add_del(self,
698 src_address,
699 dst_address,
700 outer_fib_id=0,
701 is_teb=0,
702 is_add=1,
703 is_ip6=0):
704 """ Add a GRE tunnel
705
706 :param src_address:
707 :param dst_address:
708 :param outer_fib_id: (Default value = 0)
709 :param is_add: (Default value = 1)
710 :param is_ipv6: (Default value = 0)
711 :param is_teb: (Default value = 0)
712 """
713
714 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100715 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200716 {'is_add': is_add,
717 'is_ipv6': is_ip6,
718 'teb': is_teb,
719 'src_address': src_address,
720 'dst_address': dst_address,
721 'outer_fib_id': outer_fib_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000722 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000723
724 def mpls_route_add_del(
725 self,
726 label,
727 eos,
728 next_hop_proto_is_ip4,
729 next_hop_address,
730 next_hop_sw_if_index=0xFFFFFFFF,
731 table_id=0,
732 next_hop_table_id=0,
733 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200734 next_hop_n_out_labels=0,
735 next_hop_out_label_stack=[],
736 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000737 create_vrf_if_needed=0,
738 is_resolve_host=0,
739 is_resolve_attached=0,
740 is_add=1,
741 is_drop=0,
742 is_multipath=0,
743 classify_table_index=0xFFFFFFFF,
744 is_classify=0,
745 not_last=0):
746 """
747
748 :param dst_address_length:
749 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
750 :param dst_address:
751 :param next_hop_address:
752 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
753 :param vrf_id: (Default value = 0)
754 :param lookup_in_vrf: (Default value = 0)
755 :param classify_table_index: (Default value = 0xFFFFFFFF)
756 :param create_vrf_if_needed: (Default value = 0)
757 :param is_add: (Default value = 1)
758 :param is_drop: (Default value = 0)
759 :param is_ipv6: (Default value = 0)
760 :param is_local: (Default value = 0)
761 :param is_classify: (Default value = 0)
762 :param is_multipath: (Default value = 0)
763 :param is_resolve_host: (Default value = 0)
764 :param is_resolve_attached: (Default value = 0)
765 :param not_last: (Default value = 0)
766 :param next_hop_weight: (Default value = 1)
767
768 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000769
770 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100771 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200772 {'mr_label': label,
773 'mr_eos': eos,
774 'mr_table_id': table_id,
775 'mr_classify_table_index': classify_table_index,
776 'mr_create_table_if_needed': create_vrf_if_needed,
777 'mr_is_add': is_add,
778 'mr_is_classify': is_classify,
779 'mr_is_multipath': is_multipath,
780 'mr_is_resolve_host': is_resolve_host,
781 'mr_is_resolve_attached': is_resolve_attached,
782 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
783 'mr_next_hop_weight': next_hop_weight,
784 'mr_next_hop': next_hop_address,
785 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
786 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
787 'mr_next_hop_table_id': next_hop_table_id,
788 'mr_next_hop_via_label': next_hop_via_label,
789 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +0000790
791 def mpls_ip_bind_unbind(
792 self,
793 label,
794 dst_address,
795 dst_address_length,
796 table_id=0,
797 ip_table_id=0,
798 is_ip4=1,
799 create_vrf_if_needed=0,
800 is_bind=1):
801 """
802 """
803 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100804 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200805 {'mb_mpls_table_id': table_id,
806 'mb_label': label,
807 'mb_ip_table_id': ip_table_id,
808 'mb_create_table_if_needed': create_vrf_if_needed,
809 'mb_is_bind': is_bind,
810 'mb_is_ip4': is_ip4,
811 'mb_address_length': dst_address_length,
812 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000813
814 def mpls_tunnel_add_del(
815 self,
816 tun_sw_if_index,
817 next_hop_proto_is_ip4,
818 next_hop_address,
819 next_hop_sw_if_index=0xFFFFFFFF,
820 next_hop_table_id=0,
821 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200822 next_hop_n_out_labels=0,
823 next_hop_out_label_stack=[],
824 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000825 create_vrf_if_needed=0,
826 is_add=1,
827 l2_only=0):
828 """
829
830 :param dst_address_length:
831 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
832 :param dst_address:
833 :param next_hop_address:
834 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
835 :param vrf_id: (Default value = 0)
836 :param lookup_in_vrf: (Default value = 0)
837 :param classify_table_index: (Default value = 0xFFFFFFFF)
838 :param create_vrf_if_needed: (Default value = 0)
839 :param is_add: (Default value = 1)
840 :param is_drop: (Default value = 0)
841 :param is_ipv6: (Default value = 0)
842 :param is_local: (Default value = 0)
843 :param is_classify: (Default value = 0)
844 :param is_multipath: (Default value = 0)
845 :param is_resolve_host: (Default value = 0)
846 :param is_resolve_attached: (Default value = 0)
847 :param not_last: (Default value = 0)
848 :param next_hop_weight: (Default value = 1)
849
850 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000851 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100852 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200853 {'mt_sw_if_index': tun_sw_if_index,
854 'mt_is_add': is_add,
855 'mt_l2_only': l2_only,
856 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
857 'mt_next_hop_weight': next_hop_weight,
858 'mt_next_hop': next_hop_address,
859 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
860 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
861 'mt_next_hop_table_id': next_hop_table_id,
862 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800863
864 def snat_interface_add_del_feature(
865 self,
866 sw_if_index,
867 is_inside=1,
868 is_add=1):
869 """Enable/disable S-NAT feature on the interface
870
871 :param sw_if_index: Software index of the interface
872 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
873 :param is_add: 1 if add, 0 if delete (Default value = 1)
874 """
875 return self.api(
876 self.papi.snat_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200877 {'is_add': is_add,
878 'is_inside': is_inside,
879 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800880
881 def snat_add_static_mapping(
882 self,
883 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800884 external_ip=0,
885 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800886 local_port=0,
887 external_port=0,
888 addr_only=1,
889 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800890 protocol=0,
Matus Fabiande886752016-12-07 03:38:19 -0800891 is_add=1,
892 is_ip4=1):
893 """Add/delete S-NAT static mapping
894
895 :param local_ip: Local IP address
896 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800897 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800898 :param local_port: Local port number (Default value = 0)
899 :param external_port: External port number (Default value = 0)
900 :param addr_only: 1 if address only mapping, 0 if address and port
901 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800902 :param protocol: IP protocol (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -0800903 :param is_add: 1 if add, 0 if delete (Default value = 1)
904 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
905 """
906 return self.api(
907 self.papi.snat_add_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200908 {'is_add': is_add,
909 'is_ip4': is_ip4,
910 'addr_only': addr_only,
911 'local_ip_address': local_ip,
912 'external_ip_address': external_ip,
913 'local_port': local_port,
914 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800915 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800916 'vrf_id': vrf_id,
917 'protocol': protocol})
Matus Fabiande886752016-12-07 03:38:19 -0800918
919 def snat_add_address_range(
920 self,
921 first_ip_address,
922 last_ip_address,
923 is_add=1,
924 is_ip4=1):
925 """Add/del S-NAT address range
926
927 :param first_ip_address: First IP address
928 :param last_ip_address: Last IP address
929 :param is_add: 1 if add, 0 if delete (Default value = 1)
930 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
931 """
932 return self.api(
933 self.papi.snat_add_address_range,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200934 {'is_ip4': is_ip4,
935 'first_ip_address': first_ip_address,
936 'last_ip_address': last_ip_address,
937 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -0800938
939 def snat_address_dump(self):
940 """Dump S-NAT addresses
941 :return: Dictionary of S-NAT addresses
942 """
943 return self.api(self.papi.snat_address_dump, {})
944
945 def snat_interface_dump(self):
946 """Dump interfaces with S-NAT feature
947 :return: Dictionary of interfaces with S-NAT feature
948 """
949 return self.api(self.papi.snat_interface_dump, {})
950
951 def snat_static_mapping_dump(self):
952 """Dump S-NAT static mappings
953 :return: Dictionary of S-NAT static mappings
954 """
955 return self.api(self.papi.snat_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200956
Matus Fabian9902fcd2016-12-21 23:58:46 -0800957 def snat_show_config(self):
958 """Show S-NAT config
959 :return: S-NAT config parameters
960 """
961 return self.api(self.papi.snat_show_config, {})
962
Matus Fabian8bf68e82017-01-12 04:24:35 -0800963 def snat_add_interface_addr(
964 self,
965 sw_if_index,
966 is_add=1):
967 """Add/del S-NAT address from interface
968
969 :param sw_if_index: Software index of the interface
970 :param is_add: 1 if add, 0 if delete (Default value = 1)
971 """
972 return self.api(self.papi.snat_add_del_interface_addr,
973 {'is_add': is_add, 'sw_if_index': sw_if_index})
974
975 def snat_interface_addr_dump(self):
976 """Dump S-NAT addresses interfaces
977 :return: Dictionary of S-NAT addresses interfaces
978 """
979 return self.api(self.papi.snat_interface_addr_dump, {})
980
Matus Fabianeea28d72017-01-13 04:15:54 -0800981 def snat_ipfix(
982 self,
983 domain_id=1,
984 src_port=4739,
985 enable=1):
986 """Enable/disable S-NAT IPFIX logging
987
988 :param domain_id: Observation domain ID (Default value = 1)
989 :param src_port: Source port number (Default value = 4739)
990 :param enable: 1 if enable, 0 if disable (Default value = 1)
991 """
992 return self.api(
993 self.papi.snat_ipfix_enable_disable,
994 {'domain_id': domain_id,
995 'src_port': src_port,
996 'enable': enable})
997
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200998 def control_ping(self):
999 self.api(self.papi.control_ping)
1000
1001 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001002 detect_mult, local_addr, peer_addr, is_ipv6=0,
1003 bfd_key_id=None, conf_key_id=None):
1004 if bfd_key_id is None:
1005 return self.api(self.papi.bfd_udp_add,
1006 {
1007 'sw_if_index': sw_if_index,
1008 'desired_min_tx': desired_min_tx,
1009 'required_min_rx': required_min_rx,
1010 'local_addr': local_addr,
1011 'peer_addr': peer_addr,
1012 'is_ipv6': is_ipv6,
1013 'detect_mult': detect_mult,
1014 })
1015 else:
1016 return self.api(self.papi.bfd_udp_add,
1017 {
1018 'sw_if_index': sw_if_index,
1019 'desired_min_tx': desired_min_tx,
1020 'required_min_rx': required_min_rx,
1021 'local_addr': local_addr,
1022 'peer_addr': peer_addr,
1023 'is_ipv6': is_ipv6,
1024 'detect_mult': detect_mult,
1025 'is_authenticated': 1,
1026 'bfd_key_id': bfd_key_id,
1027 'conf_key_id': conf_key_id,
1028 })
1029
Klement Sekeraa57a9702017-02-02 06:58:07 +01001030 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1031 detect_mult, local_addr, peer_addr, is_ipv6=0):
1032 return self.api(self.papi.bfd_udp_mod,
1033 {
1034 'sw_if_index': sw_if_index,
1035 'desired_min_tx': desired_min_tx,
1036 'required_min_rx': required_min_rx,
1037 'local_addr': local_addr,
1038 'peer_addr': peer_addr,
1039 'is_ipv6': is_ipv6,
1040 'detect_mult': detect_mult,
1041 })
1042
Klement Sekerab17dd962017-01-09 07:43:48 +01001043 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1044 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1045 is_delayed=False):
1046 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001047 {
1048 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001049 'local_addr': local_addr,
1050 'peer_addr': peer_addr,
1051 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001052 'is_delayed': 1 if is_delayed else 0,
1053 'bfd_key_id': bfd_key_id,
1054 'conf_key_id': conf_key_id,
1055 })
1056
1057 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1058 is_ipv6=0, is_delayed=False):
1059 return self.api(self.papi.bfd_udp_auth_deactivate,
1060 {
1061 'sw_if_index': sw_if_index,
1062 'local_addr': local_addr,
1063 'peer_addr': peer_addr,
1064 'is_ipv6': is_ipv6,
1065 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001066 })
1067
1068 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1069 return self.api(self.papi.bfd_udp_del,
1070 {
1071 'sw_if_index': sw_if_index,
1072 'local_addr': local_addr,
1073 'peer_addr': peer_addr,
1074 'is_ipv6': is_ipv6,
1075 })
1076
1077 def bfd_udp_session_dump(self):
1078 return self.api(self.papi.bfd_udp_session_dump, {})
1079
Klement Sekerab17dd962017-01-09 07:43:48 +01001080 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1081 peer_addr, is_ipv6=0):
1082 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001083 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001084 'sw_if_index': sw_if_index,
1085 'local_addr': local_addr,
1086 'peer_addr': peer_addr,
1087 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001088 })
1089
1090 def want_bfd_events(self, enable_disable=1):
1091 return self.api(self.papi.want_bfd_events, {
1092 'enable_disable': enable_disable,
1093 'pid': os.getpid(),
1094 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001095
Klement Sekerab17dd962017-01-09 07:43:48 +01001096 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1097 return self.api(self.papi.bfd_auth_set_key, {
1098 'conf_key_id': conf_key_id,
1099 'auth_type': auth_type,
1100 'key': key,
1101 'key_len': len(key),
1102 })
1103
1104 def bfd_auth_del_key(self, conf_key_id):
1105 return self.api(self.papi.bfd_auth_del_key, {
1106 'conf_key_id': conf_key_id,
1107 })
1108
1109 def bfd_auth_keys_dump(self):
1110 return self.api(self.papi.bfd_auth_keys_dump, {})
1111
Steve Shin7957d6e2016-12-19 09:24:50 -08001112 def classify_add_del_table(
1113 self,
1114 is_add,
1115 mask,
1116 match_n_vectors=1,
1117 table_index=0xFFFFFFFF,
1118 nbuckets=2,
1119 memory_size=2097152,
1120 skip_n_vectors=0,
1121 next_table_index=0xFFFFFFFF,
1122 miss_next_index=0xFFFFFFFF,
1123 current_data_flag=0,
1124 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001125 """
1126 :param is_add:
1127 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001128 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001129 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001130 :param nbuckets: (Default value = 2)
1131 :param memory_size: (Default value = 2097152)
1132 :param skip_n_vectors: (Default value = 0)
1133 :param next_table_index: (Default value = 0xFFFFFFFF)
1134 :param miss_next_index: (Default value = 0xFFFFFFFF)
1135 :param current_data_flag: (Default value = 0)
1136 :param current_data_offset: (Default value = 0)
1137 """
1138
1139 return self.api(
1140 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001141 {'is_add': is_add,
1142 'table_index': table_index,
1143 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001144 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001145 'skip_n_vectors': skip_n_vectors,
1146 'match_n_vectors': match_n_vectors,
1147 'next_table_index': next_table_index,
1148 'miss_next_index': miss_next_index,
1149 'current_data_flag': current_data_flag,
1150 'current_data_offset': current_data_offset,
1151 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001152
1153 def classify_add_del_session(
1154 self,
1155 is_add,
1156 table_index,
1157 match,
1158 opaque_index=0xFFFFFFFF,
1159 hit_next_index=0xFFFFFFFF,
1160 advance=0,
1161 action=0,
1162 metadata=0):
1163 """
1164 :param is_add:
1165 :param table_index:
1166 :param match:
1167 :param opaque_index: (Default value = 0xFFFFFFFF)
1168 :param hit_next_index: (Default value = 0xFFFFFFFF)
1169 :param advance: (Default value = 0)
1170 :param action: (Default value = 0)
1171 :param metadata: (Default value = 0)
1172 """
1173
1174 return self.api(
1175 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001176 {'is_add': is_add,
1177 'table_index': table_index,
1178 'hit_next_index': hit_next_index,
1179 'opaque_index': opaque_index,
1180 'advance': advance,
1181 'action': action,
1182 'metadata': metadata,
1183 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001184
1185 def input_acl_set_interface(
1186 self,
1187 is_add,
1188 sw_if_index,
1189 ip4_table_index=0xFFFFFFFF,
1190 ip6_table_index=0xFFFFFFFF,
1191 l2_table_index=0xFFFFFFFF):
1192 """
1193 :param is_add:
1194 :param sw_if_index:
1195 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1196 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1197 :param l2_table_index: (Default value = 0xFFFFFFFF)
1198 """
1199
1200 return self.api(
1201 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001202 {'sw_if_index': sw_if_index,
1203 'ip4_table_index': ip4_table_index,
1204 'ip6_table_index': ip6_table_index,
1205 'l2_table_index': l2_table_index,
1206 'is_add': is_add})
1207
1208 def set_ipfix_exporter(
1209 self,
1210 collector_address,
1211 src_address,
1212 path_mtu,
1213 template_interval,
1214 vrf_id=0,
1215 collector_port=4739,
1216 udp_checksum=0):
1217 return self.api(
1218 self.papi.set_ipfix_exporter,
1219 {
1220 'collector_address': collector_address,
1221 'collector_port': collector_port,
1222 'src_address': src_address,
1223 'vrf_id': vrf_id,
1224 'path_mtu': path_mtu,
1225 'template_interval': template_interval,
1226 'udp_checksum': udp_checksum,
1227 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001228
1229 def dhcp_proxy_config(self,
1230 dhcp_server,
1231 dhcp_src_address,
1232 rx_table_id=0,
1233 server_table_id=0,
1234 is_add=1,
1235 is_ipv6=0,
1236 insert_circuit_id=0):
1237 return self.api(
1238 self.papi.dhcp_proxy_config_2,
1239 {
1240 'rx_vrf_id': rx_table_id,
1241 'server_vrf_id': server_table_id,
1242 'is_ipv6': is_ipv6,
1243 'is_add': is_add,
1244 'insert_circuit_id': insert_circuit_id,
1245 'dhcp_server': dhcp_server,
1246 'dhcp_src_address': dhcp_src_address,
1247 })
1248
1249 def dhcp_proxy_set_vss(self,
1250 table_id,
1251 fib_id,
1252 oui,
1253 is_add=1,
1254 is_ip6=0):
1255 return self.api(
1256 self.papi.dhcp_proxy_set_vss,
1257 {
1258 'tbl_id': table_id,
1259 'fib_id': fib_id,
1260 'is_ipv6': is_ip6,
1261 'is_add': is_add,
1262 'oui': oui,
1263 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001264
1265 def ip_mroute_add_del(self,
1266 src_address,
1267 grp_address,
1268 grp_address_length,
1269 e_flags,
1270 next_hop_sw_if_index,
1271 i_flags,
1272 table_id=0,
1273 create_vrf_if_needed=0,
1274 is_add=1,
1275 is_ipv6=0,
1276 is_local=0):
1277 """
1278 """
1279 return self.api(
1280 self.papi.ip_mroute_add_del,
1281 {'next_hop_sw_if_index': next_hop_sw_if_index,
1282 'entry_flags': e_flags,
1283 'itf_flags': i_flags,
1284 'create_vrf_if_needed': create_vrf_if_needed,
1285 'is_add': is_add,
1286 'is_ipv6': is_ipv6,
1287 'is_local': is_local,
1288 'grp_address_length': grp_address_length,
1289 'grp_address': grp_address,
1290 'src_address': src_address})
1291
1292 def mfib_signal_dump(self):
1293 return self.api(self.papi.mfib_signal_dump, {})