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_ra_prefix(self,
299 val_lifetime=0xffffffff,
300 pref_lifetime=0xffffffff):
301 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
302 {'sw_if_index': sw_if_index,
304 'address_length': address_length,
305 'use_default': use_default,
306 'no_advertise': no_advertise,
307 'off_link': off_link,
308 'no_autoconfig': no_autoconfig,
309 'no_onlink': no_onlink,
311 'val_lifetime': val_lifetime,
312 'pref_lifetime': pref_lifetime})
314 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
316 Enable/Disable An interface for IPv6
318 return self.api(self.papi.sw_interface_ip6_enable_disable,
319 {'sw_if_index': sw_if_index,
322 def vxlan_add_del_tunnel(
326 mcast_sw_if_index=0xFFFFFFFF,
330 decap_next_index=0xFFFFFFFF,
336 :param is_add: (Default value = 1)
337 :param is_ipv6: (Default value = 0)
338 :param encap_vrf_id: (Default value = 0)
339 :param decap_next_index: (Default value = 0xFFFFFFFF)
340 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
341 :param vni: (Default value = 0)
344 return self.api(self.papi.vxlan_add_del_tunnel,
347 'src_address': src_addr,
348 'dst_address': dst_addr,
349 'mcast_sw_if_index': mcast_sw_if_index,
350 'encap_vrf_id': encap_vrf_id,
351 'decap_next_index': decap_next_index,
354 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
355 learn=1, arp_term=0, is_add=1):
356 """Create/delete bridge domain.
358 :param int bd_id: Bridge domain index.
359 :param int flood: Enable/disable bcast/mcast flooding in the BD.
361 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
363 :param int forward: Enable/disable forwarding on all interfaces in
364 the BD. (Default value = 1)
365 :param int learn: Enable/disable learning on all interfaces in the BD.
367 :param int arp_term: Enable/disable arp termination in the BD.
369 :param int is_add: Add or delete flag. (Default value = 1)
371 return self.api(self.papi.bridge_domain_add_del,
374 'uu_flood': uu_flood,
377 'arp_term': arp_term,
380 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
381 filter_mac=0, bvi_mac=0):
382 """Create/delete L2 FIB entry.
384 :param str mac: MAC address to create FIB entry for.
385 :param int bd_id: Bridge domain index.
386 :param int sw_if_index: Software interface index of the interface.
387 :param int is_add: Add or delete flag. (Default value = 1)
388 :param int static_mac: Set to 1 to create static MAC entry.
390 :param int filter_mac: Set to 1 to drop packet that's source or
391 destination MAC address contains defined MAC address.
393 :param int bvi_mac: Set to 1 to create entry that points to BVI
394 interface. (Default value = 0)
396 return self.api(self.papi.l2fib_add_del,
397 {'mac': self._convert_mac(mac),
399 'sw_if_index': sw_if_index,
401 'static_mac': static_mac,
402 'filter_mac': filter_mac,
405 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
406 shg=0, bvi=0, enable=1):
407 """Add/remove interface to/from bridge domain.
409 :param int sw_if_index: Software interface index of the interface.
410 :param int bd_id: Bridge domain index.
411 :param int shg: Split-horizon group index. (Default value = 0)
412 :param int bvi: Set interface as a bridge group virtual interface.
414 :param int enable: Add or remove interface. (Default value = 1)
416 return self.api(self.papi.sw_interface_set_l2_bridge,
417 {'rx_sw_if_index': sw_if_index,
423 def bridge_flags(self, bd_id, is_set, feature_bitmap):
424 """Enable/disable required feature of the bridge domain with defined ID.
426 :param int bd_id: Bridge domain ID.
427 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
428 :param int feature_bitmap: Bitmap value of the feature to be set:
432 - uu-flood (1 << 3) or
435 return self.api(self.papi.bridge_flags,
438 'feature_bitmap': feature_bitmap})
440 def bridge_domain_dump(self, bd_id=0):
443 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
444 existing bridge domains returned)
445 :return: Dictionary of bridge domain(s) data.
447 return self.api(self.papi.bridge_domain_dump,
450 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
452 """Create or delete unidirectional cross-connect from Tx interface to
455 :param int rx_sw_if_index: Software interface index of Rx interface.
456 :param int tx_sw_if_index: Software interface index of Tx interface.
457 :param int enable: Create cross-connect if equal to 1, delete
458 cross-connect if equal to 0.
461 return self.api(self.papi.sw_interface_set_l2_xconnect,
462 {'rx_sw_if_index': rx_sw_if_index,
463 'tx_sw_if_index': tx_sw_if_index,
466 def sw_interface_set_l2_tag_rewrite(
473 """L2 interface vlan tag rewrite configure request
474 :param client_index - opaque cookie to identify the sender
475 :param context - sender context, to match reply w/ request
476 :param sw_if_index - interface the operation is applied to
477 :param vtr_op - Choose from l2_vtr_op_t enum values
478 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
479 :param tag1 - Needed for any push or translate vtr op
480 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
483 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
484 {'sw_if_index': sw_if_index,
490 def sw_interface_set_flags(self, sw_if_index, admin_up_down,
491 link_up_down=0, deleted=0):
494 :param admin_up_down:
496 :param link_up_down: (Default value = 0)
497 :param deleted: (Default value = 0)
500 return self.api(self.papi.sw_interface_set_flags,
501 {'sw_if_index': sw_if_index,
502 'admin_up_down': admin_up_down,
503 'link_up_down': link_up_down,
506 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
507 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
508 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
509 """Create subinterface
510 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
512 :param sub_id: param inner_vlan:
516 :param no_tags: (Default value = 0)
517 :param one_tag: (Default value = 0)
518 :param two_tags: (Default value = 0)
519 :param dot1ad: (Default value = 0)
520 :param exact_match: (Default value = 0)
521 :param default_sub: (Default value = 0)
522 :param outer_vlan_id_any: (Default value = 0)
523 :param inner_vlan_id_any: (Default value = 0)
527 self.papi.create_subif,
528 {'sw_if_index': sw_if_index,
532 'two_tags': two_tags,
534 'exact_match': exact_match,
535 'default_sub': default_sub,
536 'outer_vlan_id_any': outer_vlan_id_any,
537 'inner_vlan_id_any': inner_vlan_id_any,
538 'outer_vlan_id': outer_vlan,
539 'inner_vlan_id': inner_vlan})
541 def delete_subif(self, sw_if_index):
542 """Delete subinterface
546 return self.api(self.papi.delete_subif,
547 {'sw_if_index': sw_if_index})
549 def create_vlan_subif(self, sw_if_index, vlan):
556 return self.api(self.papi.create_vlan_subif,
557 {'sw_if_index': sw_if_index,
560 def create_loopback(self, mac=''):
563 :param mac: (Optional)
565 return self.api(self.papi.create_loopback,
566 {'mac_address': mac})
568 def delete_loopback(self, sw_if_index):
569 return self.api(self.papi.delete_loopback,
570 {'sw_if_index': sw_if_index, })
572 def ip_add_del_route(
577 next_hop_sw_if_index=0xFFFFFFFF,
581 next_hop_n_out_labels=0,
582 next_hop_out_label_stack=[],
583 next_hop_via_label=MPLS_LABEL_INVALID,
584 create_vrf_if_needed=0,
586 is_resolve_attached=0,
587 classify_table_index=0xFFFFFFFF,
599 :param dst_address_length:
600 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
602 :param next_hop_address:
603 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
604 :param vrf_id: (Default value = 0)
605 :param lookup_in_vrf: (Default value = 0)
606 :param classify_table_index: (Default value = 0xFFFFFFFF)
607 :param create_vrf_if_needed: (Default value = 0)
608 :param is_add: (Default value = 1)
609 :param is_drop: (Default value = 0)
610 :param is_ipv6: (Default value = 0)
611 :param is_local: (Default value = 0)
612 :param is_classify: (Default value = 0)
613 :param is_multipath: (Default value = 0)
614 :param is_resolve_host: (Default value = 0)
615 :param is_resolve_attached: (Default value = 0)
616 :param not_last: (Default value = 0)
617 :param next_hop_weight: (Default value = 1)
622 self.papi.ip_add_del_route,
623 {'next_hop_sw_if_index': next_hop_sw_if_index,
624 'table_id': table_id,
625 'classify_table_index': classify_table_index,
626 'next_hop_table_id': next_hop_table_id,
627 'create_vrf_if_needed': create_vrf_if_needed,
630 'is_unreach': is_unreach,
631 'is_prohibit': is_prohibit,
633 'is_local': is_local,
634 'is_classify': is_classify,
635 'is_multipath': is_multipath,
636 'is_resolve_host': is_resolve_host,
637 'is_resolve_attached': is_resolve_attached,
638 'not_last': not_last,
639 'next_hop_weight': next_hop_weight,
640 'dst_address_length': dst_address_length,
641 'dst_address': dst_address,
642 'next_hop_address': next_hop_address,
643 'next_hop_n_out_labels': next_hop_n_out_labels,
644 'next_hop_via_label': next_hop_via_label,
645 'next_hop_out_label_stack': next_hop_out_label_stack})
647 def ip_fib_dump(self):
648 return self.api(self.papi.ip_fib_dump, {})
650 def ip6_fib_dump(self):
651 return self.api(self.papi.ip6_fib_dump, {})
653 def ip_neighbor_add_del(self,
661 """ Add neighbor MAC to IPv4 or IPv6 address.
666 :param is_add: (Default value = 1)
667 :param is_ipv6: (Default value = 0)
668 :param is_static: (Default value = 0)
672 self.papi.ip_neighbor_add_del,
673 {'sw_if_index': sw_if_index,
676 'is_static': is_static,
677 'mac_address': mac_address,
678 'dst_address': dst_address
682 def ip_neighbor_dump(self,
685 """ Return IP neighbor dump.
688 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
692 self.papi.ip_neighbor_dump,
694 'sw_if_index': sw_if_index
698 def proxy_arp_add_del(self,
703 """ Config Proxy Arp Range.
705 :param low_address: Start address in the rnage to Proxy for
706 :param hi_address: End address in the rnage to Proxy for
707 :param vrf_id: The VRF/table in which to proxy
711 self.papi.proxy_arp_add_del,
714 'low_address': low_address,
715 'hi_address': hi_address,
719 def proxy_arp_intfc_enable_disable(self,
722 """ Enable/Disable an interface for proxy ARP requests
724 :param sw_if_index: Interface
725 :param enable_disable: Enable/Disable
729 self.papi.proxy_arp_intfc_enable_disable,
730 {'sw_if_index': sw_if_index,
731 'enable_disable': is_enable
739 """ Reset VRF (remove all routes etc.) request.
741 :param int vrf_id: ID of the FIB table / VRF to reset.
742 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
756 """ Reset VRF (remove all routes etc.) request.
758 :param int vrf_id: ID of the FIB table / VRF to reset.
759 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
774 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
783 def sw_interface_span_enable_disable(
784 self, sw_if_index_from, sw_if_index_to, state=1):
787 :param sw_if_index_from:
788 :param sw_if_index_to:
791 return self.api(self.papi.sw_interface_span_enable_disable,
792 {'sw_if_index_from': sw_if_index_from,
793 'sw_if_index_to': sw_if_index_to,
796 def gre_tunnel_add_del(self,
807 :param outer_fib_id: (Default value = 0)
808 :param is_add: (Default value = 1)
809 :param is_ipv6: (Default value = 0)
810 :param is_teb: (Default value = 0)
814 self.papi.gre_add_del_tunnel,
818 'src_address': src_address,
819 'dst_address': dst_address,
820 'outer_fib_id': outer_fib_id}
823 def mpls_fib_dump(self):
824 return self.api(self.papi.mpls_fib_dump, {})
826 def mpls_route_add_del(
830 next_hop_proto_is_ip4,
832 next_hop_sw_if_index=0xFFFFFFFF,
836 next_hop_n_out_labels=0,
837 next_hop_out_label_stack=[],
838 next_hop_via_label=MPLS_LABEL_INVALID,
839 create_vrf_if_needed=0,
841 is_resolve_attached=0,
845 classify_table_index=0xFFFFFFFF,
850 :param dst_address_length:
851 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
853 :param next_hop_address:
854 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
855 :param vrf_id: (Default value = 0)
856 :param lookup_in_vrf: (Default value = 0)
857 :param classify_table_index: (Default value = 0xFFFFFFFF)
858 :param create_vrf_if_needed: (Default value = 0)
859 :param is_add: (Default value = 1)
860 :param is_drop: (Default value = 0)
861 :param is_ipv6: (Default value = 0)
862 :param is_local: (Default value = 0)
863 :param is_classify: (Default value = 0)
864 :param is_multipath: (Default value = 0)
865 :param is_resolve_host: (Default value = 0)
866 :param is_resolve_attached: (Default value = 0)
867 :param not_last: (Default value = 0)
868 :param next_hop_weight: (Default value = 1)
873 self.papi.mpls_route_add_del,
876 'mr_table_id': table_id,
877 'mr_classify_table_index': classify_table_index,
878 'mr_create_table_if_needed': create_vrf_if_needed,
880 'mr_is_classify': is_classify,
881 'mr_is_multipath': is_multipath,
882 'mr_is_resolve_host': is_resolve_host,
883 'mr_is_resolve_attached': is_resolve_attached,
884 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
885 'mr_next_hop_weight': next_hop_weight,
886 'mr_next_hop': next_hop_address,
887 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
888 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
889 'mr_next_hop_table_id': next_hop_table_id,
890 'mr_next_hop_via_label': next_hop_via_label,
891 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
893 def mpls_ip_bind_unbind(
901 create_vrf_if_needed=0,
906 self.papi.mpls_ip_bind_unbind,
907 {'mb_mpls_table_id': table_id,
909 'mb_ip_table_id': ip_table_id,
910 'mb_create_table_if_needed': create_vrf_if_needed,
911 'mb_is_bind': is_bind,
913 'mb_address_length': dst_address_length,
914 'mb_address': dst_address})
916 def mpls_tunnel_add_del(
919 next_hop_proto_is_ip4,
921 next_hop_sw_if_index=0xFFFFFFFF,
924 next_hop_n_out_labels=0,
925 next_hop_out_label_stack=[],
926 next_hop_via_label=MPLS_LABEL_INVALID,
927 create_vrf_if_needed=0,
932 :param dst_address_length:
933 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
935 :param next_hop_address:
936 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
937 :param vrf_id: (Default value = 0)
938 :param lookup_in_vrf: (Default value = 0)
939 :param classify_table_index: (Default value = 0xFFFFFFFF)
940 :param create_vrf_if_needed: (Default value = 0)
941 :param is_add: (Default value = 1)
942 :param is_drop: (Default value = 0)
943 :param is_ipv6: (Default value = 0)
944 :param is_local: (Default value = 0)
945 :param is_classify: (Default value = 0)
946 :param is_multipath: (Default value = 0)
947 :param is_resolve_host: (Default value = 0)
948 :param is_resolve_attached: (Default value = 0)
949 :param not_last: (Default value = 0)
950 :param next_hop_weight: (Default value = 1)
954 self.papi.mpls_tunnel_add_del,
955 {'mt_sw_if_index': tun_sw_if_index,
957 'mt_l2_only': l2_only,
958 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
959 'mt_next_hop_weight': next_hop_weight,
960 'mt_next_hop': next_hop_address,
961 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
962 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
963 'mt_next_hop_table_id': next_hop_table_id,
964 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
966 def snat_interface_add_del_feature(
971 """Enable/disable S-NAT feature on the interface
973 :param sw_if_index: Software index of the interface
974 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
975 :param is_add: 1 if add, 0 if delete (Default value = 1)
978 self.papi.snat_interface_add_del_feature,
980 'is_inside': is_inside,
981 'sw_if_index': sw_if_index})
983 def snat_add_static_mapping(
987 external_sw_if_index=0xFFFFFFFF,
995 """Add/delete S-NAT static mapping
997 :param local_ip: Local IP address
998 :param external_ip: External IP address
999 :param external_sw_if_index: External interface instead of IP address
1000 :param local_port: Local port number (Default value = 0)
1001 :param external_port: External port number (Default value = 0)
1002 :param addr_only: 1 if address only mapping, 0 if address and port
1003 :param vrf_id: VRF ID
1004 :param protocol: IP protocol (Default value = 0)
1005 :param is_add: 1 if add, 0 if delete (Default value = 1)
1006 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1009 self.papi.snat_add_static_mapping,
1012 'addr_only': addr_only,
1013 'local_ip_address': local_ip,
1014 'external_ip_address': external_ip,
1015 'local_port': local_port,
1016 'external_port': external_port,
1017 'external_sw_if_index': external_sw_if_index,
1019 'protocol': protocol})
1021 def snat_add_address_range(
1027 """Add/del S-NAT address range
1029 :param first_ip_address: First IP address
1030 :param last_ip_address: Last IP address
1031 :param is_add: 1 if add, 0 if delete (Default value = 1)
1032 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1035 self.papi.snat_add_address_range,
1037 'first_ip_address': first_ip_address,
1038 'last_ip_address': last_ip_address,
1041 def snat_address_dump(self):
1042 """Dump S-NAT addresses
1043 :return: Dictionary of S-NAT addresses
1045 return self.api(self.papi.snat_address_dump, {})
1047 def snat_interface_dump(self):
1048 """Dump interfaces with S-NAT feature
1049 :return: Dictionary of interfaces with S-NAT feature
1051 return self.api(self.papi.snat_interface_dump, {})
1053 def snat_static_mapping_dump(self):
1054 """Dump S-NAT static mappings
1055 :return: Dictionary of S-NAT static mappings
1057 return self.api(self.papi.snat_static_mapping_dump, {})
1059 def snat_show_config(self):
1060 """Show S-NAT config
1061 :return: S-NAT config parameters
1063 return self.api(self.papi.snat_show_config, {})
1065 def snat_add_interface_addr(
1069 """Add/del S-NAT address from interface
1071 :param sw_if_index: Software index of the interface
1072 :param is_add: 1 if add, 0 if delete (Default value = 1)
1074 return self.api(self.papi.snat_add_del_interface_addr,
1075 {'is_add': is_add, 'sw_if_index': sw_if_index})
1077 def snat_interface_addr_dump(self):
1078 """Dump S-NAT addresses interfaces
1079 :return: Dictionary of S-NAT addresses interfaces
1081 return self.api(self.papi.snat_interface_addr_dump, {})
1088 """Enable/disable S-NAT IPFIX logging
1090 :param domain_id: Observation domain ID (Default value = 1)
1091 :param src_port: Source port number (Default value = 4739)
1092 :param enable: 1 if enable, 0 if disable (Default value = 1)
1095 self.papi.snat_ipfix_enable_disable,
1096 {'domain_id': domain_id,
1097 'src_port': src_port,
1100 def snat_user_session_dump(
1104 """Dump S-NAT user's sessions
1106 :param ip_address: ip adress of the user to be dumped
1107 :param cpu_index: cpu_index on which the user is
1108 :param vrf_id: VRF ID
1109 :return: Dictionary of S-NAT sessions
1112 self.papi.snat_user_session_dump,
1113 {'ip_address': ip_address,
1116 def snat_user_dump(self):
1119 :return: Dictionary of S-NAT users
1121 return self.api(self.papi.snat_user_dump, {})
1123 def control_ping(self):
1124 self.api(self.papi.control_ping)
1126 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
1127 detect_mult, local_addr, peer_addr, is_ipv6=0,
1128 bfd_key_id=None, conf_key_id=None):
1129 if bfd_key_id is None:
1130 return self.api(self.papi.bfd_udp_add,
1132 'sw_if_index': sw_if_index,
1133 'desired_min_tx': desired_min_tx,
1134 'required_min_rx': required_min_rx,
1135 'local_addr': local_addr,
1136 'peer_addr': peer_addr,
1138 'detect_mult': detect_mult,
1141 return self.api(self.papi.bfd_udp_add,
1143 'sw_if_index': sw_if_index,
1144 'desired_min_tx': desired_min_tx,
1145 'required_min_rx': required_min_rx,
1146 'local_addr': local_addr,
1147 'peer_addr': peer_addr,
1149 'detect_mult': detect_mult,
1150 'is_authenticated': 1,
1151 'bfd_key_id': bfd_key_id,
1152 'conf_key_id': conf_key_id,
1155 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1156 detect_mult, local_addr, peer_addr, is_ipv6=0):
1157 return self.api(self.papi.bfd_udp_mod,
1159 'sw_if_index': sw_if_index,
1160 'desired_min_tx': desired_min_tx,
1161 'required_min_rx': required_min_rx,
1162 'local_addr': local_addr,
1163 'peer_addr': peer_addr,
1165 'detect_mult': detect_mult,
1168 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1169 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1171 return self.api(self.papi.bfd_udp_auth_activate,
1173 'sw_if_index': sw_if_index,
1174 'local_addr': local_addr,
1175 'peer_addr': peer_addr,
1177 'is_delayed': 1 if is_delayed else 0,
1178 'bfd_key_id': bfd_key_id,
1179 'conf_key_id': conf_key_id,
1182 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1183 is_ipv6=0, is_delayed=False):
1184 return self.api(self.papi.bfd_udp_auth_deactivate,
1186 'sw_if_index': sw_if_index,
1187 'local_addr': local_addr,
1188 'peer_addr': peer_addr,
1190 'is_delayed': 1 if is_delayed else 0,
1193 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1194 return self.api(self.papi.bfd_udp_del,
1196 'sw_if_index': sw_if_index,
1197 'local_addr': local_addr,
1198 'peer_addr': peer_addr,
1202 def bfd_udp_session_dump(self):
1203 return self.api(self.papi.bfd_udp_session_dump, {})
1205 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1206 peer_addr, is_ipv6=0):
1207 return self.api(self.papi.bfd_udp_session_set_flags, {
1208 'admin_up_down': admin_up_down,
1209 'sw_if_index': sw_if_index,
1210 'local_addr': local_addr,
1211 'peer_addr': peer_addr,
1215 def want_bfd_events(self, enable_disable=1):
1216 return self.api(self.papi.want_bfd_events, {
1217 'enable_disable': enable_disable,
1221 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1222 return self.api(self.papi.bfd_auth_set_key, {
1223 'conf_key_id': conf_key_id,
1224 'auth_type': auth_type,
1226 'key_len': len(key),
1229 def bfd_auth_del_key(self, conf_key_id):
1230 return self.api(self.papi.bfd_auth_del_key, {
1231 'conf_key_id': conf_key_id,
1234 def bfd_auth_keys_dump(self):
1235 return self.api(self.papi.bfd_auth_keys_dump, {})
1237 def bfd_udp_set_echo_source(self, sw_if_index):
1238 return self.api(self.papi.bfd_udp_set_echo_source,
1239 {'sw_if_index': sw_if_index})
1241 def bfd_udp_del_echo_source(self):
1242 return self.api(self.papi.bfd_udp_del_echo_source, {})
1244 def classify_add_del_table(
1249 table_index=0xFFFFFFFF,
1251 memory_size=2097152,
1253 next_table_index=0xFFFFFFFF,
1254 miss_next_index=0xFFFFFFFF,
1255 current_data_flag=0,
1256 current_data_offset=0):
1260 :param match_n_vectors: (Default value = 1)
1261 :param table_index: (Default value = 0xFFFFFFFF)
1262 :param nbuckets: (Default value = 2)
1263 :param memory_size: (Default value = 2097152)
1264 :param skip_n_vectors: (Default value = 0)
1265 :param next_table_index: (Default value = 0xFFFFFFFF)
1266 :param miss_next_index: (Default value = 0xFFFFFFFF)
1267 :param current_data_flag: (Default value = 0)
1268 :param current_data_offset: (Default value = 0)
1272 self.papi.classify_add_del_table,
1274 'table_index': table_index,
1275 'nbuckets': nbuckets,
1276 'memory_size': memory_size,
1277 'skip_n_vectors': skip_n_vectors,
1278 'match_n_vectors': match_n_vectors,
1279 'next_table_index': next_table_index,
1280 'miss_next_index': miss_next_index,
1281 'current_data_flag': current_data_flag,
1282 'current_data_offset': current_data_offset,
1285 def classify_add_del_session(
1290 opaque_index=0xFFFFFFFF,
1291 hit_next_index=0xFFFFFFFF,
1299 :param opaque_index: (Default value = 0xFFFFFFFF)
1300 :param hit_next_index: (Default value = 0xFFFFFFFF)
1301 :param advance: (Default value = 0)
1302 :param action: (Default value = 0)
1303 :param metadata: (Default value = 0)
1307 self.papi.classify_add_del_session,
1309 'table_index': table_index,
1310 'hit_next_index': hit_next_index,
1311 'opaque_index': opaque_index,
1314 'metadata': metadata,
1317 def input_acl_set_interface(
1321 ip4_table_index=0xFFFFFFFF,
1322 ip6_table_index=0xFFFFFFFF,
1323 l2_table_index=0xFFFFFFFF):
1327 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1328 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1329 :param l2_table_index: (Default value = 0xFFFFFFFF)
1333 self.papi.input_acl_set_interface,
1334 {'sw_if_index': sw_if_index,
1335 'ip4_table_index': ip4_table_index,
1336 'ip6_table_index': ip6_table_index,
1337 'l2_table_index': l2_table_index,
1340 def set_ipfix_exporter(
1347 collector_port=4739,
1350 self.papi.set_ipfix_exporter,
1352 'collector_address': collector_address,
1353 'collector_port': collector_port,
1354 'src_address': src_address,
1356 'path_mtu': path_mtu,
1357 'template_interval': template_interval,
1358 'udp_checksum': udp_checksum,
1361 def dhcp_proxy_config(self,
1369 self.papi.dhcp_proxy_config,
1371 'rx_vrf_id': rx_table_id,
1372 'server_vrf_id': server_table_id,
1375 'dhcp_server': dhcp_server,
1376 'dhcp_src_address': dhcp_src_address,
1379 def dhcp_proxy_set_vss(self,
1386 self.papi.dhcp_proxy_set_vss,
1395 def ip_mroute_add_del(self,
1400 next_hop_sw_if_index,
1403 create_vrf_if_needed=0,
1410 self.papi.ip_mroute_add_del,
1411 {'next_hop_sw_if_index': next_hop_sw_if_index,
1412 'entry_flags': e_flags,
1413 'itf_flags': i_flags,
1414 'create_vrf_if_needed': create_vrf_if_needed,
1417 'is_local': is_local,
1418 'grp_address_length': grp_address_length,
1419 'grp_address': grp_address,
1420 'src_address': src_address})
1422 def mfib_signal_dump(self):
1423 return self.api(self.papi.mfib_signal_dump, {})
1425 def ip_mfib_dump(self):
1426 return self.api(self.papi.ip_mfib_dump, {})
1428 def lisp_enable_disable(self, is_enabled):
1430 self.papi.lisp_enable_disable,
1432 'is_en': is_enabled,
1435 def lisp_locator_set(self,
1439 self.papi.lisp_add_del_locator_set,
1442 'locator_set_name': ls_name
1445 def lisp_locator_set_dump(self):
1446 return self.api(self.papi.lisp_locator_set_dump, {})
1448 def lisp_locator(self,
1455 self.papi.lisp_add_del_locator,
1458 'locator_set_name': ls_name,
1459 'sw_if_index': sw_if_index,
1460 'priority': priority,
1464 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1466 self.papi.lisp_locator_dump,
1468 'is_index_set': is_index_set,
1470 'ls_index': ls_index,
1473 def lisp_local_mapping(self,
1483 self.papi.lisp_add_del_local_eid,
1485 'locator_set_name': ls_name,
1487 'eid_type': eid_type,
1489 'prefix_len': prefix_len,
1495 def lisp_eid_table_dump(self,
1503 self.papi.lisp_eid_table_dump,
1506 'prefix_length': prefix_length,
1508 'eid_type': eid_type,
1510 'filter': filter_opt,
1513 def lisp_remote_mapping(self,
1523 self.papi.lisp_add_del_remote_mapping,
1526 'eid_type': eid_type,
1528 'eid_len': eid_prefix_len,
1529 'rloc_num': rlocs_num,
1532 'is_src_dst': is_src_dst,
1535 def lisp_adjacency(self,
1544 self.papi.lisp_add_del_adjacency,
1548 'eid_type': eid_type,
1551 'leid_len': leid_len,
1552 'reid_len': reid_len,
1555 def lisp_adjacencies_get(self, vni=0):
1557 self.papi.lisp_adjacencies_get,