5 from collections import deque
7 # Sphinx creates auto-generated documentation by importing the python source
8 # 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.
13 no_vpp_papi = os.getenv("NO_VPP_PAPI")
14 if no_vpp_papi == "1":
20 from vpp_papi import VPP
22 # from vnet/vnet/mpls/mpls_types.h
23 MPLS_IETF_MAX_LABEL = 0xfffff
24 MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
31 class UnexpectedApiReturnValueError(Exception):
32 """ exception raised when the API return value is unexpected """
36 class VppPapiProvider(object):
37 """VPP-api provider using vpp-papi
39 @property hook: hook object providing before and after api/cli hooks
42 _zero, _negative = range(2)
44 def __init__(self, name, shm_prefix, test_class):
45 self.hook = Hook("vpp-papi-provider")
47 self.shm_prefix = shm_prefix
48 self.test_class = test_class
49 self._expect_api_retval = self._zero
50 self._expect_stack = []
53 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
54 for root, dirnames, filenames in os.walk(install_dir):
55 for filename in fnmatch.filter(filenames, '*.api.json'):
56 jsonfiles.append(os.path.join(root, filename))
58 self.vpp = VPP(jsonfiles)
59 self._events = deque()
64 def expect_negative_api_retval(self):
65 """ Expect API failure """
66 self._expect_stack.append(self._expect_api_retval)
67 self._expect_api_retval = self._negative
70 def expect_zero_api_retval(self):
71 """ Expect API success """
72 self._expect_stack.append(self._expect_api_retval)
73 self._expect_api_retval = self._zero
76 def __exit__(self, exc_type, exc_value, traceback):
77 self._expect_api_retval = self._expect_stack.pop()
79 def register_hook(self, hook):
80 """Replace hook registration with new hook
87 def collect_events(self):
88 """ Collect all events from the internal queue and clear the queue. """
90 self._events = deque()
93 def wait_for_event(self, timeout, name=None):
94 """ Wait for and return next event. """
96 self.test_class.logger.debug("Expecting event within %ss",
99 self.test_class.logger.debug("Expecting event '%s' within %ss",
102 self.test_class.logger.debug("Not waiting, event already queued")
103 limit = time.time() + timeout
104 while time.time() < limit:
106 e = self._events.popleft()
107 if name and type(e).__name__ != name:
109 "Unexpected event received: %s, expected: %s" %
110 (type(e).__name__, name))
111 self.test_class.logger.debug("Returning event %s:%s" %
114 time.sleep(0) # yield
115 raise Exception("Event did not occur within timeout")
117 def __call__(self, name, event):
118 """ Enqueue event in the internal event queue. """
119 # FIXME use the name instead of relying on type(e).__name__ ?
120 # FIXME #2 if this throws, it is eaten silently, Ole?
121 self.test_class.logger.debug("New event: %s: %s" % (name, event))
122 self._events.append(event)
125 """Connect the API to VPP"""
126 self.vpp.connect(self.name, self.shm_prefix)
127 self.papi = self.vpp.api
128 self.vpp.register_event_callback(self)
130 def disconnect(self):
131 """Disconnect the API from VPP"""
132 self.vpp.disconnect()
134 def api(self, api_fn, api_args, expected_retval=0):
135 """ Call API function and check it's return value.
136 Call the appropriate hooks before and after the API call
138 :param api_fn: API function to call
139 :param api_args: tuple of API function arguments
140 :param expected_retval: Expected return value (Default value = 0)
141 :returns: reply from the API
144 self.hook.before_api(api_fn.__name__, api_args)
145 reply = api_fn(**api_args)
146 if self._expect_api_retval == self._negative:
147 if hasattr(reply, 'retval') and reply.retval >= 0:
148 msg = "API call passed unexpectedly: expected negative "\
149 "return value instead of %d in %s" % \
150 (reply.retval, repr(reply))
151 self.test_class.logger.info(msg)
152 raise UnexpectedApiReturnValueError(msg)
153 elif self._expect_api_retval == self._zero:
154 if hasattr(reply, 'retval') and reply.retval != expected_retval:
155 msg = "API call failed, expected zero return value instead "\
156 "of %d in %s" % (expected_retval, repr(reply))
157 self.test_class.logger.info(msg)
158 raise UnexpectedApiReturnValueError(msg)
160 raise Exception("Internal error, unexpected value for "
161 "self._expect_api_retval %s" %
162 self._expect_api_retval)
163 self.hook.after_api(api_fn.__name__, api_args)
167 """ Execute a CLI, calling the before/after hooks appropriately.
169 :param cli: CLI to execute
173 self.hook.before_cli(cli)
175 r = self.papi.cli_inband(length=len(cli), cmd=cli)
176 self.hook.after_cli(cli)
177 if hasattr(r, 'reply'):
178 return r.reply.decode().rstrip('\x00')
180 def ppcli(self, cli):
181 """ Helper method to print CLI command in case of info logging level.
183 :param cli: CLI to execute
186 return cli + "\n" + str(self.cli(cli))
188 def _convert_mac(self, mac):
189 return int(mac.replace(":", ""), 16) << 16
191 def show_version(self):
193 return self.api(self.papi.show_version, {})
195 def pg_create_interface(self, pg_index):
201 return self.api(self.papi.pg_create_interface,
202 {"interface_id": pg_index})
204 def sw_interface_dump(self, filter=None):
207 :param filter: (Default value = None)
210 if filter is not None:
211 args = {"name_filter_valid": 1, "name_filter": filter}
214 return self.api(self.papi.sw_interface_dump, args)
216 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
217 """ Set the IPvX Table-id for the Interface
224 return self.api(self.papi.sw_interface_set_table,
225 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
228 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
229 is_ipv6=0, is_add=1, del_all=0):
232 :param addr: param is_ipv6: (Default value = 0)
235 :param is_ipv6: (Default value = 0)
236 :param is_add: (Default value = 1)
237 :param del_all: (Default value = 0)
240 return self.api(self.papi.sw_interface_add_del_address,
241 {'sw_if_index': sw_if_index,
245 'address_length': addr_len,
248 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
250 """ Set the Interface to be unnumbered
252 :param is_add: (Default value = 1)
253 :param sw_if_index - interface That will be unnumbered
254 :param ip_sw_if_index - interface with an IP addres
257 return self.api(self.papi.sw_interface_set_unnumbered,
258 {'sw_if_index': ip_sw_if_index,
259 'unnumbered_sw_if_index': sw_if_index,
262 def sw_interface_enable_disable_mpls(self, sw_if_index,
265 Enable/Disable MPLS on the interface
267 :param is_enable: (Default value = 1)
270 return self.api(self.papi.sw_interface_set_mpls_enable,
271 {'sw_if_index': sw_if_index,
272 'enable': is_enable})
274 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
275 return self.api(self.papi.sw_interface_ip6nd_ra_config,
276 {'sw_if_index': sw_if_index,
277 'suppress': suppress})
279 def ip6_sw_interface_ra_config(self, sw_if_index,
283 return self.api(self.papi.sw_interface_ip6nd_ra_config,
284 {'sw_if_index': sw_if_index,
286 'suppress': suppress,
287 'send_unicast': send_unicast})
289 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
291 Enable/Disable An interface for IPv6
293 return self.api(self.papi.sw_interface_ip6_enable_disable,
294 {'sw_if_index': sw_if_index,
297 def vxlan_add_del_tunnel(
301 mcast_sw_if_index=0xFFFFFFFF,
305 decap_next_index=0xFFFFFFFF,
311 :param is_add: (Default value = 1)
312 :param is_ipv6: (Default value = 0)
313 :param encap_vrf_id: (Default value = 0)
314 :param decap_next_index: (Default value = 0xFFFFFFFF)
315 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
316 :param vni: (Default value = 0)
319 return self.api(self.papi.vxlan_add_del_tunnel,
322 'src_address': src_addr,
323 'dst_address': dst_addr,
324 'mcast_sw_if_index': mcast_sw_if_index,
325 'encap_vrf_id': encap_vrf_id,
326 'decap_next_index': decap_next_index,
329 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
330 learn=1, arp_term=0, is_add=1):
331 """Create/delete bridge domain.
333 :param int bd_id: Bridge domain index.
334 :param int flood: Enable/disable bcast/mcast flooding in the BD.
336 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
338 :param int forward: Enable/disable forwarding on all interfaces in
339 the BD. (Default value = 1)
340 :param int learn: Enable/disable learning on all interfaces in the BD.
342 :param int arp_term: Enable/disable arp termination in the BD.
344 :param int is_add: Add or delete flag. (Default value = 1)
346 return self.api(self.papi.bridge_domain_add_del,
349 'uu_flood': uu_flood,
352 'arp_term': arp_term,
355 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
356 filter_mac=0, bvi_mac=0):
357 """Create/delete L2 FIB entry.
359 :param str mac: MAC address to create FIB entry for.
360 :param int bd_id: Bridge domain index.
361 :param int sw_if_index: Software interface index of the interface.
362 :param int is_add: Add or delete flag. (Default value = 1)
363 :param int static_mac: Set to 1 to create static MAC entry.
365 :param int filter_mac: Set to 1 to drop packet that's source or
366 destination MAC address contains defined MAC address.
368 :param int bvi_mac: Set to 1 to create entry that points to BVI
369 interface. (Default value = 0)
371 return self.api(self.papi.l2fib_add_del,
372 {'mac': self._convert_mac(mac),
374 'sw_if_index': sw_if_index,
376 'static_mac': static_mac,
377 'filter_mac': filter_mac,
380 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
381 shg=0, bvi=0, enable=1):
382 """Add/remove interface to/from bridge domain.
384 :param int sw_if_index: Software interface index of the interface.
385 :param int bd_id: Bridge domain index.
386 :param int shg: Split-horizon group index. (Default value = 0)
387 :param int bvi: Set interface as a bridge group virtual interface.
389 :param int enable: Add or remove interface. (Default value = 1)
391 return self.api(self.papi.sw_interface_set_l2_bridge,
392 {'rx_sw_if_index': sw_if_index,
398 def bridge_flags(self, bd_id, is_set, feature_bitmap):
399 """Enable/disable required feature of the bridge domain with defined ID.
401 :param int bd_id: Bridge domain ID.
402 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
403 :param int feature_bitmap: Bitmap value of the feature to be set:
407 - uu-flood (1 << 3) or
410 return self.api(self.papi.bridge_flags,
413 'feature_bitmap': feature_bitmap})
415 def bridge_domain_dump(self, bd_id=0):
418 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
419 existing bridge domains returned)
420 :return: Dictionary of bridge domain(s) data.
422 return self.api(self.papi.bridge_domain_dump,
425 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
427 """Create or delete unidirectional cross-connect from Tx interface to
430 :param int rx_sw_if_index: Software interface index of Rx interface.
431 :param int tx_sw_if_index: Software interface index of Tx interface.
432 :param int enable: Create cross-connect if equal to 1, delete
433 cross-connect if equal to 0.
436 return self.api(self.papi.sw_interface_set_l2_xconnect,
437 {'rx_sw_if_index': rx_sw_if_index,
438 'tx_sw_if_index': tx_sw_if_index,
441 def sw_interface_set_l2_tag_rewrite(
448 """L2 interface vlan tag rewrite configure request
449 :param client_index - opaque cookie to identify the sender
450 :param context - sender context, to match reply w/ request
451 :param sw_if_index - interface the operation is applied to
452 :param vtr_op - Choose from l2_vtr_op_t enum values
453 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
454 :param tag1 - Needed for any push or translate vtr op
455 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
458 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
459 {'sw_if_index': sw_if_index,
465 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
466 link_up_down=0, deleted=0):
469 :param admin_up_down:
471 :param link_up_down: (Default value = 0)
472 :param deleted: (Default value = 0)
475 return self.api(self.papi.sw_interface_set_flags,
476 {'sw_if_index': sw_if_index,
477 'admin_up_down': admin_up_down,
478 'link_up_down': link_up_down,
481 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
482 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
483 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
484 """Create subinterface
485 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
487 :param sub_id: param inner_vlan:
491 :param no_tags: (Default value = 0)
492 :param one_tag: (Default value = 0)
493 :param two_tags: (Default value = 0)
494 :param dot1ad: (Default value = 0)
495 :param exact_match: (Default value = 0)
496 :param default_sub: (Default value = 0)
497 :param outer_vlan_id_any: (Default value = 0)
498 :param inner_vlan_id_any: (Default value = 0)
502 self.papi.create_subif,
503 {'sw_if_index': sw_if_index,
507 'two_tags': two_tags,
509 'exact_match': exact_match,
510 'default_sub': default_sub,
511 'outer_vlan_id_any': outer_vlan_id_any,
512 'inner_vlan_id_any': inner_vlan_id_any,
513 'outer_vlan_id': outer_vlan,
514 'inner_vlan_id': inner_vlan})
516 def delete_subif(self, sw_if_index):
517 """Delete subinterface
521 return self.api(self.papi.delete_subif,
522 {'sw_if_index': sw_if_index})
524 def create_vlan_subif(self, sw_if_index, vlan):
531 return self.api(self.papi.create_vlan_subif,
532 {'sw_if_index': sw_if_index,
535 def create_loopback(self, mac=''):
538 :param mac: (Optional)
540 return self.api(self.papi.create_loopback,
541 {'mac_address': mac})
543 def delete_loopback(self, sw_if_index):
544 return self.api(self.papi.delete_loopback,
545 {'sw_if_index': sw_if_index, })
547 def ip_add_del_route(
552 next_hop_sw_if_index=0xFFFFFFFF,
556 next_hop_n_out_labels=0,
557 next_hop_out_label_stack=[],
558 next_hop_via_label=MPLS_LABEL_INVALID,
559 create_vrf_if_needed=0,
561 is_resolve_attached=0,
562 classify_table_index=0xFFFFFFFF,
574 :param dst_address_length:
575 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
577 :param next_hop_address:
578 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
579 :param vrf_id: (Default value = 0)
580 :param lookup_in_vrf: (Default value = 0)
581 :param classify_table_index: (Default value = 0xFFFFFFFF)
582 :param create_vrf_if_needed: (Default value = 0)
583 :param is_add: (Default value = 1)
584 :param is_drop: (Default value = 0)
585 :param is_ipv6: (Default value = 0)
586 :param is_local: (Default value = 0)
587 :param is_classify: (Default value = 0)
588 :param is_multipath: (Default value = 0)
589 :param is_resolve_host: (Default value = 0)
590 :param is_resolve_attached: (Default value = 0)
591 :param not_last: (Default value = 0)
592 :param next_hop_weight: (Default value = 1)
597 self.papi.ip_add_del_route,
598 {'next_hop_sw_if_index': next_hop_sw_if_index,
599 'table_id': table_id,
600 'classify_table_index': classify_table_index,
601 'next_hop_table_id': next_hop_table_id,
602 'create_vrf_if_needed': create_vrf_if_needed,
605 'is_unreach': is_unreach,
606 'is_prohibit': is_prohibit,
608 'is_local': is_local,
609 'is_classify': is_classify,
610 'is_multipath': is_multipath,
611 'is_resolve_host': is_resolve_host,
612 'is_resolve_attached': is_resolve_attached,
613 'not_last': not_last,
614 'next_hop_weight': next_hop_weight,
615 'dst_address_length': dst_address_length,
616 'dst_address': dst_address,
617 'next_hop_address': next_hop_address,
618 'next_hop_n_out_labels': next_hop_n_out_labels,
619 'next_hop_via_label': next_hop_via_label,
620 'next_hop_out_label_stack': next_hop_out_label_stack})
622 def ip_fib_dump(self):
623 return self.api(self.papi.ip_fib_dump, {})
625 def ip6_fib_dump(self):
626 return self.api(self.papi.ip6_fib_dump, {})
628 def ip_neighbor_add_del(self,
636 """ Add neighbor MAC to IPv4 or IPv6 address.
641 :param is_add: (Default value = 1)
642 :param is_ipv6: (Default value = 0)
643 :param is_static: (Default value = 0)
647 self.papi.ip_neighbor_add_del,
648 {'sw_if_index': sw_if_index,
651 'is_static': is_static,
652 'mac_address': mac_address,
653 'dst_address': dst_address
657 def ip_neighbor_dump(self,
660 """ Return IP neighbor dump.
663 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
667 self.papi.ip_neighbor_dump,
669 'sw_if_index': sw_if_index
673 def proxy_arp_add_del(self,
678 """ Config Proxy Arp Range.
680 :param low_address: Start address in the rnage to Proxy for
681 :param hi_address: End address in the rnage to Proxy for
682 :param vrf_id: The VRF/table in which to proxy
686 self.papi.proxy_arp_add_del,
689 'low_address': low_address,
690 'hi_address': hi_address,
694 def proxy_arp_intfc_enable_disable(self,
697 """ Enable/Disable an interface for proxy ARP requests
699 :param sw_if_index: Interface
700 :param enable_disable: Enable/Disable
704 self.papi.proxy_arp_intfc_enable_disable,
705 {'sw_if_index': sw_if_index,
706 'enable_disable': is_enable
714 """ Reset VRF (remove all routes etc.) request.
716 :param int vrf_id: ID of the FIB table / VRF to reset.
717 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
731 """ Reset VRF (remove all routes etc.) request.
733 :param int vrf_id: ID of the FIB table / VRF to reset.
734 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
749 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
758 def sw_interface_span_enable_disable(
759 self, sw_if_index_from, sw_if_index_to, state=1):
762 :param sw_if_index_from:
763 :param sw_if_index_to:
766 return self.api(self.papi.sw_interface_span_enable_disable,
767 {'sw_if_index_from': sw_if_index_from,
768 'sw_if_index_to': sw_if_index_to,
771 def gre_tunnel_add_del(self,
782 :param outer_fib_id: (Default value = 0)
783 :param is_add: (Default value = 1)
784 :param is_ipv6: (Default value = 0)
785 :param is_teb: (Default value = 0)
789 self.papi.gre_add_del_tunnel,
793 'src_address': src_address,
794 'dst_address': dst_address,
795 'outer_fib_id': outer_fib_id}
798 def mpls_fib_dump(self):
799 return self.api(self.papi.mpls_fib_dump, {})
801 def mpls_route_add_del(
805 next_hop_proto_is_ip4,
807 next_hop_sw_if_index=0xFFFFFFFF,
811 next_hop_n_out_labels=0,
812 next_hop_out_label_stack=[],
813 next_hop_via_label=MPLS_LABEL_INVALID,
814 create_vrf_if_needed=0,
816 is_resolve_attached=0,
820 classify_table_index=0xFFFFFFFF,
825 :param dst_address_length:
826 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
828 :param next_hop_address:
829 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
830 :param vrf_id: (Default value = 0)
831 :param lookup_in_vrf: (Default value = 0)
832 :param classify_table_index: (Default value = 0xFFFFFFFF)
833 :param create_vrf_if_needed: (Default value = 0)
834 :param is_add: (Default value = 1)
835 :param is_drop: (Default value = 0)
836 :param is_ipv6: (Default value = 0)
837 :param is_local: (Default value = 0)
838 :param is_classify: (Default value = 0)
839 :param is_multipath: (Default value = 0)
840 :param is_resolve_host: (Default value = 0)
841 :param is_resolve_attached: (Default value = 0)
842 :param not_last: (Default value = 0)
843 :param next_hop_weight: (Default value = 1)
848 self.papi.mpls_route_add_del,
851 'mr_table_id': table_id,
852 'mr_classify_table_index': classify_table_index,
853 'mr_create_table_if_needed': create_vrf_if_needed,
855 'mr_is_classify': is_classify,
856 'mr_is_multipath': is_multipath,
857 'mr_is_resolve_host': is_resolve_host,
858 'mr_is_resolve_attached': is_resolve_attached,
859 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
860 'mr_next_hop_weight': next_hop_weight,
861 'mr_next_hop': next_hop_address,
862 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
863 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
864 'mr_next_hop_table_id': next_hop_table_id,
865 'mr_next_hop_via_label': next_hop_via_label,
866 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
868 def mpls_ip_bind_unbind(
876 create_vrf_if_needed=0,
881 self.papi.mpls_ip_bind_unbind,
882 {'mb_mpls_table_id': table_id,
884 'mb_ip_table_id': ip_table_id,
885 'mb_create_table_if_needed': create_vrf_if_needed,
886 'mb_is_bind': is_bind,
888 'mb_address_length': dst_address_length,
889 'mb_address': dst_address})
891 def mpls_tunnel_add_del(
894 next_hop_proto_is_ip4,
896 next_hop_sw_if_index=0xFFFFFFFF,
899 next_hop_n_out_labels=0,
900 next_hop_out_label_stack=[],
901 next_hop_via_label=MPLS_LABEL_INVALID,
902 create_vrf_if_needed=0,
907 :param dst_address_length:
908 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
910 :param next_hop_address:
911 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
912 :param vrf_id: (Default value = 0)
913 :param lookup_in_vrf: (Default value = 0)
914 :param classify_table_index: (Default value = 0xFFFFFFFF)
915 :param create_vrf_if_needed: (Default value = 0)
916 :param is_add: (Default value = 1)
917 :param is_drop: (Default value = 0)
918 :param is_ipv6: (Default value = 0)
919 :param is_local: (Default value = 0)
920 :param is_classify: (Default value = 0)
921 :param is_multipath: (Default value = 0)
922 :param is_resolve_host: (Default value = 0)
923 :param is_resolve_attached: (Default value = 0)
924 :param not_last: (Default value = 0)
925 :param next_hop_weight: (Default value = 1)
929 self.papi.mpls_tunnel_add_del,
930 {'mt_sw_if_index': tun_sw_if_index,
932 'mt_l2_only': l2_only,
933 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
934 'mt_next_hop_weight': next_hop_weight,
935 'mt_next_hop': next_hop_address,
936 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
937 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
938 'mt_next_hop_table_id': next_hop_table_id,
939 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
941 def snat_interface_add_del_feature(
946 """Enable/disable S-NAT feature on the interface
948 :param sw_if_index: Software index of the interface
949 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
950 :param is_add: 1 if add, 0 if delete (Default value = 1)
953 self.papi.snat_interface_add_del_feature,
955 'is_inside': is_inside,
956 'sw_if_index': sw_if_index})
958 def snat_add_static_mapping(
962 external_sw_if_index=0xFFFFFFFF,
970 """Add/delete S-NAT static mapping
972 :param local_ip: Local IP address
973 :param external_ip: External IP address
974 :param external_sw_if_index: External interface instead of IP address
975 :param local_port: Local port number (Default value = 0)
976 :param external_port: External port number (Default value = 0)
977 :param addr_only: 1 if address only mapping, 0 if address and port
978 :param vrf_id: VRF ID
979 :param protocol: IP protocol (Default value = 0)
980 :param is_add: 1 if add, 0 if delete (Default value = 1)
981 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
984 self.papi.snat_add_static_mapping,
987 'addr_only': addr_only,
988 'local_ip_address': local_ip,
989 'external_ip_address': external_ip,
990 'local_port': local_port,
991 'external_port': external_port,
992 'external_sw_if_index': external_sw_if_index,
994 'protocol': protocol})
996 def snat_add_address_range(
1002 """Add/del S-NAT address range
1004 :param first_ip_address: First IP address
1005 :param last_ip_address: Last IP address
1006 :param is_add: 1 if add, 0 if delete (Default value = 1)
1007 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1010 self.papi.snat_add_address_range,
1012 'first_ip_address': first_ip_address,
1013 'last_ip_address': last_ip_address,
1016 def snat_address_dump(self):
1017 """Dump S-NAT addresses
1018 :return: Dictionary of S-NAT addresses
1020 return self.api(self.papi.snat_address_dump, {})
1022 def snat_interface_dump(self):
1023 """Dump interfaces with S-NAT feature
1024 :return: Dictionary of interfaces with S-NAT feature
1026 return self.api(self.papi.snat_interface_dump, {})
1028 def snat_static_mapping_dump(self):
1029 """Dump S-NAT static mappings
1030 :return: Dictionary of S-NAT static mappings
1032 return self.api(self.papi.snat_static_mapping_dump, {})
1034 def snat_show_config(self):
1035 """Show S-NAT config
1036 :return: S-NAT config parameters
1038 return self.api(self.papi.snat_show_config, {})
1040 def snat_add_interface_addr(
1044 """Add/del S-NAT address from interface
1046 :param sw_if_index: Software index of the interface
1047 :param is_add: 1 if add, 0 if delete (Default value = 1)
1049 return self.api(self.papi.snat_add_del_interface_addr,
1050 {'is_add': is_add, 'sw_if_index': sw_if_index})
1052 def snat_interface_addr_dump(self):
1053 """Dump S-NAT addresses interfaces
1054 :return: Dictionary of S-NAT addresses interfaces
1056 return self.api(self.papi.snat_interface_addr_dump, {})
1063 """Enable/disable S-NAT IPFIX logging
1065 :param domain_id: Observation domain ID (Default value = 1)
1066 :param src_port: Source port number (Default value = 4739)
1067 :param enable: 1 if enable, 0 if disable (Default value = 1)
1070 self.papi.snat_ipfix_enable_disable,
1071 {'domain_id': domain_id,
1072 'src_port': src_port,
1075 def snat_user_session_dump(
1079 """Dump S-NAT user's sessions
1081 :param ip_address: ip adress of the user to be dumped
1082 :param cpu_index: cpu_index on which the user is
1083 :param vrf_id: VRF ID
1084 :return: Dictionary of S-NAT sessions
1087 self.papi.snat_user_session_dump,
1088 {'ip_address': ip_address,
1091 def snat_user_dump(self):
1094 :return: Dictionary of S-NAT users
1096 return self.api(self.papi.snat_user_dump, {})
1098 def control_ping(self):
1099 self.api(self.papi.control_ping)
1101 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
1102 detect_mult, local_addr, peer_addr, is_ipv6=0,
1103 bfd_key_id=None, conf_key_id=None):
1104 if bfd_key_id is None:
1105 return self.api(self.papi.bfd_udp_add,
1107 'sw_if_index': sw_if_index,
1108 'desired_min_tx': desired_min_tx,
1109 'required_min_rx': required_min_rx,
1110 'local_addr': local_addr,
1111 'peer_addr': peer_addr,
1113 'detect_mult': detect_mult,
1116 return self.api(self.papi.bfd_udp_add,
1118 'sw_if_index': sw_if_index,
1119 'desired_min_tx': desired_min_tx,
1120 'required_min_rx': required_min_rx,
1121 'local_addr': local_addr,
1122 'peer_addr': peer_addr,
1124 'detect_mult': detect_mult,
1125 'is_authenticated': 1,
1126 'bfd_key_id': bfd_key_id,
1127 'conf_key_id': conf_key_id,
1130 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1131 detect_mult, local_addr, peer_addr, is_ipv6=0):
1132 return self.api(self.papi.bfd_udp_mod,
1134 'sw_if_index': sw_if_index,
1135 'desired_min_tx': desired_min_tx,
1136 'required_min_rx': required_min_rx,
1137 'local_addr': local_addr,
1138 'peer_addr': peer_addr,
1140 'detect_mult': detect_mult,
1143 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1144 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1146 return self.api(self.papi.bfd_udp_auth_activate,
1148 'sw_if_index': sw_if_index,
1149 'local_addr': local_addr,
1150 'peer_addr': peer_addr,
1152 'is_delayed': 1 if is_delayed else 0,
1153 'bfd_key_id': bfd_key_id,
1154 'conf_key_id': conf_key_id,
1157 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1158 is_ipv6=0, is_delayed=False):
1159 return self.api(self.papi.bfd_udp_auth_deactivate,
1161 'sw_if_index': sw_if_index,
1162 'local_addr': local_addr,
1163 'peer_addr': peer_addr,
1165 'is_delayed': 1 if is_delayed else 0,
1168 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1169 return self.api(self.papi.bfd_udp_del,
1171 'sw_if_index': sw_if_index,
1172 'local_addr': local_addr,
1173 'peer_addr': peer_addr,
1177 def bfd_udp_session_dump(self):
1178 return self.api(self.papi.bfd_udp_session_dump, {})
1180 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1181 peer_addr, is_ipv6=0):
1182 return self.api(self.papi.bfd_udp_session_set_flags, {
1183 'admin_up_down': admin_up_down,
1184 'sw_if_index': sw_if_index,
1185 'local_addr': local_addr,
1186 'peer_addr': peer_addr,
1190 def want_bfd_events(self, enable_disable=1):
1191 return self.api(self.papi.want_bfd_events, {
1192 'enable_disable': enable_disable,
1196 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1197 return self.api(self.papi.bfd_auth_set_key, {
1198 'conf_key_id': conf_key_id,
1199 'auth_type': auth_type,
1201 'key_len': len(key),
1204 def bfd_auth_del_key(self, conf_key_id):
1205 return self.api(self.papi.bfd_auth_del_key, {
1206 'conf_key_id': conf_key_id,
1209 def bfd_auth_keys_dump(self):
1210 return self.api(self.papi.bfd_auth_keys_dump, {})
1212 def bfd_udp_set_echo_source(self, sw_if_index):
1213 return self.api(self.papi.bfd_udp_set_echo_source,
1214 {'sw_if_index': sw_if_index})
1216 def bfd_udp_del_echo_source(self):
1217 return self.api(self.papi.bfd_udp_del_echo_source, {})
1219 def classify_add_del_table(
1224 table_index=0xFFFFFFFF,
1226 memory_size=2097152,
1228 next_table_index=0xFFFFFFFF,
1229 miss_next_index=0xFFFFFFFF,
1230 current_data_flag=0,
1231 current_data_offset=0):
1235 :param match_n_vectors: (Default value = 1)
1236 :param table_index: (Default value = 0xFFFFFFFF)
1237 :param nbuckets: (Default value = 2)
1238 :param memory_size: (Default value = 2097152)
1239 :param skip_n_vectors: (Default value = 0)
1240 :param next_table_index: (Default value = 0xFFFFFFFF)
1241 :param miss_next_index: (Default value = 0xFFFFFFFF)
1242 :param current_data_flag: (Default value = 0)
1243 :param current_data_offset: (Default value = 0)
1247 self.papi.classify_add_del_table,
1249 'table_index': table_index,
1250 'nbuckets': nbuckets,
1251 'memory_size': memory_size,
1252 'skip_n_vectors': skip_n_vectors,
1253 'match_n_vectors': match_n_vectors,
1254 'next_table_index': next_table_index,
1255 'miss_next_index': miss_next_index,
1256 'current_data_flag': current_data_flag,
1257 'current_data_offset': current_data_offset,
1260 def classify_add_del_session(
1265 opaque_index=0xFFFFFFFF,
1266 hit_next_index=0xFFFFFFFF,
1274 :param opaque_index: (Default value = 0xFFFFFFFF)
1275 :param hit_next_index: (Default value = 0xFFFFFFFF)
1276 :param advance: (Default value = 0)
1277 :param action: (Default value = 0)
1278 :param metadata: (Default value = 0)
1282 self.papi.classify_add_del_session,
1284 'table_index': table_index,
1285 'hit_next_index': hit_next_index,
1286 'opaque_index': opaque_index,
1289 'metadata': metadata,
1292 def input_acl_set_interface(
1296 ip4_table_index=0xFFFFFFFF,
1297 ip6_table_index=0xFFFFFFFF,
1298 l2_table_index=0xFFFFFFFF):
1302 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1303 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1304 :param l2_table_index: (Default value = 0xFFFFFFFF)
1308 self.papi.input_acl_set_interface,
1309 {'sw_if_index': sw_if_index,
1310 'ip4_table_index': ip4_table_index,
1311 'ip6_table_index': ip6_table_index,
1312 'l2_table_index': l2_table_index,
1315 def set_ipfix_exporter(
1322 collector_port=4739,
1325 self.papi.set_ipfix_exporter,
1327 'collector_address': collector_address,
1328 'collector_port': collector_port,
1329 'src_address': src_address,
1331 'path_mtu': path_mtu,
1332 'template_interval': template_interval,
1333 'udp_checksum': udp_checksum,
1336 def dhcp_proxy_config(self,
1344 self.papi.dhcp_proxy_config,
1346 'rx_vrf_id': rx_table_id,
1347 'server_vrf_id': server_table_id,
1350 'dhcp_server': dhcp_server,
1351 'dhcp_src_address': dhcp_src_address,
1354 def dhcp_proxy_set_vss(self,
1361 self.papi.dhcp_proxy_set_vss,
1370 def ip_mroute_add_del(self,
1375 next_hop_sw_if_index,
1378 create_vrf_if_needed=0,
1385 self.papi.ip_mroute_add_del,
1386 {'next_hop_sw_if_index': next_hop_sw_if_index,
1387 'entry_flags': e_flags,
1388 'itf_flags': i_flags,
1389 'create_vrf_if_needed': create_vrf_if_needed,
1392 'is_local': is_local,
1393 'grp_address_length': grp_address_length,
1394 'grp_address': grp_address,
1395 'src_address': src_address})
1397 def mfib_signal_dump(self):
1398 return self.api(self.papi.mfib_signal_dump, {})
1400 def ip_mfib_dump(self):
1401 return self.api(self.papi.ip_mfib_dump, {})
1403 def lisp_enable_disable(self, is_enabled):
1405 self.papi.lisp_enable_disable,
1407 'is_en': is_enabled,
1410 def lisp_locator_set(self,
1414 self.papi.lisp_add_del_locator_set,
1417 'locator_set_name': ls_name
1420 def lisp_locator_set_dump(self):
1421 return self.api(self.papi.lisp_locator_set_dump, {})
1423 def lisp_locator(self,
1430 self.papi.lisp_add_del_locator,
1433 'locator_set_name': ls_name,
1434 'sw_if_index': sw_if_index,
1435 'priority': priority,
1439 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1441 self.papi.lisp_locator_dump,
1443 'is_index_set': is_index_set,
1445 'ls_index': ls_index,
1448 def lisp_local_mapping(self,
1458 self.papi.lisp_add_del_local_eid,
1460 'locator_set_name': ls_name,
1462 'eid_type': eid_type,
1464 'prefix_len': prefix_len,
1470 def lisp_eid_table_dump(self,
1478 self.papi.lisp_eid_table_dump,
1481 'prefix_length': prefix_length,
1483 'eid_type': eid_type,
1485 'filter': filter_opt,
1488 def lisp_remote_mapping(self,
1498 self.papi.lisp_add_del_remote_mapping,
1501 'eid_type': eid_type,
1503 'eid_len': eid_prefix_len,
1504 'rloc_num': rlocs_num,
1507 'is_src_dst': is_src_dst,
1510 def lisp_adjacency(self,
1519 self.papi.lisp_add_del_adjacency,
1523 'eid_type': eid_type,
1526 'leid_len': leid_len,
1527 'reid_len': reid_len,
1530 def lisp_adjacencies_get(self, vni=0):
1532 self.papi.lisp_adjacencies_get,