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
39 class UnexpectedApiReturnValueError(Exception):
40 """ exception raised when the API return value is unexpected """
44 class VppPapiProvider(object):
45 """VPP-api provider using vpp-papi
47 @property hook: hook object providing before and after api/cli hooks
50 _zero, _negative = range(2)
52 def __init__(self, name, shm_prefix, test_class):
53 self.hook = Hook("vpp-papi-provider")
55 self.shm_prefix = shm_prefix
56 self.test_class = test_class
57 self._expect_api_retval = self._zero
58 self._expect_stack = []
61 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
62 for root, dirnames, filenames in os.walk(install_dir):
63 for filename in fnmatch.filter(filenames, '*.api.json'):
64 jsonfiles.append(os.path.join(root, filename))
66 self.vpp = VPP(jsonfiles, logger=test_class.logger)
67 self._events = deque()
72 def expect_negative_api_retval(self):
73 """ Expect API failure """
74 self._expect_stack.append(self._expect_api_retval)
75 self._expect_api_retval = self._negative
78 def expect_zero_api_retval(self):
79 """ Expect API success """
80 self._expect_stack.append(self._expect_api_retval)
81 self._expect_api_retval = self._zero
84 def __exit__(self, exc_type, exc_value, traceback):
85 self._expect_api_retval = self._expect_stack.pop()
87 def register_hook(self, hook):
88 """Replace hook registration with new hook
95 def collect_events(self):
96 """ Collect all events from the internal queue and clear the queue. """
98 self._events = deque()
101 def wait_for_event(self, timeout, name=None):
102 """ Wait for and return next event. """
104 self.test_class.logger.debug("Expecting event '%s' within %ss",
107 self.test_class.logger.debug("Expecting event within %ss",
110 self.test_class.logger.debug("Not waiting, event already queued")
111 limit = time.time() + timeout
112 while time.time() < limit:
114 e = self._events.popleft()
115 if name and type(e).__name__ != name:
117 "Unexpected event received: %s, expected: %s" %
118 (type(e).__name__, name))
119 self.test_class.logger.debug("Returning event %s:%s" %
122 time.sleep(0) # yield
123 raise Exception("Event did not occur within timeout")
125 def __call__(self, name, event):
126 """ Enqueue event in the internal event queue. """
127 # FIXME use the name instead of relying on type(e).__name__ ?
128 # FIXME #2 if this throws, it is eaten silently, Ole?
129 self.test_class.logger.debug("New event: %s: %s" % (name, event))
130 self._events.append(event)
133 """Connect the API to VPP"""
134 self.vpp.connect(self.name, self.shm_prefix)
135 self.papi = self.vpp.api
136 self.vpp.register_event_callback(self)
138 def disconnect(self):
139 """Disconnect the API from VPP"""
140 self.vpp.disconnect()
142 def api(self, api_fn, api_args, expected_retval=0):
143 """ Call API function and check it's return value.
144 Call the appropriate hooks before and after the API call
146 :param api_fn: API function to call
147 :param api_args: tuple of API function arguments
148 :param expected_retval: Expected return value (Default value = 0)
149 :returns: reply from the API
152 self.hook.before_api(api_fn.__name__, api_args)
153 reply = api_fn(**api_args)
154 if self._expect_api_retval == self._negative:
155 if hasattr(reply, 'retval') and reply.retval >= 0:
156 msg = "API call passed unexpectedly: expected negative "\
157 "return value instead of %d in %s" % \
158 (reply.retval, repr(reply))
159 self.test_class.logger.info(msg)
160 raise UnexpectedApiReturnValueError(msg)
161 elif self._expect_api_retval == self._zero:
162 if hasattr(reply, 'retval') and reply.retval != expected_retval:
163 msg = "API call failed, expected %d return value instead "\
164 "of %d in %s" % (expected_retval, reply.retval,
166 self.test_class.logger.info(msg)
167 raise UnexpectedApiReturnValueError(msg)
169 raise Exception("Internal error, unexpected value for "
170 "self._expect_api_retval %s" %
171 self._expect_api_retval)
172 self.hook.after_api(api_fn.__name__, api_args)
176 """ Execute a CLI, calling the before/after hooks appropriately.
178 :param cli: CLI to execute
182 self.hook.before_cli(cli)
184 r = self.papi.cli_inband(length=len(cli), cmd=cli)
185 self.hook.after_cli(cli)
186 if hasattr(r, 'reply'):
187 return r.reply.decode().rstrip('\x00')
189 def ppcli(self, cli):
190 """ Helper method to print CLI command in case of info logging level.
192 :param cli: CLI to execute
195 return cli + "\n" + str(self.cli(cli))
197 def _convert_mac(self, mac):
198 return mac.replace(':', '').decode('hex')
200 def show_version(self):
202 return self.api(self.papi.show_version, {})
204 def pg_create_interface(self, pg_index):
210 return self.api(self.papi.pg_create_interface,
211 {"interface_id": pg_index})
213 def sw_interface_dump(self, filter=None):
216 :param filter: (Default value = None)
219 if filter is not None:
220 args = {"name_filter_valid": 1, "name_filter": filter}
223 return self.api(self.papi.sw_interface_dump, args)
225 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
226 """ Set the IPvX Table-id for the Interface
233 return self.api(self.papi.sw_interface_set_table,
234 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
237 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
238 is_ipv6=0, is_add=1, del_all=0):
241 :param addr: param is_ipv6: (Default value = 0)
244 :param is_ipv6: (Default value = 0)
245 :param is_add: (Default value = 1)
246 :param del_all: (Default value = 0)
249 return self.api(self.papi.sw_interface_add_del_address,
250 {'sw_if_index': sw_if_index,
254 'address_length': addr_len,
257 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
259 """ Set the Interface to be unnumbered
261 :param is_add: (Default value = 1)
262 :param sw_if_index - interface That will be unnumbered
263 :param ip_sw_if_index - interface with an IP addres
266 return self.api(self.papi.sw_interface_set_unnumbered,
267 {'sw_if_index': ip_sw_if_index,
268 'unnumbered_sw_if_index': sw_if_index,
271 def sw_interface_enable_disable_mpls(self, sw_if_index,
274 Enable/Disable MPLS on the interface
276 :param is_enable: (Default value = 1)
279 return self.api(self.papi.sw_interface_set_mpls_enable,
280 {'sw_if_index': sw_if_index,
281 'enable': is_enable})
283 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
284 return self.api(self.papi.sw_interface_ip6nd_ra_config,
285 {'sw_if_index': sw_if_index,
286 'suppress': suppress})
288 def set_ip_flow_hash(self,
297 return self.api(self.papi.set_ip_flow_hash,
307 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
308 return self.api(self.papi.ip6nd_proxy_add_del,
310 'sw_if_index': sw_if_index,
313 def ip6_sw_interface_ra_config(self, sw_if_index,
317 return self.api(self.papi.sw_interface_ip6nd_ra_config,
318 {'sw_if_index': sw_if_index,
320 'suppress': suppress,
321 'send_unicast': send_unicast})
323 def ip6_sw_interface_ra_prefix(self,
333 val_lifetime=0xffffffff,
334 pref_lifetime=0xffffffff):
335 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
336 {'sw_if_index': sw_if_index,
338 'address_length': address_length,
339 'use_default': use_default,
340 'no_advertise': no_advertise,
341 'off_link': off_link,
342 'no_autoconfig': no_autoconfig,
343 'no_onlink': no_onlink,
345 'val_lifetime': val_lifetime,
346 'pref_lifetime': pref_lifetime})
348 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
350 Enable/Disable An interface for IPv6
352 return self.api(self.papi.sw_interface_ip6_enable_disable,
353 {'sw_if_index': sw_if_index,
356 def vxlan_add_del_tunnel(
360 mcast_sw_if_index=0xFFFFFFFF,
364 decap_next_index=0xFFFFFFFF,
370 :param is_add: (Default value = 1)
371 :param is_ipv6: (Default value = 0)
372 :param encap_vrf_id: (Default value = 0)
373 :param decap_next_index: (Default value = 0xFFFFFFFF)
374 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
375 :param vni: (Default value = 0)
378 return self.api(self.papi.vxlan_add_del_tunnel,
381 'src_address': src_addr,
382 'dst_address': dst_addr,
383 'mcast_sw_if_index': mcast_sw_if_index,
384 'encap_vrf_id': encap_vrf_id,
385 'decap_next_index': decap_next_index,
388 def geneve_add_del_tunnel(
392 mcast_sw_if_index=0xFFFFFFFF,
396 decap_next_index=0xFFFFFFFF,
402 :param is_add: (Default value = 1)
403 :param is_ipv6: (Default value = 0)
404 :param encap_vrf_id: (Default value = 0)
405 :param decap_next_index: (Default value = 0xFFFFFFFF)
406 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
407 :param vni: (Default value = 0)
410 return self.api(self.papi.geneve_add_del_tunnel,
413 'local_address': local_addr,
414 'remote_address': remote_addr,
415 'mcast_sw_if_index': mcast_sw_if_index,
416 'encap_vrf_id': encap_vrf_id,
417 'decap_next_index': decap_next_index,
420 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
421 learn=1, arp_term=0, is_add=1):
422 """Create/delete bridge domain.
424 :param int bd_id: Bridge domain index.
425 :param int flood: Enable/disable bcast/mcast flooding in the BD.
427 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
429 :param int forward: Enable/disable forwarding on all interfaces in
430 the BD. (Default value = 1)
431 :param int learn: Enable/disable learning on all interfaces in the BD.
433 :param int arp_term: Enable/disable arp termination in the BD.
435 :param int is_add: Add or delete flag. (Default value = 1)
437 return self.api(self.papi.bridge_domain_add_del,
440 'uu_flood': uu_flood,
443 'arp_term': arp_term,
446 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
447 return self.api(self.papi.bd_ip_mac_add_del,
454 def want_ip4_arp_events(self, enable_disable=1, address=0):
455 return self.api(self.papi.want_ip4_arp_events,
456 {'enable_disable': enable_disable,
458 'pid': os.getpid(), })
460 def want_ip6_nd_events(self, enable_disable=1, address=0):
461 return self.api(self.papi.want_ip6_nd_events,
462 {'enable_disable': enable_disable,
464 'pid': os.getpid(), })
466 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
467 max_macs_in_event=0, learn_limit=0):
468 return self.api(self.papi.want_l2_macs_events,
469 {'enable_disable': enable_disable,
470 'scan_delay': scan_delay,
471 'max_macs_in_event': max_macs_in_event,
472 'learn_limit': learn_limit,
473 'pid': os.getpid(), })
475 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
476 filter_mac=0, bvi_mac=0):
477 """Create/delete L2 FIB entry.
479 :param str mac: MAC address to create FIB entry for.
480 :param int bd_id: Bridge domain index.
481 :param int sw_if_index: Software interface index of the interface.
482 :param int is_add: Add or delete flag. (Default value = 1)
483 :param int static_mac: Set to 1 to create static MAC entry.
485 :param int filter_mac: Set to 1 to drop packet that's source or
486 destination MAC address contains defined MAC address.
488 :param int bvi_mac: Set to 1 to create entry that points to BVI
489 interface. (Default value = 0)
491 return self.api(self.papi.l2fib_add_del,
492 {'mac': self._convert_mac(mac),
494 'sw_if_index': sw_if_index,
496 'static_mac': static_mac,
497 'filter_mac': filter_mac,
500 def l2fib_flush_int(self, sw_if_index):
501 """Flush L2 FIB entries for sw_if_index.
503 :param int sw_if_index: Software interface index of the interface.
505 return self.api(self.papi.l2fib_flush_int,
506 {'sw_if_index': sw_if_index})
508 def l2fib_flush_bd(self, bd_id):
509 """Flush L2 FIB entries for bd_id.
511 :param int sw_if_index: Bridge Domain id.
513 return self.api(self.papi.l2fib_flush_bd,
516 def l2fib_flush_all(self):
519 return self.api(self.papi.l2fib_flush_all, {})
521 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
522 shg=0, bvi=0, enable=1):
523 """Add/remove interface to/from bridge domain.
525 :param int sw_if_index: Software interface index of the interface.
526 :param int bd_id: Bridge domain index.
527 :param int shg: Split-horizon group index. (Default value = 0)
528 :param int bvi: Set interface as a bridge group virtual interface.
530 :param int enable: Add or remove interface. (Default value = 1)
532 return self.api(self.papi.sw_interface_set_l2_bridge,
533 {'rx_sw_if_index': sw_if_index,
539 def bridge_flags(self, bd_id, is_set, feature_bitmap):
540 """Enable/disable required feature of the bridge domain with defined ID.
542 :param int bd_id: Bridge domain ID.
543 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
544 :param int feature_bitmap: Bitmap value of the feature to be set:
548 - uu-flood (1 << 3) or
551 return self.api(self.papi.bridge_flags,
554 'feature_bitmap': feature_bitmap})
556 def bridge_domain_dump(self, bd_id=0):
559 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
560 existing bridge domains returned)
561 :return: Dictionary of bridge domain(s) data.
563 return self.api(self.papi.bridge_domain_dump,
566 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
568 """Create or delete unidirectional cross-connect from Tx interface to
571 :param int rx_sw_if_index: Software interface index of Rx interface.
572 :param int tx_sw_if_index: Software interface index of Tx interface.
573 :param int enable: Create cross-connect if equal to 1, delete
574 cross-connect if equal to 0.
577 return self.api(self.papi.sw_interface_set_l2_xconnect,
578 {'rx_sw_if_index': rx_sw_if_index,
579 'tx_sw_if_index': tx_sw_if_index,
582 def sw_interface_set_l2_tag_rewrite(
589 """L2 interface vlan tag rewrite configure request
590 :param client_index - opaque cookie to identify the sender
591 :param context - sender context, to match reply w/ request
592 :param sw_if_index - interface the operation is applied to
593 :param vtr_op - Choose from l2_vtr_op_t enum values
594 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
595 :param tag1 - Needed for any push or translate vtr op
596 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
599 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
600 {'sw_if_index': sw_if_index,
606 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
609 :param admin_up_down:
613 return self.api(self.papi.sw_interface_set_flags,
614 {'sw_if_index': sw_if_index,
615 'admin_up_down': admin_up_down})
617 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
618 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
619 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
620 """Create subinterface
621 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
623 :param sub_id: param inner_vlan:
627 :param no_tags: (Default value = 0)
628 :param one_tag: (Default value = 0)
629 :param two_tags: (Default value = 0)
630 :param dot1ad: (Default value = 0)
631 :param exact_match: (Default value = 0)
632 :param default_sub: (Default value = 0)
633 :param outer_vlan_id_any: (Default value = 0)
634 :param inner_vlan_id_any: (Default value = 0)
638 self.papi.create_subif,
639 {'sw_if_index': sw_if_index,
643 'two_tags': two_tags,
645 'exact_match': exact_match,
646 'default_sub': default_sub,
647 'outer_vlan_id_any': outer_vlan_id_any,
648 'inner_vlan_id_any': inner_vlan_id_any,
649 'outer_vlan_id': outer_vlan,
650 'inner_vlan_id': inner_vlan})
652 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
653 """Create p2p ethernet subinterface
655 :param sw_if_index: main (parent) interface
656 :param remote_mac: client (remote) mac address
660 self.papi.p2p_ethernet_add,
661 {'parent_if_index': sw_if_index,
662 'remote_mac': remote_mac,
663 'subif_id': subif_id})
665 def delete_subif(self, sw_if_index):
666 """Delete subinterface
670 return self.api(self.papi.delete_subif,
671 {'sw_if_index': sw_if_index})
673 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
674 """Delete p2p ethernet subinterface
676 :param sw_if_index: main (parent) interface
677 :param remote_mac: client (remote) mac address
681 self.papi.p2p_ethernet_del,
682 {'parent_if_index': sw_if_index,
683 'remote_mac': remote_mac})
685 def create_vlan_subif(self, sw_if_index, vlan):
692 return self.api(self.papi.create_vlan_subif,
693 {'sw_if_index': sw_if_index,
696 def create_loopback(self, mac=''):
699 :param mac: (Optional)
701 return self.api(self.papi.create_loopback,
702 {'mac_address': mac})
704 def delete_loopback(self, sw_if_index):
705 return self.api(self.papi.delete_loopback,
706 {'sw_if_index': sw_if_index, })
708 def ip_table_add_del(self,
715 :param is_add: (Default value = 1)
716 :param is_ipv6: (Default value = 0)
721 self.papi.ip_table_add_del,
722 {'table_id': table_id,
726 def ip_add_del_route(
731 next_hop_sw_if_index=0xFFFFFFFF,
735 next_hop_n_out_labels=0,
736 next_hop_out_label_stack=[],
737 next_hop_via_label=MPLS_LABEL_INVALID,
738 next_hop_id=0xFFFFFFFF,
740 is_resolve_attached=0,
741 classify_table_index=0xFFFFFFFF,
755 :param dst_address_length:
756 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
758 :param next_hop_address:
759 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
760 :param vrf_id: (Default value = 0)
761 :param lookup_in_vrf: (Default value = 0)
762 :param classify_table_index: (Default value = 0xFFFFFFFF)
763 :param is_add: (Default value = 1)
764 :param is_drop: (Default value = 0)
765 :param is_ipv6: (Default value = 0)
766 :param is_local: (Default value = 0)
767 :param is_classify: (Default value = 0)
768 :param is_multipath: (Default value = 0)
769 :param is_resolve_host: (Default value = 0)
770 :param is_resolve_attached: (Default value = 0)
771 :param is_l2_bridged: (Default value = 0)
772 :param is_source_lookup: (Default value = 0)
773 :param next_hop_weight: (Default value = 1)
778 self.papi.ip_add_del_route,
779 {'next_hop_sw_if_index': next_hop_sw_if_index,
780 'table_id': table_id,
781 'classify_table_index': classify_table_index,
782 'next_hop_table_id': next_hop_table_id,
785 'is_unreach': is_unreach,
786 'is_prohibit': is_prohibit,
788 'is_local': is_local,
789 'is_classify': is_classify,
790 'is_multipath': is_multipath,
791 'is_resolve_host': is_resolve_host,
792 'is_resolve_attached': is_resolve_attached,
793 'is_l2_bridged': is_l2_bridged,
794 'is_source_lookup': is_source_lookup,
795 'is_udp_encap': is_udp_encap,
796 'next_hop_weight': next_hop_weight,
797 'dst_address_length': dst_address_length,
798 'dst_address': dst_address,
799 'next_hop_id': next_hop_id,
800 'next_hop_address': next_hop_address,
801 'next_hop_n_out_labels': next_hop_n_out_labels,
802 'next_hop_via_label': next_hop_via_label,
803 'next_hop_out_label_stack': next_hop_out_label_stack})
805 def ip_fib_dump(self):
806 return self.api(self.papi.ip_fib_dump, {})
808 def ip6_fib_dump(self):
809 return self.api(self.papi.ip6_fib_dump, {})
811 def ip_neighbor_add_del(self,
820 """ Add neighbor MAC to IPv4 or IPv6 address.
825 :param is_add: (Default value = 1)
826 :param is_ipv6: (Default value = 0)
827 :param is_static: (Default value = 0)
828 :param is_no_adj_fib: (Default value = 0)
832 self.papi.ip_neighbor_add_del,
833 {'sw_if_index': sw_if_index,
836 'is_static': is_static,
837 'is_no_adj_fib': is_no_adj_fib,
838 'mac_address': mac_address,
839 'dst_address': dst_address
843 def ip_neighbor_dump(self,
846 """ Return IP neighbor dump.
849 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
853 self.papi.ip_neighbor_dump,
855 'sw_if_index': sw_if_index
859 def proxy_arp_add_del(self,
864 """ Config Proxy Arp Range.
866 :param low_address: Start address in the rnage to Proxy for
867 :param hi_address: End address in the rnage to Proxy for
868 :param vrf_id: The VRF/table in which to proxy
872 self.papi.proxy_arp_add_del,
875 'low_address': low_address,
876 'hi_address': hi_address,
880 def proxy_arp_intfc_enable_disable(self,
883 """ Enable/Disable an interface for proxy ARP requests
885 :param sw_if_index: Interface
886 :param enable_disable: Enable/Disable
890 self.papi.proxy_arp_intfc_enable_disable,
891 {'sw_if_index': sw_if_index,
892 'enable_disable': is_enable
900 """ Reset VRF (remove all routes etc.) request.
902 :param int vrf_id: ID of the FIB table / VRF to reset.
903 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
917 """ Reset VRF (remove all routes etc.) request.
919 :param int vrf_id: ID of the FIB table / VRF to reset.
920 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
935 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
944 def sw_interface_span_enable_disable(
945 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
948 :param sw_if_index_from:
949 :param sw_if_index_to:
953 return self.api(self.papi.sw_interface_span_enable_disable,
954 {'sw_if_index_from': sw_if_index_from,
955 'sw_if_index_to': sw_if_index_to,
960 def gre_tunnel_add_del(self,
971 :param outer_fib_id: (Default value = 0)
972 :param is_add: (Default value = 1)
973 :param is_ipv6: (Default value = 0)
974 :param is_teb: (Default value = 0)
978 self.papi.gre_add_del_tunnel,
982 'src_address': src_address,
983 'dst_address': dst_address,
984 'outer_fib_id': outer_fib_id}
987 def udp_encap_add_del(self,
997 :param id: user provided ID
1002 :param outer_fib_id: (Default value = 0)
1003 :param is_add: (Default value = 1)
1004 :param is_ipv6: (Default value = 0)
1008 self.papi.udp_encap_add_del,
1014 'src_port': src_port,
1015 'dst_port': dst_port,
1016 'table_id': table_id}
1019 def udp_encap_dump(self):
1020 return self.api(self.papi.udp_encap_dump, {})
1022 def mpls_fib_dump(self):
1023 return self.api(self.papi.mpls_fib_dump, {})
1025 def mpls_table_add_del(
1032 :param is_add: (Default value = 1)
1037 self.papi.mpls_table_add_del,
1038 {'mt_table_id': table_id,
1039 'mt_is_add': is_add})
1041 def mpls_route_add_del(
1047 next_hop_sw_if_index=0xFFFFFFFF,
1049 next_hop_table_id=0,
1051 next_hop_n_out_labels=0,
1052 next_hop_out_label_stack=[],
1053 next_hop_via_label=MPLS_LABEL_INVALID,
1055 is_resolve_attached=0,
1062 classify_table_index=0xFFFFFFFF,
1066 :param dst_address_length:
1067 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1069 :param next_hop_address:
1070 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1071 :param vrf_id: (Default value = 0)
1072 :param lookup_in_vrf: (Default value = 0)
1073 :param classify_table_index: (Default value = 0xFFFFFFFF)
1074 :param is_add: (Default value = 1)
1075 :param is_drop: (Default value = 0)
1076 :param is_ipv6: (Default value = 0)
1077 :param is_local: (Default value = 0)
1078 :param is_classify: (Default value = 0)
1079 :param is_multipath: (Default value = 0)
1080 :param is_multicast: (Default value = 0)
1081 :param is_resolve_host: (Default value = 0)
1082 :param is_resolve_attached: (Default value = 0)
1083 :param next_hop_weight: (Default value = 1)
1088 self.papi.mpls_route_add_del,
1091 'mr_table_id': table_id,
1092 'mr_classify_table_index': classify_table_index,
1093 'mr_is_add': is_add,
1094 'mr_is_classify': is_classify,
1095 'mr_is_multipath': is_multipath,
1096 'mr_is_multicast': is_multicast,
1097 'mr_is_resolve_host': is_resolve_host,
1098 'mr_is_resolve_attached': is_resolve_attached,
1099 'mr_is_interface_rx': is_interface_rx,
1100 'mr_is_rpf_id': is_rpf_id,
1101 'mr_next_hop_proto': next_hop_proto,
1102 'mr_next_hop_weight': next_hop_weight,
1103 'mr_next_hop': next_hop_address,
1104 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1105 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1106 'mr_next_hop_table_id': next_hop_table_id,
1107 'mr_next_hop_via_label': next_hop_via_label,
1108 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
1110 def mpls_ip_bind_unbind(
1122 self.papi.mpls_ip_bind_unbind,
1123 {'mb_mpls_table_id': table_id,
1125 'mb_ip_table_id': ip_table_id,
1126 'mb_is_bind': is_bind,
1127 'mb_is_ip4': is_ip4,
1128 'mb_address_length': dst_address_length,
1129 'mb_address': dst_address})
1131 def mpls_tunnel_add_del(
1134 next_hop_proto_is_ip4,
1136 next_hop_sw_if_index=0xFFFFFFFF,
1137 next_hop_table_id=0,
1139 next_hop_n_out_labels=0,
1140 next_hop_out_label_stack=[],
1141 next_hop_via_label=MPLS_LABEL_INVALID,
1147 :param dst_address_length:
1148 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1150 :param next_hop_address:
1151 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1152 :param vrf_id: (Default value = 0)
1153 :param lookup_in_vrf: (Default value = 0)
1154 :param classify_table_index: (Default value = 0xFFFFFFFF)
1155 :param is_add: (Default value = 1)
1156 :param is_drop: (Default value = 0)
1157 :param is_ipv6: (Default value = 0)
1158 :param is_local: (Default value = 0)
1159 :param is_classify: (Default value = 0)
1160 :param is_multipath: (Default value = 0)
1161 :param is_resolve_host: (Default value = 0)
1162 :param is_resolve_attached: (Default value = 0)
1163 :param next_hop_weight: (Default value = 1)
1164 :param is_multicast: (Default value = 0)
1168 self.papi.mpls_tunnel_add_del,
1169 {'mt_sw_if_index': tun_sw_if_index,
1170 'mt_is_add': is_add,
1171 'mt_l2_only': l2_only,
1172 'mt_is_multicast': is_multicast,
1173 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1174 'mt_next_hop_weight': next_hop_weight,
1175 'mt_next_hop': next_hop_address,
1176 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1177 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1178 'mt_next_hop_table_id': next_hop_table_id,
1179 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
1181 def nat44_interface_add_del_feature(
1186 """Enable/disable NAT44 feature on the interface
1188 :param sw_if_index: Software index of the interface
1189 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1190 :param is_add: 1 if add, 0 if delete (Default value = 1)
1193 self.papi.nat44_interface_add_del_feature,
1195 'is_inside': is_inside,
1196 'sw_if_index': sw_if_index})
1198 def nat44_interface_add_del_output_feature(
1203 """Enable/disable NAT44 output feature on the interface
1205 :param sw_if_index: Software index of the interface
1206 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1207 :param is_add: 1 if add, 0 if delete (Default value = 1)
1210 self.papi.nat44_interface_add_del_output_feature,
1212 'is_inside': is_inside,
1213 'sw_if_index': sw_if_index})
1215 def nat44_add_del_static_mapping(
1219 external_sw_if_index=0xFFFFFFFF,
1226 """Add/delete NAT44 static mapping
1228 :param local_ip: Local IP address
1229 :param external_ip: External IP address
1230 :param external_sw_if_index: External interface instead of IP address
1231 :param local_port: Local port number (Default value = 0)
1232 :param external_port: External port number (Default value = 0)
1233 :param addr_only: 1 if address only mapping, 0 if address and port
1234 :param vrf_id: VRF ID
1235 :param protocol: IP protocol (Default value = 0)
1236 :param is_add: 1 if add, 0 if delete (Default value = 1)
1239 self.papi.nat44_add_del_static_mapping,
1241 'addr_only': addr_only,
1242 'local_ip_address': local_ip,
1243 'external_ip_address': external_ip,
1244 'local_port': local_port,
1245 'external_port': external_port,
1246 'external_sw_if_index': external_sw_if_index,
1248 'protocol': protocol})
1250 def nat44_add_del_address_range(
1256 """Add/del NAT44 address range
1258 :param first_ip_address: First IP address
1259 :param last_ip_address: Last IP address
1260 :param vrf_id: VRF id for the address range
1261 :param is_add: 1 if add, 0 if delete (Default value = 1)
1264 self.papi.nat44_add_del_address_range,
1265 {'first_ip_address': first_ip_address,
1266 'last_ip_address': last_ip_address,
1270 def nat44_address_dump(self):
1271 """Dump NAT44 addresses
1272 :return: Dictionary of NAT44 addresses
1274 return self.api(self.papi.nat44_address_dump, {})
1276 def nat44_interface_dump(self):
1277 """Dump interfaces with NAT44 feature
1278 :return: Dictionary of interfaces with NAT44 feature
1280 return self.api(self.papi.nat44_interface_dump, {})
1282 def nat44_interface_output_feature_dump(self):
1283 """Dump interfaces with NAT44 output feature
1284 :return: Dictionary of interfaces with NAT44 output feature
1286 return self.api(self.papi.nat44_interface_output_feature_dump, {})
1288 def nat44_static_mapping_dump(self):
1289 """Dump NAT44 static mappings
1290 :return: Dictionary of NAT44 static mappings
1292 return self.api(self.papi.nat44_static_mapping_dump, {})
1294 def nat_show_config(self):
1295 """Show NAT plugin config
1296 :return: NAT plugin config parameters
1298 return self.api(self.papi.nat_show_config, {})
1300 def nat44_add_interface_addr(
1304 """Add/del NAT44 address from interface
1306 :param sw_if_index: Software index of the interface
1307 :param is_add: 1 if add, 0 if delete (Default value = 1)
1309 return self.api(self.papi.nat44_add_del_interface_addr,
1310 {'is_add': is_add, 'sw_if_index': sw_if_index})
1312 def nat44_interface_addr_dump(self):
1313 """Dump NAT44 addresses interfaces
1314 :return: Dictionary of NAT44 addresses interfaces
1316 return self.api(self.papi.nat44_interface_addr_dump, {})
1323 """Enable/disable NAT IPFIX logging
1325 :param domain_id: Observation domain ID (Default value = 1)
1326 :param src_port: Source port number (Default value = 4739)
1327 :param enable: 1 if enable, 0 if disable (Default value = 1)
1330 self.papi.nat_ipfix_enable_disable,
1331 {'domain_id': domain_id,
1332 'src_port': src_port,
1335 def nat44_user_session_dump(
1339 """Dump NAT44 user's sessions
1341 :param ip_address: ip adress of the user to be dumped
1342 :param cpu_index: cpu_index on which the user is
1343 :param vrf_id: VRF ID
1344 :return: Dictionary of S-NAT sessions
1347 self.papi.nat44_user_session_dump,
1348 {'ip_address': ip_address,
1351 def nat44_user_dump(self):
1354 :return: Dictionary of NAT44 users
1356 return self.api(self.papi.nat44_user_dump, {})
1358 def nat44_add_del_lb_static_mapping(
1367 """Add/delete NAT44 load balancing static mapping
1369 :param is_add - 1 if add, 0 if delete
1372 self.papi.nat44_add_del_lb_static_mapping,
1374 'external_addr': external_addr,
1375 'external_port': external_port,
1376 'protocol': protocol,
1378 'local_num': local_num,
1381 def nat44_lb_static_mapping_dump(self):
1382 """Dump NAT44 load balancing static mappings
1384 :return: Dictionary of NAT44 load balancing static mapping
1386 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1388 def nat44_del_session(
1395 """Delete NAT44 session
1397 :param addr: IPv4 address
1398 :param por: port number
1399 :param protocol: IP protocol number
1400 :param vrf_id: VRF ID
1401 :param is_in: 1 if inside network addres and port pari, 0 if outside
1404 self.papi.nat44_del_session,
1407 'protocol': protocol,
1418 """Set NAT virtual fragmentation reassembly
1420 :param timeout: reassembly timeout (Default 2sec)
1421 :param max_reass: maximum concurrent reassemblies (Default 1024)
1422 :param max_frag: maximum fragmets per reassembly (Default 5)
1423 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1424 :param is_ip6: 1 if IPv6, 0 if IPv4
1427 self.papi.nat_set_reass,
1428 {'timeout': timeout,
1429 'max_reass': max_reass,
1430 'max_frag': max_frag,
1431 'drop_frag': drop_frag,
1434 def nat_get_reass(self):
1435 """Get NAT virtual fragmentation reassembly configuration
1437 :return: NAT virtual fragmentation reassembly configuration
1439 return self.api(self.papi.nat_get_reass, {})
1441 def nat_reass_dump(self):
1442 """Dump NAT virtual fragmentation reassemblies
1444 :return: Dictionary of NAT virtual fragmentation reassemblies
1446 return self.api(self.papi.nat_reass_dump, {})
1448 def nat_det_add_del_map(
1455 """Add/delete deterministic NAT mapping
1457 :param is_add - 1 if add, 0 if delete
1458 :param in_addr - inside IP address
1459 :param in_plen - inside IP address prefix length
1460 :param out_addr - outside IP address
1461 :param out_plen - outside IP address prefix length
1464 self.papi.nat_det_add_del_map,
1469 'out_addr': out_addr,
1470 'out_plen': out_plen})
1472 def nat_det_forward(
1475 """Get outside address and port range from inside address
1477 :param in_addr - inside IP address
1480 self.papi.nat_det_forward,
1481 {'in_addr': in_addr,
1484 def nat_det_reverse(
1488 """Get inside address from outside address and port
1490 :param out_addr - outside IP address
1491 :param out_port - outside port
1494 self.papi.nat_det_reverse,
1495 {'out_addr': out_addr,
1496 'out_port': out_port})
1498 def nat_det_map_dump(self):
1499 """Dump deterministic NAT mappings
1501 :return: Dictionary of deterministic NAT mappings
1503 return self.api(self.papi.nat_det_map_dump, {})
1505 def nat_det_set_timeouts(
1508 tcp_established=7440,
1511 """Set values of timeouts for deterministic NAT (in seconds)
1513 :param udp - UDP timeout (Default value = 300)
1514 :param tcp_established - TCP established timeout (Default value = 7440)
1515 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1516 :param icmp - ICMP timeout (Default value = 60)
1519 self.papi.nat_det_set_timeouts,
1521 'tcp_established': tcp_established,
1522 'tcp_transitory': tcp_transitory,
1525 def nat_det_get_timeouts(self):
1526 """Get values of timeouts for deterministic NAT
1528 :return: Timeouts for deterministic NAT (in seconds)
1530 return self.api(self.papi.nat_det_get_timeouts, {})
1532 def nat_det_close_session_out(
1538 """Close deterministic NAT session using outside address and port
1540 :param out_addr - outside IP address
1541 :param out_port - outside port
1542 :param ext_addr - external host IP address
1543 :param ext_port - external host port
1546 self.papi.nat_det_close_session_out,
1547 {'out_addr': out_addr,
1548 'out_port': out_port,
1549 'ext_addr': ext_addr,
1550 'ext_port': ext_port})
1552 def nat_det_close_session_in(
1558 """Close deterministic NAT session using inside address and port
1560 :param in_addr - inside IP address
1561 :param in_port - inside port
1562 :param ext_addr - external host IP address
1563 :param ext_port - external host port
1566 self.papi.nat_det_close_session_in,
1567 {'in_addr': in_addr,
1569 'ext_addr': ext_addr,
1570 'ext_port': ext_port,
1573 def nat_det_session_dump(
1576 """Dump deterministic NAT sessions belonging to a user
1578 :param user_addr - inside IP address of the user
1579 :return: Dictionary of deterministic NAT sessions
1582 self.papi.nat_det_session_dump,
1584 'user_addr': user_addr})
1586 def nat64_add_del_pool_addr_range(
1592 """Add/del address range to NAT64 pool
1594 :param start_addr: First IP address
1595 :param end_addr: Last IP address
1596 :param vrf_id: VRF id for the address range
1597 :param is_add: 1 if add, 0 if delete (Default value = 1)
1600 self.papi.nat64_add_del_pool_addr_range,
1601 {'start_addr': start_addr,
1602 'end_addr': end_addr,
1606 def nat64_pool_addr_dump(self):
1607 """Dump NAT64 pool addresses
1608 :return: Dictionary of NAT64 pool addresses
1610 return self.api(self.papi.nat64_pool_addr_dump, {})
1612 def nat64_add_del_interface(
1617 """Enable/disable NAT64 feature on the interface
1618 :param sw_if_index: Index of the interface
1619 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1620 :param is_add: 1 if add, 0 if delete (Default value = 1)
1623 self.papi.nat64_add_del_interface,
1624 {'sw_if_index': sw_if_index,
1625 'is_inside': is_inside,
1628 def nat64_interface_dump(self):
1629 """Dump interfaces with NAT64 feature
1630 :return: Dictionary of interfaces with NAT64 feature
1632 return self.api(self.papi.nat64_interface_dump, {})
1634 def nat64_add_del_static_bib(
1643 """Add/delete S-NAT static BIB entry
1645 :param in_ip: Inside IPv6 address
1646 :param out_ip: Outside IPv4 address
1647 :param in_port: Inside port number
1648 :param out_port: Outside port number
1649 :param protocol: IP protocol
1650 :param vrf_id: VRF ID (Default value = 0)
1651 :param is_add: 1 if add, 0 if delete (Default value = 1)
1654 self.papi.nat64_add_del_static_bib,
1663 def nat64_bib_dump(self, protocol=255):
1666 :param protocol: IP protocol (Default value = 255, all BIBs)
1667 :returns: Dictionary of NAT64 BIB entries
1669 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1671 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1672 tcp_incoming_syn=6):
1673 """Set values of timeouts for NAT64 (in seconds)
1675 :param udpi: UDP timeout (Default value = 300)
1676 :param icmp: ICMP timeout (Default value = 60)
1677 :param tcp_trans: TCP transitory timeout (Default value = 240)
1678 :param tcp_est: TCP established timeout (Default value = 7440)
1679 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
1682 self.papi.nat64_set_timeouts,
1685 'tcp_trans': tcp_trans,
1687 'tcp_incoming_syn': tcp_incoming_syn})
1689 def nat64_get_timeouts(self):
1690 """Get values of timeouts for NAT64
1692 :return: Timeouts for NAT64 (in seconds)
1694 return self.api(self.papi.nat64_get_timeouts, {})
1696 def nat64_st_dump(self, protocol=255):
1697 """Dump NAT64 session table
1699 :param protocol: IP protocol (Default value = 255, all STs)
1700 :returns: Dictionary of NAT64 sesstion table entries
1702 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1704 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1705 """Add/del NAT64 prefix
1707 :param prefix: NAT64 prefix
1708 :param plen: NAT64 prefix length
1709 :param vrf_id: VRF id of tenant (Default 0)
1710 :param is_add: 1 if add, 0 if delete (Default value = 1)
1713 self.papi.nat64_add_del_prefix,
1719 def nat64_prefix_dump(self):
1720 """Dump NAT64 prefix
1722 :returns: Dictionary of NAT64 prefixes
1724 return self.api(self.papi.nat64_prefix_dump, {})
1726 def dslite_set_aftr_addr(self, ip6, ip4):
1727 """Set DS-Lite AFTR addresses
1729 :param ip4: IPv4 address
1730 :param ip6: IPv6 address
1733 self.papi.dslite_set_aftr_addr,
1737 def dslite_add_del_pool_addr_range(
1742 """Add/del address range to DS-Lite pool
1744 :param start_addr: First IP address
1745 :param end_addr: Last IP address
1746 :param is_add: 1 if add, 0 if delete (Default value = 1)
1749 self.papi.dslite_add_del_pool_addr_range,
1750 {'start_addr': start_addr,
1751 'end_addr': end_addr,
1754 def control_ping(self):
1755 self.api(self.papi.control_ping)
1757 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
1758 detect_mult, local_addr, peer_addr, is_ipv6=0,
1759 bfd_key_id=None, conf_key_id=None):
1760 if bfd_key_id is None:
1761 return self.api(self.papi.bfd_udp_add,
1763 'sw_if_index': sw_if_index,
1764 'desired_min_tx': desired_min_tx,
1765 'required_min_rx': required_min_rx,
1766 'local_addr': local_addr,
1767 'peer_addr': peer_addr,
1769 'detect_mult': detect_mult,
1772 return self.api(self.papi.bfd_udp_add,
1774 'sw_if_index': sw_if_index,
1775 'desired_min_tx': desired_min_tx,
1776 'required_min_rx': required_min_rx,
1777 'local_addr': local_addr,
1778 'peer_addr': peer_addr,
1780 'detect_mult': detect_mult,
1781 'is_authenticated': 1,
1782 'bfd_key_id': bfd_key_id,
1783 'conf_key_id': conf_key_id,
1786 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1787 detect_mult, local_addr, peer_addr, is_ipv6=0):
1788 return self.api(self.papi.bfd_udp_mod,
1790 'sw_if_index': sw_if_index,
1791 'desired_min_tx': desired_min_tx,
1792 'required_min_rx': required_min_rx,
1793 'local_addr': local_addr,
1794 'peer_addr': peer_addr,
1796 'detect_mult': detect_mult,
1799 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1800 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1802 return self.api(self.papi.bfd_udp_auth_activate,
1804 'sw_if_index': sw_if_index,
1805 'local_addr': local_addr,
1806 'peer_addr': peer_addr,
1808 'is_delayed': 1 if is_delayed else 0,
1809 'bfd_key_id': bfd_key_id,
1810 'conf_key_id': conf_key_id,
1813 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1814 is_ipv6=0, is_delayed=False):
1815 return self.api(self.papi.bfd_udp_auth_deactivate,
1817 'sw_if_index': sw_if_index,
1818 'local_addr': local_addr,
1819 'peer_addr': peer_addr,
1821 'is_delayed': 1 if is_delayed else 0,
1824 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1825 return self.api(self.papi.bfd_udp_del,
1827 'sw_if_index': sw_if_index,
1828 'local_addr': local_addr,
1829 'peer_addr': peer_addr,
1833 def bfd_udp_session_dump(self):
1834 return self.api(self.papi.bfd_udp_session_dump, {})
1836 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1837 peer_addr, is_ipv6=0):
1838 return self.api(self.papi.bfd_udp_session_set_flags, {
1839 'admin_up_down': admin_up_down,
1840 'sw_if_index': sw_if_index,
1841 'local_addr': local_addr,
1842 'peer_addr': peer_addr,
1846 def want_bfd_events(self, enable_disable=1):
1847 return self.api(self.papi.want_bfd_events, {
1848 'enable_disable': enable_disable,
1852 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1853 return self.api(self.papi.bfd_auth_set_key, {
1854 'conf_key_id': conf_key_id,
1855 'auth_type': auth_type,
1857 'key_len': len(key),
1860 def bfd_auth_del_key(self, conf_key_id):
1861 return self.api(self.papi.bfd_auth_del_key, {
1862 'conf_key_id': conf_key_id,
1865 def bfd_auth_keys_dump(self):
1866 return self.api(self.papi.bfd_auth_keys_dump, {})
1868 def bfd_udp_set_echo_source(self, sw_if_index):
1869 return self.api(self.papi.bfd_udp_set_echo_source,
1870 {'sw_if_index': sw_if_index})
1872 def bfd_udp_del_echo_source(self):
1873 return self.api(self.papi.bfd_udp_del_echo_source, {})
1875 def classify_add_del_table(
1880 table_index=0xFFFFFFFF,
1882 memory_size=2097152,
1884 next_table_index=0xFFFFFFFF,
1885 miss_next_index=0xFFFFFFFF,
1886 current_data_flag=0,
1887 current_data_offset=0):
1891 :param match_n_vectors: (Default value = 1)
1892 :param table_index: (Default value = 0xFFFFFFFF)
1893 :param nbuckets: (Default value = 2)
1894 :param memory_size: (Default value = 2097152)
1895 :param skip_n_vectors: (Default value = 0)
1896 :param next_table_index: (Default value = 0xFFFFFFFF)
1897 :param miss_next_index: (Default value = 0xFFFFFFFF)
1898 :param current_data_flag: (Default value = 0)
1899 :param current_data_offset: (Default value = 0)
1903 self.papi.classify_add_del_table,
1905 'table_index': table_index,
1906 'nbuckets': nbuckets,
1907 'memory_size': memory_size,
1908 'skip_n_vectors': skip_n_vectors,
1909 'match_n_vectors': match_n_vectors,
1910 'next_table_index': next_table_index,
1911 'miss_next_index': miss_next_index,
1912 'current_data_flag': current_data_flag,
1913 'current_data_offset': current_data_offset,
1916 def classify_add_del_session(
1921 opaque_index=0xFFFFFFFF,
1922 hit_next_index=0xFFFFFFFF,
1930 :param opaque_index: (Default value = 0xFFFFFFFF)
1931 :param hit_next_index: (Default value = 0xFFFFFFFF)
1932 :param advance: (Default value = 0)
1933 :param action: (Default value = 0)
1934 :param metadata: (Default value = 0)
1938 self.papi.classify_add_del_session,
1940 'table_index': table_index,
1941 'hit_next_index': hit_next_index,
1942 'opaque_index': opaque_index,
1945 'metadata': metadata,
1948 def input_acl_set_interface(
1952 ip4_table_index=0xFFFFFFFF,
1953 ip6_table_index=0xFFFFFFFF,
1954 l2_table_index=0xFFFFFFFF):
1958 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1959 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1960 :param l2_table_index: (Default value = 0xFFFFFFFF)
1964 self.papi.input_acl_set_interface,
1965 {'sw_if_index': sw_if_index,
1966 'ip4_table_index': ip4_table_index,
1967 'ip6_table_index': ip6_table_index,
1968 'l2_table_index': l2_table_index,
1971 def set_ipfix_exporter(
1978 collector_port=4739,
1981 self.papi.set_ipfix_exporter,
1983 'collector_address': collector_address,
1984 'collector_port': collector_port,
1985 'src_address': src_address,
1987 'path_mtu': path_mtu,
1988 'template_interval': template_interval,
1989 'udp_checksum': udp_checksum,
1992 def dhcp_proxy_config(self,
2000 self.papi.dhcp_proxy_config,
2002 'rx_vrf_id': rx_table_id,
2003 'server_vrf_id': server_table_id,
2006 'dhcp_server': dhcp_server,
2007 'dhcp_src_address': dhcp_src_address,
2010 def dhcp_proxy_set_vss(self,
2017 self.papi.dhcp_proxy_set_vss,
2026 def dhcp_client(self,
2031 want_dhcp_events=0):
2033 self.papi.dhcp_client_config,
2035 'sw_if_index': sw_if_index,
2036 'hostname': hostname,
2037 'client_id': client_id,
2039 'want_dhcp_event': want_dhcp_events,
2043 def ip_mroute_add_del(self,
2048 next_hop_sw_if_index,
2058 self.papi.ip_mroute_add_del,
2059 {'next_hop_sw_if_index': next_hop_sw_if_index,
2060 'entry_flags': e_flags,
2061 'itf_flags': i_flags,
2062 'table_id': table_id,
2066 'is_local': is_local,
2067 'grp_address_length': grp_address_length,
2068 'grp_address': grp_address,
2069 'src_address': src_address})
2071 def mfib_signal_dump(self):
2072 return self.api(self.papi.mfib_signal_dump, {})
2074 def ip_mfib_dump(self):
2075 return self.api(self.papi.ip_mfib_dump, {})
2077 def lisp_enable_disable(self, is_enabled):
2079 self.papi.lisp_enable_disable,
2081 'is_en': is_enabled,
2084 def lisp_locator_set(self,
2088 self.papi.lisp_add_del_locator_set,
2091 'locator_set_name': ls_name
2094 def lisp_locator_set_dump(self):
2095 return self.api(self.papi.lisp_locator_set_dump, {})
2097 def lisp_locator(self,
2104 self.papi.lisp_add_del_locator,
2107 'locator_set_name': ls_name,
2108 'sw_if_index': sw_if_index,
2109 'priority': priority,
2113 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2115 self.papi.lisp_locator_dump,
2117 'is_index_set': is_index_set,
2119 'ls_index': ls_index,
2122 def lisp_local_mapping(self,
2132 self.papi.lisp_add_del_local_eid,
2134 'locator_set_name': ls_name,
2136 'eid_type': eid_type,
2138 'prefix_len': prefix_len,
2144 def lisp_eid_table_dump(self,
2152 self.papi.lisp_eid_table_dump,
2155 'prefix_length': prefix_length,
2157 'eid_type': eid_type,
2159 'filter': filter_opt,
2162 def lisp_remote_mapping(self,
2172 self.papi.lisp_add_del_remote_mapping,
2175 'eid_type': eid_type,
2177 'eid_len': eid_prefix_len,
2178 'rloc_num': rlocs_num,
2181 'is_src_dst': is_src_dst,
2184 def lisp_adjacency(self,
2193 self.papi.lisp_add_del_adjacency,
2197 'eid_type': eid_type,
2200 'leid_len': leid_len,
2201 'reid_len': reid_len,
2204 def lisp_adjacencies_get(self, vni=0):
2206 self.papi.lisp_adjacencies_get,
2211 def map_add_domain(self,
2224 self.papi.map_add_domain,
2226 'ip6_prefix': ip6_prefix,
2227 'ip6_prefix_len': ip6_prefix_len,
2228 'ip4_prefix': ip4_prefix,
2229 'ip4_prefix_len': ip4_prefix_len,
2231 'ip6_src_prefix_len': ip6_src_prefix_len,
2232 'ea_bits_len': ea_bits_len,
2233 'psid_offset': psid_offset,
2234 'psid_length': psid_length,
2235 'is_translation': is_translation,
2239 def gtpu_add_del_tunnel(
2245 mcast_sw_if_index=0xFFFFFFFF,
2247 decap_next_index=0xFFFFFFFF,
2251 :param is_add: (Default value = 1)
2252 :param is_ipv6: (Default value = 0)
2255 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2256 :param encap_vrf_id: (Default value = 0)
2257 :param decap_next_index: (Default value = 0xFFFFFFFF)
2258 :param teid: (Default value = 0)
2261 return self.api(self.papi.gtpu_add_del_tunnel,
2264 'src_address': src_addr,
2265 'dst_address': dst_addr,
2266 'mcast_sw_if_index': mcast_sw_if_index,
2267 'encap_vrf_id': encap_vrf_id,
2268 'decap_next_index': decap_next_index,
2271 def vxlan_gpe_add_del_tunnel(
2275 mcast_sw_if_index=0xFFFFFFFF,
2286 :param is_add: (Default value = 1)
2287 :param is_ipv6: (Default value = 0)
2288 :param encap_vrf_id: (Default value = 0)
2289 :param decap_vrf_id: (Default value = 0)
2290 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2291 :param protocol: (Default value = 3)
2292 :param vni: (Default value = 0)
2295 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2300 'mcast_sw_if_index': mcast_sw_if_index,
2301 'encap_vrf_id': encap_vrf_id,
2302 'decap_vrf_id': decap_vrf_id,
2303 'protocol': protocol,
2306 def pppoe_add_del_session(
2316 :param is_add: (Default value = 1)
2317 :param is_ipv6: (Default value = 0)
2319 :param session_id: (Default value = 0)
2321 :param decap_vrf_id: (Default value = 0)
2324 return self.api(self.papi.pppoe_add_del_session,
2327 'session_id': session_id,
2328 'client_ip': client_ip,
2329 'decap_vrf_id': decap_vrf_id,
2330 'client_mac': client_mac})
2332 def sr_localsid_add_del(self,
2338 sw_if_index=0xFFFFFFFF,
2342 """ Add/del IPv6 SR local-SID.
2344 :param localsid_addr:
2345 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2346 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2348 :param is_del: (Default value = 0)
2349 :param end_psp: (Default value = 0)
2350 :param sw_if_index: (Default value = 0xFFFFFFFF)
2351 :param vlan_index: (Default value = 0)
2352 :param fib_table: (Default value = 0)
2355 self.papi.sr_localsid_add_del,
2357 'localsid_addr': localsid_addr,
2359 'behavior': behavior,
2360 'sw_if_index': sw_if_index,
2361 'vlan_index': vlan_index,
2362 'fib_table': fib_table,
2377 :param bsid_addr: bindingSID of the SR Policy
2378 :param weight: weight of the sid list. optional. (default: 1)
2379 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2381 :param type: type/behavior of the SR policy. (default or spray) \
2383 :param fib_table: VRF where to install the FIB entry for the BSID \
2385 :param n_segments: number of segments \
2387 :param segments: a vector of IPv6 address composing the segment list \
2391 self.papi.sr_policy_add,
2392 {'bsid_addr': bsid_addr,
2394 'is_encap': is_encap,
2396 'fib_table': fib_table,
2397 'n_segments': n_segments,
2398 'segments': segments
2407 :param bsid: bindingSID of the SR Policy
2408 :param sr_policy_index: index of the sr policy (default: 0)
2411 self.papi.sr_policy_del,
2412 {'bsid_addr': bsid_addr,
2413 'sr_policy_index': sr_policy_index
2416 def sr_steering_add_del(
2427 Steer traffic L2 and L3 traffic through a given SR policy
2429 :param is_del: delete or add
2430 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2431 :param sr_policy: is the index of the SR Policy (alt to bsid)
2432 :param table_id: is the VRF where to install the FIB entry for the BSID
2433 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2434 :param mask_width: is the mask for L3 traffic type
2435 :param sw_if_index: is the incoming interface for L2 traffic
2436 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2439 self.papi.sr_steering_add_del,
2441 'bsid_addr': bsid_addr,
2442 'sr_policy_index': sr_policy_index,
2443 'table_id': table_id,
2444 'prefix_addr': prefix_addr,
2445 'mask_width': mask_width,
2446 'sw_if_index': sw_if_index,
2447 'traffic_type': traffic_type
2450 def acl_add_replace(self, acl_index, r, tag='',
2452 """Add/replace an ACL
2453 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2454 :param acl_rule r: ACL rules array.
2455 :param str tag: symbolic tag (description) for this ACL.
2456 :param int count: number of rules.
2458 return self.api(self.papi.acl_add_replace,
2459 {'acl_index': acl_index,
2463 expected_retval=expected_retval)
2465 def acl_del(self, acl_index, expected_retval=0):
2471 return self.api(self.papi.acl_del,
2472 {'acl_index': acl_index},
2473 expected_retval=expected_retval)
2475 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2477 return self.api(self.papi.acl_interface_set_acl_list,
2478 {'sw_if_index': sw_if_index,
2482 expected_retval=expected_retval)
2484 def acl_dump(self, acl_index, expected_retval=0):
2485 return self.api(self.papi.acl_dump,
2486 {'acl_index': acl_index},
2487 expected_retval=expected_retval)
2489 def macip_acl_add(self, rules, tag=""):
2492 :param rules: list of rules for given acl
2496 return self.api(self.papi.macip_acl_add,
2498 'count': len(rules),
2501 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2504 :param rules: list of rules for given acl
2508 return self.api(self.papi.macip_acl_add_replace,
2509 {'acl_index': acl_index,
2511 'count': len(rules),
2514 def macip_acl_del(self, acl_index):
2520 return self.api(self.papi.macip_acl_del,
2521 {'acl_index': acl_index})
2523 def macip_acl_interface_add_del(self,
2527 """ Add MACIP acl to interface
2531 :param is_add: (Default value = 1)
2534 return self.api(self.papi.macip_acl_interface_add_del,
2536 'sw_if_index': sw_if_index,
2537 'acl_index': acl_index})
2539 def macip_acl_interface_get(self):
2540 """ Return interface acls dump
2543 self.papi.macip_acl_interface_get, {})
2545 def macip_acl_dump(self, acl_index=4294967295):
2546 """ Return MACIP acl dump
2550 self.papi.macip_acl_dump, {'acl_index': acl_index})
2552 def policer_add_del(self,
2563 conform_action_type=1,
2565 exceed_action_type=0,
2567 violate_action_type=0,
2569 return self.api(self.papi.policer_add_del,
2576 'rate_type': rate_type,
2577 'round_type': round_type,
2579 'color_aware': color_aware,
2580 'conform_action_type': conform_action_type,
2581 'conform_dscp': conform_dscp,
2582 'exceed_action_type': exceed_action_type,
2583 'exceed_dscp': exceed_dscp,
2584 'violate_action_type': violate_action_type,
2585 'violate_dscp': violate_dscp})
2587 def ip_punt_police(self,
2591 return self.api(self.papi.ip_punt_police,
2592 {'policer_index': policer_index,
2596 def ip_punt_redirect(self,
2602 return self.api(self.papi.ip_punt_redirect,
2603 {'rx_sw_if_index': rx_sw_if_index,
2604 'tx_sw_if_index': tx_sw_if_index,