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(
1028 """Add/del S-NAT address range
1030 :param first_ip_address: First IP address
1031 :param last_ip_address: Last IP address
1032 :param vrf_id: VRF id for the address range
1033 :param is_add: 1 if add, 0 if delete (Default value = 1)
1034 :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1037 self.papi.snat_add_address_range,
1039 'first_ip_address': first_ip_address,
1040 'last_ip_address': last_ip_address,
1044 def snat_address_dump(self):
1045 """Dump S-NAT addresses
1046 :return: Dictionary of S-NAT addresses
1048 return self.api(self.papi.snat_address_dump, {})
1050 def snat_interface_dump(self):
1051 """Dump interfaces with S-NAT feature
1052 :return: Dictionary of interfaces with S-NAT feature
1054 return self.api(self.papi.snat_interface_dump, {})
1056 def snat_static_mapping_dump(self):
1057 """Dump S-NAT static mappings
1058 :return: Dictionary of S-NAT static mappings
1060 return self.api(self.papi.snat_static_mapping_dump, {})
1062 def snat_show_config(self):
1063 """Show S-NAT config
1064 :return: S-NAT config parameters
1066 return self.api(self.papi.snat_show_config, {})
1068 def snat_add_interface_addr(
1072 """Add/del S-NAT address from interface
1074 :param sw_if_index: Software index of the interface
1075 :param is_add: 1 if add, 0 if delete (Default value = 1)
1077 return self.api(self.papi.snat_add_del_interface_addr,
1078 {'is_add': is_add, 'sw_if_index': sw_if_index})
1080 def snat_interface_addr_dump(self):
1081 """Dump S-NAT addresses interfaces
1082 :return: Dictionary of S-NAT addresses interfaces
1084 return self.api(self.papi.snat_interface_addr_dump, {})
1091 """Enable/disable S-NAT IPFIX logging
1093 :param domain_id: Observation domain ID (Default value = 1)
1094 :param src_port: Source port number (Default value = 4739)
1095 :param enable: 1 if enable, 0 if disable (Default value = 1)
1098 self.papi.snat_ipfix_enable_disable,
1099 {'domain_id': domain_id,
1100 'src_port': src_port,
1103 def snat_user_session_dump(
1107 """Dump S-NAT user's sessions
1109 :param ip_address: ip adress of the user to be dumped
1110 :param cpu_index: cpu_index on which the user is
1111 :param vrf_id: VRF ID
1112 :return: Dictionary of S-NAT sessions
1115 self.papi.snat_user_session_dump,
1116 {'ip_address': ip_address,
1119 def snat_user_dump(self):
1122 :return: Dictionary of S-NAT users
1124 return self.api(self.papi.snat_user_dump, {})
1126 def snat_add_det_map(
1133 """Add/delete S-NAT deterministic mapping
1135 :param is_add - 1 if add, 0 if delete
1136 :param in_addr - inside IP address
1137 :param in_plen - inside IP address prefix length
1138 :param out_addr - outside IP address
1139 :param out_plen - outside IP address prefix length
1142 self.papi.snat_add_det_map,
1146 'out_addr': out_addr,
1147 'out_plen': out_plen})
1149 def snat_det_forward(
1152 """Get outside address and port range from inside address
1154 :param in_addr - inside IP address
1157 self.papi.snat_det_forward,
1158 {'in_addr': in_addr})
1160 def snat_det_reverse(
1164 """Get inside address from outside address and port
1166 :param out_addr - outside IP address
1167 :param out_port - outside port
1170 self.papi.snat_det_reverse,
1171 {'out_addr': out_addr,
1172 'out_port': out_port})
1174 def control_ping(self):
1175 self.api(self.papi.control_ping)
1177 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
1178 detect_mult, local_addr, peer_addr, is_ipv6=0,
1179 bfd_key_id=None, conf_key_id=None):
1180 if bfd_key_id is None:
1181 return self.api(self.papi.bfd_udp_add,
1183 'sw_if_index': sw_if_index,
1184 'desired_min_tx': desired_min_tx,
1185 'required_min_rx': required_min_rx,
1186 'local_addr': local_addr,
1187 'peer_addr': peer_addr,
1189 'detect_mult': detect_mult,
1192 return self.api(self.papi.bfd_udp_add,
1194 'sw_if_index': sw_if_index,
1195 'desired_min_tx': desired_min_tx,
1196 'required_min_rx': required_min_rx,
1197 'local_addr': local_addr,
1198 'peer_addr': peer_addr,
1200 'detect_mult': detect_mult,
1201 'is_authenticated': 1,
1202 'bfd_key_id': bfd_key_id,
1203 'conf_key_id': conf_key_id,
1206 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1207 detect_mult, local_addr, peer_addr, is_ipv6=0):
1208 return self.api(self.papi.bfd_udp_mod,
1210 'sw_if_index': sw_if_index,
1211 'desired_min_tx': desired_min_tx,
1212 'required_min_rx': required_min_rx,
1213 'local_addr': local_addr,
1214 'peer_addr': peer_addr,
1216 'detect_mult': detect_mult,
1219 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1220 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1222 return self.api(self.papi.bfd_udp_auth_activate,
1224 'sw_if_index': sw_if_index,
1225 'local_addr': local_addr,
1226 'peer_addr': peer_addr,
1228 'is_delayed': 1 if is_delayed else 0,
1229 'bfd_key_id': bfd_key_id,
1230 'conf_key_id': conf_key_id,
1233 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1234 is_ipv6=0, is_delayed=False):
1235 return self.api(self.papi.bfd_udp_auth_deactivate,
1237 'sw_if_index': sw_if_index,
1238 'local_addr': local_addr,
1239 'peer_addr': peer_addr,
1241 'is_delayed': 1 if is_delayed else 0,
1244 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1245 return self.api(self.papi.bfd_udp_del,
1247 'sw_if_index': sw_if_index,
1248 'local_addr': local_addr,
1249 'peer_addr': peer_addr,
1253 def bfd_udp_session_dump(self):
1254 return self.api(self.papi.bfd_udp_session_dump, {})
1256 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1257 peer_addr, is_ipv6=0):
1258 return self.api(self.papi.bfd_udp_session_set_flags, {
1259 'admin_up_down': admin_up_down,
1260 'sw_if_index': sw_if_index,
1261 'local_addr': local_addr,
1262 'peer_addr': peer_addr,
1266 def want_bfd_events(self, enable_disable=1):
1267 return self.api(self.papi.want_bfd_events, {
1268 'enable_disable': enable_disable,
1272 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1273 return self.api(self.papi.bfd_auth_set_key, {
1274 'conf_key_id': conf_key_id,
1275 'auth_type': auth_type,
1277 'key_len': len(key),
1280 def bfd_auth_del_key(self, conf_key_id):
1281 return self.api(self.papi.bfd_auth_del_key, {
1282 'conf_key_id': conf_key_id,
1285 def bfd_auth_keys_dump(self):
1286 return self.api(self.papi.bfd_auth_keys_dump, {})
1288 def bfd_udp_set_echo_source(self, sw_if_index):
1289 return self.api(self.papi.bfd_udp_set_echo_source,
1290 {'sw_if_index': sw_if_index})
1292 def bfd_udp_del_echo_source(self):
1293 return self.api(self.papi.bfd_udp_del_echo_source, {})
1295 def classify_add_del_table(
1300 table_index=0xFFFFFFFF,
1302 memory_size=2097152,
1304 next_table_index=0xFFFFFFFF,
1305 miss_next_index=0xFFFFFFFF,
1306 current_data_flag=0,
1307 current_data_offset=0):
1311 :param match_n_vectors: (Default value = 1)
1312 :param table_index: (Default value = 0xFFFFFFFF)
1313 :param nbuckets: (Default value = 2)
1314 :param memory_size: (Default value = 2097152)
1315 :param skip_n_vectors: (Default value = 0)
1316 :param next_table_index: (Default value = 0xFFFFFFFF)
1317 :param miss_next_index: (Default value = 0xFFFFFFFF)
1318 :param current_data_flag: (Default value = 0)
1319 :param current_data_offset: (Default value = 0)
1323 self.papi.classify_add_del_table,
1325 'table_index': table_index,
1326 'nbuckets': nbuckets,
1327 'memory_size': memory_size,
1328 'skip_n_vectors': skip_n_vectors,
1329 'match_n_vectors': match_n_vectors,
1330 'next_table_index': next_table_index,
1331 'miss_next_index': miss_next_index,
1332 'current_data_flag': current_data_flag,
1333 'current_data_offset': current_data_offset,
1336 def classify_add_del_session(
1341 opaque_index=0xFFFFFFFF,
1342 hit_next_index=0xFFFFFFFF,
1350 :param opaque_index: (Default value = 0xFFFFFFFF)
1351 :param hit_next_index: (Default value = 0xFFFFFFFF)
1352 :param advance: (Default value = 0)
1353 :param action: (Default value = 0)
1354 :param metadata: (Default value = 0)
1358 self.papi.classify_add_del_session,
1360 'table_index': table_index,
1361 'hit_next_index': hit_next_index,
1362 'opaque_index': opaque_index,
1365 'metadata': metadata,
1368 def input_acl_set_interface(
1372 ip4_table_index=0xFFFFFFFF,
1373 ip6_table_index=0xFFFFFFFF,
1374 l2_table_index=0xFFFFFFFF):
1378 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1379 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1380 :param l2_table_index: (Default value = 0xFFFFFFFF)
1384 self.papi.input_acl_set_interface,
1385 {'sw_if_index': sw_if_index,
1386 'ip4_table_index': ip4_table_index,
1387 'ip6_table_index': ip6_table_index,
1388 'l2_table_index': l2_table_index,
1391 def set_ipfix_exporter(
1398 collector_port=4739,
1401 self.papi.set_ipfix_exporter,
1403 'collector_address': collector_address,
1404 'collector_port': collector_port,
1405 'src_address': src_address,
1407 'path_mtu': path_mtu,
1408 'template_interval': template_interval,
1409 'udp_checksum': udp_checksum,
1412 def dhcp_proxy_config(self,
1420 self.papi.dhcp_proxy_config,
1422 'rx_vrf_id': rx_table_id,
1423 'server_vrf_id': server_table_id,
1426 'dhcp_server': dhcp_server,
1427 'dhcp_src_address': dhcp_src_address,
1430 def dhcp_proxy_set_vss(self,
1437 self.papi.dhcp_proxy_set_vss,
1446 def ip_mroute_add_del(self,
1451 next_hop_sw_if_index,
1454 create_vrf_if_needed=0,
1461 self.papi.ip_mroute_add_del,
1462 {'next_hop_sw_if_index': next_hop_sw_if_index,
1463 'entry_flags': e_flags,
1464 'itf_flags': i_flags,
1465 'create_vrf_if_needed': create_vrf_if_needed,
1468 'is_local': is_local,
1469 'grp_address_length': grp_address_length,
1470 'grp_address': grp_address,
1471 'src_address': src_address})
1473 def mfib_signal_dump(self):
1474 return self.api(self.papi.mfib_signal_dump, {})
1476 def ip_mfib_dump(self):
1477 return self.api(self.papi.ip_mfib_dump, {})
1479 def lisp_enable_disable(self, is_enabled):
1481 self.papi.lisp_enable_disable,
1483 'is_en': is_enabled,
1486 def lisp_locator_set(self,
1490 self.papi.lisp_add_del_locator_set,
1493 'locator_set_name': ls_name
1496 def lisp_locator_set_dump(self):
1497 return self.api(self.papi.lisp_locator_set_dump, {})
1499 def lisp_locator(self,
1506 self.papi.lisp_add_del_locator,
1509 'locator_set_name': ls_name,
1510 'sw_if_index': sw_if_index,
1511 'priority': priority,
1515 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1517 self.papi.lisp_locator_dump,
1519 'is_index_set': is_index_set,
1521 'ls_index': ls_index,
1524 def lisp_local_mapping(self,
1534 self.papi.lisp_add_del_local_eid,
1536 'locator_set_name': ls_name,
1538 'eid_type': eid_type,
1540 'prefix_len': prefix_len,
1546 def lisp_eid_table_dump(self,
1554 self.papi.lisp_eid_table_dump,
1557 'prefix_length': prefix_length,
1559 'eid_type': eid_type,
1561 'filter': filter_opt,
1564 def lisp_remote_mapping(self,
1574 self.papi.lisp_add_del_remote_mapping,
1577 'eid_type': eid_type,
1579 'eid_len': eid_prefix_len,
1580 'rloc_num': rlocs_num,
1583 'is_src_dst': is_src_dst,
1586 def lisp_adjacency(self,
1595 self.papi.lisp_add_del_adjacency,
1599 'eid_type': eid_type,
1602 'leid_len': leid_len,
1603 'reid_len': reid_len,
1606 def lisp_adjacencies_get(self, vni=0):
1608 self.papi.lisp_adjacencies_get,