From fa1c3bd7ce26b2f601659c8da84c4eedbef3dbaa Mon Sep 17 00:00:00 2001 From: user Date: Mon, 14 Nov 2022 08:19:00 -0800 Subject: [PATCH 1/6] Adding refactoring of saineighbor.py --- ptf/sai_adapter.py | 47673 +++++++++++++++++++++++++++++++++++++++++ ptf/sai_base_test.py | 2 +- ptf/sai_utils.py | 2 +- ptf/saineighbor.py | 365 +- 4 files changed, 47953 insertions(+), 89 deletions(-) create mode 100644 ptf/sai_adapter.py diff --git a/ptf/sai_adapter.py b/ptf/sai_adapter.py new file mode 100644 index 000000000..e733dea99 --- /dev/null +++ b/ptf/sai_adapter.py @@ -0,0 +1,47673 @@ +# Copyright 2021-present Intel Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Thrift SAI interface basic tests +""" + +# This file is AUTO-GENERATED - do not edit it. +# pylint: disable=too-many-arguments,too-many-branches,global-statement +# pylint: disable=too-many-return-statements,line-too-long,invalid-name + +from sai_thrift.ttypes import * +from sai_thrift.sai_headers import * + +# Since RPC server started to throw exception, +# sai_adapter.CATCH_EXCEPTIONS can be set to True +# to enable backward compatibility. +# In order to catch exceptions and get error codes +# in the application, it should be disabled. +CATCH_EXCEPTIONS = True +status = 0 + + +# acl API + +def sai_thrift_create_acl_table(client, + acl_stage=None, + acl_bind_point_type_list=None, + size=None, + acl_action_type_list=None, + field_src_ipv6=None, + field_src_ipv6_word3=None, + field_src_ipv6_word2=None, + field_src_ipv6_word1=None, + field_src_ipv6_word0=None, + field_dst_ipv6=None, + field_dst_ipv6_word3=None, + field_dst_ipv6_word2=None, + field_dst_ipv6_word1=None, + field_dst_ipv6_word0=None, + field_inner_src_ipv6=None, + field_inner_dst_ipv6=None, + field_src_mac=None, + field_dst_mac=None, + field_src_ip=None, + field_dst_ip=None, + field_inner_src_ip=None, + field_inner_dst_ip=None, + field_in_ports=None, + field_out_ports=None, + field_in_port=None, + field_out_port=None, + field_src_port=None, + field_outer_vlan_id=None, + field_outer_vlan_pri=None, + field_outer_vlan_cfi=None, + field_inner_vlan_id=None, + field_inner_vlan_pri=None, + field_inner_vlan_cfi=None, + field_l4_src_port=None, + field_l4_dst_port=None, + field_inner_l4_src_port=None, + field_inner_l4_dst_port=None, + field_ether_type=None, + field_inner_ether_type=None, + field_ip_protocol=None, + field_inner_ip_protocol=None, + field_ip_identification=None, + field_dscp=None, + field_ecn=None, + field_ttl=None, + field_tos=None, + field_ip_flags=None, + field_tcp_flags=None, + field_acl_ip_type=None, + field_acl_ip_frag=None, + field_ipv6_flow_label=None, + field_tc=None, + field_icmp_type=None, + field_icmp_code=None, + field_icmpv6_type=None, + field_icmpv6_code=None, + field_packet_vlan=None, + field_tunnel_vni=None, + field_has_vlan_tag=None, + field_macsec_sci=None, + field_mpls_label0_label=None, + field_mpls_label0_ttl=None, + field_mpls_label0_exp=None, + field_mpls_label0_bos=None, + field_mpls_label1_label=None, + field_mpls_label1_ttl=None, + field_mpls_label1_exp=None, + field_mpls_label1_bos=None, + field_mpls_label2_label=None, + field_mpls_label2_ttl=None, + field_mpls_label2_exp=None, + field_mpls_label2_bos=None, + field_mpls_label3_label=None, + field_mpls_label3_ttl=None, + field_mpls_label3_exp=None, + field_mpls_label3_bos=None, + field_mpls_label4_label=None, + field_mpls_label4_ttl=None, + field_mpls_label4_exp=None, + field_mpls_label4_bos=None, + field_fdb_dst_user_meta=None, + field_route_dst_user_meta=None, + field_neighbor_dst_user_meta=None, + field_port_user_meta=None, + field_vlan_user_meta=None, + field_acl_user_meta=None, + field_fdb_npu_meta_dst_hit=None, + field_neighbor_npu_meta_dst_hit=None, + field_route_npu_meta_dst_hit=None, + field_bth_opcode=None, + field_aeth_syndrome=None, + user_defined_field_group_min=None, + user_defined_field_group_max=None, + field_acl_range_type=None, + field_ipv6_next_header=None, + field_gre_key=None, + field_tam_int_type=None, + custom_attribute=None): + """ + sai_create_acl_table() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of acl_table CREATE attributes. + + Returns: + sai_thrift_object_id_t: acl_table_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if acl_stage is not None: + attribute_value = sai_thrift_attribute_value_t(s32=acl_stage) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_STAGE, + value=attribute_value) + attr_list.append(attribute) + + if acl_bind_point_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=acl_bind_point_type_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if size is not None: + attribute_value = sai_thrift_attribute_value_t(u32=size) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if acl_action_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=acl_action_type_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word3 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_ipv6_word3) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD3, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word2 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_ipv6_word2) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD2, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word1 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_ipv6_word1) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD1, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word0 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_ipv6_word0) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD0, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word3 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_ipv6_word3) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD3, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word2 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_ipv6_word2) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD2, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word1 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_ipv6_word1) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD1, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word0 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_ipv6_word0) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD0, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_src_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_src_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_dst_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_dst_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_src_mac is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_mac) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_MAC, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_mac is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_mac) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_MAC, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_in_ports is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_in_ports) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IN_PORTS, + value=attribute_value) + attr_list.append(attribute) + + if field_out_ports is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_out_ports) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUT_PORTS, + value=attribute_value) + attr_list.append(attribute) + + if field_in_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_in_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IN_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_out_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_out_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUT_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_outer_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_outer_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if field_outer_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_outer_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if field_outer_vlan_cfi is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_outer_vlan_cfi) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_CFI, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_vlan_cfi is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_vlan_cfi) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_CFI, + value=attribute_value) + attr_list.append(attribute) + + if field_l4_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_l4_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_L4_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_l4_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_l4_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_L4_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_l4_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_l4_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_l4_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_l4_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_ether_type is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ether_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_ether_type is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_ether_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_ETHER_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_ip_protocol is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ip_protocol) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_ip_protocol is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_inner_ip_protocol) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_IP_PROTOCOL, + value=attribute_value) + attr_list.append(attribute) + + if field_ip_identification is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ip_identification) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IP_IDENTIFICATION, + value=attribute_value) + attr_list.append(attribute) + + if field_dscp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_dscp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DSCP, + value=attribute_value) + attr_list.append(attribute) + + if field_ecn is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ecn) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ECN, + value=attribute_value) + attr_list.append(attribute) + + if field_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_tos is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_tos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TOS, + value=attribute_value) + attr_list.append(attribute) + + if field_ip_flags is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ip_flags) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IP_FLAGS, + value=attribute_value) + attr_list.append(attribute) + + if field_tcp_flags is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_tcp_flags) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TCP_FLAGS, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_ip_type is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_acl_ip_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_ip_frag is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_acl_ip_frag) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_FRAG, + value=attribute_value) + attr_list.append(attribute) + + if field_ipv6_flow_label is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ipv6_flow_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IPV6_FLOW_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_tc is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_tc) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TC, + value=attribute_value) + attr_list.append(attribute) + + if field_icmp_type is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_icmp_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMP_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_icmp_code is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_icmp_code) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE, + value=attribute_value) + attr_list.append(attribute) + + if field_icmpv6_type is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_icmpv6_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_icmpv6_code is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_icmpv6_code) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_CODE, + value=attribute_value) + attr_list.append(attribute) + + if field_packet_vlan is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_packet_vlan) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_PACKET_VLAN, + value=attribute_value) + attr_list.append(attribute) + + if field_tunnel_vni is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_tunnel_vni) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TUNNEL_VNI, + value=attribute_value) + attr_list.append(attribute) + + if field_has_vlan_tag is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_has_vlan_tag) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_HAS_VLAN_TAG, + value=attribute_value) + attr_list.append(attribute) + + if field_macsec_sci is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_macsec_sci) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_label is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label0_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label0_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_exp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label0_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_bos is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label0_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_label is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label1_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label1_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_exp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label1_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_bos is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label1_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_label is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label2_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label2_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_exp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label2_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_bos is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label2_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_label is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label3_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label3_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_exp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label3_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_bos is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label3_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_label is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label4_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label4_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_exp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label4_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_bos is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_mpls_label4_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_fdb_dst_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_fdb_dst_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_FDB_DST_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_route_dst_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_route_dst_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ROUTE_DST_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_neighbor_dst_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_neighbor_dst_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_DST_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_port_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_port_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_PORT_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_vlan_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_vlan_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_VLAN_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_acl_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_fdb_npu_meta_dst_hit is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_fdb_npu_meta_dst_hit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_FDB_NPU_META_DST_HIT, + value=attribute_value) + attr_list.append(attribute) + + if field_neighbor_npu_meta_dst_hit is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_neighbor_npu_meta_dst_hit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT, + value=attribute_value) + attr_list.append(attribute) + + if field_route_npu_meta_dst_hit is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_route_npu_meta_dst_hit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ROUTE_NPU_META_DST_HIT, + value=attribute_value) + attr_list.append(attribute) + + if field_bth_opcode is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_bth_opcode) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_BTH_OPCODE, + value=attribute_value) + attr_list.append(attribute) + + if field_aeth_syndrome is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_aeth_syndrome) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_AETH_SYNDROME, + value=attribute_value) + attr_list.append(attribute) + + if user_defined_field_group_min is not None: + attribute_value = sai_thrift_attribute_value_t(oid=user_defined_field_group_min) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MIN, + value=attribute_value) + attr_list.append(attribute) + + if user_defined_field_group_max is not None: + attribute_value = sai_thrift_attribute_value_t(oid=user_defined_field_group_max) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MAX, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_range_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=field_acl_range_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_ipv6_next_header is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_ipv6_next_header) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IPV6_NEXT_HEADER, + value=attribute_value) + attr_list.append(attribute) + + if field_gre_key is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_gre_key) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_GRE_KEY, + value=attribute_value) + attr_list.append(attribute) + + if field_tam_int_type is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=field_tam_int_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TAM_INT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_acl_table(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_acl_table(client, + acl_table_oid): + """ + sai_remove_acl_table() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + acl_table_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_acl_table(acl_table_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_acl_table_attribute(client, + acl_table_oid, + custom_attribute=None): + """ + sai_set_acl_table_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + acl_table_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del acl_table_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_acl_table_attribute(client, + acl_table_oid, + acl_stage=None, + acl_bind_point_type_list=None, + size=None, + acl_action_type_list=None, + field_src_ipv6=None, + field_src_ipv6_word3=None, + field_src_ipv6_word2=None, + field_src_ipv6_word1=None, + field_src_ipv6_word0=None, + field_dst_ipv6=None, + field_dst_ipv6_word3=None, + field_dst_ipv6_word2=None, + field_dst_ipv6_word1=None, + field_dst_ipv6_word0=None, + field_inner_src_ipv6=None, + field_inner_dst_ipv6=None, + field_src_mac=None, + field_dst_mac=None, + field_src_ip=None, + field_dst_ip=None, + field_inner_src_ip=None, + field_inner_dst_ip=None, + field_in_ports=None, + field_out_ports=None, + field_in_port=None, + field_out_port=None, + field_src_port=None, + field_outer_vlan_id=None, + field_outer_vlan_pri=None, + field_outer_vlan_cfi=None, + field_inner_vlan_id=None, + field_inner_vlan_pri=None, + field_inner_vlan_cfi=None, + field_l4_src_port=None, + field_l4_dst_port=None, + field_inner_l4_src_port=None, + field_inner_l4_dst_port=None, + field_ether_type=None, + field_inner_ether_type=None, + field_ip_protocol=None, + field_inner_ip_protocol=None, + field_ip_identification=None, + field_dscp=None, + field_ecn=None, + field_ttl=None, + field_tos=None, + field_ip_flags=None, + field_tcp_flags=None, + field_acl_ip_type=None, + field_acl_ip_frag=None, + field_ipv6_flow_label=None, + field_tc=None, + field_icmp_type=None, + field_icmp_code=None, + field_icmpv6_type=None, + field_icmpv6_code=None, + field_packet_vlan=None, + field_tunnel_vni=None, + field_has_vlan_tag=None, + field_macsec_sci=None, + field_mpls_label0_label=None, + field_mpls_label0_ttl=None, + field_mpls_label0_exp=None, + field_mpls_label0_bos=None, + field_mpls_label1_label=None, + field_mpls_label1_ttl=None, + field_mpls_label1_exp=None, + field_mpls_label1_bos=None, + field_mpls_label2_label=None, + field_mpls_label2_ttl=None, + field_mpls_label2_exp=None, + field_mpls_label2_bos=None, + field_mpls_label3_label=None, + field_mpls_label3_ttl=None, + field_mpls_label3_exp=None, + field_mpls_label3_bos=None, + field_mpls_label4_label=None, + field_mpls_label4_ttl=None, + field_mpls_label4_exp=None, + field_mpls_label4_bos=None, + field_fdb_dst_user_meta=None, + field_route_dst_user_meta=None, + field_neighbor_dst_user_meta=None, + field_port_user_meta=None, + field_vlan_user_meta=None, + field_acl_user_meta=None, + field_fdb_npu_meta_dst_hit=None, + field_neighbor_npu_meta_dst_hit=None, + field_route_npu_meta_dst_hit=None, + field_bth_opcode=None, + field_aeth_syndrome=None, + user_defined_field_group_min=None, + user_defined_field_group_max=None, + field_acl_range_type=None, + field_ipv6_next_header=None, + field_gre_key=None, + field_tam_int_type=None, + entry_list=None, + available_acl_entry=None, + available_acl_counter=None, + custom_attribute=None): + """ + sai_get_acl_table_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + acl_table_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_table GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if acl_stage is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_STAGE) + attr_list.append(attribute) + + if acl_bind_point_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=acl_bind_point_type_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if size is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_SIZE) + attr_list.append(attribute) + + if acl_action_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=acl_action_type_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6) + attr_list.append(attribute) + + if field_src_ipv6_word3 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD3) + attr_list.append(attribute) + + if field_src_ipv6_word2 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD2) + attr_list.append(attribute) + + if field_src_ipv6_word1 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD1) + attr_list.append(attribute) + + if field_src_ipv6_word0 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD0) + attr_list.append(attribute) + + if field_dst_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6) + attr_list.append(attribute) + + if field_dst_ipv6_word3 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD3) + attr_list.append(attribute) + + if field_dst_ipv6_word2 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD2) + attr_list.append(attribute) + + if field_dst_ipv6_word1 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD1) + attr_list.append(attribute) + + if field_dst_ipv6_word0 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD0) + attr_list.append(attribute) + + if field_inner_src_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IPV6) + attr_list.append(attribute) + + if field_inner_dst_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IPV6) + attr_list.append(attribute) + + if field_src_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_MAC) + attr_list.append(attribute) + + if field_dst_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_MAC) + attr_list.append(attribute) + + if field_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_IP) + attr_list.append(attribute) + + if field_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DST_IP) + attr_list.append(attribute) + + if field_inner_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IP) + attr_list.append(attribute) + + if field_inner_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IP) + attr_list.append(attribute) + + if field_in_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IN_PORTS) + attr_list.append(attribute) + + if field_out_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUT_PORTS) + attr_list.append(attribute) + + if field_in_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IN_PORT) + attr_list.append(attribute) + + if field_out_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUT_PORT) + attr_list.append(attribute) + + if field_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_SRC_PORT) + attr_list.append(attribute) + + if field_outer_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_ID) + attr_list.append(attribute) + + if field_outer_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_PRI) + attr_list.append(attribute) + + if field_outer_vlan_cfi is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_CFI) + attr_list.append(attribute) + + if field_inner_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_ID) + attr_list.append(attribute) + + if field_inner_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_PRI) + attr_list.append(attribute) + + if field_inner_vlan_cfi is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_CFI) + attr_list.append(attribute) + + if field_l4_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_L4_SRC_PORT) + attr_list.append(attribute) + + if field_l4_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_L4_DST_PORT) + attr_list.append(attribute) + + if field_inner_l4_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_SRC_PORT) + attr_list.append(attribute) + + if field_inner_l4_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_DST_PORT) + attr_list.append(attribute) + + if field_ether_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE) + attr_list.append(attribute) + + if field_inner_ether_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_ETHER_TYPE) + attr_list.append(attribute) + + if field_ip_protocol is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL) + attr_list.append(attribute) + + if field_inner_ip_protocol is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_INNER_IP_PROTOCOL) + attr_list.append(attribute) + + if field_ip_identification is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IP_IDENTIFICATION) + attr_list.append(attribute) + + if field_dscp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_DSCP) + attr_list.append(attribute) + + if field_ecn is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ECN) + attr_list.append(attribute) + + if field_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TTL) + attr_list.append(attribute) + + if field_tos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TOS) + attr_list.append(attribute) + + if field_ip_flags is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IP_FLAGS) + attr_list.append(attribute) + + if field_tcp_flags is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TCP_FLAGS) + attr_list.append(attribute) + + if field_acl_ip_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE) + attr_list.append(attribute) + + if field_acl_ip_frag is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_FRAG) + attr_list.append(attribute) + + if field_ipv6_flow_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IPV6_FLOW_LABEL) + attr_list.append(attribute) + + if field_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TC) + attr_list.append(attribute) + + if field_icmp_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMP_TYPE) + attr_list.append(attribute) + + if field_icmp_code is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE) + attr_list.append(attribute) + + if field_icmpv6_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_TYPE) + attr_list.append(attribute) + + if field_icmpv6_code is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_CODE) + attr_list.append(attribute) + + if field_packet_vlan is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_PACKET_VLAN) + attr_list.append(attribute) + + if field_tunnel_vni is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TUNNEL_VNI) + attr_list.append(attribute) + + if field_has_vlan_tag is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_HAS_VLAN_TAG) + attr_list.append(attribute) + + if field_macsec_sci is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI) + attr_list.append(attribute) + + if field_mpls_label0_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_LABEL) + attr_list.append(attribute) + + if field_mpls_label0_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_TTL) + attr_list.append(attribute) + + if field_mpls_label0_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_EXP) + attr_list.append(attribute) + + if field_mpls_label0_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_BOS) + attr_list.append(attribute) + + if field_mpls_label1_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_LABEL) + attr_list.append(attribute) + + if field_mpls_label1_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_TTL) + attr_list.append(attribute) + + if field_mpls_label1_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_EXP) + attr_list.append(attribute) + + if field_mpls_label1_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_BOS) + attr_list.append(attribute) + + if field_mpls_label2_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_LABEL) + attr_list.append(attribute) + + if field_mpls_label2_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_TTL) + attr_list.append(attribute) + + if field_mpls_label2_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_EXP) + attr_list.append(attribute) + + if field_mpls_label2_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_BOS) + attr_list.append(attribute) + + if field_mpls_label3_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_LABEL) + attr_list.append(attribute) + + if field_mpls_label3_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_TTL) + attr_list.append(attribute) + + if field_mpls_label3_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_EXP) + attr_list.append(attribute) + + if field_mpls_label3_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_BOS) + attr_list.append(attribute) + + if field_mpls_label4_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_LABEL) + attr_list.append(attribute) + + if field_mpls_label4_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_TTL) + attr_list.append(attribute) + + if field_mpls_label4_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_EXP) + attr_list.append(attribute) + + if field_mpls_label4_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_BOS) + attr_list.append(attribute) + + if field_fdb_dst_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_FDB_DST_USER_META) + attr_list.append(attribute) + + if field_route_dst_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ROUTE_DST_USER_META) + attr_list.append(attribute) + + if field_neighbor_dst_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_DST_USER_META) + attr_list.append(attribute) + + if field_port_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_PORT_USER_META) + attr_list.append(attribute) + + if field_vlan_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_VLAN_USER_META) + attr_list.append(attribute) + + if field_acl_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_USER_META) + attr_list.append(attribute) + + if field_fdb_npu_meta_dst_hit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_FDB_NPU_META_DST_HIT) + attr_list.append(attribute) + + if field_neighbor_npu_meta_dst_hit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT) + attr_list.append(attribute) + + if field_route_npu_meta_dst_hit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ROUTE_NPU_META_DST_HIT) + attr_list.append(attribute) + + if field_bth_opcode is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_BTH_OPCODE) + attr_list.append(attribute) + + if field_aeth_syndrome is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_AETH_SYNDROME) + attr_list.append(attribute) + + if user_defined_field_group_min is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MIN) + attr_list.append(attribute) + + if user_defined_field_group_max is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MAX) + attr_list.append(attribute) + + if field_acl_range_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=field_acl_range_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_ipv6_next_header is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_IPV6_NEXT_HEADER) + attr_list.append(attribute) + + if field_gre_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_GRE_KEY) + attr_list.append(attribute) + + if field_tam_int_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_FIELD_TAM_INT_TYPE) + attr_list.append(attribute) + + if entry_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=entry_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_ENTRY_LIST, + value=attribute_value) + attr_list.append(attribute) + + if available_acl_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_ENTRY) + attr_list.append(attribute) + + if available_acl_counter is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_COUNTER) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_acl_table_attribute(acl_table_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ACL_TABLE_ATTR_ACL_STAGE: + attrs["SAI_ACL_TABLE_ATTR_ACL_STAGE"] = attr.value.s32 + attrs["acl_stage"] = attr.value.s32 + + if attr.id == SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST: + attrs["SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST"] = attr.value.s32list + attrs["acl_bind_point_type_list"] = attr.value.s32list + + if attr.id == SAI_ACL_TABLE_ATTR_SIZE: + attrs["SAI_ACL_TABLE_ATTR_SIZE"] = attr.value.u32 + attrs["size"] = attr.value.u32 + + if attr.id == SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST: + attrs["SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST"] = attr.value.s32list + attrs["acl_action_type_list"] = attr.value.s32list + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6"] = attr.value.booldata + attrs["field_src_ipv6"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD3: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD3"] = attr.value.booldata + attrs["field_src_ipv6_word3"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD2: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD2"] = attr.value.booldata + attrs["field_src_ipv6_word2"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD1: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD1"] = attr.value.booldata + attrs["field_src_ipv6_word1"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD0: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6_WORD0"] = attr.value.booldata + attrs["field_src_ipv6_word0"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6"] = attr.value.booldata + attrs["field_dst_ipv6"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD3: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD3"] = attr.value.booldata + attrs["field_dst_ipv6_word3"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD2: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD2"] = attr.value.booldata + attrs["field_dst_ipv6_word2"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD1: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD1"] = attr.value.booldata + attrs["field_dst_ipv6_word1"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD0: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6_WORD0"] = attr.value.booldata + attrs["field_dst_ipv6_word0"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IPV6: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IPV6"] = attr.value.booldata + attrs["field_inner_src_ipv6"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IPV6: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IPV6"] = attr.value.booldata + attrs["field_inner_dst_ipv6"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_MAC: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_MAC"] = attr.value.booldata + attrs["field_src_mac"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_MAC: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_MAC"] = attr.value.booldata + attrs["field_dst_mac"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_IP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_IP"] = attr.value.booldata + attrs["field_src_ip"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DST_IP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DST_IP"] = attr.value.booldata + attrs["field_dst_ip"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_SRC_IP"] = attr.value.booldata + attrs["field_inner_src_ip"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_DST_IP"] = attr.value.booldata + attrs["field_inner_dst_ip"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IN_PORTS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IN_PORTS"] = attr.value.booldata + attrs["field_in_ports"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_OUT_PORTS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_OUT_PORTS"] = attr.value.booldata + attrs["field_out_ports"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IN_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IN_PORT"] = attr.value.booldata + attrs["field_in_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_OUT_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_OUT_PORT"] = attr.value.booldata + attrs["field_out_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_SRC_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_SRC_PORT"] = attr.value.booldata + attrs["field_src_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_ID: + attrs["SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_ID"] = attr.value.booldata + attrs["field_outer_vlan_id"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_PRI: + attrs["SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_PRI"] = attr.value.booldata + attrs["field_outer_vlan_pri"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_CFI: + attrs["SAI_ACL_TABLE_ATTR_FIELD_OUTER_VLAN_CFI"] = attr.value.booldata + attrs["field_outer_vlan_cfi"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_ID: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_ID"] = attr.value.booldata + attrs["field_inner_vlan_id"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_PRI: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_PRI"] = attr.value.booldata + attrs["field_inner_vlan_pri"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_CFI: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_VLAN_CFI"] = attr.value.booldata + attrs["field_inner_vlan_cfi"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_L4_SRC_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_L4_SRC_PORT"] = attr.value.booldata + attrs["field_l4_src_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_L4_DST_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_L4_DST_PORT"] = attr.value.booldata + attrs["field_l4_dst_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_SRC_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_SRC_PORT"] = attr.value.booldata + attrs["field_inner_l4_src_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_DST_PORT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_L4_DST_PORT"] = attr.value.booldata + attrs["field_inner_l4_dst_port"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE"] = attr.value.booldata + attrs["field_ether_type"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_ETHER_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_ETHER_TYPE"] = attr.value.booldata + attrs["field_inner_ether_type"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL"] = attr.value.booldata + attrs["field_ip_protocol"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_INNER_IP_PROTOCOL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_INNER_IP_PROTOCOL"] = attr.value.booldata + attrs["field_inner_ip_protocol"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IP_IDENTIFICATION: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IP_IDENTIFICATION"] = attr.value.booldata + attrs["field_ip_identification"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_DSCP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_DSCP"] = attr.value.booldata + attrs["field_dscp"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ECN: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ECN"] = attr.value.booldata + attrs["field_ecn"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_TTL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_TTL"] = attr.value.booldata + attrs["field_ttl"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_TOS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_TOS"] = attr.value.booldata + attrs["field_tos"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IP_FLAGS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IP_FLAGS"] = attr.value.booldata + attrs["field_ip_flags"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_TCP_FLAGS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_TCP_FLAGS"] = attr.value.booldata + attrs["field_tcp_flags"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE"] = attr.value.booldata + attrs["field_acl_ip_type"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_FRAG: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_FRAG"] = attr.value.booldata + attrs["field_acl_ip_frag"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IPV6_FLOW_LABEL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IPV6_FLOW_LABEL"] = attr.value.booldata + attrs["field_ipv6_flow_label"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_TC: + attrs["SAI_ACL_TABLE_ATTR_FIELD_TC"] = attr.value.booldata + attrs["field_tc"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ICMP_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ICMP_TYPE"] = attr.value.booldata + attrs["field_icmp_type"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE"] = attr.value.booldata + attrs["field_icmp_code"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_TYPE"] = attr.value.booldata + attrs["field_icmpv6_type"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_CODE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_CODE"] = attr.value.booldata + attrs["field_icmpv6_code"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_PACKET_VLAN: + attrs["SAI_ACL_TABLE_ATTR_FIELD_PACKET_VLAN"] = attr.value.booldata + attrs["field_packet_vlan"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_TUNNEL_VNI: + attrs["SAI_ACL_TABLE_ATTR_FIELD_TUNNEL_VNI"] = attr.value.booldata + attrs["field_tunnel_vni"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_HAS_VLAN_TAG: + attrs["SAI_ACL_TABLE_ATTR_FIELD_HAS_VLAN_TAG"] = attr.value.booldata + attrs["field_has_vlan_tag"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MACSEC_SCI"] = attr.value.booldata + attrs["field_macsec_sci"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_LABEL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_LABEL"] = attr.value.booldata + attrs["field_mpls_label0_label"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_TTL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_TTL"] = attr.value.booldata + attrs["field_mpls_label0_ttl"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_EXP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_EXP"] = attr.value.booldata + attrs["field_mpls_label0_exp"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_BOS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL0_BOS"] = attr.value.booldata + attrs["field_mpls_label0_bos"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_LABEL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_LABEL"] = attr.value.booldata + attrs["field_mpls_label1_label"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_TTL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_TTL"] = attr.value.booldata + attrs["field_mpls_label1_ttl"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_EXP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_EXP"] = attr.value.booldata + attrs["field_mpls_label1_exp"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_BOS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL1_BOS"] = attr.value.booldata + attrs["field_mpls_label1_bos"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_LABEL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_LABEL"] = attr.value.booldata + attrs["field_mpls_label2_label"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_TTL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_TTL"] = attr.value.booldata + attrs["field_mpls_label2_ttl"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_EXP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_EXP"] = attr.value.booldata + attrs["field_mpls_label2_exp"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_BOS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL2_BOS"] = attr.value.booldata + attrs["field_mpls_label2_bos"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_LABEL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_LABEL"] = attr.value.booldata + attrs["field_mpls_label3_label"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_TTL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_TTL"] = attr.value.booldata + attrs["field_mpls_label3_ttl"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_EXP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_EXP"] = attr.value.booldata + attrs["field_mpls_label3_exp"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_BOS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL3_BOS"] = attr.value.booldata + attrs["field_mpls_label3_bos"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_LABEL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_LABEL"] = attr.value.booldata + attrs["field_mpls_label4_label"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_TTL: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_TTL"] = attr.value.booldata + attrs["field_mpls_label4_ttl"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_EXP: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_EXP"] = attr.value.booldata + attrs["field_mpls_label4_exp"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_BOS: + attrs["SAI_ACL_TABLE_ATTR_FIELD_MPLS_LABEL4_BOS"] = attr.value.booldata + attrs["field_mpls_label4_bos"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_FDB_DST_USER_META: + attrs["SAI_ACL_TABLE_ATTR_FIELD_FDB_DST_USER_META"] = attr.value.booldata + attrs["field_fdb_dst_user_meta"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ROUTE_DST_USER_META: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ROUTE_DST_USER_META"] = attr.value.booldata + attrs["field_route_dst_user_meta"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_DST_USER_META: + attrs["SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_DST_USER_META"] = attr.value.booldata + attrs["field_neighbor_dst_user_meta"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_PORT_USER_META: + attrs["SAI_ACL_TABLE_ATTR_FIELD_PORT_USER_META"] = attr.value.booldata + attrs["field_port_user_meta"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_VLAN_USER_META: + attrs["SAI_ACL_TABLE_ATTR_FIELD_VLAN_USER_META"] = attr.value.booldata + attrs["field_vlan_user_meta"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ACL_USER_META: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ACL_USER_META"] = attr.value.booldata + attrs["field_acl_user_meta"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_FDB_NPU_META_DST_HIT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_FDB_NPU_META_DST_HIT"] = attr.value.booldata + attrs["field_fdb_npu_meta_dst_hit"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT"] = attr.value.booldata + attrs["field_neighbor_npu_meta_dst_hit"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ROUTE_NPU_META_DST_HIT: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ROUTE_NPU_META_DST_HIT"] = attr.value.booldata + attrs["field_route_npu_meta_dst_hit"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_BTH_OPCODE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_BTH_OPCODE"] = attr.value.booldata + attrs["field_bth_opcode"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_AETH_SYNDROME: + attrs["SAI_ACL_TABLE_ATTR_FIELD_AETH_SYNDROME"] = attr.value.booldata + attrs["field_aeth_syndrome"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MIN: + attrs["SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MIN"] = attr.value.oid + attrs["user_defined_field_group_min"] = attr.value.oid + + if attr.id == SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MAX: + attrs["SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MAX"] = attr.value.oid + attrs["user_defined_field_group_max"] = attr.value.oid + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE"] = attr.value.s32list + attrs["field_acl_range_type"] = attr.value.s32list + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_IPV6_NEXT_HEADER: + attrs["SAI_ACL_TABLE_ATTR_FIELD_IPV6_NEXT_HEADER"] = attr.value.booldata + attrs["field_ipv6_next_header"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_GRE_KEY: + attrs["SAI_ACL_TABLE_ATTR_FIELD_GRE_KEY"] = attr.value.booldata + attrs["field_gre_key"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_FIELD_TAM_INT_TYPE: + attrs["SAI_ACL_TABLE_ATTR_FIELD_TAM_INT_TYPE"] = attr.value.booldata + attrs["field_tam_int_type"] = attr.value.booldata + + if attr.id == SAI_ACL_TABLE_ATTR_ENTRY_LIST: + attrs["SAI_ACL_TABLE_ATTR_ENTRY_LIST"] = attr.value.objlist + attrs["entry_list"] = attr.value.objlist + + if attr.id == SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_ENTRY: + attrs["SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_ENTRY"] = attr.value.u32 + attrs["available_acl_entry"] = attr.value.u32 + + if attr.id == SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_COUNTER: + attrs["SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_COUNTER"] = attr.value.u32 + attrs["available_acl_counter"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_acl_entry(client, + table_id=None, + priority=None, + admin_state=None, + field_src_ipv6=None, + field_src_ipv6_word3=None, + field_src_ipv6_word2=None, + field_src_ipv6_word1=None, + field_src_ipv6_word0=None, + field_dst_ipv6=None, + field_dst_ipv6_word3=None, + field_dst_ipv6_word2=None, + field_dst_ipv6_word1=None, + field_dst_ipv6_word0=None, + field_inner_src_ipv6=None, + field_inner_dst_ipv6=None, + field_src_mac=None, + field_dst_mac=None, + field_src_ip=None, + field_dst_ip=None, + field_inner_src_ip=None, + field_inner_dst_ip=None, + field_in_ports=None, + field_out_ports=None, + field_in_port=None, + field_out_port=None, + field_src_port=None, + field_outer_vlan_id=None, + field_outer_vlan_pri=None, + field_outer_vlan_cfi=None, + field_inner_vlan_id=None, + field_inner_vlan_pri=None, + field_inner_vlan_cfi=None, + field_l4_src_port=None, + field_l4_dst_port=None, + field_inner_l4_src_port=None, + field_inner_l4_dst_port=None, + field_ether_type=None, + field_inner_ether_type=None, + field_ip_protocol=None, + field_inner_ip_protocol=None, + field_ip_identification=None, + field_dscp=None, + field_ecn=None, + field_ttl=None, + field_tos=None, + field_ip_flags=None, + field_tcp_flags=None, + field_acl_ip_type=None, + field_acl_ip_frag=None, + field_ipv6_flow_label=None, + field_tc=None, + field_icmp_type=None, + field_icmp_code=None, + field_icmpv6_type=None, + field_icmpv6_code=None, + field_packet_vlan=None, + field_tunnel_vni=None, + field_has_vlan_tag=None, + field_macsec_sci=None, + field_mpls_label0_label=None, + field_mpls_label0_ttl=None, + field_mpls_label0_exp=None, + field_mpls_label0_bos=None, + field_mpls_label1_label=None, + field_mpls_label1_ttl=None, + field_mpls_label1_exp=None, + field_mpls_label1_bos=None, + field_mpls_label2_label=None, + field_mpls_label2_ttl=None, + field_mpls_label2_exp=None, + field_mpls_label2_bos=None, + field_mpls_label3_label=None, + field_mpls_label3_ttl=None, + field_mpls_label3_exp=None, + field_mpls_label3_bos=None, + field_mpls_label4_label=None, + field_mpls_label4_ttl=None, + field_mpls_label4_exp=None, + field_mpls_label4_bos=None, + field_fdb_dst_user_meta=None, + field_route_dst_user_meta=None, + field_neighbor_dst_user_meta=None, + field_port_user_meta=None, + field_vlan_user_meta=None, + field_acl_user_meta=None, + field_fdb_npu_meta_dst_hit=None, + field_neighbor_npu_meta_dst_hit=None, + field_route_npu_meta_dst_hit=None, + field_bth_opcode=None, + field_aeth_syndrome=None, + user_defined_field_group_min=None, + user_defined_field_group_max=None, + field_acl_range_type=None, + field_ipv6_next_header=None, + field_gre_key=None, + field_tam_int_type=None, + action_redirect=None, + action_endpoint_ip=None, + action_redirect_list=None, + action_packet_action=None, + action_flood=None, + action_counter=None, + action_mirror_ingress=None, + action_mirror_egress=None, + action_set_policer=None, + action_decrement_ttl=None, + action_set_tc=None, + action_set_packet_color=None, + action_set_inner_vlan_id=None, + action_set_inner_vlan_pri=None, + action_set_outer_vlan_id=None, + action_set_outer_vlan_pri=None, + action_add_vlan_id=None, + action_add_vlan_pri=None, + action_set_src_mac=None, + action_set_dst_mac=None, + action_set_src_ip=None, + action_set_dst_ip=None, + action_set_src_ipv6=None, + action_set_dst_ipv6=None, + action_set_dscp=None, + action_set_ecn=None, + action_set_l4_src_port=None, + action_set_l4_dst_port=None, + action_ingress_samplepacket_enable=None, + action_egress_samplepacket_enable=None, + action_set_acl_meta_data=None, + action_egress_block_port_list=None, + action_set_user_trap_id=None, + action_set_do_not_learn=None, + action_acl_dtel_flow_op=None, + action_dtel_int_session=None, + action_dtel_drop_report_enable=None, + action_dtel_tail_drop_report_enable=None, + action_dtel_flow_sample_percent=None, + action_dtel_report_all_packets=None, + action_no_nat=None, + action_int_insert=None, + action_int_delete=None, + action_int_report_flow=None, + action_int_report_drops=None, + action_int_report_tail_drops=None, + action_tam_int_object=None, + action_set_isolation_group=None, + action_macsec_flow=None, + action_set_lag_hash_id=None, + action_set_ecmp_hash_id=None, + action_set_vrf=None, + action_set_forwarding_class=None, + custom_attribute=None): + """ + sai_create_acl_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of acl_entry CREATE attributes. + + Returns: + sai_thrift_object_id_t: acl_entry_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if table_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=table_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_TABLE_ID, + value=attribute_value) + attr_list.append(attribute) + + if priority is not None: + attribute_value = sai_thrift_attribute_value_t(u32=priority) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if admin_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_state) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ADMIN_STATE, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word3 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word3) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD3, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word2 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word2) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD2, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word1 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word1) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD1, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ipv6_word0 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word0) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD0, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word3 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word3) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD3, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word2 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word2) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD2, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word1 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word1) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD1, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ipv6_word0 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word0) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD0, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_src_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_src_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_dst_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_dst_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if field_src_mac is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_mac) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_MAC, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_mac is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_mac) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_MAC, + value=attribute_value) + attr_list.append(attribute) + + if field_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if field_in_ports is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_in_ports) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IN_PORTS, + value=attribute_value) + attr_list.append(attribute) + + if field_out_ports is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_out_ports) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORTS, + value=attribute_value) + attr_list.append(attribute) + + if field_in_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_in_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IN_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_out_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_out_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_outer_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_outer_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if field_outer_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_outer_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if field_outer_vlan_cfi is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_outer_vlan_cfi) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_CFI, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_vlan_cfi is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_vlan_cfi) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_CFI, + value=attribute_value) + attr_list.append(attribute) + + if field_l4_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_l4_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_L4_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_l4_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_l4_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_L4_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_l4_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_l4_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_l4_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_l4_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if field_ether_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ether_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_ether_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_ether_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_ETHER_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_ip_protocol is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ip_protocol) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_PROTOCOL, + value=attribute_value) + attr_list.append(attribute) + + if field_inner_ip_protocol is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_inner_ip_protocol) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_IP_PROTOCOL, + value=attribute_value) + attr_list.append(attribute) + + if field_ip_identification is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ip_identification) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_IDENTIFICATION, + value=attribute_value) + attr_list.append(attribute) + + if field_dscp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_dscp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DSCP, + value=attribute_value) + attr_list.append(attribute) + + if field_ecn is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ecn) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ECN, + value=attribute_value) + attr_list.append(attribute) + + if field_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_tos is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_tos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TOS, + value=attribute_value) + attr_list.append(attribute) + + if field_ip_flags is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ip_flags) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_FLAGS, + value=attribute_value) + attr_list.append(attribute) + + if field_tcp_flags is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_tcp_flags) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TCP_FLAGS, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_ip_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_acl_ip_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_ip_frag is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_acl_ip_frag) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_FRAG, + value=attribute_value) + attr_list.append(attribute) + + if field_ipv6_flow_label is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ipv6_flow_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IPV6_FLOW_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_tc is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_tc) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TC, + value=attribute_value) + attr_list.append(attribute) + + if field_icmp_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_icmp_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMP_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_icmp_code is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_icmp_code) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMP_CODE, + value=attribute_value) + attr_list.append(attribute) + + if field_icmpv6_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_icmpv6_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_icmpv6_code is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_icmpv6_code) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_CODE, + value=attribute_value) + attr_list.append(attribute) + + if field_packet_vlan is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_packet_vlan) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_PACKET_VLAN, + value=attribute_value) + attr_list.append(attribute) + + if field_tunnel_vni is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_tunnel_vni) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_VNI, + value=attribute_value) + attr_list.append(attribute) + + if field_has_vlan_tag is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_has_vlan_tag) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_HAS_VLAN_TAG, + value=attribute_value) + attr_list.append(attribute) + + if field_macsec_sci is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_macsec_sci) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MACSEC_SCI, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_label is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_exp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label0_bos is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_label is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_exp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label1_bos is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_label is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_exp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label2_bos is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_label is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_exp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label3_bos is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_label is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_TTL, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_exp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_exp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_EXP, + value=attribute_value) + attr_list.append(attribute) + + if field_mpls_label4_bos is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_bos) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_BOS, + value=attribute_value) + attr_list.append(attribute) + + if field_fdb_dst_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_fdb_dst_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_FDB_DST_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_route_dst_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_route_dst_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_DST_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_neighbor_dst_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_neighbor_dst_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_DST_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_port_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_port_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_PORT_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_vlan_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_vlan_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_VLAN_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_user_meta is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_acl_user_meta) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_USER_META, + value=attribute_value) + attr_list.append(attribute) + + if field_fdb_npu_meta_dst_hit is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_fdb_npu_meta_dst_hit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_FDB_NPU_META_DST_HIT, + value=attribute_value) + attr_list.append(attribute) + + if field_neighbor_npu_meta_dst_hit is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_neighbor_npu_meta_dst_hit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT, + value=attribute_value) + attr_list.append(attribute) + + if field_route_npu_meta_dst_hit is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_route_npu_meta_dst_hit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_NPU_META_DST_HIT, + value=attribute_value) + attr_list.append(attribute) + + if field_bth_opcode is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_bth_opcode) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_BTH_OPCODE, + value=attribute_value) + attr_list.append(attribute) + + if field_aeth_syndrome is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_aeth_syndrome) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_AETH_SYNDROME, + value=attribute_value) + attr_list.append(attribute) + + if user_defined_field_group_min is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=user_defined_field_group_min) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MIN, + value=attribute_value) + attr_list.append(attribute) + + if user_defined_field_group_max is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=user_defined_field_group_max) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MAX, + value=attribute_value) + attr_list.append(attribute) + + if field_acl_range_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_acl_range_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if field_ipv6_next_header is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_ipv6_next_header) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IPV6_NEXT_HEADER, + value=attribute_value) + attr_list.append(attribute) + + if field_gre_key is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_gre_key) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_GRE_KEY, + value=attribute_value) + attr_list.append(attribute) + + if field_tam_int_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=field_tam_int_type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TAM_INT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if action_redirect is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_redirect) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT, + value=attribute_value) + attr_list.append(attribute) + + if action_endpoint_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_endpoint_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ENDPOINT_IP, + value=attribute_value) + attr_list.append(attribute) + + if action_redirect_list is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_redirect_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if action_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if action_flood is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_flood) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_FLOOD, + value=attribute_value) + attr_list.append(attribute) + + if action_counter is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_counter) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_COUNTER, + value=attribute_value) + attr_list.append(attribute) + + if action_mirror_ingress is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_mirror_ingress) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS, + value=attribute_value) + attr_list.append(attribute) + + if action_mirror_egress is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_mirror_egress) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_EGRESS, + value=attribute_value) + attr_list.append(attribute) + + if action_set_policer is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_policer) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_POLICER, + value=attribute_value) + attr_list.append(attribute) + + if action_decrement_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_decrement_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DECREMENT_TTL, + value=attribute_value) + attr_list.append(attribute) + + if action_set_tc is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_tc) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_TC, + value=attribute_value) + attr_list.append(attribute) + + if action_set_packet_color is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_packet_color) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR, + value=attribute_value) + attr_list.append(attribute) + + if action_set_inner_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_inner_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if action_set_inner_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_inner_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if action_set_outer_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_outer_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if action_set_outer_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_outer_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if action_add_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_add_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if action_add_vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_add_vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if action_set_src_mac is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_src_mac) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_MAC, + value=attribute_value) + attr_list.append(attribute) + + if action_set_dst_mac is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_dst_mac) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_MAC, + value=attribute_value) + attr_list.append(attribute) + + if action_set_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if action_set_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if action_set_src_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_src_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if action_set_dst_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_dst_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if action_set_dscp is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_dscp) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DSCP, + value=attribute_value) + attr_list.append(attribute) + + if action_set_ecn is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_ecn) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ECN, + value=attribute_value) + attr_list.append(attribute) + + if action_set_l4_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_l4_src_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if action_set_l4_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_l4_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if action_ingress_samplepacket_enable is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_ingress_samplepacket_enable) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INGRESS_SAMPLEPACKET_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if action_egress_samplepacket_enable is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_egress_samplepacket_enable) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_SAMPLEPACKET_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if action_set_acl_meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_acl_meta_data) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ACL_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if action_egress_block_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_egress_block_port_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_BLOCK_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if action_set_user_trap_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_user_trap_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID, + value=attribute_value) + attr_list.append(attribute) + + if action_set_do_not_learn is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_do_not_learn) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DO_NOT_LEARN, + value=attribute_value) + attr_list.append(attribute) + + if action_acl_dtel_flow_op is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_acl_dtel_flow_op) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ACL_DTEL_FLOW_OP, + value=attribute_value) + attr_list.append(attribute) + + if action_dtel_int_session is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_dtel_int_session) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_INT_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if action_dtel_drop_report_enable is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_dtel_drop_report_enable) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_DROP_REPORT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if action_dtel_tail_drop_report_enable is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_dtel_tail_drop_report_enable) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_TAIL_DROP_REPORT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if action_dtel_flow_sample_percent is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_dtel_flow_sample_percent) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_FLOW_SAMPLE_PERCENT, + value=attribute_value) + attr_list.append(attribute) + + if action_dtel_report_all_packets is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_dtel_report_all_packets) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_REPORT_ALL_PACKETS, + value=attribute_value) + attr_list.append(attribute) + + if action_no_nat is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_no_nat) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_NO_NAT, + value=attribute_value) + attr_list.append(attribute) + + if action_int_insert is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_int_insert) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_INSERT, + value=attribute_value) + attr_list.append(attribute) + + if action_int_delete is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_int_delete) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_DELETE, + value=attribute_value) + attr_list.append(attribute) + + if action_int_report_flow is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_int_report_flow) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_FLOW, + value=attribute_value) + attr_list.append(attribute) + + if action_int_report_drops is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_int_report_drops) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_DROPS, + value=attribute_value) + attr_list.append(attribute) + + if action_int_report_tail_drops is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_int_report_tail_drops) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_TAIL_DROPS, + value=attribute_value) + attr_list.append(attribute) + + if action_tam_int_object is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_tam_int_object) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_TAM_INT_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if action_set_isolation_group is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_isolation_group) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ISOLATION_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if action_macsec_flow is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_macsec_flow) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MACSEC_FLOW, + value=attribute_value) + attr_list.append(attribute) + + if action_set_lag_hash_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_lag_hash_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_LAG_HASH_ID, + value=attribute_value) + attr_list.append(attribute) + + if action_set_ecmp_hash_id is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_ecmp_hash_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID, + value=attribute_value) + attr_list.append(attribute) + + if action_set_vrf is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_vrf) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF, + value=attribute_value) + attr_list.append(attribute) + + if action_set_forwarding_class is not None: + attribute_value = sai_thrift_attribute_value_t(aclaction=action_set_forwarding_class) + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_FORWARDING_CLASS, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_acl_entry(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_acl_entry(client, + acl_entry_oid): + """ + sai_remove_acl_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + acl_entry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_acl_entry(acl_entry_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_acl_entry_attribute(client, + acl_entry_oid, + priority=None, + admin_state=None, + field_src_ipv6=None, + field_src_ipv6_word3=None, + field_src_ipv6_word2=None, + field_src_ipv6_word1=None, + field_src_ipv6_word0=None, + field_dst_ipv6=None, + field_dst_ipv6_word3=None, + field_dst_ipv6_word2=None, + field_dst_ipv6_word1=None, + field_dst_ipv6_word0=None, + field_inner_src_ipv6=None, + field_inner_dst_ipv6=None, + field_src_mac=None, + field_dst_mac=None, + field_src_ip=None, + field_dst_ip=None, + field_inner_src_ip=None, + field_inner_dst_ip=None, + field_in_ports=None, + field_out_ports=None, + field_in_port=None, + field_out_port=None, + field_src_port=None, + field_outer_vlan_id=None, + field_outer_vlan_pri=None, + field_outer_vlan_cfi=None, + field_inner_vlan_id=None, + field_inner_vlan_pri=None, + field_inner_vlan_cfi=None, + field_l4_src_port=None, + field_l4_dst_port=None, + field_inner_l4_src_port=None, + field_inner_l4_dst_port=None, + field_ether_type=None, + field_inner_ether_type=None, + field_ip_protocol=None, + field_inner_ip_protocol=None, + field_ip_identification=None, + field_dscp=None, + field_ecn=None, + field_ttl=None, + field_tos=None, + field_ip_flags=None, + field_tcp_flags=None, + field_acl_ip_type=None, + field_acl_ip_frag=None, + field_ipv6_flow_label=None, + field_tc=None, + field_icmp_type=None, + field_icmp_code=None, + field_icmpv6_type=None, + field_icmpv6_code=None, + field_packet_vlan=None, + field_tunnel_vni=None, + field_has_vlan_tag=None, + field_macsec_sci=None, + field_mpls_label0_label=None, + field_mpls_label0_ttl=None, + field_mpls_label0_exp=None, + field_mpls_label0_bos=None, + field_mpls_label1_label=None, + field_mpls_label1_ttl=None, + field_mpls_label1_exp=None, + field_mpls_label1_bos=None, + field_mpls_label2_label=None, + field_mpls_label2_ttl=None, + field_mpls_label2_exp=None, + field_mpls_label2_bos=None, + field_mpls_label3_label=None, + field_mpls_label3_ttl=None, + field_mpls_label3_exp=None, + field_mpls_label3_bos=None, + field_mpls_label4_label=None, + field_mpls_label4_ttl=None, + field_mpls_label4_exp=None, + field_mpls_label4_bos=None, + field_fdb_dst_user_meta=None, + field_route_dst_user_meta=None, + field_neighbor_dst_user_meta=None, + field_port_user_meta=None, + field_vlan_user_meta=None, + field_acl_user_meta=None, + field_fdb_npu_meta_dst_hit=None, + field_neighbor_npu_meta_dst_hit=None, + field_route_npu_meta_dst_hit=None, + field_bth_opcode=None, + field_aeth_syndrome=None, + user_defined_field_group_min=None, + user_defined_field_group_max=None, + field_acl_range_type=None, + field_ipv6_next_header=None, + field_gre_key=None, + field_tam_int_type=None, + action_redirect=None, + action_endpoint_ip=None, + action_redirect_list=None, + action_packet_action=None, + action_flood=None, + action_counter=None, + action_mirror_ingress=None, + action_mirror_egress=None, + action_set_policer=None, + action_decrement_ttl=None, + action_set_tc=None, + action_set_packet_color=None, + action_set_inner_vlan_id=None, + action_set_inner_vlan_pri=None, + action_set_outer_vlan_id=None, + action_set_outer_vlan_pri=None, + action_add_vlan_id=None, + action_add_vlan_pri=None, + action_set_src_mac=None, + action_set_dst_mac=None, + action_set_src_ip=None, + action_set_dst_ip=None, + action_set_src_ipv6=None, + action_set_dst_ipv6=None, + action_set_dscp=None, + action_set_ecn=None, + action_set_l4_src_port=None, + action_set_l4_dst_port=None, + action_ingress_samplepacket_enable=None, + action_egress_samplepacket_enable=None, + action_set_acl_meta_data=None, + action_egress_block_port_list=None, + action_set_user_trap_id=None, + action_set_do_not_learn=None, + action_acl_dtel_flow_op=None, + action_dtel_int_session=None, + action_dtel_drop_report_enable=None, + action_dtel_tail_drop_report_enable=None, + action_dtel_flow_sample_percent=None, + action_dtel_report_all_packets=None, + action_no_nat=None, + action_int_insert=None, + action_int_delete=None, + action_int_report_flow=None, + action_int_report_drops=None, + action_int_report_tail_drops=None, + action_tam_int_object=None, + action_set_isolation_group=None, + action_macsec_flow=None, + action_set_lag_hash_id=None, + action_set_ecmp_hash_id=None, + action_set_vrf=None, + action_set_forwarding_class=None, + custom_attribute=None): + """ + sai_set_acl_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + acl_entry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if priority is not None: + attr_value = sai_thrift_attribute_value_t(u32=priority) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_PRIORITY, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if admin_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_state) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ADMIN_STATE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_ipv6_word3 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word3) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD3, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_ipv6_word2 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word2) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD2, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_ipv6_word1 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word1) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD1, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_ipv6_word0 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_ipv6_word0) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD0, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_ipv6_word3 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word3) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD3, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_ipv6_word2 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word2) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD2, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_ipv6_word1 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word1) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD1, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_ipv6_word0 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_ipv6_word0) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD0, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_src_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_src_ipv6) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IPV6, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_dst_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_dst_ipv6) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IPV6, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_mac is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_mac) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_MAC, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_mac is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_mac) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_MAC, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dst_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dst_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_src_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_src_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_dst_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_dst_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_in_ports is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_in_ports) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IN_PORTS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_out_ports is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_out_ports) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORTS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_in_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_in_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IN_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_out_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_out_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_src_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_src_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_outer_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_outer_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_outer_vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_outer_vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_outer_vlan_cfi is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_outer_vlan_cfi) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_CFI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_vlan_cfi is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_vlan_cfi) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_CFI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_l4_src_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_l4_src_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_L4_SRC_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_l4_dst_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_l4_dst_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_L4_DST_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_l4_src_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_l4_src_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_SRC_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_l4_dst_port is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_l4_dst_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_DST_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ether_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ether_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_ether_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_ether_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_ETHER_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ip_protocol is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ip_protocol) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_PROTOCOL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_inner_ip_protocol is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_inner_ip_protocol) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_IP_PROTOCOL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ip_identification is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ip_identification) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_IDENTIFICATION, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_dscp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_dscp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DSCP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ecn is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ecn) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ECN, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_tos is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_tos) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TOS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ip_flags is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ip_flags) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_FLAGS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_tcp_flags is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_tcp_flags) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TCP_FLAGS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_acl_ip_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_acl_ip_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_acl_ip_frag is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_acl_ip_frag) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_FRAG, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ipv6_flow_label is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ipv6_flow_label) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IPV6_FLOW_LABEL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_tc is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_tc) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TC, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_icmp_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_icmp_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMP_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_icmp_code is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_icmp_code) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMP_CODE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_icmpv6_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_icmpv6_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_icmpv6_code is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_icmpv6_code) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_CODE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_packet_vlan is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_packet_vlan) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_PACKET_VLAN, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_tunnel_vni is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_tunnel_vni) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_VNI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_has_vlan_tag is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_has_vlan_tag) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_HAS_VLAN_TAG, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_macsec_sci is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_macsec_sci) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MACSEC_SCI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label0_label is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_label) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_LABEL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label0_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label0_exp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_exp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_EXP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label0_bos is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label0_bos) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_BOS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label1_label is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_label) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_LABEL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label1_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label1_exp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_exp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_EXP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label1_bos is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label1_bos) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_BOS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label2_label is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_label) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_LABEL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label2_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label2_exp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_exp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_EXP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label2_bos is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label2_bos) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_BOS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label3_label is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_label) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_LABEL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label3_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label3_exp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_exp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_EXP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label3_bos is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label3_bos) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_BOS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label4_label is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_label) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_LABEL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label4_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label4_exp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_exp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_EXP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_mpls_label4_bos is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_mpls_label4_bos) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_BOS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_fdb_dst_user_meta is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_fdb_dst_user_meta) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_FDB_DST_USER_META, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_route_dst_user_meta is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_route_dst_user_meta) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_DST_USER_META, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_neighbor_dst_user_meta is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_neighbor_dst_user_meta) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_DST_USER_META, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_port_user_meta is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_port_user_meta) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_PORT_USER_META, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_vlan_user_meta is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_vlan_user_meta) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_VLAN_USER_META, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_acl_user_meta is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_acl_user_meta) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_USER_META, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_fdb_npu_meta_dst_hit is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_fdb_npu_meta_dst_hit) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_FDB_NPU_META_DST_HIT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_neighbor_npu_meta_dst_hit is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_neighbor_npu_meta_dst_hit) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_route_npu_meta_dst_hit is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_route_npu_meta_dst_hit) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_NPU_META_DST_HIT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_bth_opcode is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_bth_opcode) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_BTH_OPCODE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_aeth_syndrome is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_aeth_syndrome) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_AETH_SYNDROME, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if user_defined_field_group_min is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=user_defined_field_group_min) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MIN, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if user_defined_field_group_max is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=user_defined_field_group_max) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MAX, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_acl_range_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_acl_range_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_ipv6_next_header is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_ipv6_next_header) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IPV6_NEXT_HEADER, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_gre_key is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_gre_key) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_GRE_KEY, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if field_tam_int_type is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=field_tam_int_type) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TAM_INT_TYPE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_redirect is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_redirect) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_endpoint_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_endpoint_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ENDPOINT_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_redirect_list is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_redirect_list) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_packet_action) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_flood is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_flood) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_FLOOD, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_counter is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_counter) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_COUNTER, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_mirror_ingress is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_mirror_ingress) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_mirror_egress is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_mirror_egress) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_EGRESS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_policer is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_policer) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_POLICER, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_decrement_ttl is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_decrement_ttl) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DECREMENT_TTL, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_tc is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_tc) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_TC, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_packet_color is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_packet_color) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_inner_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_inner_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_inner_vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_inner_vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_outer_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_outer_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_outer_vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_outer_vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_add_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_add_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_add_vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_add_vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_src_mac is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_src_mac) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_MAC, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_dst_mac is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_dst_mac) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_MAC, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_src_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_src_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_dst_ip is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_dst_ip) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_src_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_src_ipv6) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IPV6, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_dst_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_dst_ipv6) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IPV6, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_dscp is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_dscp) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DSCP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_ecn is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_ecn) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ECN, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_l4_src_port is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_l4_src_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_SRC_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_l4_dst_port is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_l4_dst_port) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_DST_PORT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_ingress_samplepacket_enable is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_ingress_samplepacket_enable) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INGRESS_SAMPLEPACKET_ENABLE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_egress_samplepacket_enable is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_egress_samplepacket_enable) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_SAMPLEPACKET_ENABLE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_acl_meta_data is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_acl_meta_data) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ACL_META_DATA, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_egress_block_port_list is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_egress_block_port_list) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_BLOCK_PORT_LIST, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_user_trap_id is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_user_trap_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_do_not_learn is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_do_not_learn) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DO_NOT_LEARN, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_acl_dtel_flow_op is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_acl_dtel_flow_op) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ACL_DTEL_FLOW_OP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_dtel_int_session is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_dtel_int_session) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_INT_SESSION, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_dtel_drop_report_enable is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_dtel_drop_report_enable) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_DROP_REPORT_ENABLE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_dtel_tail_drop_report_enable is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_dtel_tail_drop_report_enable) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_TAIL_DROP_REPORT_ENABLE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_dtel_flow_sample_percent is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_dtel_flow_sample_percent) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_FLOW_SAMPLE_PERCENT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_dtel_report_all_packets is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_dtel_report_all_packets) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_REPORT_ALL_PACKETS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_no_nat is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_no_nat) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_NO_NAT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_int_insert is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_int_insert) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_INSERT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_int_delete is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_int_delete) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_DELETE, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_int_report_flow is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_int_report_flow) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_FLOW, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_int_report_drops is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_int_report_drops) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_DROPS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_int_report_tail_drops is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_int_report_tail_drops) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_TAIL_DROPS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_tam_int_object is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_tam_int_object) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_TAM_INT_OBJECT, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_isolation_group is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_isolation_group) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ISOLATION_GROUP, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_macsec_flow is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_macsec_flow) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MACSEC_FLOW, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_lag_hash_id is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_lag_hash_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_LAG_HASH_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_ecmp_hash_id is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_ecmp_hash_id) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_vrf is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_vrf) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if action_set_forwarding_class is not None: + attr_value = sai_thrift_attribute_value_t(aclaction=action_set_forwarding_class) + attr = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_FORWARDING_CLASS, + value=attr_value) + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_acl_entry_attribute(acl_entry_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_acl_entry_attribute(client, + acl_entry_oid, + table_id=None, + priority=None, + admin_state=None, + field_src_ipv6=None, + field_src_ipv6_word3=None, + field_src_ipv6_word2=None, + field_src_ipv6_word1=None, + field_src_ipv6_word0=None, + field_dst_ipv6=None, + field_dst_ipv6_word3=None, + field_dst_ipv6_word2=None, + field_dst_ipv6_word1=None, + field_dst_ipv6_word0=None, + field_inner_src_ipv6=None, + field_inner_dst_ipv6=None, + field_src_mac=None, + field_dst_mac=None, + field_src_ip=None, + field_dst_ip=None, + field_inner_src_ip=None, + field_inner_dst_ip=None, + field_in_ports=None, + field_out_ports=None, + field_in_port=None, + field_out_port=None, + field_src_port=None, + field_outer_vlan_id=None, + field_outer_vlan_pri=None, + field_outer_vlan_cfi=None, + field_inner_vlan_id=None, + field_inner_vlan_pri=None, + field_inner_vlan_cfi=None, + field_l4_src_port=None, + field_l4_dst_port=None, + field_inner_l4_src_port=None, + field_inner_l4_dst_port=None, + field_ether_type=None, + field_inner_ether_type=None, + field_ip_protocol=None, + field_inner_ip_protocol=None, + field_ip_identification=None, + field_dscp=None, + field_ecn=None, + field_ttl=None, + field_tos=None, + field_ip_flags=None, + field_tcp_flags=None, + field_acl_ip_type=None, + field_acl_ip_frag=None, + field_ipv6_flow_label=None, + field_tc=None, + field_icmp_type=None, + field_icmp_code=None, + field_icmpv6_type=None, + field_icmpv6_code=None, + field_packet_vlan=None, + field_tunnel_vni=None, + field_has_vlan_tag=None, + field_macsec_sci=None, + field_mpls_label0_label=None, + field_mpls_label0_ttl=None, + field_mpls_label0_exp=None, + field_mpls_label0_bos=None, + field_mpls_label1_label=None, + field_mpls_label1_ttl=None, + field_mpls_label1_exp=None, + field_mpls_label1_bos=None, + field_mpls_label2_label=None, + field_mpls_label2_ttl=None, + field_mpls_label2_exp=None, + field_mpls_label2_bos=None, + field_mpls_label3_label=None, + field_mpls_label3_ttl=None, + field_mpls_label3_exp=None, + field_mpls_label3_bos=None, + field_mpls_label4_label=None, + field_mpls_label4_ttl=None, + field_mpls_label4_exp=None, + field_mpls_label4_bos=None, + field_fdb_dst_user_meta=None, + field_route_dst_user_meta=None, + field_neighbor_dst_user_meta=None, + field_port_user_meta=None, + field_vlan_user_meta=None, + field_acl_user_meta=None, + field_fdb_npu_meta_dst_hit=None, + field_neighbor_npu_meta_dst_hit=None, + field_route_npu_meta_dst_hit=None, + field_bth_opcode=None, + field_aeth_syndrome=None, + user_defined_field_group_min=None, + user_defined_field_group_max=None, + field_acl_range_type=None, + field_ipv6_next_header=None, + field_gre_key=None, + field_tam_int_type=None, + action_redirect=None, + action_endpoint_ip=None, + action_redirect_list=None, + action_packet_action=None, + action_flood=None, + action_counter=None, + action_mirror_ingress=None, + action_mirror_egress=None, + action_set_policer=None, + action_decrement_ttl=None, + action_set_tc=None, + action_set_packet_color=None, + action_set_inner_vlan_id=None, + action_set_inner_vlan_pri=None, + action_set_outer_vlan_id=None, + action_set_outer_vlan_pri=None, + action_add_vlan_id=None, + action_add_vlan_pri=None, + action_set_src_mac=None, + action_set_dst_mac=None, + action_set_src_ip=None, + action_set_dst_ip=None, + action_set_src_ipv6=None, + action_set_dst_ipv6=None, + action_set_dscp=None, + action_set_ecn=None, + action_set_l4_src_port=None, + action_set_l4_dst_port=None, + action_ingress_samplepacket_enable=None, + action_egress_samplepacket_enable=None, + action_set_acl_meta_data=None, + action_egress_block_port_list=None, + action_set_user_trap_id=None, + action_set_do_not_learn=None, + action_acl_dtel_flow_op=None, + action_dtel_int_session=None, + action_dtel_drop_report_enable=None, + action_dtel_tail_drop_report_enable=None, + action_dtel_flow_sample_percent=None, + action_dtel_report_all_packets=None, + action_no_nat=None, + action_int_insert=None, + action_int_delete=None, + action_int_report_flow=None, + action_int_report_drops=None, + action_int_report_tail_drops=None, + action_tam_int_object=None, + action_set_isolation_group=None, + action_macsec_flow=None, + action_set_lag_hash_id=None, + action_set_ecmp_hash_id=None, + action_set_vrf=None, + action_set_forwarding_class=None, + custom_attribute=None): + """ + sai_get_acl_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + acl_entry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if table_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_TABLE_ID) + attr_list.append(attribute) + + if priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_PRIORITY) + attr_list.append(attribute) + + if admin_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ADMIN_STATE) + attr_list.append(attribute) + + if field_src_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6) + attr_list.append(attribute) + + if field_src_ipv6_word3 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD3) + attr_list.append(attribute) + + if field_src_ipv6_word2 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD2) + attr_list.append(attribute) + + if field_src_ipv6_word1 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD1) + attr_list.append(attribute) + + if field_src_ipv6_word0 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD0) + attr_list.append(attribute) + + if field_dst_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6) + attr_list.append(attribute) + + if field_dst_ipv6_word3 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD3) + attr_list.append(attribute) + + if field_dst_ipv6_word2 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD2) + attr_list.append(attribute) + + if field_dst_ipv6_word1 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD1) + attr_list.append(attribute) + + if field_dst_ipv6_word0 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD0) + attr_list.append(attribute) + + if field_inner_src_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IPV6) + attr_list.append(attribute) + + if field_inner_dst_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IPV6) + attr_list.append(attribute) + + if field_src_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_MAC) + attr_list.append(attribute) + + if field_dst_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_MAC) + attr_list.append(attribute) + + if field_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP) + attr_list.append(attribute) + + if field_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DST_IP) + attr_list.append(attribute) + + if field_inner_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IP) + attr_list.append(attribute) + + if field_inner_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IP) + attr_list.append(attribute) + + if field_in_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IN_PORTS) + attr_list.append(attribute) + + if field_out_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORTS) + attr_list.append(attribute) + + if field_in_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IN_PORT) + attr_list.append(attribute) + + if field_out_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORT) + attr_list.append(attribute) + + if field_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_SRC_PORT) + attr_list.append(attribute) + + if field_outer_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_ID) + attr_list.append(attribute) + + if field_outer_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_PRI) + attr_list.append(attribute) + + if field_outer_vlan_cfi is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_CFI) + attr_list.append(attribute) + + if field_inner_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_ID) + attr_list.append(attribute) + + if field_inner_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_PRI) + attr_list.append(attribute) + + if field_inner_vlan_cfi is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_CFI) + attr_list.append(attribute) + + if field_l4_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_L4_SRC_PORT) + attr_list.append(attribute) + + if field_l4_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_L4_DST_PORT) + attr_list.append(attribute) + + if field_inner_l4_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_SRC_PORT) + attr_list.append(attribute) + + if field_inner_l4_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_DST_PORT) + attr_list.append(attribute) + + if field_ether_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE) + attr_list.append(attribute) + + if field_inner_ether_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_ETHER_TYPE) + attr_list.append(attribute) + + if field_ip_protocol is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_PROTOCOL) + attr_list.append(attribute) + + if field_inner_ip_protocol is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_INNER_IP_PROTOCOL) + attr_list.append(attribute) + + if field_ip_identification is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_IDENTIFICATION) + attr_list.append(attribute) + + if field_dscp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_DSCP) + attr_list.append(attribute) + + if field_ecn is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ECN) + attr_list.append(attribute) + + if field_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TTL) + attr_list.append(attribute) + + if field_tos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TOS) + attr_list.append(attribute) + + if field_ip_flags is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IP_FLAGS) + attr_list.append(attribute) + + if field_tcp_flags is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TCP_FLAGS) + attr_list.append(attribute) + + if field_acl_ip_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_TYPE) + attr_list.append(attribute) + + if field_acl_ip_frag is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_FRAG) + attr_list.append(attribute) + + if field_ipv6_flow_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IPV6_FLOW_LABEL) + attr_list.append(attribute) + + if field_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TC) + attr_list.append(attribute) + + if field_icmp_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMP_TYPE) + attr_list.append(attribute) + + if field_icmp_code is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMP_CODE) + attr_list.append(attribute) + + if field_icmpv6_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE) + attr_list.append(attribute) + + if field_icmpv6_code is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_CODE) + attr_list.append(attribute) + + if field_packet_vlan is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_PACKET_VLAN) + attr_list.append(attribute) + + if field_tunnel_vni is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_VNI) + attr_list.append(attribute) + + if field_has_vlan_tag is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_HAS_VLAN_TAG) + attr_list.append(attribute) + + if field_macsec_sci is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MACSEC_SCI) + attr_list.append(attribute) + + if field_mpls_label0_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_LABEL) + attr_list.append(attribute) + + if field_mpls_label0_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_TTL) + attr_list.append(attribute) + + if field_mpls_label0_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_EXP) + attr_list.append(attribute) + + if field_mpls_label0_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_BOS) + attr_list.append(attribute) + + if field_mpls_label1_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_LABEL) + attr_list.append(attribute) + + if field_mpls_label1_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_TTL) + attr_list.append(attribute) + + if field_mpls_label1_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_EXP) + attr_list.append(attribute) + + if field_mpls_label1_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_BOS) + attr_list.append(attribute) + + if field_mpls_label2_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_LABEL) + attr_list.append(attribute) + + if field_mpls_label2_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_TTL) + attr_list.append(attribute) + + if field_mpls_label2_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_EXP) + attr_list.append(attribute) + + if field_mpls_label2_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_BOS) + attr_list.append(attribute) + + if field_mpls_label3_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_LABEL) + attr_list.append(attribute) + + if field_mpls_label3_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_TTL) + attr_list.append(attribute) + + if field_mpls_label3_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_EXP) + attr_list.append(attribute) + + if field_mpls_label3_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_BOS) + attr_list.append(attribute) + + if field_mpls_label4_label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_LABEL) + attr_list.append(attribute) + + if field_mpls_label4_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_TTL) + attr_list.append(attribute) + + if field_mpls_label4_exp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_EXP) + attr_list.append(attribute) + + if field_mpls_label4_bos is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_BOS) + attr_list.append(attribute) + + if field_fdb_dst_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_FDB_DST_USER_META) + attr_list.append(attribute) + + if field_route_dst_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_DST_USER_META) + attr_list.append(attribute) + + if field_neighbor_dst_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_DST_USER_META) + attr_list.append(attribute) + + if field_port_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_PORT_USER_META) + attr_list.append(attribute) + + if field_vlan_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_VLAN_USER_META) + attr_list.append(attribute) + + if field_acl_user_meta is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_USER_META) + attr_list.append(attribute) + + if field_fdb_npu_meta_dst_hit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_FDB_NPU_META_DST_HIT) + attr_list.append(attribute) + + if field_neighbor_npu_meta_dst_hit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT) + attr_list.append(attribute) + + if field_route_npu_meta_dst_hit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_NPU_META_DST_HIT) + attr_list.append(attribute) + + if field_bth_opcode is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_BTH_OPCODE) + attr_list.append(attribute) + + if field_aeth_syndrome is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_AETH_SYNDROME) + attr_list.append(attribute) + + if user_defined_field_group_min is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MIN) + attr_list.append(attribute) + + if user_defined_field_group_max is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MAX) + attr_list.append(attribute) + + if field_acl_range_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE) + attr_list.append(attribute) + + if field_ipv6_next_header is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_IPV6_NEXT_HEADER) + attr_list.append(attribute) + + if field_gre_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_GRE_KEY) + attr_list.append(attribute) + + if field_tam_int_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_FIELD_TAM_INT_TYPE) + attr_list.append(attribute) + + if action_redirect is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT) + attr_list.append(attribute) + + if action_endpoint_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ENDPOINT_IP) + attr_list.append(attribute) + + if action_redirect_list is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST) + attr_list.append(attribute) + + if action_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION) + attr_list.append(attribute) + + if action_flood is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_FLOOD) + attr_list.append(attribute) + + if action_counter is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_COUNTER) + attr_list.append(attribute) + + if action_mirror_ingress is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS) + attr_list.append(attribute) + + if action_mirror_egress is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_EGRESS) + attr_list.append(attribute) + + if action_set_policer is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_POLICER) + attr_list.append(attribute) + + if action_decrement_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DECREMENT_TTL) + attr_list.append(attribute) + + if action_set_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_TC) + attr_list.append(attribute) + + if action_set_packet_color is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR) + attr_list.append(attribute) + + if action_set_inner_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_ID) + attr_list.append(attribute) + + if action_set_inner_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_PRI) + attr_list.append(attribute) + + if action_set_outer_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_ID) + attr_list.append(attribute) + + if action_set_outer_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_PRI) + attr_list.append(attribute) + + if action_add_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_ID) + attr_list.append(attribute) + + if action_add_vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_PRI) + attr_list.append(attribute) + + if action_set_src_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_MAC) + attr_list.append(attribute) + + if action_set_dst_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_MAC) + attr_list.append(attribute) + + if action_set_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IP) + attr_list.append(attribute) + + if action_set_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IP) + attr_list.append(attribute) + + if action_set_src_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IPV6) + attr_list.append(attribute) + + if action_set_dst_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IPV6) + attr_list.append(attribute) + + if action_set_dscp is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DSCP) + attr_list.append(attribute) + + if action_set_ecn is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ECN) + attr_list.append(attribute) + + if action_set_l4_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_SRC_PORT) + attr_list.append(attribute) + + if action_set_l4_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_DST_PORT) + attr_list.append(attribute) + + if action_ingress_samplepacket_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INGRESS_SAMPLEPACKET_ENABLE) + attr_list.append(attribute) + + if action_egress_samplepacket_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_SAMPLEPACKET_ENABLE) + attr_list.append(attribute) + + if action_set_acl_meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ACL_META_DATA) + attr_list.append(attribute) + + if action_egress_block_port_list is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_BLOCK_PORT_LIST) + attr_list.append(attribute) + + if action_set_user_trap_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID) + attr_list.append(attribute) + + if action_set_do_not_learn is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_DO_NOT_LEARN) + attr_list.append(attribute) + + if action_acl_dtel_flow_op is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_ACL_DTEL_FLOW_OP) + attr_list.append(attribute) + + if action_dtel_int_session is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_INT_SESSION) + attr_list.append(attribute) + + if action_dtel_drop_report_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_DROP_REPORT_ENABLE) + attr_list.append(attribute) + + if action_dtel_tail_drop_report_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_TAIL_DROP_REPORT_ENABLE) + attr_list.append(attribute) + + if action_dtel_flow_sample_percent is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_FLOW_SAMPLE_PERCENT) + attr_list.append(attribute) + + if action_dtel_report_all_packets is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_DTEL_REPORT_ALL_PACKETS) + attr_list.append(attribute) + + if action_no_nat is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_NO_NAT) + attr_list.append(attribute) + + if action_int_insert is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_INSERT) + attr_list.append(attribute) + + if action_int_delete is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_DELETE) + attr_list.append(attribute) + + if action_int_report_flow is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_FLOW) + attr_list.append(attribute) + + if action_int_report_drops is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_DROPS) + attr_list.append(attribute) + + if action_int_report_tail_drops is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_TAIL_DROPS) + attr_list.append(attribute) + + if action_tam_int_object is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_TAM_INT_OBJECT) + attr_list.append(attribute) + + if action_set_isolation_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ISOLATION_GROUP) + attr_list.append(attribute) + + if action_macsec_flow is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_MACSEC_FLOW) + attr_list.append(attribute) + + if action_set_lag_hash_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_LAG_HASH_ID) + attr_list.append(attribute) + + if action_set_ecmp_hash_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID) + attr_list.append(attribute) + + if action_set_vrf is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF) + attr_list.append(attribute) + + if action_set_forwarding_class is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_ENTRY_ATTR_ACTION_SET_FORWARDING_CLASS) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_acl_entry_attribute(acl_entry_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ACL_ENTRY_ATTR_TABLE_ID: + attrs["SAI_ACL_ENTRY_ATTR_TABLE_ID"] = attr.value.oid + attrs["table_id"] = attr.value.oid + + if attr.id == SAI_ACL_ENTRY_ATTR_PRIORITY: + attrs["SAI_ACL_ENTRY_ATTR_PRIORITY"] = attr.value.u32 + attrs["priority"] = attr.value.u32 + + if attr.id == SAI_ACL_ENTRY_ATTR_ADMIN_STATE: + attrs["SAI_ACL_ENTRY_ATTR_ADMIN_STATE"] = attr.value.booldata + attrs["admin_state"] = attr.value.booldata + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6"] = attr.value.aclfield + attrs["field_src_ipv6"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD3: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD3"] = attr.value.aclfield + attrs["field_src_ipv6_word3"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD2: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD2"] = attr.value.aclfield + attrs["field_src_ipv6_word2"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD1: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD1"] = attr.value.aclfield + attrs["field_src_ipv6_word1"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD0: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_IPV6_WORD0"] = attr.value.aclfield + attrs["field_src_ipv6_word0"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6"] = attr.value.aclfield + attrs["field_dst_ipv6"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD3: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD3"] = attr.value.aclfield + attrs["field_dst_ipv6_word3"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD2: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD2"] = attr.value.aclfield + attrs["field_dst_ipv6_word2"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD1: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD1"] = attr.value.aclfield + attrs["field_dst_ipv6_word1"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD0: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_IPV6_WORD0"] = attr.value.aclfield + attrs["field_dst_ipv6_word0"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IPV6: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IPV6"] = attr.value.aclfield + attrs["field_inner_src_ipv6"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IPV6: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IPV6"] = attr.value.aclfield + attrs["field_inner_dst_ipv6"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_MAC: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_MAC"] = attr.value.aclfield + attrs["field_src_mac"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_MAC: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_MAC"] = attr.value.aclfield + attrs["field_dst_mac"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP"] = attr.value.aclfield + attrs["field_src_ip"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DST_IP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DST_IP"] = attr.value.aclfield + attrs["field_dst_ip"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_SRC_IP"] = attr.value.aclfield + attrs["field_inner_src_ip"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_DST_IP"] = attr.value.aclfield + attrs["field_inner_dst_ip"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IN_PORTS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IN_PORTS"] = attr.value.aclfield + attrs["field_in_ports"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORTS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORTS"] = attr.value.aclfield + attrs["field_out_ports"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IN_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IN_PORT"] = attr.value.aclfield + attrs["field_in_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORT"] = attr.value.aclfield + attrs["field_out_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_SRC_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_SRC_PORT"] = attr.value.aclfield + attrs["field_src_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_ID: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_ID"] = attr.value.aclfield + attrs["field_outer_vlan_id"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_PRI: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_PRI"] = attr.value.aclfield + attrs["field_outer_vlan_pri"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_CFI: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_OUTER_VLAN_CFI"] = attr.value.aclfield + attrs["field_outer_vlan_cfi"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_ID: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_ID"] = attr.value.aclfield + attrs["field_inner_vlan_id"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_PRI: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_PRI"] = attr.value.aclfield + attrs["field_inner_vlan_pri"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_CFI: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_VLAN_CFI"] = attr.value.aclfield + attrs["field_inner_vlan_cfi"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_L4_SRC_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_L4_SRC_PORT"] = attr.value.aclfield + attrs["field_l4_src_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_L4_DST_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_L4_DST_PORT"] = attr.value.aclfield + attrs["field_l4_dst_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_SRC_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_SRC_PORT"] = attr.value.aclfield + attrs["field_inner_l4_src_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_DST_PORT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_L4_DST_PORT"] = attr.value.aclfield + attrs["field_inner_l4_dst_port"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE"] = attr.value.aclfield + attrs["field_ether_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_ETHER_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_ETHER_TYPE"] = attr.value.aclfield + attrs["field_inner_ether_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IP_PROTOCOL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IP_PROTOCOL"] = attr.value.aclfield + attrs["field_ip_protocol"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_INNER_IP_PROTOCOL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_INNER_IP_PROTOCOL"] = attr.value.aclfield + attrs["field_inner_ip_protocol"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IP_IDENTIFICATION: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IP_IDENTIFICATION"] = attr.value.aclfield + attrs["field_ip_identification"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_DSCP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_DSCP"] = attr.value.aclfield + attrs["field_dscp"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ECN: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ECN"] = attr.value.aclfield + attrs["field_ecn"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_TTL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_TTL"] = attr.value.aclfield + attrs["field_ttl"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_TOS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_TOS"] = attr.value.aclfield + attrs["field_tos"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IP_FLAGS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IP_FLAGS"] = attr.value.aclfield + attrs["field_ip_flags"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_TCP_FLAGS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_TCP_FLAGS"] = attr.value.aclfield + attrs["field_tcp_flags"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_TYPE"] = attr.value.aclfield + attrs["field_acl_ip_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_FRAG: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ACL_IP_FRAG"] = attr.value.aclfield + attrs["field_acl_ip_frag"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IPV6_FLOW_LABEL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IPV6_FLOW_LABEL"] = attr.value.aclfield + attrs["field_ipv6_flow_label"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_TC: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_TC"] = attr.value.aclfield + attrs["field_tc"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ICMP_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ICMP_TYPE"] = attr.value.aclfield + attrs["field_icmp_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ICMP_CODE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ICMP_CODE"] = attr.value.aclfield + attrs["field_icmp_code"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE"] = attr.value.aclfield + attrs["field_icmpv6_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_CODE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_CODE"] = attr.value.aclfield + attrs["field_icmpv6_code"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_PACKET_VLAN: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_PACKET_VLAN"] = attr.value.aclfield + attrs["field_packet_vlan"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_VNI: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_TUNNEL_VNI"] = attr.value.aclfield + attrs["field_tunnel_vni"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_HAS_VLAN_TAG: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_HAS_VLAN_TAG"] = attr.value.aclfield + attrs["field_has_vlan_tag"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MACSEC_SCI: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MACSEC_SCI"] = attr.value.aclfield + attrs["field_macsec_sci"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_LABEL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_LABEL"] = attr.value.aclfield + attrs["field_mpls_label0_label"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_TTL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_TTL"] = attr.value.aclfield + attrs["field_mpls_label0_ttl"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_EXP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_EXP"] = attr.value.aclfield + attrs["field_mpls_label0_exp"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_BOS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL0_BOS"] = attr.value.aclfield + attrs["field_mpls_label0_bos"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_LABEL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_LABEL"] = attr.value.aclfield + attrs["field_mpls_label1_label"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_TTL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_TTL"] = attr.value.aclfield + attrs["field_mpls_label1_ttl"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_EXP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_EXP"] = attr.value.aclfield + attrs["field_mpls_label1_exp"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_BOS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL1_BOS"] = attr.value.aclfield + attrs["field_mpls_label1_bos"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_LABEL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_LABEL"] = attr.value.aclfield + attrs["field_mpls_label2_label"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_TTL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_TTL"] = attr.value.aclfield + attrs["field_mpls_label2_ttl"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_EXP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_EXP"] = attr.value.aclfield + attrs["field_mpls_label2_exp"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_BOS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL2_BOS"] = attr.value.aclfield + attrs["field_mpls_label2_bos"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_LABEL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_LABEL"] = attr.value.aclfield + attrs["field_mpls_label3_label"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_TTL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_TTL"] = attr.value.aclfield + attrs["field_mpls_label3_ttl"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_EXP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_EXP"] = attr.value.aclfield + attrs["field_mpls_label3_exp"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_BOS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL3_BOS"] = attr.value.aclfield + attrs["field_mpls_label3_bos"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_LABEL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_LABEL"] = attr.value.aclfield + attrs["field_mpls_label4_label"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_TTL: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_TTL"] = attr.value.aclfield + attrs["field_mpls_label4_ttl"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_EXP: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_EXP"] = attr.value.aclfield + attrs["field_mpls_label4_exp"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_BOS: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_MPLS_LABEL4_BOS"] = attr.value.aclfield + attrs["field_mpls_label4_bos"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_FDB_DST_USER_META: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_FDB_DST_USER_META"] = attr.value.aclfield + attrs["field_fdb_dst_user_meta"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_DST_USER_META: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_DST_USER_META"] = attr.value.aclfield + attrs["field_route_dst_user_meta"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_DST_USER_META: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_DST_USER_META"] = attr.value.aclfield + attrs["field_neighbor_dst_user_meta"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_PORT_USER_META: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_PORT_USER_META"] = attr.value.aclfield + attrs["field_port_user_meta"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_VLAN_USER_META: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_VLAN_USER_META"] = attr.value.aclfield + attrs["field_vlan_user_meta"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ACL_USER_META: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ACL_USER_META"] = attr.value.aclfield + attrs["field_acl_user_meta"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_FDB_NPU_META_DST_HIT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_FDB_NPU_META_DST_HIT"] = attr.value.aclfield + attrs["field_fdb_npu_meta_dst_hit"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_NEIGHBOR_NPU_META_DST_HIT"] = attr.value.aclfield + attrs["field_neighbor_npu_meta_dst_hit"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_NPU_META_DST_HIT: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ROUTE_NPU_META_DST_HIT"] = attr.value.aclfield + attrs["field_route_npu_meta_dst_hit"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_BTH_OPCODE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_BTH_OPCODE"] = attr.value.aclfield + attrs["field_bth_opcode"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_AETH_SYNDROME: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_AETH_SYNDROME"] = attr.value.aclfield + attrs["field_aeth_syndrome"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MIN: + attrs["SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MIN"] = attr.value.aclfield + attrs["user_defined_field_group_min"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MAX: + attrs["SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MAX"] = attr.value.aclfield + attrs["user_defined_field_group_max"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE"] = attr.value.aclfield + attrs["field_acl_range_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_IPV6_NEXT_HEADER: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_IPV6_NEXT_HEADER"] = attr.value.aclfield + attrs["field_ipv6_next_header"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_GRE_KEY: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_GRE_KEY"] = attr.value.aclfield + attrs["field_gre_key"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_FIELD_TAM_INT_TYPE: + attrs["SAI_ACL_ENTRY_ATTR_FIELD_TAM_INT_TYPE"] = attr.value.aclfield + attrs["field_tam_int_type"] = attr.value.aclfield + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT"] = attr.value.aclaction + attrs["action_redirect"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_ENDPOINT_IP: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_ENDPOINT_IP"] = attr.value.aclaction + attrs["action_endpoint_ip"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST"] = attr.value.aclaction + attrs["action_redirect_list"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION"] = attr.value.aclaction + attrs["action_packet_action"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_FLOOD: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_FLOOD"] = attr.value.aclaction + attrs["action_flood"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_COUNTER: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_COUNTER"] = attr.value.aclaction + attrs["action_counter"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS"] = attr.value.aclaction + attrs["action_mirror_ingress"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_EGRESS: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_EGRESS"] = attr.value.aclaction + attrs["action_mirror_egress"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_POLICER: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_POLICER"] = attr.value.aclaction + attrs["action_set_policer"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_DECREMENT_TTL: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_DECREMENT_TTL"] = attr.value.aclaction + attrs["action_decrement_ttl"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_TC: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_TC"] = attr.value.aclaction + attrs["action_set_tc"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR"] = attr.value.aclaction + attrs["action_set_packet_color"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_ID: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_ID"] = attr.value.aclaction + attrs["action_set_inner_vlan_id"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_PRI: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_VLAN_PRI"] = attr.value.aclaction + attrs["action_set_inner_vlan_pri"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_ID: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_ID"] = attr.value.aclaction + attrs["action_set_outer_vlan_id"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_PRI: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_OUTER_VLAN_PRI"] = attr.value.aclaction + attrs["action_set_outer_vlan_pri"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_ID: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_ID"] = attr.value.aclaction + attrs["action_add_vlan_id"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_PRI: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_ADD_VLAN_PRI"] = attr.value.aclaction + attrs["action_add_vlan_pri"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_MAC: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_MAC"] = attr.value.aclaction + attrs["action_set_src_mac"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_MAC: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_MAC"] = attr.value.aclaction + attrs["action_set_dst_mac"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IP: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IP"] = attr.value.aclaction + attrs["action_set_src_ip"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IP: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IP"] = attr.value.aclaction + attrs["action_set_dst_ip"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IPV6: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_SRC_IPV6"] = attr.value.aclaction + attrs["action_set_src_ipv6"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IPV6: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_DST_IPV6"] = attr.value.aclaction + attrs["action_set_dst_ipv6"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_DSCP: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_DSCP"] = attr.value.aclaction + attrs["action_set_dscp"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_ECN: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_ECN"] = attr.value.aclaction + attrs["action_set_ecn"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_SRC_PORT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_SRC_PORT"] = attr.value.aclaction + attrs["action_set_l4_src_port"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_DST_PORT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_L4_DST_PORT"] = attr.value.aclaction + attrs["action_set_l4_dst_port"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_INGRESS_SAMPLEPACKET_ENABLE: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_INGRESS_SAMPLEPACKET_ENABLE"] = attr.value.aclaction + attrs["action_ingress_samplepacket_enable"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_SAMPLEPACKET_ENABLE: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_SAMPLEPACKET_ENABLE"] = attr.value.aclaction + attrs["action_egress_samplepacket_enable"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_ACL_META_DATA: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_ACL_META_DATA"] = attr.value.aclaction + attrs["action_set_acl_meta_data"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_BLOCK_PORT_LIST: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_EGRESS_BLOCK_PORT_LIST"] = attr.value.aclaction + attrs["action_egress_block_port_list"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_USER_TRAP_ID"] = attr.value.aclaction + attrs["action_set_user_trap_id"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_DO_NOT_LEARN: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_DO_NOT_LEARN"] = attr.value.aclaction + attrs["action_set_do_not_learn"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_ACL_DTEL_FLOW_OP: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_ACL_DTEL_FLOW_OP"] = attr.value.aclaction + attrs["action_acl_dtel_flow_op"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_DTEL_INT_SESSION: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_DTEL_INT_SESSION"] = attr.value.aclaction + attrs["action_dtel_int_session"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_DTEL_DROP_REPORT_ENABLE: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_DTEL_DROP_REPORT_ENABLE"] = attr.value.aclaction + attrs["action_dtel_drop_report_enable"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_DTEL_TAIL_DROP_REPORT_ENABLE: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_DTEL_TAIL_DROP_REPORT_ENABLE"] = attr.value.aclaction + attrs["action_dtel_tail_drop_report_enable"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_DTEL_FLOW_SAMPLE_PERCENT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_DTEL_FLOW_SAMPLE_PERCENT"] = attr.value.aclaction + attrs["action_dtel_flow_sample_percent"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_DTEL_REPORT_ALL_PACKETS: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_DTEL_REPORT_ALL_PACKETS"] = attr.value.aclaction + attrs["action_dtel_report_all_packets"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_NO_NAT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_NO_NAT"] = attr.value.aclaction + attrs["action_no_nat"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_INT_INSERT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_INT_INSERT"] = attr.value.aclaction + attrs["action_int_insert"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_INT_DELETE: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_INT_DELETE"] = attr.value.aclaction + attrs["action_int_delete"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_FLOW: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_FLOW"] = attr.value.aclaction + attrs["action_int_report_flow"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_DROPS: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_DROPS"] = attr.value.aclaction + attrs["action_int_report_drops"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_TAIL_DROPS: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_INT_REPORT_TAIL_DROPS"] = attr.value.aclaction + attrs["action_int_report_tail_drops"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_TAM_INT_OBJECT: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_TAM_INT_OBJECT"] = attr.value.aclaction + attrs["action_tam_int_object"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_ISOLATION_GROUP: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_ISOLATION_GROUP"] = attr.value.aclaction + attrs["action_set_isolation_group"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_MACSEC_FLOW: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_MACSEC_FLOW"] = attr.value.aclaction + attrs["action_macsec_flow"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_LAG_HASH_ID: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_LAG_HASH_ID"] = attr.value.aclaction + attrs["action_set_lag_hash_id"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ID"] = attr.value.aclaction + attrs["action_set_ecmp_hash_id"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_VRF"] = attr.value.aclaction + attrs["action_set_vrf"] = attr.value.aclaction + + if attr.id == SAI_ACL_ENTRY_ATTR_ACTION_SET_FORWARDING_CLASS: + attrs["SAI_ACL_ENTRY_ATTR_ACTION_SET_FORWARDING_CLASS"] = attr.value.aclaction + attrs["action_set_forwarding_class"] = attr.value.aclaction + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_acl_counter(client, + table_id=None, + enable_packet_count=None, + enable_byte_count=None, + packets=None, + bytes=None, + label=None, + custom_attribute=None): + """ + sai_create_acl_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of acl_counter CREATE attributes. + + Returns: + sai_thrift_object_id_t: acl_counter_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if table_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=table_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_TABLE_ID, + value=attribute_value) + attr_list.append(attribute) + + if enable_packet_count is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_packet_count) + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if enable_byte_count is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_byte_count) + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if packets is not None: + attribute_value = sai_thrift_attribute_value_t(u64=packets) + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_PACKETS, + value=attribute_value) + attr_list.append(attribute) + + if bytes is not None: + attribute_value = sai_thrift_attribute_value_t(u64=bytes) + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_BYTES, + value=attribute_value) + attr_list.append(attribute) + + if label is not None: + attribute_value = sai_thrift_attribute_value_t(chardata=label) + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_acl_counter(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_acl_counter(client, + acl_counter_oid): + """ + sai_remove_acl_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + acl_counter_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_acl_counter(acl_counter_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_acl_counter_attribute(client, + acl_counter_oid, + packets=None, + bytes=None, + label=None, + custom_attribute=None): + """ + sai_set_acl_counter_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + acl_counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_counter SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if packets is not None: + attr_value = sai_thrift_attribute_value_t(u64=packets) + attr = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_PACKETS, + value=attr_value) + client.sai_thrift_set_acl_counter_attribute(acl_counter_oid, attr) + + if bytes is not None: + attr_value = sai_thrift_attribute_value_t(u64=bytes) + attr = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_BYTES, + value=attr_value) + client.sai_thrift_set_acl_counter_attribute(acl_counter_oid, attr) + + if label is not None: + attr_value = sai_thrift_attribute_value_t(chardata=label) + attr = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_LABEL, + value=attr_value) + client.sai_thrift_set_acl_counter_attribute(acl_counter_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_acl_counter_attribute(acl_counter_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_acl_counter_attribute(client, + acl_counter_oid, + table_id=None, + enable_packet_count=None, + enable_byte_count=None, + packets=None, + bytes=None, + label=None, + custom_attribute=None): + """ + sai_get_acl_counter_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + acl_counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_counter GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if table_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_TABLE_ID) + attr_list.append(attribute) + + if enable_packet_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT) + attr_list.append(attribute) + + if enable_byte_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT) + attr_list.append(attribute) + + if packets is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_PACKETS) + attr_list.append(attribute) + + if bytes is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_BYTES) + attr_list.append(attribute) + + if label is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_COUNTER_ATTR_LABEL) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_acl_counter_attribute(acl_counter_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ACL_COUNTER_ATTR_TABLE_ID: + attrs["SAI_ACL_COUNTER_ATTR_TABLE_ID"] = attr.value.oid + attrs["table_id"] = attr.value.oid + + if attr.id == SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT: + attrs["SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT"] = attr.value.booldata + attrs["enable_packet_count"] = attr.value.booldata + + if attr.id == SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT: + attrs["SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT"] = attr.value.booldata + attrs["enable_byte_count"] = attr.value.booldata + + if attr.id == SAI_ACL_COUNTER_ATTR_PACKETS: + attrs["SAI_ACL_COUNTER_ATTR_PACKETS"] = attr.value.u64 + attrs["packets"] = attr.value.u64 + + if attr.id == SAI_ACL_COUNTER_ATTR_BYTES: + attrs["SAI_ACL_COUNTER_ATTR_BYTES"] = attr.value.u64 + attrs["bytes"] = attr.value.u64 + + if attr.id == SAI_ACL_COUNTER_ATTR_LABEL: + attrs["SAI_ACL_COUNTER_ATTR_LABEL"] = attr.value.chardata + attrs["label"] = attr.value.chardata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_acl_range(client, + type=None, + limit=None, + custom_attribute=None): + """ + sai_create_acl_range() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of acl_range CREATE attributes. + + Returns: + sai_thrift_object_id_t: acl_range_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_RANGE_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if limit is not None: + attribute_value = sai_thrift_attribute_value_t(u32range=limit) + attribute = sai_thrift_attribute_t(id=SAI_ACL_RANGE_ATTR_LIMIT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_acl_range(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_acl_range(client, + acl_range_oid): + """ + sai_remove_acl_range() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + acl_range_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_acl_range(acl_range_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_acl_range_attribute(client, + acl_range_oid, + custom_attribute=None): + """ + sai_set_acl_range_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + acl_range_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del acl_range_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_acl_range_attribute(client, + acl_range_oid, + type=None, + limit=None, + custom_attribute=None): + """ + sai_get_acl_range_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + acl_range_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_range GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_RANGE_ATTR_TYPE) + attr_list.append(attribute) + + if limit is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_RANGE_ATTR_LIMIT) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_acl_range_attribute(acl_range_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ACL_RANGE_ATTR_TYPE: + attrs["SAI_ACL_RANGE_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_ACL_RANGE_ATTR_LIMIT: + attrs["SAI_ACL_RANGE_ATTR_LIMIT"] = attr.value.u32range + attrs["limit"] = attr.value.u32range + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_acl_table_group(client, + acl_stage=None, + acl_bind_point_type_list=None, + type=None, + custom_attribute=None): + """ + sai_create_acl_table_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of acl_table_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: acl_table_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if acl_stage is not None: + attribute_value = sai_thrift_attribute_value_t(s32=acl_stage) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE, + value=attribute_value) + attr_list.append(attribute) + + if acl_bind_point_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=acl_bind_point_type_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_acl_table_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_acl_table_group(client, + acl_table_group_oid): + """ + sai_remove_acl_table_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + acl_table_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_acl_table_group(acl_table_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_acl_table_group_attribute(client, + acl_table_group_oid, + custom_attribute=None): + """ + sai_set_acl_table_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + acl_table_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del acl_table_group_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_acl_table_group_attribute(client, + acl_table_group_oid, + acl_stage=None, + acl_bind_point_type_list=None, + type=None, + member_list=None, + custom_attribute=None): + """ + sai_get_acl_table_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + acl_table_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_table_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if acl_stage is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE) + attr_list.append(attribute) + + if acl_bind_point_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=acl_bind_point_type_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_TYPE) + attr_list.append(attribute) + + if member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=member_list) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_ATTR_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_acl_table_group_attribute(acl_table_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE: + attrs["SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE"] = attr.value.s32 + attrs["acl_stage"] = attr.value.s32 + + if attr.id == SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST: + attrs["SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST"] = attr.value.s32list + attrs["acl_bind_point_type_list"] = attr.value.s32list + + if attr.id == SAI_ACL_TABLE_GROUP_ATTR_TYPE: + attrs["SAI_ACL_TABLE_GROUP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_ACL_TABLE_GROUP_ATTR_MEMBER_LIST: + attrs["SAI_ACL_TABLE_GROUP_ATTR_MEMBER_LIST"] = attr.value.objlist + attrs["member_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_acl_table_group_member(client, + acl_table_group_id=None, + acl_table_id=None, + priority=None, + custom_attribute=None): + """ + sai_create_acl_table_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of acl_table_group_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: acl_table_group_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if acl_table_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=acl_table_group_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if acl_table_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=acl_table_id) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID, + value=attribute_value) + attr_list.append(attribute) + + if priority is not None: + attribute_value = sai_thrift_attribute_value_t(u32=priority) + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_acl_table_group_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_acl_table_group_member(client, + acl_table_group_member_oid): + """ + sai_remove_acl_table_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + acl_table_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_acl_table_group_member(acl_table_group_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_acl_table_group_member_attribute(client, + acl_table_group_member_oid, + custom_attribute=None): + """ + sai_set_acl_table_group_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + acl_table_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del acl_table_group_member_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_acl_table_group_member_attribute(client, + acl_table_group_member_oid, + acl_table_group_id=None, + acl_table_id=None, + priority=None, + custom_attribute=None): + """ + sai_get_acl_table_group_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + acl_table_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of acl_table_group_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if acl_table_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID) + attr_list.append(attribute) + + if acl_table_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID) + attr_list.append(attribute) + + if priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_acl_table_group_member_attribute(acl_table_group_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID: + attrs["SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID"] = attr.value.oid + attrs["acl_table_group_id"] = attr.value.oid + + if attr.id == SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID: + attrs["SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID"] = attr.value.oid + attrs["acl_table_id"] = attr.value.oid + + if attr.id == SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY: + attrs["SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY"] = attr.value.u32 + attrs["priority"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# bfd API + +def sai_thrift_create_bfd_session(client, + type=None, + virtual_router=None, + port=None, + local_discriminator=None, + remote_discriminator=None, + udp_src_port=None, + vlan_id=None, + bfd_encapsulation_type=None, + iphdr_version=None, + src_ip_address=None, + dst_ip_address=None, + tunnel_src_ip_address=None, + tunnel_dst_ip_address=None, + src_mac_address=None, + dst_mac_address=None, + min_tx=None, + min_rx=None, + multiplier=None, + hw_lookup_valid=None, + tc=None, + vlan_tpid=None, + vlan_pri=None, + vlan_cfi=None, + vlan_header_valid=None, + tos=None, + ttl=None, + tunnel_tos=None, + tunnel_ttl=None, + echo_enable=None, + multihop=None, + cbit=None, + offload_type=None, + custom_attribute=None): + """ + sai_create_bfd_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of bfd_session CREATE attributes. + + Returns: + sai_thrift_object_id_t: bfd_session_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if virtual_router is not None: + attribute_value = sai_thrift_attribute_value_t(oid=virtual_router) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VIRTUAL_ROUTER, + value=attribute_value) + attr_list.append(attribute) + + if port is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_PORT, + value=attribute_value) + attr_list.append(attribute) + + if local_discriminator is not None: + attribute_value = sai_thrift_attribute_value_t(u32=local_discriminator) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_LOCAL_DISCRIMINATOR, + value=attribute_value) + attr_list.append(attribute) + + if remote_discriminator is not None: + attribute_value = sai_thrift_attribute_value_t(u32=remote_discriminator) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_REMOTE_DISCRIMINATOR, + value=attribute_value) + attr_list.append(attribute) + + if udp_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(u32=udp_src_port) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_UDP_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if bfd_encapsulation_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=bfd_encapsulation_type) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_BFD_ENCAPSULATION_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if iphdr_version is not None: + attribute_value = sai_thrift_attribute_value_t(u8=iphdr_version) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_IPHDR_VERSION, + value=attribute_value) + attr_list.append(attribute) + + if src_ip_address is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=src_ip_address) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip_address is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=dst_ip_address) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_src_ip_address is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=tunnel_src_ip_address) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_SRC_IP_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_dst_ip_address is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=tunnel_dst_ip_address) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_DST_IP_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_SRC_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if dst_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=dst_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if min_tx is not None: + attribute_value = sai_thrift_attribute_value_t(u32=min_tx) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MIN_TX, + value=attribute_value) + attr_list.append(attribute) + + if min_rx is not None: + attribute_value = sai_thrift_attribute_value_t(u32=min_rx) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MIN_RX, + value=attribute_value) + attr_list.append(attribute) + + if multiplier is not None: + attribute_value = sai_thrift_attribute_value_t(u8=multiplier) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MULTIPLIER, + value=attribute_value) + attr_list.append(attribute) + + if hw_lookup_valid is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=hw_lookup_valid) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_HW_LOOKUP_VALID, + value=attribute_value) + attr_list.append(attribute) + + if tc is not None: + attribute_value = sai_thrift_attribute_value_t(u8=tc) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TC, + value=attribute_value) + attr_list.append(attribute) + + if vlan_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_tpid) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_TPID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(u8=vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if vlan_cfi is not None: + attribute_value = sai_thrift_attribute_value_t(u8=vlan_cfi) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_CFI, + value=attribute_value) + attr_list.append(attribute) + + if vlan_header_valid is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=vlan_header_valid) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_HEADER_VALID, + value=attribute_value) + attr_list.append(attribute) + + if tos is not None: + attribute_value = sai_thrift_attribute_value_t(u8=tos) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TOS, + value=attribute_value) + attr_list.append(attribute) + + if ttl is not None: + attribute_value = sai_thrift_attribute_value_t(u8=ttl) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TTL, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_tos is not None: + attribute_value = sai_thrift_attribute_value_t(u8=tunnel_tos) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_TOS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(u8=tunnel_ttl) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_TTL, + value=attribute_value) + attr_list.append(attribute) + + if echo_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=echo_enable) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_ECHO_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if multihop is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=multihop) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MULTIHOP, + value=attribute_value) + attr_list.append(attribute) + + if cbit is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=cbit) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_CBIT, + value=attribute_value) + attr_list.append(attribute) + + if offload_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=offload_type) + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_OFFLOAD_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_bfd_session(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_bfd_session(client, + bfd_session_oid): + """ + sai_remove_bfd_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bfd_session_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_bfd_session(bfd_session_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_bfd_session_attribute(client, + bfd_session_oid, + virtual_router=None, + port=None, + tc=None, + vlan_tpid=None, + vlan_pri=None, + vlan_cfi=None, + iphdr_version=None, + tos=None, + ttl=None, + tunnel_tos=None, + tunnel_ttl=None, + src_mac_address=None, + dst_mac_address=None, + echo_enable=None, + min_tx=None, + min_rx=None, + multiplier=None, + custom_attribute=None): + """ + sai_set_bfd_session_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + bfd_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of bfd_session SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if virtual_router is not None: + attr_value = sai_thrift_attribute_value_t(oid=virtual_router) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VIRTUAL_ROUTER, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if port is not None: + attr_value = sai_thrift_attribute_value_t(oid=port) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_PORT, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if tc is not None: + attr_value = sai_thrift_attribute_value_t(u8=tc) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TC, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if vlan_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=vlan_tpid) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_TPID, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(u8=vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if vlan_cfi is not None: + attr_value = sai_thrift_attribute_value_t(u8=vlan_cfi) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_CFI, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if iphdr_version is not None: + attr_value = sai_thrift_attribute_value_t(u8=iphdr_version) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_IPHDR_VERSION, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if tos is not None: + attr_value = sai_thrift_attribute_value_t(u8=tos) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TOS, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if ttl is not None: + attr_value = sai_thrift_attribute_value_t(u8=ttl) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TTL, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if tunnel_tos is not None: + attr_value = sai_thrift_attribute_value_t(u8=tunnel_tos) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_TOS, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if tunnel_ttl is not None: + attr_value = sai_thrift_attribute_value_t(u8=tunnel_ttl) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_TTL, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if src_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_SRC_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if dst_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=dst_mac_address) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if echo_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=echo_enable) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_ECHO_ENABLE, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if min_tx is not None: + attr_value = sai_thrift_attribute_value_t(u32=min_tx) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MIN_TX, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if min_rx is not None: + attr_value = sai_thrift_attribute_value_t(u32=min_rx) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MIN_RX, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if multiplier is not None: + attr_value = sai_thrift_attribute_value_t(u8=multiplier) + attr = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MULTIPLIER, + value=attr_value) + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_bfd_session_attribute(bfd_session_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_bfd_session_attribute(client, + bfd_session_oid, + type=None, + hw_lookup_valid=None, + virtual_router=None, + port=None, + local_discriminator=None, + remote_discriminator=None, + udp_src_port=None, + tc=None, + vlan_tpid=None, + vlan_id=None, + vlan_pri=None, + vlan_cfi=None, + vlan_header_valid=None, + bfd_encapsulation_type=None, + iphdr_version=None, + tos=None, + ttl=None, + src_ip_address=None, + dst_ip_address=None, + tunnel_tos=None, + tunnel_ttl=None, + tunnel_src_ip_address=None, + tunnel_dst_ip_address=None, + src_mac_address=None, + dst_mac_address=None, + echo_enable=None, + multihop=None, + cbit=None, + min_tx=None, + min_rx=None, + multiplier=None, + remote_min_tx=None, + remote_min_rx=None, + state=None, + offload_type=None, + negotiated_tx=None, + negotiated_rx=None, + local_diag=None, + remote_diag=None, + remote_multiplier=None, + custom_attribute=None): + """ + sai_get_bfd_session_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + bfd_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of bfd_session GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TYPE) + attr_list.append(attribute) + + if hw_lookup_valid is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_HW_LOOKUP_VALID) + attr_list.append(attribute) + + if virtual_router is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VIRTUAL_ROUTER) + attr_list.append(attribute) + + if port is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_PORT) + attr_list.append(attribute) + + if local_discriminator is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_LOCAL_DISCRIMINATOR) + attr_list.append(attribute) + + if remote_discriminator is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_REMOTE_DISCRIMINATOR) + attr_list.append(attribute) + + if udp_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_UDP_SRC_PORT) + attr_list.append(attribute) + + if tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TC) + attr_list.append(attribute) + + if vlan_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_TPID) + attr_list.append(attribute) + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_ID) + attr_list.append(attribute) + + if vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_PRI) + attr_list.append(attribute) + + if vlan_cfi is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_CFI) + attr_list.append(attribute) + + if vlan_header_valid is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_VLAN_HEADER_VALID) + attr_list.append(attribute) + + if bfd_encapsulation_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_BFD_ENCAPSULATION_TYPE) + attr_list.append(attribute) + + if iphdr_version is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_IPHDR_VERSION) + attr_list.append(attribute) + + if tos is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TOS) + attr_list.append(attribute) + + if ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TTL) + attr_list.append(attribute) + + if src_ip_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS) + attr_list.append(attribute) + + if dst_ip_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS) + attr_list.append(attribute) + + if tunnel_tos is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_TOS) + attr_list.append(attribute) + + if tunnel_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_TTL) + attr_list.append(attribute) + + if tunnel_src_ip_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_SRC_IP_ADDRESS) + attr_list.append(attribute) + + if tunnel_dst_ip_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_TUNNEL_DST_IP_ADDRESS) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_SRC_MAC_ADDRESS) + attr_list.append(attribute) + + if dst_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS) + attr_list.append(attribute) + + if echo_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_ECHO_ENABLE) + attr_list.append(attribute) + + if multihop is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MULTIHOP) + attr_list.append(attribute) + + if cbit is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_CBIT) + attr_list.append(attribute) + + if min_tx is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MIN_TX) + attr_list.append(attribute) + + if min_rx is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MIN_RX) + attr_list.append(attribute) + + if multiplier is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_MULTIPLIER) + attr_list.append(attribute) + + if remote_min_tx is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_REMOTE_MIN_TX) + attr_list.append(attribute) + + if remote_min_rx is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_REMOTE_MIN_RX) + attr_list.append(attribute) + + if state is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_STATE) + attr_list.append(attribute) + + if offload_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_OFFLOAD_TYPE) + attr_list.append(attribute) + + if negotiated_tx is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_NEGOTIATED_TX) + attr_list.append(attribute) + + if negotiated_rx is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_NEGOTIATED_RX) + attr_list.append(attribute) + + if local_diag is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_LOCAL_DIAG) + attr_list.append(attribute) + + if remote_diag is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_REMOTE_DIAG) + attr_list.append(attribute) + + if remote_multiplier is not None: + attribute = sai_thrift_attribute_t(id=SAI_BFD_SESSION_ATTR_REMOTE_MULTIPLIER) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_bfd_session_attribute(bfd_session_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_BFD_SESSION_ATTR_TYPE: + attrs["SAI_BFD_SESSION_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_BFD_SESSION_ATTR_HW_LOOKUP_VALID: + attrs["SAI_BFD_SESSION_ATTR_HW_LOOKUP_VALID"] = attr.value.booldata + attrs["hw_lookup_valid"] = attr.value.booldata + + if attr.id == SAI_BFD_SESSION_ATTR_VIRTUAL_ROUTER: + attrs["SAI_BFD_SESSION_ATTR_VIRTUAL_ROUTER"] = attr.value.oid + attrs["virtual_router"] = attr.value.oid + + if attr.id == SAI_BFD_SESSION_ATTR_PORT: + attrs["SAI_BFD_SESSION_ATTR_PORT"] = attr.value.oid + attrs["port"] = attr.value.oid + + if attr.id == SAI_BFD_SESSION_ATTR_LOCAL_DISCRIMINATOR: + attrs["SAI_BFD_SESSION_ATTR_LOCAL_DISCRIMINATOR"] = attr.value.u32 + attrs["local_discriminator"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_REMOTE_DISCRIMINATOR: + attrs["SAI_BFD_SESSION_ATTR_REMOTE_DISCRIMINATOR"] = attr.value.u32 + attrs["remote_discriminator"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_UDP_SRC_PORT: + attrs["SAI_BFD_SESSION_ATTR_UDP_SRC_PORT"] = attr.value.u32 + attrs["udp_src_port"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_TC: + attrs["SAI_BFD_SESSION_ATTR_TC"] = attr.value.u8 + attrs["tc"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_VLAN_TPID: + attrs["SAI_BFD_SESSION_ATTR_VLAN_TPID"] = attr.value.u16 + attrs["vlan_tpid"] = attr.value.u16 + + if attr.id == SAI_BFD_SESSION_ATTR_VLAN_ID: + attrs["SAI_BFD_SESSION_ATTR_VLAN_ID"] = attr.value.u16 + attrs["vlan_id"] = attr.value.u16 + + if attr.id == SAI_BFD_SESSION_ATTR_VLAN_PRI: + attrs["SAI_BFD_SESSION_ATTR_VLAN_PRI"] = attr.value.u8 + attrs["vlan_pri"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_VLAN_CFI: + attrs["SAI_BFD_SESSION_ATTR_VLAN_CFI"] = attr.value.u8 + attrs["vlan_cfi"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_VLAN_HEADER_VALID: + attrs["SAI_BFD_SESSION_ATTR_VLAN_HEADER_VALID"] = attr.value.booldata + attrs["vlan_header_valid"] = attr.value.booldata + + if attr.id == SAI_BFD_SESSION_ATTR_BFD_ENCAPSULATION_TYPE: + attrs["SAI_BFD_SESSION_ATTR_BFD_ENCAPSULATION_TYPE"] = attr.value.s32 + attrs["bfd_encapsulation_type"] = attr.value.s32 + + if attr.id == SAI_BFD_SESSION_ATTR_IPHDR_VERSION: + attrs["SAI_BFD_SESSION_ATTR_IPHDR_VERSION"] = attr.value.u8 + attrs["iphdr_version"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_TOS: + attrs["SAI_BFD_SESSION_ATTR_TOS"] = attr.value.u8 + attrs["tos"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_TTL: + attrs["SAI_BFD_SESSION_ATTR_TTL"] = attr.value.u8 + attrs["ttl"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS: + attrs["SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS"] = attr.value.ipaddr + attrs["src_ip_address"] = attr.value.ipaddr + + if attr.id == SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS: + attrs["SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS"] = attr.value.ipaddr + attrs["dst_ip_address"] = attr.value.ipaddr + + if attr.id == SAI_BFD_SESSION_ATTR_TUNNEL_TOS: + attrs["SAI_BFD_SESSION_ATTR_TUNNEL_TOS"] = attr.value.u8 + attrs["tunnel_tos"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_TUNNEL_TTL: + attrs["SAI_BFD_SESSION_ATTR_TUNNEL_TTL"] = attr.value.u8 + attrs["tunnel_ttl"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_TUNNEL_SRC_IP_ADDRESS: + attrs["SAI_BFD_SESSION_ATTR_TUNNEL_SRC_IP_ADDRESS"] = attr.value.ipaddr + attrs["tunnel_src_ip_address"] = attr.value.ipaddr + + if attr.id == SAI_BFD_SESSION_ATTR_TUNNEL_DST_IP_ADDRESS: + attrs["SAI_BFD_SESSION_ATTR_TUNNEL_DST_IP_ADDRESS"] = attr.value.ipaddr + attrs["tunnel_dst_ip_address"] = attr.value.ipaddr + + if attr.id == SAI_BFD_SESSION_ATTR_SRC_MAC_ADDRESS: + attrs["SAI_BFD_SESSION_ATTR_SRC_MAC_ADDRESS"] = attr.value.mac + attrs["src_mac_address"] = attr.value.mac + + if attr.id == SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS: + attrs["SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS"] = attr.value.mac + attrs["dst_mac_address"] = attr.value.mac + + if attr.id == SAI_BFD_SESSION_ATTR_ECHO_ENABLE: + attrs["SAI_BFD_SESSION_ATTR_ECHO_ENABLE"] = attr.value.booldata + attrs["echo_enable"] = attr.value.booldata + + if attr.id == SAI_BFD_SESSION_ATTR_MULTIHOP: + attrs["SAI_BFD_SESSION_ATTR_MULTIHOP"] = attr.value.booldata + attrs["multihop"] = attr.value.booldata + + if attr.id == SAI_BFD_SESSION_ATTR_CBIT: + attrs["SAI_BFD_SESSION_ATTR_CBIT"] = attr.value.booldata + attrs["cbit"] = attr.value.booldata + + if attr.id == SAI_BFD_SESSION_ATTR_MIN_TX: + attrs["SAI_BFD_SESSION_ATTR_MIN_TX"] = attr.value.u32 + attrs["min_tx"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_MIN_RX: + attrs["SAI_BFD_SESSION_ATTR_MIN_RX"] = attr.value.u32 + attrs["min_rx"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_MULTIPLIER: + attrs["SAI_BFD_SESSION_ATTR_MULTIPLIER"] = attr.value.u8 + attrs["multiplier"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_REMOTE_MIN_TX: + attrs["SAI_BFD_SESSION_ATTR_REMOTE_MIN_TX"] = attr.value.u32 + attrs["remote_min_tx"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_REMOTE_MIN_RX: + attrs["SAI_BFD_SESSION_ATTR_REMOTE_MIN_RX"] = attr.value.u32 + attrs["remote_min_rx"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_STATE: + attrs["SAI_BFD_SESSION_ATTR_STATE"] = attr.value.s32 + attrs["state"] = attr.value.s32 + + if attr.id == SAI_BFD_SESSION_ATTR_OFFLOAD_TYPE: + attrs["SAI_BFD_SESSION_ATTR_OFFLOAD_TYPE"] = attr.value.s32 + attrs["offload_type"] = attr.value.s32 + + if attr.id == SAI_BFD_SESSION_ATTR_NEGOTIATED_TX: + attrs["SAI_BFD_SESSION_ATTR_NEGOTIATED_TX"] = attr.value.u32 + attrs["negotiated_tx"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_NEGOTIATED_RX: + attrs["SAI_BFD_SESSION_ATTR_NEGOTIATED_RX"] = attr.value.u32 + attrs["negotiated_rx"] = attr.value.u32 + + if attr.id == SAI_BFD_SESSION_ATTR_LOCAL_DIAG: + attrs["SAI_BFD_SESSION_ATTR_LOCAL_DIAG"] = attr.value.u8 + attrs["local_diag"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_REMOTE_DIAG: + attrs["SAI_BFD_SESSION_ATTR_REMOTE_DIAG"] = attr.value.u8 + attrs["remote_diag"] = attr.value.u8 + + if attr.id == SAI_BFD_SESSION_ATTR_REMOTE_MULTIPLIER: + attrs["SAI_BFD_SESSION_ATTR_REMOTE_MULTIPLIER"] = attr.value.u8 + attrs["remote_multiplier"] = attr.value.u8 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_bfd_session_stats(client, + bfd_session_oid): + """ + sai_get_bfd_session_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bfd_session_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS) + counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS) + counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS) + + counters = [0] * 3 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_bfd_session_stats(bfd_session_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BFD_SESSION_STAT_IN_PACKETS"] = counters[0] + stats["SAI_BFD_SESSION_STAT_OUT_PACKETS"] = counters[1] + stats["SAI_BFD_SESSION_STAT_DROP_PACKETS"] = counters[2] + + return stats + + +def sai_thrift_get_bfd_session_stats_ext(client, + bfd_session_oid, + mode): + """ + sai_get_bfd_session_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bfd_session_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS) + counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS) + counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS) + + counters = [0] * 3 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_bfd_session_stats_ext(bfd_session_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BFD_SESSION_STAT_IN_PACKETS"] = counters[0] + stats["SAI_BFD_SESSION_STAT_OUT_PACKETS"] = counters[1] + stats["SAI_BFD_SESSION_STAT_DROP_PACKETS"] = counters[2] + + return stats + + +def sai_thrift_clear_bfd_session_stats(client, + bfd_session_oid): + """ + sai_clear_bfd_session_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bfd_session_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BFD_SESSION_STAT_IN_PACKETS) + counter_ids.append(SAI_BFD_SESSION_STAT_OUT_PACKETS) + counter_ids.append(SAI_BFD_SESSION_STAT_DROP_PACKETS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_bfd_session_stats(bfd_session_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# bridge API + +def sai_thrift_create_bridge_port(client, + type=None, + port_id=None, + vlan_id=None, + rif_id=None, + tunnel_id=None, + bridge_id=None, + tagging_mode=None, + fdb_learning_mode=None, + max_learned_addresses=None, + fdb_learning_limit_violation_packet_action=None, + admin_state=None, + ingress_filtering=None, + egress_filtering=None, + isolation_group=None, + custom_attribute=None): + """ + sai_create_bridge_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of bridge_port CREATE attributes. + + Returns: + sai_thrift_object_id_t: bridge_port_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if rif_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=rif_id) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_RIF_ID, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=tunnel_id) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TUNNEL_ID, + value=attribute_value) + attr_list.append(attribute) + + if bridge_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_id) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_BRIDGE_ID, + value=attribute_value) + attr_list.append(attribute) + + if tagging_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tagging_mode) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TAGGING_MODE, + value=attribute_value) + attr_list.append(attribute) + + if fdb_learning_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fdb_learning_mode) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE, + value=attribute_value) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_MAX_LEARNED_ADDRESSES, + value=attribute_value) + attr_list.append(attribute) + + if fdb_learning_limit_violation_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fdb_learning_limit_violation_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if admin_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_state) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_ADMIN_STATE, + value=attribute_value) + attr_list.append(attribute) + + if ingress_filtering is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ingress_filtering) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_INGRESS_FILTERING, + value=attribute_value) + attr_list.append(attribute) + + if egress_filtering is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=egress_filtering) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_EGRESS_FILTERING, + value=attribute_value) + attr_list.append(attribute) + + if isolation_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=isolation_group) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_ISOLATION_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_bridge_port(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_bridge_port(client, + bridge_port_oid): + """ + sai_remove_bridge_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_bridge_port(bridge_port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_bridge_port_attribute(client, + bridge_port_oid, + tagging_mode=None, + bridge_id=None, + fdb_learning_mode=None, + max_learned_addresses=None, + fdb_learning_limit_violation_packet_action=None, + admin_state=None, + ingress_filtering=None, + egress_filtering=None, + isolation_group=None, + custom_attribute=None): + """ + sai_set_bridge_port_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + bridge_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of bridge_port SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if tagging_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=tagging_mode) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TAGGING_MODE, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if bridge_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=bridge_id) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_BRIDGE_ID, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if fdb_learning_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=fdb_learning_mode) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if max_learned_addresses is not None: + attr_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_MAX_LEARNED_ADDRESSES, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if fdb_learning_limit_violation_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=fdb_learning_limit_violation_packet_action) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if admin_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_state) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_ADMIN_STATE, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if ingress_filtering is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ingress_filtering) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_INGRESS_FILTERING, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if egress_filtering is not None: + attr_value = sai_thrift_attribute_value_t(booldata=egress_filtering) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_EGRESS_FILTERING, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if isolation_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=isolation_group) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_ISOLATION_GROUP, + value=attr_value) + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_bridge_port_attribute(bridge_port_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_bridge_port_attribute(client, + bridge_port_oid, + type=None, + port_id=None, + tagging_mode=None, + vlan_id=None, + rif_id=None, + tunnel_id=None, + bridge_id=None, + fdb_learning_mode=None, + max_learned_addresses=None, + fdb_learning_limit_violation_packet_action=None, + admin_state=None, + ingress_filtering=None, + egress_filtering=None, + isolation_group=None, + custom_attribute=None): + """ + sai_get_bridge_port_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + bridge_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of bridge_port GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TYPE) + attr_list.append(attribute) + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_PORT_ID) + attr_list.append(attribute) + + if tagging_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TAGGING_MODE) + attr_list.append(attribute) + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_VLAN_ID) + attr_list.append(attribute) + + if rif_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_RIF_ID) + attr_list.append(attribute) + + if tunnel_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_TUNNEL_ID) + attr_list.append(attribute) + + if bridge_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_BRIDGE_ID) + attr_list.append(attribute) + + if fdb_learning_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_MAX_LEARNED_ADDRESSES) + attr_list.append(attribute) + + if fdb_learning_limit_violation_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION_PACKET_ACTION) + attr_list.append(attribute) + + if admin_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_ADMIN_STATE) + attr_list.append(attribute) + + if ingress_filtering is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_INGRESS_FILTERING) + attr_list.append(attribute) + + if egress_filtering is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_EGRESS_FILTERING) + attr_list.append(attribute) + + if isolation_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_PORT_ATTR_ISOLATION_GROUP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_bridge_port_attribute(bridge_port_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_BRIDGE_PORT_ATTR_TYPE: + attrs["SAI_BRIDGE_PORT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_PORT_ATTR_PORT_ID: + attrs["SAI_BRIDGE_PORT_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_BRIDGE_PORT_ATTR_TAGGING_MODE: + attrs["SAI_BRIDGE_PORT_ATTR_TAGGING_MODE"] = attr.value.s32 + attrs["tagging_mode"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_PORT_ATTR_VLAN_ID: + attrs["SAI_BRIDGE_PORT_ATTR_VLAN_ID"] = attr.value.u16 + attrs["vlan_id"] = attr.value.u16 + + if attr.id == SAI_BRIDGE_PORT_ATTR_RIF_ID: + attrs["SAI_BRIDGE_PORT_ATTR_RIF_ID"] = attr.value.oid + attrs["rif_id"] = attr.value.oid + + if attr.id == SAI_BRIDGE_PORT_ATTR_TUNNEL_ID: + attrs["SAI_BRIDGE_PORT_ATTR_TUNNEL_ID"] = attr.value.oid + attrs["tunnel_id"] = attr.value.oid + + if attr.id == SAI_BRIDGE_PORT_ATTR_BRIDGE_ID: + attrs["SAI_BRIDGE_PORT_ATTR_BRIDGE_ID"] = attr.value.oid + attrs["bridge_id"] = attr.value.oid + + if attr.id == SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE: + attrs["SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE"] = attr.value.s32 + attrs["fdb_learning_mode"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_PORT_ATTR_MAX_LEARNED_ADDRESSES: + attrs["SAI_BRIDGE_PORT_ATTR_MAX_LEARNED_ADDRESSES"] = attr.value.u32 + attrs["max_learned_addresses"] = attr.value.u32 + + if attr.id == SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION_PACKET_ACTION: + attrs["SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION_PACKET_ACTION"] = attr.value.s32 + attrs["fdb_learning_limit_violation_packet_action"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_PORT_ATTR_ADMIN_STATE: + attrs["SAI_BRIDGE_PORT_ATTR_ADMIN_STATE"] = attr.value.booldata + attrs["admin_state"] = attr.value.booldata + + if attr.id == SAI_BRIDGE_PORT_ATTR_INGRESS_FILTERING: + attrs["SAI_BRIDGE_PORT_ATTR_INGRESS_FILTERING"] = attr.value.booldata + attrs["ingress_filtering"] = attr.value.booldata + + if attr.id == SAI_BRIDGE_PORT_ATTR_EGRESS_FILTERING: + attrs["SAI_BRIDGE_PORT_ATTR_EGRESS_FILTERING"] = attr.value.booldata + attrs["egress_filtering"] = attr.value.booldata + + if attr.id == SAI_BRIDGE_PORT_ATTR_ISOLATION_GROUP: + attrs["SAI_BRIDGE_PORT_ATTR_ISOLATION_GROUP"] = attr.value.oid + attrs["isolation_group"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_bridge_port_stats(client, + bridge_port_oid): + """ + sai_get_bridge_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BRIDGE_PORT_STAT_IN_OCTETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_IN_PACKETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_OUT_OCTETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_OUT_PACKETS) + + counters = [0] * 4 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_bridge_port_stats(bridge_port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BRIDGE_PORT_STAT_IN_OCTETS"] = counters[0] + stats["SAI_BRIDGE_PORT_STAT_IN_PACKETS"] = counters[1] + stats["SAI_BRIDGE_PORT_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_BRIDGE_PORT_STAT_OUT_PACKETS"] = counters[3] + + return stats + + +def sai_thrift_get_bridge_port_stats_ext(client, + bridge_port_oid, + mode): + """ + sai_get_bridge_port_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_port_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BRIDGE_PORT_STAT_IN_OCTETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_IN_PACKETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_OUT_OCTETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_OUT_PACKETS) + + counters = [0] * 4 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_bridge_port_stats_ext(bridge_port_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BRIDGE_PORT_STAT_IN_OCTETS"] = counters[0] + stats["SAI_BRIDGE_PORT_STAT_IN_PACKETS"] = counters[1] + stats["SAI_BRIDGE_PORT_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_BRIDGE_PORT_STAT_OUT_PACKETS"] = counters[3] + + return stats + + +def sai_thrift_clear_bridge_port_stats(client, + bridge_port_oid): + """ + sai_clear_bridge_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BRIDGE_PORT_STAT_IN_OCTETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_IN_PACKETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_OUT_OCTETS) + counter_ids.append(SAI_BRIDGE_PORT_STAT_OUT_PACKETS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_bridge_port_stats(bridge_port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_bridge(client, + type=None, + max_learned_addresses=None, + learn_disable=None, + unknown_unicast_flood_control_type=None, + unknown_unicast_flood_group=None, + unknown_multicast_flood_control_type=None, + unknown_multicast_flood_group=None, + broadcast_flood_control_type=None, + broadcast_flood_group=None, + custom_attribute=None): + """ + sai_create_bridge() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of bridge CREATE attributes. + + Returns: + sai_thrift_object_id_t: bridge_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_MAX_LEARNED_ADDRESSES, + value=attribute_value) + attr_list.append(attribute) + + if learn_disable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=learn_disable) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_LEARN_DISABLE, + value=attribute_value) + attr_list.append(attribute) + + if unknown_unicast_flood_control_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=unknown_unicast_flood_control_type) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if unknown_unicast_flood_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_unicast_flood_group) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if unknown_multicast_flood_control_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=unknown_multicast_flood_control_type) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if unknown_multicast_flood_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_multicast_flood_group) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if broadcast_flood_control_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=broadcast_flood_control_type) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_BROADCAST_FLOOD_CONTROL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if broadcast_flood_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=broadcast_flood_group) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_BROADCAST_FLOOD_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_bridge(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_bridge(client, + bridge_oid): + """ + sai_remove_bridge() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_bridge(bridge_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_bridge_attribute(client, + bridge_oid, + max_learned_addresses=None, + learn_disable=None, + unknown_unicast_flood_control_type=None, + unknown_unicast_flood_group=None, + unknown_multicast_flood_control_type=None, + unknown_multicast_flood_group=None, + broadcast_flood_control_type=None, + broadcast_flood_group=None, + custom_attribute=None): + """ + sai_set_bridge_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + bridge_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of bridge SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if max_learned_addresses is not None: + attr_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_MAX_LEARNED_ADDRESSES, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if learn_disable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=learn_disable) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_LEARN_DISABLE, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if unknown_unicast_flood_control_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=unknown_unicast_flood_control_type) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if unknown_unicast_flood_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_unicast_flood_group) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if unknown_multicast_flood_control_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=unknown_multicast_flood_control_type) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if unknown_multicast_flood_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_multicast_flood_group) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if broadcast_flood_control_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=broadcast_flood_control_type) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_BROADCAST_FLOOD_CONTROL_TYPE, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if broadcast_flood_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=broadcast_flood_group) + attr = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_BROADCAST_FLOOD_GROUP, + value=attr_value) + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_bridge_attribute(bridge_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_bridge_attribute(client, + bridge_oid, + type=None, + port_list=None, + max_learned_addresses=None, + learn_disable=None, + unknown_unicast_flood_control_type=None, + unknown_unicast_flood_group=None, + unknown_multicast_flood_control_type=None, + unknown_multicast_flood_group=None, + broadcast_flood_control_type=None, + broadcast_flood_group=None, + custom_attribute=None): + """ + sai_get_bridge_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + bridge_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of bridge GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_TYPE) + attr_list.append(attribute) + + if port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=port_list) + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_MAX_LEARNED_ADDRESSES) + attr_list.append(attribute) + + if learn_disable is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_LEARN_DISABLE) + attr_list.append(attribute) + + if unknown_unicast_flood_control_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE) + attr_list.append(attribute) + + if unknown_unicast_flood_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP) + attr_list.append(attribute) + + if unknown_multicast_flood_control_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE) + attr_list.append(attribute) + + if unknown_multicast_flood_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP) + attr_list.append(attribute) + + if broadcast_flood_control_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_BROADCAST_FLOOD_CONTROL_TYPE) + attr_list.append(attribute) + + if broadcast_flood_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_BRIDGE_ATTR_BROADCAST_FLOOD_GROUP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_bridge_attribute(bridge_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_BRIDGE_ATTR_TYPE: + attrs["SAI_BRIDGE_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_ATTR_PORT_LIST: + attrs["SAI_BRIDGE_ATTR_PORT_LIST"] = attr.value.objlist + attrs["port_list"] = attr.value.objlist + + if attr.id == SAI_BRIDGE_ATTR_MAX_LEARNED_ADDRESSES: + attrs["SAI_BRIDGE_ATTR_MAX_LEARNED_ADDRESSES"] = attr.value.u32 + attrs["max_learned_addresses"] = attr.value.u32 + + if attr.id == SAI_BRIDGE_ATTR_LEARN_DISABLE: + attrs["SAI_BRIDGE_ATTR_LEARN_DISABLE"] = attr.value.booldata + attrs["learn_disable"] = attr.value.booldata + + if attr.id == SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE: + attrs["SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE"] = attr.value.s32 + attrs["unknown_unicast_flood_control_type"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP: + attrs["SAI_BRIDGE_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP"] = attr.value.oid + attrs["unknown_unicast_flood_group"] = attr.value.oid + + if attr.id == SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE: + attrs["SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE"] = attr.value.s32 + attrs["unknown_multicast_flood_control_type"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP: + attrs["SAI_BRIDGE_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP"] = attr.value.oid + attrs["unknown_multicast_flood_group"] = attr.value.oid + + if attr.id == SAI_BRIDGE_ATTR_BROADCAST_FLOOD_CONTROL_TYPE: + attrs["SAI_BRIDGE_ATTR_BROADCAST_FLOOD_CONTROL_TYPE"] = attr.value.s32 + attrs["broadcast_flood_control_type"] = attr.value.s32 + + if attr.id == SAI_BRIDGE_ATTR_BROADCAST_FLOOD_GROUP: + attrs["SAI_BRIDGE_ATTR_BROADCAST_FLOOD_GROUP"] = attr.value.oid + attrs["broadcast_flood_group"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_bridge_stats(client, + bridge_oid): + """ + sai_get_bridge_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BRIDGE_STAT_IN_OCTETS) + counter_ids.append(SAI_BRIDGE_STAT_IN_PACKETS) + counter_ids.append(SAI_BRIDGE_STAT_OUT_OCTETS) + counter_ids.append(SAI_BRIDGE_STAT_OUT_PACKETS) + + counters = [0] * 4 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_bridge_stats(bridge_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BRIDGE_STAT_IN_OCTETS"] = counters[0] + stats["SAI_BRIDGE_STAT_IN_PACKETS"] = counters[1] + stats["SAI_BRIDGE_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_BRIDGE_STAT_OUT_PACKETS"] = counters[3] + + return stats + + +def sai_thrift_get_bridge_stats_ext(client, + bridge_oid, + mode): + """ + sai_get_bridge_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BRIDGE_STAT_IN_OCTETS) + counter_ids.append(SAI_BRIDGE_STAT_IN_PACKETS) + counter_ids.append(SAI_BRIDGE_STAT_OUT_OCTETS) + counter_ids.append(SAI_BRIDGE_STAT_OUT_PACKETS) + + counters = [0] * 4 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_bridge_stats_ext(bridge_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BRIDGE_STAT_IN_OCTETS"] = counters[0] + stats["SAI_BRIDGE_STAT_IN_PACKETS"] = counters[1] + stats["SAI_BRIDGE_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_BRIDGE_STAT_OUT_PACKETS"] = counters[3] + + return stats + + +def sai_thrift_clear_bridge_stats(client, + bridge_oid): + """ + sai_clear_bridge_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + bridge_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BRIDGE_STAT_IN_OCTETS) + counter_ids.append(SAI_BRIDGE_STAT_IN_PACKETS) + counter_ids.append(SAI_BRIDGE_STAT_OUT_OCTETS) + counter_ids.append(SAI_BRIDGE_STAT_OUT_PACKETS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_bridge_stats(bridge_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# buffer API + +def sai_thrift_create_ingress_priority_group(client, + port=None, + index=None, + buffer_profile=None, + tam=None, + custom_attribute=None): + """ + sai_create_ingress_priority_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of ingress_priority_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: ingress_priority_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port) + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_PORT, + value=attribute_value) + attr_list.append(attribute) + + if index is not None: + attribute_value = sai_thrift_attribute_value_t(u8=index) + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if buffer_profile is not None: + attribute_value = sai_thrift_attribute_value_t(oid=buffer_profile) + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE, + value=attribute_value) + attr_list.append(attribute) + + if tam is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam) + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_TAM, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_ingress_priority_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_ingress_priority_group(client, + ingress_priority_group_oid): + """ + sai_remove_ingress_priority_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ingress_priority_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ingress_priority_group(ingress_priority_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ingress_priority_group_attribute(client, + ingress_priority_group_oid, + buffer_profile=None, + tam=None, + custom_attribute=None): + """ + sai_set_ingress_priority_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ingress_priority_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ingress_priority_group SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if buffer_profile is not None: + attr_value = sai_thrift_attribute_value_t(oid=buffer_profile) + attr = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE, + value=attr_value) + client.sai_thrift_set_ingress_priority_group_attribute(ingress_priority_group_oid, attr) + + if tam is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam) + attr = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_TAM, + value=attr_value) + client.sai_thrift_set_ingress_priority_group_attribute(ingress_priority_group_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_ingress_priority_group_attribute(ingress_priority_group_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_ingress_priority_group_attribute(client, + ingress_priority_group_oid, + buffer_profile=None, + port=None, + tam=None, + index=None, + custom_attribute=None): + """ + sai_get_ingress_priority_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ingress_priority_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ingress_priority_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if buffer_profile is not None: + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE) + attr_list.append(attribute) + + if port is not None: + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_PORT) + attr_list.append(attribute) + + if tam is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam) + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_TAM, + value=attribute_value) + attr_list.append(attribute) + + if index is not None: + attribute = sai_thrift_attribute_t(id=SAI_INGRESS_PRIORITY_GROUP_ATTR_INDEX) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ingress_priority_group_attribute(ingress_priority_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE: + attrs["SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE"] = attr.value.oid + attrs["buffer_profile"] = attr.value.oid + + if attr.id == SAI_INGRESS_PRIORITY_GROUP_ATTR_PORT: + attrs["SAI_INGRESS_PRIORITY_GROUP_ATTR_PORT"] = attr.value.oid + attrs["port"] = attr.value.oid + + if attr.id == SAI_INGRESS_PRIORITY_GROUP_ATTR_TAM: + attrs["SAI_INGRESS_PRIORITY_GROUP_ATTR_TAM"] = attr.value.objlist + attrs["tam"] = attr.value.objlist + + if attr.id == SAI_INGRESS_PRIORITY_GROUP_ATTR_INDEX: + attrs["SAI_INGRESS_PRIORITY_GROUP_ATTR_INDEX"] = attr.value.u8 + attrs["index"] = attr.value.u8 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_ingress_priority_group_stats(client, + ingress_priority_group_oid): + """ + sai_get_ingress_priority_group_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ingress_priority_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 10 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_ingress_priority_group_stats(ingress_priority_group_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS"] = counters[0] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES"] = counters[1] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES"] = counters[2] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_WATERMARK_BYTES"] = counters[3] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[4] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES"] = counters[5] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES"] = counters[6] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES"] = counters[7] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS"] = counters[8] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_CUSTOM_RANGE_BASE"] = counters[9] + + return stats + + +def sai_thrift_get_ingress_priority_group_stats_ext(client, + ingress_priority_group_oid, + mode): + """ + sai_get_ingress_priority_group_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ingress_priority_group_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 10 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_ingress_priority_group_stats_ext(ingress_priority_group_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS"] = counters[0] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES"] = counters[1] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES"] = counters[2] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_WATERMARK_BYTES"] = counters[3] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[4] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES"] = counters[5] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES"] = counters[6] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES"] = counters[7] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS"] = counters[8] + stats["SAI_INGRESS_PRIORITY_GROUP_STAT_CUSTOM_RANGE_BASE"] = counters[9] + + return stats + + +def sai_thrift_clear_ingress_priority_group_stats(client, + ingress_priority_group_oid): + """ + sai_clear_ingress_priority_group_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ingress_priority_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_INGRESS_PRIORITY_GROUP_STAT_CUSTOM_RANGE_BASE) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_ingress_priority_group_stats(ingress_priority_group_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_buffer_pool(client, + type=None, + size=None, + threshold_mode=None, + tam=None, + xoff_size=None, + wred_profile_id=None, + custom_attribute=None): + """ + sai_create_buffer_pool() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of buffer_pool CREATE attributes. + + Returns: + sai_thrift_object_id_t: buffer_pool_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if size is not None: + attribute_value = sai_thrift_attribute_value_t(u64=size) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if threshold_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=threshold_mode) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_THRESHOLD_MODE, + value=attribute_value) + attr_list.append(attribute) + + if tam is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_TAM, + value=attribute_value) + attr_list.append(attribute) + + if xoff_size is not None: + attribute_value = sai_thrift_attribute_value_t(u64=xoff_size) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_XOFF_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if wred_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=wred_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_WRED_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_buffer_pool(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_buffer_pool(client, + buffer_pool_oid): + """ + sai_remove_buffer_pool() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + buffer_pool_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_buffer_pool(buffer_pool_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_buffer_pool_attribute(client, + buffer_pool_oid, + size=None, + tam=None, + xoff_size=None, + wred_profile_id=None, + custom_attribute=None): + """ + sai_set_buffer_pool_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + buffer_pool_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of buffer_pool SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if size is not None: + attr_value = sai_thrift_attribute_value_t(u64=size) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_SIZE, + value=attr_value) + client.sai_thrift_set_buffer_pool_attribute(buffer_pool_oid, attr) + + if tam is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_TAM, + value=attr_value) + client.sai_thrift_set_buffer_pool_attribute(buffer_pool_oid, attr) + + if xoff_size is not None: + attr_value = sai_thrift_attribute_value_t(u64=xoff_size) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_XOFF_SIZE, + value=attr_value) + client.sai_thrift_set_buffer_pool_attribute(buffer_pool_oid, attr) + + if wred_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=wred_profile_id) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_WRED_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_buffer_pool_attribute(buffer_pool_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_buffer_pool_attribute(buffer_pool_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_buffer_pool_attribute(client, + buffer_pool_oid, + shared_size=None, + type=None, + size=None, + threshold_mode=None, + tam=None, + xoff_size=None, + wred_profile_id=None, + custom_attribute=None): + """ + sai_get_buffer_pool_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + buffer_pool_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of buffer_pool GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if shared_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_SHARED_SIZE) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_TYPE) + attr_list.append(attribute) + + if size is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_SIZE) + attr_list.append(attribute) + + if threshold_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_THRESHOLD_MODE) + attr_list.append(attribute) + + if tam is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_TAM, + value=attribute_value) + attr_list.append(attribute) + + if xoff_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_XOFF_SIZE) + attr_list.append(attribute) + + if wred_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_POOL_ATTR_WRED_PROFILE_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_buffer_pool_attribute(buffer_pool_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_BUFFER_POOL_ATTR_SHARED_SIZE: + attrs["SAI_BUFFER_POOL_ATTR_SHARED_SIZE"] = attr.value.u64 + attrs["shared_size"] = attr.value.u64 + + if attr.id == SAI_BUFFER_POOL_ATTR_TYPE: + attrs["SAI_BUFFER_POOL_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_BUFFER_POOL_ATTR_SIZE: + attrs["SAI_BUFFER_POOL_ATTR_SIZE"] = attr.value.u64 + attrs["size"] = attr.value.u64 + + if attr.id == SAI_BUFFER_POOL_ATTR_THRESHOLD_MODE: + attrs["SAI_BUFFER_POOL_ATTR_THRESHOLD_MODE"] = attr.value.s32 + attrs["threshold_mode"] = attr.value.s32 + + if attr.id == SAI_BUFFER_POOL_ATTR_TAM: + attrs["SAI_BUFFER_POOL_ATTR_TAM"] = attr.value.objlist + attrs["tam"] = attr.value.objlist + + if attr.id == SAI_BUFFER_POOL_ATTR_XOFF_SIZE: + attrs["SAI_BUFFER_POOL_ATTR_XOFF_SIZE"] = attr.value.u64 + attrs["xoff_size"] = attr.value.u64 + + if attr.id == SAI_BUFFER_POOL_ATTR_WRED_PROFILE_ID: + attrs["SAI_BUFFER_POOL_ATTR_WRED_PROFILE_ID"] = attr.value.oid + attrs["wred_profile_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_buffer_pool_stats(client, + buffer_pool_oid): + """ + sai_get_buffer_pool_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + buffer_pool_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 22 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_buffer_pool_stats(buffer_pool_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES"] = counters[0] + stats["SAI_BUFFER_POOL_STAT_WATERMARK_BYTES"] = counters[1] + stats["SAI_BUFFER_POOL_STAT_DROPPED_PACKETS"] = counters[2] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[3] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[4] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[5] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[6] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_PACKETS"] = counters[7] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_BYTES"] = counters[8] + stats["SAI_BUFFER_POOL_STAT_WRED_DROPPED_PACKETS"] = counters[9] + stats["SAI_BUFFER_POOL_STAT_WRED_DROPPED_BYTES"] = counters[10] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS"] = counters[11] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES"] = counters[12] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS"] = counters[13] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES"] = counters[14] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS"] = counters[15] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_BYTES"] = counters[16] + stats["SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_PACKETS"] = counters[17] + stats["SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_BYTES"] = counters[18] + stats["SAI_BUFFER_POOL_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES"] = counters[19] + stats["SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES"] = counters[20] + stats["SAI_BUFFER_POOL_STAT_CUSTOM_RANGE_BASE"] = counters[21] + + return stats + + +def sai_thrift_get_buffer_pool_stats_ext(client, + buffer_pool_oid, + mode): + """ + sai_get_buffer_pool_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + buffer_pool_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 22 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_buffer_pool_stats_ext(buffer_pool_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES"] = counters[0] + stats["SAI_BUFFER_POOL_STAT_WATERMARK_BYTES"] = counters[1] + stats["SAI_BUFFER_POOL_STAT_DROPPED_PACKETS"] = counters[2] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[3] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[4] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[5] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[6] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_PACKETS"] = counters[7] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_BYTES"] = counters[8] + stats["SAI_BUFFER_POOL_STAT_WRED_DROPPED_PACKETS"] = counters[9] + stats["SAI_BUFFER_POOL_STAT_WRED_DROPPED_BYTES"] = counters[10] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS"] = counters[11] + stats["SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES"] = counters[12] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS"] = counters[13] + stats["SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES"] = counters[14] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS"] = counters[15] + stats["SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_BYTES"] = counters[16] + stats["SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_PACKETS"] = counters[17] + stats["SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_BYTES"] = counters[18] + stats["SAI_BUFFER_POOL_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES"] = counters[19] + stats["SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES"] = counters[20] + stats["SAI_BUFFER_POOL_STAT_CUSTOM_RANGE_BASE"] = counters[21] + + return stats + + +def sai_thrift_clear_buffer_pool_stats(client, + buffer_pool_oid): + """ + sai_clear_buffer_pool_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + buffer_pool_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_BUFFER_POOL_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_XOFF_ROOM_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_XOFF_ROOM_WATERMARK_BYTES) + counter_ids.append(SAI_BUFFER_POOL_STAT_CUSTOM_RANGE_BASE) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_buffer_pool_stats(buffer_pool_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_buffer_profile(client, + pool_id=None, + reserved_buffer_size=None, + threshold_mode=None, + shared_dynamic_th=None, + shared_static_th=None, + xoff_th=None, + xon_th=None, + xon_offset_th=None, + custom_attribute=None): + """ + sai_create_buffer_profile() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of buffer_profile CREATE attributes. + + Returns: + sai_thrift_object_id_t: buffer_profile_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if pool_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=pool_id) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_POOL_ID, + value=attribute_value) + attr_list.append(attribute) + + if reserved_buffer_size is not None: + attribute_value = sai_thrift_attribute_value_t(u64=reserved_buffer_size) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if threshold_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=threshold_mode) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE, + value=attribute_value) + attr_list.append(attribute) + + if shared_dynamic_th is not None: + attribute_value = sai_thrift_attribute_value_t(s8=shared_dynamic_th) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH, + value=attribute_value) + attr_list.append(attribute) + + if shared_static_th is not None: + attribute_value = sai_thrift_attribute_value_t(u64=shared_static_th) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH, + value=attribute_value) + attr_list.append(attribute) + + if xoff_th is not None: + attribute_value = sai_thrift_attribute_value_t(u64=xoff_th) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XOFF_TH, + value=attribute_value) + attr_list.append(attribute) + + if xon_th is not None: + attribute_value = sai_thrift_attribute_value_t(u64=xon_th) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XON_TH, + value=attribute_value) + attr_list.append(attribute) + + if xon_offset_th is not None: + attribute_value = sai_thrift_attribute_value_t(u64=xon_offset_th) + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XON_OFFSET_TH, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_buffer_profile(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_buffer_profile(client, + buffer_profile_oid): + """ + sai_remove_buffer_profile() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + buffer_profile_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_buffer_profile(buffer_profile_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_buffer_profile_attribute(client, + buffer_profile_oid, + reserved_buffer_size=None, + shared_dynamic_th=None, + shared_static_th=None, + xoff_th=None, + xon_th=None, + xon_offset_th=None, + custom_attribute=None): + """ + sai_set_buffer_profile_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + buffer_profile_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of buffer_profile SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if reserved_buffer_size is not None: + attr_value = sai_thrift_attribute_value_t(u64=reserved_buffer_size) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE, + value=attr_value) + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + if shared_dynamic_th is not None: + attr_value = sai_thrift_attribute_value_t(s8=shared_dynamic_th) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH, + value=attr_value) + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + if shared_static_th is not None: + attr_value = sai_thrift_attribute_value_t(u64=shared_static_th) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH, + value=attr_value) + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + if xoff_th is not None: + attr_value = sai_thrift_attribute_value_t(u64=xoff_th) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XOFF_TH, + value=attr_value) + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + if xon_th is not None: + attr_value = sai_thrift_attribute_value_t(u64=xon_th) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XON_TH, + value=attr_value) + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + if xon_offset_th is not None: + attr_value = sai_thrift_attribute_value_t(u64=xon_offset_th) + attr = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XON_OFFSET_TH, + value=attr_value) + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_buffer_profile_attribute(buffer_profile_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_buffer_profile_attribute(client, + buffer_profile_oid, + pool_id=None, + reserved_buffer_size=None, + threshold_mode=None, + shared_dynamic_th=None, + shared_static_th=None, + xoff_th=None, + xon_th=None, + xon_offset_th=None, + custom_attribute=None): + """ + sai_get_buffer_profile_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + buffer_profile_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of buffer_profile GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if pool_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_POOL_ID) + attr_list.append(attribute) + + if reserved_buffer_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE) + attr_list.append(attribute) + + if threshold_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE) + attr_list.append(attribute) + + if shared_dynamic_th is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH) + attr_list.append(attribute) + + if shared_static_th is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH) + attr_list.append(attribute) + + if xoff_th is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XOFF_TH) + attr_list.append(attribute) + + if xon_th is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XON_TH) + attr_list.append(attribute) + + if xon_offset_th is not None: + attribute = sai_thrift_attribute_t(id=SAI_BUFFER_PROFILE_ATTR_XON_OFFSET_TH) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_buffer_profile_attribute(buffer_profile_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_BUFFER_PROFILE_ATTR_POOL_ID: + attrs["SAI_BUFFER_PROFILE_ATTR_POOL_ID"] = attr.value.oid + attrs["pool_id"] = attr.value.oid + + if attr.id == SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE: + attrs["SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE"] = attr.value.u64 + attrs["reserved_buffer_size"] = attr.value.u64 + + if attr.id == SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE: + attrs["SAI_BUFFER_PROFILE_ATTR_THRESHOLD_MODE"] = attr.value.s32 + attrs["threshold_mode"] = attr.value.s32 + + if attr.id == SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH: + attrs["SAI_BUFFER_PROFILE_ATTR_SHARED_DYNAMIC_TH"] = attr.value.s8 + attrs["shared_dynamic_th"] = attr.value.s8 + + if attr.id == SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH: + attrs["SAI_BUFFER_PROFILE_ATTR_SHARED_STATIC_TH"] = attr.value.u64 + attrs["shared_static_th"] = attr.value.u64 + + if attr.id == SAI_BUFFER_PROFILE_ATTR_XOFF_TH: + attrs["SAI_BUFFER_PROFILE_ATTR_XOFF_TH"] = attr.value.u64 + attrs["xoff_th"] = attr.value.u64 + + if attr.id == SAI_BUFFER_PROFILE_ATTR_XON_TH: + attrs["SAI_BUFFER_PROFILE_ATTR_XON_TH"] = attr.value.u64 + attrs["xon_th"] = attr.value.u64 + + if attr.id == SAI_BUFFER_PROFILE_ATTR_XON_OFFSET_TH: + attrs["SAI_BUFFER_PROFILE_ATTR_XON_OFFSET_TH"] = attr.value.u64 + attrs["xon_offset_th"] = attr.value.u64 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# counter API + +def sai_thrift_create_counter(client, + type=None, + label=None, + custom_attribute=None): + """ + sai_create_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of counter CREATE attributes. + + Returns: + sai_thrift_object_id_t: counter_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_COUNTER_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if label is not None: + attribute_value = sai_thrift_attribute_value_t(chardata=label) + attribute = sai_thrift_attribute_t(id=SAI_COUNTER_ATTR_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_counter(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_counter(client, + counter_oid): + """ + sai_remove_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + counter_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_counter(counter_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_counter_attribute(client, + counter_oid, + label=None, + custom_attribute=None): + """ + sai_set_counter_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of counter SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if label is not None: + attr_value = sai_thrift_attribute_value_t(chardata=label) + attr = sai_thrift_attribute_t(id=SAI_COUNTER_ATTR_LABEL, + value=attr_value) + client.sai_thrift_set_counter_attribute(counter_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_counter_attribute(counter_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_counter_attribute(client, + counter_oid, + type=None, + label=None, + custom_attribute=None): + """ + sai_get_counter_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of counter GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_COUNTER_ATTR_TYPE) + attr_list.append(attribute) + + if label is not None: + attribute = sai_thrift_attribute_t(id=SAI_COUNTER_ATTR_LABEL) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_counter_attribute(counter_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_COUNTER_ATTR_TYPE: + attrs["SAI_COUNTER_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_COUNTER_ATTR_LABEL: + attrs["SAI_COUNTER_ATTR_LABEL"] = attr.value.chardata + attrs["label"] = attr.value.chardata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_counter_stats(client, + counter_oid): + """ + sai_get_counter_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + counter_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_COUNTER_STAT_PACKETS) + counter_ids.append(SAI_COUNTER_STAT_BYTES) + counter_ids.append(SAI_COUNTER_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 3 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_counter_stats(counter_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_COUNTER_STAT_PACKETS"] = counters[0] + stats["SAI_COUNTER_STAT_BYTES"] = counters[1] + stats["SAI_COUNTER_STAT_CUSTOM_RANGE_BASE"] = counters[2] + + return stats + + +def sai_thrift_get_counter_stats_ext(client, + counter_oid, + mode): + """ + sai_get_counter_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + counter_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_COUNTER_STAT_PACKETS) + counter_ids.append(SAI_COUNTER_STAT_BYTES) + counter_ids.append(SAI_COUNTER_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 3 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_counter_stats_ext(counter_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_COUNTER_STAT_PACKETS"] = counters[0] + stats["SAI_COUNTER_STAT_BYTES"] = counters[1] + stats["SAI_COUNTER_STAT_CUSTOM_RANGE_BASE"] = counters[2] + + return stats + + +def sai_thrift_clear_counter_stats(client, + counter_oid): + """ + sai_clear_counter_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + counter_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_COUNTER_STAT_PACKETS) + counter_ids.append(SAI_COUNTER_STAT_BYTES) + counter_ids.append(SAI_COUNTER_STAT_CUSTOM_RANGE_BASE) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_counter_stats(counter_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# debug_counter API + +def sai_thrift_create_debug_counter(client, + type=None, + bind_method=None, + in_drop_reason_list=None, + out_drop_reason_list=None, + custom_attribute=None): + """ + sai_create_debug_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of debug_counter CREATE attributes. + + Returns: + sai_thrift_object_id_t: debug_counter_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if bind_method is not None: + attribute_value = sai_thrift_attribute_value_t(s32=bind_method) + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_BIND_METHOD, + value=attribute_value) + attr_list.append(attribute) + + if in_drop_reason_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=in_drop_reason_list) + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST, + value=attribute_value) + attr_list.append(attribute) + + if out_drop_reason_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=out_drop_reason_list) + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_debug_counter(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_debug_counter(client, + debug_counter_oid): + """ + sai_remove_debug_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + debug_counter_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_debug_counter(debug_counter_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_debug_counter_attribute(client, + debug_counter_oid, + in_drop_reason_list=None, + out_drop_reason_list=None, + custom_attribute=None): + """ + sai_set_debug_counter_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + debug_counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of debug_counter SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if in_drop_reason_list is not None: + attr_value = sai_thrift_attribute_value_t(s32list=in_drop_reason_list) + attr = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST, + value=attr_value) + client.sai_thrift_set_debug_counter_attribute(debug_counter_oid, attr) + + if out_drop_reason_list is not None: + attr_value = sai_thrift_attribute_value_t(s32list=out_drop_reason_list) + attr = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST, + value=attr_value) + client.sai_thrift_set_debug_counter_attribute(debug_counter_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_debug_counter_attribute(debug_counter_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_debug_counter_attribute(client, + debug_counter_oid, + index=None, + type=None, + bind_method=None, + in_drop_reason_list=None, + out_drop_reason_list=None, + custom_attribute=None): + """ + sai_get_debug_counter_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + debug_counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of debug_counter GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if index is not None: + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_INDEX) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_TYPE) + attr_list.append(attribute) + + if bind_method is not None: + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_BIND_METHOD) + attr_list.append(attribute) + + if in_drop_reason_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=in_drop_reason_list) + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST, + value=attribute_value) + attr_list.append(attribute) + + if out_drop_reason_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=out_drop_reason_list) + attribute = sai_thrift_attribute_t(id=SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_debug_counter_attribute(debug_counter_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_DEBUG_COUNTER_ATTR_INDEX: + attrs["SAI_DEBUG_COUNTER_ATTR_INDEX"] = attr.value.u32 + attrs["index"] = attr.value.u32 + + if attr.id == SAI_DEBUG_COUNTER_ATTR_TYPE: + attrs["SAI_DEBUG_COUNTER_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_DEBUG_COUNTER_ATTR_BIND_METHOD: + attrs["SAI_DEBUG_COUNTER_ATTR_BIND_METHOD"] = attr.value.s32 + attrs["bind_method"] = attr.value.s32 + + if attr.id == SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST: + attrs["SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST"] = attr.value.s32list + attrs["in_drop_reason_list"] = attr.value.s32list + + if attr.id == SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST: + attrs["SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST"] = attr.value.s32list + attrs["out_drop_reason_list"] = attr.value.s32list + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# dtel API + +def sai_thrift_create_dtel(client, + int_endpoint_enable=None, + int_transit_enable=None, + postcard_enable=None, + drop_report_enable=None, + queue_report_enable=None, + switch_id=None, + flow_state_clear_cycle=None, + latency_sensitivity=None, + sink_port_list=None, + int_l4_dscp=None, + custom_attribute=None): + """ + sai_create_dtel() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of dtel CREATE attributes. + + Returns: + sai_thrift_object_id_t: dtel_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if int_endpoint_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=int_endpoint_enable) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_ENDPOINT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if int_transit_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=int_transit_enable) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_TRANSIT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if postcard_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=postcard_enable) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_POSTCARD_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if drop_report_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=drop_report_enable) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_DROP_REPORT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if queue_report_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=queue_report_enable) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if switch_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=switch_id) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_SWITCH_ID, + value=attribute_value) + attr_list.append(attribute) + + if flow_state_clear_cycle is not None: + attribute_value = sai_thrift_attribute_value_t(u16=flow_state_clear_cycle) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE, + value=attribute_value) + attr_list.append(attribute) + + if latency_sensitivity is not None: + attribute_value = sai_thrift_attribute_value_t(u8=latency_sensitivity) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_LATENCY_SENSITIVITY, + value=attribute_value) + attr_list.append(attribute) + + if sink_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=sink_port_list) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_SINK_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if int_l4_dscp is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=int_l4_dscp) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_L4_DSCP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_dtel(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_dtel(client, + dtel_oid): + """ + sai_remove_dtel() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + dtel_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_dtel(dtel_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_dtel_attribute(client, + dtel_oid, + int_endpoint_enable=None, + int_transit_enable=None, + postcard_enable=None, + drop_report_enable=None, + queue_report_enable=None, + switch_id=None, + flow_state_clear_cycle=None, + latency_sensitivity=None, + sink_port_list=None, + int_l4_dscp=None, + custom_attribute=None): + """ + sai_set_dtel_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + dtel_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if int_endpoint_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=int_endpoint_enable) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_ENDPOINT_ENABLE, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if int_transit_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=int_transit_enable) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_TRANSIT_ENABLE, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if postcard_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=postcard_enable) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_POSTCARD_ENABLE, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if drop_report_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=drop_report_enable) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_DROP_REPORT_ENABLE, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if queue_report_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=queue_report_enable) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if switch_id is not None: + attr_value = sai_thrift_attribute_value_t(u32=switch_id) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_SWITCH_ID, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if flow_state_clear_cycle is not None: + attr_value = sai_thrift_attribute_value_t(u16=flow_state_clear_cycle) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if latency_sensitivity is not None: + attr_value = sai_thrift_attribute_value_t(u8=latency_sensitivity) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_LATENCY_SENSITIVITY, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if sink_port_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=sink_port_list) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_SINK_PORT_LIST, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if int_l4_dscp is not None: + attr_value = sai_thrift_attribute_value_t(aclfield=int_l4_dscp) + attr = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_L4_DSCP, + value=attr_value) + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_dtel_attribute(dtel_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_dtel_attribute(client, + dtel_oid, + int_endpoint_enable=None, + int_transit_enable=None, + postcard_enable=None, + drop_report_enable=None, + queue_report_enable=None, + switch_id=None, + flow_state_clear_cycle=None, + latency_sensitivity=None, + sink_port_list=None, + int_l4_dscp=None, + custom_attribute=None): + """ + sai_get_dtel_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + dtel_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if int_endpoint_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_ENDPOINT_ENABLE) + attr_list.append(attribute) + + if int_transit_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_TRANSIT_ENABLE) + attr_list.append(attribute) + + if postcard_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_POSTCARD_ENABLE) + attr_list.append(attribute) + + if drop_report_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_DROP_REPORT_ENABLE) + attr_list.append(attribute) + + if queue_report_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE) + attr_list.append(attribute) + + if switch_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_SWITCH_ID) + attr_list.append(attribute) + + if flow_state_clear_cycle is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE) + attr_list.append(attribute) + + if latency_sensitivity is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_LATENCY_SENSITIVITY) + attr_list.append(attribute) + + if sink_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=sink_port_list) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_SINK_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if int_l4_dscp is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_ATTR_INT_L4_DSCP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_dtel_attribute(dtel_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_DTEL_ATTR_INT_ENDPOINT_ENABLE: + attrs["SAI_DTEL_ATTR_INT_ENDPOINT_ENABLE"] = attr.value.booldata + attrs["int_endpoint_enable"] = attr.value.booldata + + if attr.id == SAI_DTEL_ATTR_INT_TRANSIT_ENABLE: + attrs["SAI_DTEL_ATTR_INT_TRANSIT_ENABLE"] = attr.value.booldata + attrs["int_transit_enable"] = attr.value.booldata + + if attr.id == SAI_DTEL_ATTR_POSTCARD_ENABLE: + attrs["SAI_DTEL_ATTR_POSTCARD_ENABLE"] = attr.value.booldata + attrs["postcard_enable"] = attr.value.booldata + + if attr.id == SAI_DTEL_ATTR_DROP_REPORT_ENABLE: + attrs["SAI_DTEL_ATTR_DROP_REPORT_ENABLE"] = attr.value.booldata + attrs["drop_report_enable"] = attr.value.booldata + + if attr.id == SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE: + attrs["SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE"] = attr.value.booldata + attrs["queue_report_enable"] = attr.value.booldata + + if attr.id == SAI_DTEL_ATTR_SWITCH_ID: + attrs["SAI_DTEL_ATTR_SWITCH_ID"] = attr.value.u32 + attrs["switch_id"] = attr.value.u32 + + if attr.id == SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE: + attrs["SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE"] = attr.value.u16 + attrs["flow_state_clear_cycle"] = attr.value.u16 + + if attr.id == SAI_DTEL_ATTR_LATENCY_SENSITIVITY: + attrs["SAI_DTEL_ATTR_LATENCY_SENSITIVITY"] = attr.value.u8 + attrs["latency_sensitivity"] = attr.value.u8 + + if attr.id == SAI_DTEL_ATTR_SINK_PORT_LIST: + attrs["SAI_DTEL_ATTR_SINK_PORT_LIST"] = attr.value.objlist + attrs["sink_port_list"] = attr.value.objlist + + if attr.id == SAI_DTEL_ATTR_INT_L4_DSCP: + attrs["SAI_DTEL_ATTR_INT_L4_DSCP"] = attr.value.aclfield + attrs["int_l4_dscp"] = attr.value.aclfield + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_dtel_queue_report(client, + queue_id=None, + depth_threshold=None, + latency_threshold=None, + breach_quota=None, + tail_drop=None, + custom_attribute=None): + """ + sai_create_dtel_queue_report() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of dtel_queue_report CREATE attributes. + + Returns: + sai_thrift_object_id_t: dtel_queue_report_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if queue_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=queue_id) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_QUEUE_ID, + value=attribute_value) + attr_list.append(attribute) + + if depth_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=depth_threshold) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_DEPTH_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if latency_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=latency_threshold) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_LATENCY_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if breach_quota is not None: + attribute_value = sai_thrift_attribute_value_t(u32=breach_quota) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_BREACH_QUOTA, + value=attribute_value) + attr_list.append(attribute) + + if tail_drop is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=tail_drop) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_TAIL_DROP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_dtel_queue_report(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_dtel_queue_report(client, + dtel_queue_report_oid): + """ + sai_remove_dtel_queue_report() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + dtel_queue_report_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_dtel_queue_report(dtel_queue_report_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_dtel_queue_report_attribute(client, + dtel_queue_report_oid, + depth_threshold=None, + latency_threshold=None, + breach_quota=None, + tail_drop=None, + custom_attribute=None): + """ + sai_set_dtel_queue_report_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + dtel_queue_report_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_queue_report SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if depth_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=depth_threshold) + attr = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_DEPTH_THRESHOLD, + value=attr_value) + client.sai_thrift_set_dtel_queue_report_attribute(dtel_queue_report_oid, attr) + + if latency_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=latency_threshold) + attr = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_LATENCY_THRESHOLD, + value=attr_value) + client.sai_thrift_set_dtel_queue_report_attribute(dtel_queue_report_oid, attr) + + if breach_quota is not None: + attr_value = sai_thrift_attribute_value_t(u32=breach_quota) + attr = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_BREACH_QUOTA, + value=attr_value) + client.sai_thrift_set_dtel_queue_report_attribute(dtel_queue_report_oid, attr) + + if tail_drop is not None: + attr_value = sai_thrift_attribute_value_t(booldata=tail_drop) + attr = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_TAIL_DROP, + value=attr_value) + client.sai_thrift_set_dtel_queue_report_attribute(dtel_queue_report_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_dtel_queue_report_attribute(dtel_queue_report_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_dtel_queue_report_attribute(client, + dtel_queue_report_oid, + queue_id=None, + depth_threshold=None, + latency_threshold=None, + breach_quota=None, + tail_drop=None, + custom_attribute=None): + """ + sai_get_dtel_queue_report_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + dtel_queue_report_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_queue_report GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if queue_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_QUEUE_ID) + attr_list.append(attribute) + + if depth_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_DEPTH_THRESHOLD) + attr_list.append(attribute) + + if latency_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_LATENCY_THRESHOLD) + attr_list.append(attribute) + + if breach_quota is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_BREACH_QUOTA) + attr_list.append(attribute) + + if tail_drop is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_QUEUE_REPORT_ATTR_TAIL_DROP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_dtel_queue_report_attribute(dtel_queue_report_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_DTEL_QUEUE_REPORT_ATTR_QUEUE_ID: + attrs["SAI_DTEL_QUEUE_REPORT_ATTR_QUEUE_ID"] = attr.value.oid + attrs["queue_id"] = attr.value.oid + + if attr.id == SAI_DTEL_QUEUE_REPORT_ATTR_DEPTH_THRESHOLD: + attrs["SAI_DTEL_QUEUE_REPORT_ATTR_DEPTH_THRESHOLD"] = attr.value.u32 + attrs["depth_threshold"] = attr.value.u32 + + if attr.id == SAI_DTEL_QUEUE_REPORT_ATTR_LATENCY_THRESHOLD: + attrs["SAI_DTEL_QUEUE_REPORT_ATTR_LATENCY_THRESHOLD"] = attr.value.u32 + attrs["latency_threshold"] = attr.value.u32 + + if attr.id == SAI_DTEL_QUEUE_REPORT_ATTR_BREACH_QUOTA: + attrs["SAI_DTEL_QUEUE_REPORT_ATTR_BREACH_QUOTA"] = attr.value.u32 + attrs["breach_quota"] = attr.value.u32 + + if attr.id == SAI_DTEL_QUEUE_REPORT_ATTR_TAIL_DROP: + attrs["SAI_DTEL_QUEUE_REPORT_ATTR_TAIL_DROP"] = attr.value.booldata + attrs["tail_drop"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_dtel_int_session(client, + max_hop_count=None, + collect_switch_id=None, + collect_switch_ports=None, + collect_ingress_timestamp=None, + collect_egress_timestamp=None, + collect_queue_info=None, + custom_attribute=None): + """ + sai_create_dtel_int_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of dtel_int_session CREATE attributes. + + Returns: + sai_thrift_object_id_t: dtel_int_session_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if max_hop_count is not None: + attribute_value = sai_thrift_attribute_value_t(u8=max_hop_count) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_MAX_HOP_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if collect_switch_id is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=collect_switch_id) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_ID, + value=attribute_value) + attr_list.append(attribute) + + if collect_switch_ports is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=collect_switch_ports) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_PORTS, + value=attribute_value) + attr_list.append(attribute) + + if collect_ingress_timestamp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=collect_ingress_timestamp) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_INGRESS_TIMESTAMP, + value=attribute_value) + attr_list.append(attribute) + + if collect_egress_timestamp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=collect_egress_timestamp) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_EGRESS_TIMESTAMP, + value=attribute_value) + attr_list.append(attribute) + + if collect_queue_info is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=collect_queue_info) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_QUEUE_INFO, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_dtel_int_session(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_dtel_int_session(client, + dtel_int_session_oid): + """ + sai_remove_dtel_int_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + dtel_int_session_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_dtel_int_session(dtel_int_session_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_dtel_int_session_attribute(client, + dtel_int_session_oid, + max_hop_count=None, + collect_switch_id=None, + collect_switch_ports=None, + collect_ingress_timestamp=None, + collect_egress_timestamp=None, + collect_queue_info=None, + custom_attribute=None): + """ + sai_set_dtel_int_session_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + dtel_int_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_int_session SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if max_hop_count is not None: + attr_value = sai_thrift_attribute_value_t(u8=max_hop_count) + attr = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_MAX_HOP_COUNT, + value=attr_value) + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + if collect_switch_id is not None: + attr_value = sai_thrift_attribute_value_t(booldata=collect_switch_id) + attr = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_ID, + value=attr_value) + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + if collect_switch_ports is not None: + attr_value = sai_thrift_attribute_value_t(booldata=collect_switch_ports) + attr = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_PORTS, + value=attr_value) + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + if collect_ingress_timestamp is not None: + attr_value = sai_thrift_attribute_value_t(booldata=collect_ingress_timestamp) + attr = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_INGRESS_TIMESTAMP, + value=attr_value) + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + if collect_egress_timestamp is not None: + attr_value = sai_thrift_attribute_value_t(booldata=collect_egress_timestamp) + attr = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_EGRESS_TIMESTAMP, + value=attr_value) + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + if collect_queue_info is not None: + attr_value = sai_thrift_attribute_value_t(booldata=collect_queue_info) + attr = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_QUEUE_INFO, + value=attr_value) + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_dtel_int_session_attribute(dtel_int_session_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_dtel_int_session_attribute(client, + dtel_int_session_oid, + max_hop_count=None, + collect_switch_id=None, + collect_switch_ports=None, + collect_ingress_timestamp=None, + collect_egress_timestamp=None, + collect_queue_info=None, + custom_attribute=None): + """ + sai_get_dtel_int_session_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + dtel_int_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_int_session GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if max_hop_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_MAX_HOP_COUNT) + attr_list.append(attribute) + + if collect_switch_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_ID) + attr_list.append(attribute) + + if collect_switch_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_PORTS) + attr_list.append(attribute) + + if collect_ingress_timestamp is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_INGRESS_TIMESTAMP) + attr_list.append(attribute) + + if collect_egress_timestamp is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_EGRESS_TIMESTAMP) + attr_list.append(attribute) + + if collect_queue_info is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_INT_SESSION_ATTR_COLLECT_QUEUE_INFO) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_dtel_int_session_attribute(dtel_int_session_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_DTEL_INT_SESSION_ATTR_MAX_HOP_COUNT: + attrs["SAI_DTEL_INT_SESSION_ATTR_MAX_HOP_COUNT"] = attr.value.u8 + attrs["max_hop_count"] = attr.value.u8 + + if attr.id == SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_ID: + attrs["SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_ID"] = attr.value.booldata + attrs["collect_switch_id"] = attr.value.booldata + + if attr.id == SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_PORTS: + attrs["SAI_DTEL_INT_SESSION_ATTR_COLLECT_SWITCH_PORTS"] = attr.value.booldata + attrs["collect_switch_ports"] = attr.value.booldata + + if attr.id == SAI_DTEL_INT_SESSION_ATTR_COLLECT_INGRESS_TIMESTAMP: + attrs["SAI_DTEL_INT_SESSION_ATTR_COLLECT_INGRESS_TIMESTAMP"] = attr.value.booldata + attrs["collect_ingress_timestamp"] = attr.value.booldata + + if attr.id == SAI_DTEL_INT_SESSION_ATTR_COLLECT_EGRESS_TIMESTAMP: + attrs["SAI_DTEL_INT_SESSION_ATTR_COLLECT_EGRESS_TIMESTAMP"] = attr.value.booldata + attrs["collect_egress_timestamp"] = attr.value.booldata + + if attr.id == SAI_DTEL_INT_SESSION_ATTR_COLLECT_QUEUE_INFO: + attrs["SAI_DTEL_INT_SESSION_ATTR_COLLECT_QUEUE_INFO"] = attr.value.booldata + attrs["collect_queue_info"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_dtel_report_session(client, + src_ip=None, + dst_ip_list=None, + virtual_router_id=None, + truncate_size=None, + udp_dst_port=None, + custom_attribute=None): + """ + sai_create_dtel_report_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of dtel_report_session CREATE attributes. + + Returns: + sai_thrift_object_id_t: dtel_report_session_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=src_ip) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip_list is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddrlist=dst_ip_list) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_DST_IP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if virtual_router_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=virtual_router_id) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_VIRTUAL_ROUTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if truncate_size is not None: + attribute_value = sai_thrift_attribute_value_t(u16=truncate_size) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_TRUNCATE_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if udp_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(u16=udp_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_UDP_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_dtel_report_session(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_dtel_report_session(client, + dtel_report_session_oid): + """ + sai_remove_dtel_report_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + dtel_report_session_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_dtel_report_session(dtel_report_session_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_dtel_report_session_attribute(client, + dtel_report_session_oid, + src_ip=None, + dst_ip_list=None, + virtual_router_id=None, + truncate_size=None, + udp_dst_port=None, + custom_attribute=None): + """ + sai_set_dtel_report_session_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + dtel_report_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_report_session SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if src_ip is not None: + attr_value = sai_thrift_attribute_value_t(ipaddr=src_ip) + attr = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_SRC_IP, + value=attr_value) + client.sai_thrift_set_dtel_report_session_attribute(dtel_report_session_oid, attr) + + if dst_ip_list is not None: + attr_value = sai_thrift_attribute_value_t(ipaddrlist=dst_ip_list) + attr = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_DST_IP_LIST, + value=attr_value) + client.sai_thrift_set_dtel_report_session_attribute(dtel_report_session_oid, attr) + + if virtual_router_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=virtual_router_id) + attr = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_VIRTUAL_ROUTER_ID, + value=attr_value) + client.sai_thrift_set_dtel_report_session_attribute(dtel_report_session_oid, attr) + + if truncate_size is not None: + attr_value = sai_thrift_attribute_value_t(u16=truncate_size) + attr = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_TRUNCATE_SIZE, + value=attr_value) + client.sai_thrift_set_dtel_report_session_attribute(dtel_report_session_oid, attr) + + if udp_dst_port is not None: + attr_value = sai_thrift_attribute_value_t(u16=udp_dst_port) + attr = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_UDP_DST_PORT, + value=attr_value) + client.sai_thrift_set_dtel_report_session_attribute(dtel_report_session_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_dtel_report_session_attribute(dtel_report_session_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_dtel_report_session_attribute(client, + dtel_report_session_oid, + src_ip=None, + dst_ip_list=None, + virtual_router_id=None, + truncate_size=None, + udp_dst_port=None, + custom_attribute=None): + """ + sai_get_dtel_report_session_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + dtel_report_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_report_session GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_SRC_IP) + attr_list.append(attribute) + + if dst_ip_list is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddrlist=dst_ip_list) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_DST_IP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if virtual_router_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_VIRTUAL_ROUTER_ID) + attr_list.append(attribute) + + if truncate_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_TRUNCATE_SIZE) + attr_list.append(attribute) + + if udp_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_REPORT_SESSION_ATTR_UDP_DST_PORT) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_dtel_report_session_attribute(dtel_report_session_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_DTEL_REPORT_SESSION_ATTR_SRC_IP: + attrs["SAI_DTEL_REPORT_SESSION_ATTR_SRC_IP"] = attr.value.ipaddr + attrs["src_ip"] = attr.value.ipaddr + + if attr.id == SAI_DTEL_REPORT_SESSION_ATTR_DST_IP_LIST: + attrs["SAI_DTEL_REPORT_SESSION_ATTR_DST_IP_LIST"] = attr.value.ipaddrlist + attrs["dst_ip_list"] = attr.value.ipaddrlist + + if attr.id == SAI_DTEL_REPORT_SESSION_ATTR_VIRTUAL_ROUTER_ID: + attrs["SAI_DTEL_REPORT_SESSION_ATTR_VIRTUAL_ROUTER_ID"] = attr.value.oid + attrs["virtual_router_id"] = attr.value.oid + + if attr.id == SAI_DTEL_REPORT_SESSION_ATTR_TRUNCATE_SIZE: + attrs["SAI_DTEL_REPORT_SESSION_ATTR_TRUNCATE_SIZE"] = attr.value.u16 + attrs["truncate_size"] = attr.value.u16 + + if attr.id == SAI_DTEL_REPORT_SESSION_ATTR_UDP_DST_PORT: + attrs["SAI_DTEL_REPORT_SESSION_ATTR_UDP_DST_PORT"] = attr.value.u16 + attrs["udp_dst_port"] = attr.value.u16 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_dtel_event(client, + type=None, + report_session=None, + dscp_value=None, + custom_attribute=None): + """ + sai_create_dtel_event() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of dtel_event CREATE attributes. + + Returns: + sai_thrift_object_id_t: dtel_event_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if report_session is not None: + attribute_value = sai_thrift_attribute_value_t(oid=report_session) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_REPORT_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if dscp_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=dscp_value) + attribute = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_DSCP_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_dtel_event(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_dtel_event(client, + dtel_event_oid): + """ + sai_remove_dtel_event() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + dtel_event_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_dtel_event(dtel_event_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_dtel_event_attribute(client, + dtel_event_oid, + report_session=None, + dscp_value=None, + custom_attribute=None): + """ + sai_set_dtel_event_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + dtel_event_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_event SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if report_session is not None: + attr_value = sai_thrift_attribute_value_t(oid=report_session) + attr = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_REPORT_SESSION, + value=attr_value) + client.sai_thrift_set_dtel_event_attribute(dtel_event_oid, attr) + + if dscp_value is not None: + attr_value = sai_thrift_attribute_value_t(u8=dscp_value) + attr = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_DSCP_VALUE, + value=attr_value) + client.sai_thrift_set_dtel_event_attribute(dtel_event_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_dtel_event_attribute(dtel_event_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_dtel_event_attribute(client, + dtel_event_oid, + type=None, + report_session=None, + dscp_value=None, + custom_attribute=None): + """ + sai_get_dtel_event_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + dtel_event_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of dtel_event GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_TYPE) + attr_list.append(attribute) + + if report_session is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_REPORT_SESSION) + attr_list.append(attribute) + + if dscp_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_DTEL_EVENT_ATTR_DSCP_VALUE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_dtel_event_attribute(dtel_event_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_DTEL_EVENT_ATTR_TYPE: + attrs["SAI_DTEL_EVENT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_DTEL_EVENT_ATTR_REPORT_SESSION: + attrs["SAI_DTEL_EVENT_ATTR_REPORT_SESSION"] = attr.value.oid + attrs["report_session"] = attr.value.oid + + if attr.id == SAI_DTEL_EVENT_ATTR_DSCP_VALUE: + attrs["SAI_DTEL_EVENT_ATTR_DSCP_VALUE"] = attr.value.u8 + attrs["dscp_value"] = attr.value.u8 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# fdb API + +def sai_thrift_create_fdb_entry(client, + fdb_entry, + type=None, + packet_action=None, + user_trap_id=None, + bridge_port_id=None, + meta_data=None, + endpoint_ip=None, + counter_id=None, + allow_mac_move=None, + custom_attribute=None): + """ + sai_create_fdb_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + fdb_entry(sai_thrift_fdb_entry_t): fdb_entry IN argument + + For the other parameters, see documentation of fdb_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if user_trap_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=user_trap_id) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_USER_TRAP_ID, + value=attribute_value) + attr_list.append(attribute) + + if bridge_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_port_id) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(u32=meta_data) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if endpoint_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=endpoint_ip) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_ENDPOINT_IP, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if allow_mac_move is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=allow_mac_move) + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_ALLOW_MAC_MOVE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_fdb_entry(fdb_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_fdb_entry(client, + fdb_entry): + """ + sai_remove_fdb_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + fdb_entry(sai_thrift_fdb_entry_t): fdb_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_fdb_entry(fdb_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_fdb_entry_attribute(client, + fdb_entry, + type=None, + packet_action=None, + user_trap_id=None, + bridge_port_id=None, + meta_data=None, + endpoint_ip=None, + counter_id=None, + allow_mac_move=None, + custom_attribute=None): + """ + sai_set_fdb_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + fdb_entry(sai_thrift_fdb_entry_t): fdb_entry IN argument + + For the other parameters, see documentation of fdb_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if type is not None: + attr_value = sai_thrift_attribute_value_t(s32=type) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_TYPE, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if user_trap_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=user_trap_id) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_USER_TRAP_ID, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if bridge_port_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=bridge_port_id) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if meta_data is not None: + attr_value = sai_thrift_attribute_value_t(u32=meta_data) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_META_DATA, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if endpoint_ip is not None: + attr_value = sai_thrift_attribute_value_t(ipaddr=endpoint_ip) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_ENDPOINT_IP, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if allow_mac_move is not None: + attr_value = sai_thrift_attribute_value_t(booldata=allow_mac_move) + attr = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_ALLOW_MAC_MOVE, + value=attr_value) + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_fdb_entry_attribute(fdb_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_fdb_entry_attribute(client, + fdb_entry, + type=None, + packet_action=None, + user_trap_id=None, + bridge_port_id=None, + meta_data=None, + endpoint_ip=None, + counter_id=None, + allow_mac_move=None, + custom_attribute=None): + """ + sai_get_fdb_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + fdb_entry(sai_thrift_fdb_entry_t): fdb_entry IN argument + + For the other parameters, see documentation of fdb_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_TYPE) + attr_list.append(attribute) + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if user_trap_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_USER_TRAP_ID) + attr_list.append(attribute) + + if bridge_port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID) + attr_list.append(attribute) + + if meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_META_DATA) + attr_list.append(attribute) + + if endpoint_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_ENDPOINT_IP) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if allow_mac_move is not None: + attribute = sai_thrift_attribute_t(id=SAI_FDB_ENTRY_ATTR_ALLOW_MAC_MOVE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_fdb_entry_attribute(fdb_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_FDB_ENTRY_ATTR_TYPE: + attrs["SAI_FDB_ENTRY_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_FDB_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_FDB_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_FDB_ENTRY_ATTR_USER_TRAP_ID: + attrs["SAI_FDB_ENTRY_ATTR_USER_TRAP_ID"] = attr.value.oid + attrs["user_trap_id"] = attr.value.oid + + if attr.id == SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID: + attrs["SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"] = attr.value.oid + attrs["bridge_port_id"] = attr.value.oid + + if attr.id == SAI_FDB_ENTRY_ATTR_META_DATA: + attrs["SAI_FDB_ENTRY_ATTR_META_DATA"] = attr.value.u32 + attrs["meta_data"] = attr.value.u32 + + if attr.id == SAI_FDB_ENTRY_ATTR_ENDPOINT_IP: + attrs["SAI_FDB_ENTRY_ATTR_ENDPOINT_IP"] = attr.value.ipaddr + attrs["endpoint_ip"] = attr.value.ipaddr + + if attr.id == SAI_FDB_ENTRY_ATTR_COUNTER_ID: + attrs["SAI_FDB_ENTRY_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if attr.id == SAI_FDB_ENTRY_ATTR_ALLOW_MAC_MOVE: + attrs["SAI_FDB_ENTRY_ATTR_ALLOW_MAC_MOVE"] = attr.value.booldata + attrs["allow_mac_move"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_flush_fdb_entries(client, + bridge_port_id=None, + bv_id=None, + entry_type=None, + custom_attribute=None): + """ + sai_flush_fdb_entries() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of fdb_flush OTHER attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if bridge_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_port_id) + attribute = sai_thrift_attribute_t(id=SAI_FDB_FLUSH_ATTR_BRIDGE_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if bv_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bv_id) + attribute = sai_thrift_attribute_t(id=SAI_FDB_FLUSH_ATTR_BV_ID, + value=attribute_value) + attr_list.append(attribute) + + if entry_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=entry_type) + attribute = sai_thrift_attribute_t(id=SAI_FDB_FLUSH_ATTR_ENTRY_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_flush_fdb_entries(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_bulk_create_fdb_entry(client, + fdb_entry, + attr_count, + mode, + type=None, + packet_action=None, + user_trap_id=None, + bridge_port_id=None, + meta_data=None, + endpoint_ip=None, + counter_id=None, + allow_mac_move=None, + custom_attribute=None): + """ + sai_bulk_create_fdb_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + fdb_entry(List[sai_thrift_fdb_entry_t]): fdb_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of fdb_entry CREATE attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del fdb_entry + del attr_count + del mode + + # No function call - delete all attributes + del type + del packet_action + del user_trap_id + del bridge_port_id + del meta_data + del endpoint_ip + del counter_id + del allow_mac_move + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_remove_fdb_entry(client, + fdb_entry, + mode): + """ + sai_bulk_remove_fdb_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + fdb_entry(List[sai_thrift_fdb_entry_t]): fdb_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del fdb_entry + del mode + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_set_fdb_entry_attribute(client, + fdb_entry, + mode, + type=None, + packet_action=None, + user_trap_id=None, + bridge_port_id=None, + meta_data=None, + endpoint_ip=None, + counter_id=None, + allow_mac_move=None, + custom_attribute=None): + """ + sai_bulk_set_fdb_entry_attribute() - UNSUPPORTED + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + fdb_entry(List[sai_thrift_fdb_entry_t]): fdb_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of fdb_entry SET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del fdb_entry + del mode + + # No function call - delete all attributes + del type + del packet_action + del user_trap_id + del bridge_port_id + del meta_data + del endpoint_ip + del counter_id + del allow_mac_move + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_get_fdb_entry_attribute(client, + fdb_entry, + attr_count, + mode, + object_statuses, + type=None, + packet_action=None, + user_trap_id=None, + bridge_port_id=None, + meta_data=None, + endpoint_ip=None, + counter_id=None, + allow_mac_move=None, + custom_attribute=None): + """ + sai_bulk_get_fdb_entry_attribute() - UNSUPPORTED + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + fdb_entry(List[sai_thrift_fdb_entry_t]): fdb_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + object_statuses(List[sai_thrift_status_t]): status_list OUT argument + + For the other parameters, see documentation of fdb_entry GET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del fdb_entry + del attr_count + del mode + del object_statuses + + # No function call - delete all attributes + del type + del packet_action + del user_trap_id + del bridge_port_id + del meta_data + del endpoint_ip + del counter_id + del allow_mac_move + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +# hash API + +def sai_thrift_create_fine_grained_hash_field(client, + ipv4_mask=None, + ipv6_mask=None, + native_hash_field=None, + sequence_id=None, + custom_attribute=None): + """ + sai_create_fine_grained_hash_field() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of fine_grained_hash_field CREATE attributes. + + Returns: + sai_thrift_object_id_t: fine_grained_hash_field_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ipv4_mask is not None: + attribute_value = sai_thrift_attribute_value_t(ip4=ipv4_mask) + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV4_MASK, + value=attribute_value) + attr_list.append(attribute) + + if ipv6_mask is not None: + attribute_value = sai_thrift_attribute_value_t(ip6=ipv6_mask) + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV6_MASK, + value=attribute_value) + attr_list.append(attribute) + + if native_hash_field is not None: + attribute_value = sai_thrift_attribute_value_t(s32=native_hash_field) + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_NATIVE_HASH_FIELD, + value=attribute_value) + attr_list.append(attribute) + + if sequence_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=sequence_id) + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_SEQUENCE_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_fine_grained_hash_field(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_fine_grained_hash_field(client, + fine_grained_hash_field_oid): + """ + sai_remove_fine_grained_hash_field() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + fine_grained_hash_field_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_fine_grained_hash_field(fine_grained_hash_field_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_fine_grained_hash_field_attribute(client, + fine_grained_hash_field_oid, + custom_attribute=None): + """ + sai_set_fine_grained_hash_field_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + fine_grained_hash_field_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del fine_grained_hash_field_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_fine_grained_hash_field_attribute(client, + fine_grained_hash_field_oid, + native_hash_field=None, + ipv4_mask=None, + ipv6_mask=None, + sequence_id=None, + custom_attribute=None): + """ + sai_get_fine_grained_hash_field_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + fine_grained_hash_field_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of fine_grained_hash_field GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if native_hash_field is not None: + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_NATIVE_HASH_FIELD) + attr_list.append(attribute) + + if ipv4_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV4_MASK) + attr_list.append(attribute) + + if ipv6_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV6_MASK) + attr_list.append(attribute) + + if sequence_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_FINE_GRAINED_HASH_FIELD_ATTR_SEQUENCE_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_fine_grained_hash_field_attribute(fine_grained_hash_field_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_FINE_GRAINED_HASH_FIELD_ATTR_NATIVE_HASH_FIELD: + attrs["SAI_FINE_GRAINED_HASH_FIELD_ATTR_NATIVE_HASH_FIELD"] = attr.value.s32 + attrs["native_hash_field"] = attr.value.s32 + + if attr.id == SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV4_MASK: + attrs["SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV4_MASK"] = attr.value.ip4 + attrs["ipv4_mask"] = attr.value.ip4 + + if attr.id == SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV6_MASK: + attrs["SAI_FINE_GRAINED_HASH_FIELD_ATTR_IPV6_MASK"] = attr.value.ip6 + attrs["ipv6_mask"] = attr.value.ip6 + + if attr.id == SAI_FINE_GRAINED_HASH_FIELD_ATTR_SEQUENCE_ID: + attrs["SAI_FINE_GRAINED_HASH_FIELD_ATTR_SEQUENCE_ID"] = attr.value.u32 + attrs["sequence_id"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_hash(client, + native_hash_field_list=None, + udf_group_list=None, + fine_grained_hash_field_list=None, + custom_attribute=None): + """ + sai_create_hash() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of hash CREATE attributes. + + Returns: + sai_thrift_object_id_t: hash_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if native_hash_field_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=native_hash_field_list) + attribute = sai_thrift_attribute_t(id=SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST, + value=attribute_value) + attr_list.append(attribute) + + if udf_group_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=udf_group_list) + attribute = sai_thrift_attribute_t(id=SAI_HASH_ATTR_UDF_GROUP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if fine_grained_hash_field_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=fine_grained_hash_field_list) + attribute = sai_thrift_attribute_t(id=SAI_HASH_ATTR_FINE_GRAINED_HASH_FIELD_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_hash(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_hash(client, + hash_oid): + """ + sai_remove_hash() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + hash_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_hash(hash_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_hash_attribute(client, + hash_oid, + native_hash_field_list=None, + udf_group_list=None, + fine_grained_hash_field_list=None, + custom_attribute=None): + """ + sai_set_hash_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + hash_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hash SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if native_hash_field_list is not None: + attr_value = sai_thrift_attribute_value_t(s32list=native_hash_field_list) + attr = sai_thrift_attribute_t(id=SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST, + value=attr_value) + client.sai_thrift_set_hash_attribute(hash_oid, attr) + + if udf_group_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=udf_group_list) + attr = sai_thrift_attribute_t(id=SAI_HASH_ATTR_UDF_GROUP_LIST, + value=attr_value) + client.sai_thrift_set_hash_attribute(hash_oid, attr) + + if fine_grained_hash_field_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=fine_grained_hash_field_list) + attr = sai_thrift_attribute_t(id=SAI_HASH_ATTR_FINE_GRAINED_HASH_FIELD_LIST, + value=attr_value) + client.sai_thrift_set_hash_attribute(hash_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_hash_attribute(hash_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_hash_attribute(client, + hash_oid, + native_hash_field_list=None, + udf_group_list=None, + fine_grained_hash_field_list=None, + custom_attribute=None): + """ + sai_get_hash_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + hash_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hash GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if native_hash_field_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=native_hash_field_list) + attribute = sai_thrift_attribute_t(id=SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST, + value=attribute_value) + attr_list.append(attribute) + + if udf_group_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=udf_group_list) + attribute = sai_thrift_attribute_t(id=SAI_HASH_ATTR_UDF_GROUP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if fine_grained_hash_field_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=fine_grained_hash_field_list) + attribute = sai_thrift_attribute_t(id=SAI_HASH_ATTR_FINE_GRAINED_HASH_FIELD_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_hash_attribute(hash_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST: + attrs["SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST"] = attr.value.s32list + attrs["native_hash_field_list"] = attr.value.s32list + + if attr.id == SAI_HASH_ATTR_UDF_GROUP_LIST: + attrs["SAI_HASH_ATTR_UDF_GROUP_LIST"] = attr.value.objlist + attrs["udf_group_list"] = attr.value.objlist + + if attr.id == SAI_HASH_ATTR_FINE_GRAINED_HASH_FIELD_LIST: + attrs["SAI_HASH_ATTR_FINE_GRAINED_HASH_FIELD_LIST"] = attr.value.objlist + attrs["fine_grained_hash_field_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# hostif API + +def sai_thrift_create_hostif_trap_group(client, + admin_state=None, + queue=None, + policer=None, + custom_attribute=None): + """ + sai_create_hostif_trap_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of hostif_trap_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: hostif_trap_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if admin_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_state) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_ADMIN_STATE, + value=attribute_value) + attr_list.append(attribute) + + if queue is not None: + attribute_value = sai_thrift_attribute_value_t(u32=queue) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE, + value=attribute_value) + attr_list.append(attribute) + + if policer is not None: + attribute_value = sai_thrift_attribute_value_t(oid=policer) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_hostif_trap_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_hostif_trap_group(client, + hostif_trap_group_oid): + """ + sai_remove_hostif_trap_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + hostif_trap_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_hostif_trap_group(hostif_trap_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_hostif_trap_group_attribute(client, + hostif_trap_group_oid, + admin_state=None, + queue=None, + policer=None, + custom_attribute=None): + """ + sai_set_hostif_trap_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + hostif_trap_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_trap_group SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if admin_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_state) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_ADMIN_STATE, + value=attr_value) + client.sai_thrift_set_hostif_trap_group_attribute(hostif_trap_group_oid, attr) + + if queue is not None: + attr_value = sai_thrift_attribute_value_t(u32=queue) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE, + value=attr_value) + client.sai_thrift_set_hostif_trap_group_attribute(hostif_trap_group_oid, attr) + + if policer is not None: + attr_value = sai_thrift_attribute_value_t(oid=policer) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER, + value=attr_value) + client.sai_thrift_set_hostif_trap_group_attribute(hostif_trap_group_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_hostif_trap_group_attribute(hostif_trap_group_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_hostif_trap_group_attribute(client, + hostif_trap_group_oid, + admin_state=None, + queue=None, + policer=None, + custom_attribute=None): + """ + sai_get_hostif_trap_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + hostif_trap_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_trap_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if admin_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_ADMIN_STATE) + attr_list.append(attribute) + + if queue is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE) + attr_list.append(attribute) + + if policer is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_hostif_trap_group_attribute(hostif_trap_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_HOSTIF_TRAP_GROUP_ATTR_ADMIN_STATE: + attrs["SAI_HOSTIF_TRAP_GROUP_ATTR_ADMIN_STATE"] = attr.value.booldata + attrs["admin_state"] = attr.value.booldata + + if attr.id == SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE: + attrs["SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE"] = attr.value.u32 + attrs["queue"] = attr.value.u32 + + if attr.id == SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER: + attrs["SAI_HOSTIF_TRAP_GROUP_ATTR_POLICER"] = attr.value.oid + attrs["policer"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_hostif_trap(client, + trap_type=None, + packet_action=None, + trap_priority=None, + exclude_port_list=None, + trap_group=None, + mirror_session=None, + counter_id=None, + custom_attribute=None): + """ + sai_create_hostif_trap() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of hostif_trap CREATE attributes. + + Returns: + sai_thrift_object_id_t: hostif_trap_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if trap_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=trap_type) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if trap_priority is not None: + attribute_value = sai_thrift_attribute_value_t(u32=trap_priority) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if exclude_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=exclude_port_list) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_EXCLUDE_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if trap_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=trap_group) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_hostif_trap(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_hostif_trap(client, + hostif_trap_oid): + """ + sai_remove_hostif_trap() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + hostif_trap_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_hostif_trap(hostif_trap_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_hostif_trap_attribute(client, + hostif_trap_oid, + packet_action=None, + trap_priority=None, + exclude_port_list=None, + trap_group=None, + mirror_session=None, + counter_id=None, + custom_attribute=None): + """ + sai_set_hostif_trap_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + hostif_trap_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_trap SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + if trap_priority is not None: + attr_value = sai_thrift_attribute_value_t(u32=trap_priority) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY, + value=attr_value) + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + if exclude_port_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=exclude_port_list) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_EXCLUDE_PORT_LIST, + value=attr_value) + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + if trap_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=trap_group) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_GROUP, + value=attr_value) + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + if mirror_session is not None: + attr_value = sai_thrift_attribute_value_t(objlist=mirror_session) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_MIRROR_SESSION, + value=attr_value) + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_hostif_trap_attribute(hostif_trap_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_hostif_trap_attribute(client, + hostif_trap_oid, + trap_type=None, + packet_action=None, + trap_priority=None, + exclude_port_list=None, + trap_group=None, + mirror_session=None, + counter_id=None, + custom_attribute=None): + """ + sai_get_hostif_trap_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + hostif_trap_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_trap GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if trap_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE) + attr_list.append(attribute) + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if trap_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY) + attr_list.append(attribute) + + if exclude_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=exclude_port_list) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_EXCLUDE_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if trap_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_TRAP_GROUP) + attr_list.append(attribute) + + if mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TRAP_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_hostif_trap_attribute(hostif_trap_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE: + attrs["SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE"] = attr.value.s32 + attrs["trap_type"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION: + attrs["SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY: + attrs["SAI_HOSTIF_TRAP_ATTR_TRAP_PRIORITY"] = attr.value.u32 + attrs["trap_priority"] = attr.value.u32 + + if attr.id == SAI_HOSTIF_TRAP_ATTR_EXCLUDE_PORT_LIST: + attrs["SAI_HOSTIF_TRAP_ATTR_EXCLUDE_PORT_LIST"] = attr.value.objlist + attrs["exclude_port_list"] = attr.value.objlist + + if attr.id == SAI_HOSTIF_TRAP_ATTR_TRAP_GROUP: + attrs["SAI_HOSTIF_TRAP_ATTR_TRAP_GROUP"] = attr.value.oid + attrs["trap_group"] = attr.value.oid + + if attr.id == SAI_HOSTIF_TRAP_ATTR_MIRROR_SESSION: + attrs["SAI_HOSTIF_TRAP_ATTR_MIRROR_SESSION"] = attr.value.objlist + attrs["mirror_session"] = attr.value.objlist + + if attr.id == SAI_HOSTIF_TRAP_ATTR_COUNTER_ID: + attrs["SAI_HOSTIF_TRAP_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_hostif_user_defined_trap(client, + type=None, + trap_priority=None, + trap_group=None, + custom_attribute=None): + """ + sai_create_hostif_user_defined_trap() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of hostif_user_defined_trap CREATE attributes. + + Returns: + sai_thrift_object_id_t: hostif_user_defined_trap_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if trap_priority is not None: + attribute_value = sai_thrift_attribute_value_t(u32=trap_priority) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if trap_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=trap_group) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_hostif_user_defined_trap(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_hostif_user_defined_trap(client, + hostif_user_defined_trap_oid): + """ + sai_remove_hostif_user_defined_trap() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + hostif_user_defined_trap_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_hostif_user_defined_trap(hostif_user_defined_trap_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_hostif_user_defined_trap_attribute(client, + hostif_user_defined_trap_oid, + trap_priority=None, + trap_group=None, + custom_attribute=None): + """ + sai_set_hostif_user_defined_trap_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + hostif_user_defined_trap_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_user_defined_trap SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if trap_priority is not None: + attr_value = sai_thrift_attribute_value_t(u32=trap_priority) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_PRIORITY, + value=attr_value) + client.sai_thrift_set_hostif_user_defined_trap_attribute(hostif_user_defined_trap_oid, attr) + + if trap_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=trap_group) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_GROUP, + value=attr_value) + client.sai_thrift_set_hostif_user_defined_trap_attribute(hostif_user_defined_trap_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_hostif_user_defined_trap_attribute(hostif_user_defined_trap_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_hostif_user_defined_trap_attribute(client, + hostif_user_defined_trap_oid, + type=None, + trap_priority=None, + trap_group=None, + custom_attribute=None): + """ + sai_get_hostif_user_defined_trap_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + hostif_user_defined_trap_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_user_defined_trap GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TYPE) + attr_list.append(attribute) + + if trap_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_PRIORITY) + attr_list.append(attribute) + + if trap_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_GROUP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_hostif_user_defined_trap_attribute(hostif_user_defined_trap_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TYPE: + attrs["SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_PRIORITY: + attrs["SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_PRIORITY"] = attr.value.u32 + attrs["trap_priority"] = attr.value.u32 + + if attr.id == SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_GROUP: + attrs["SAI_HOSTIF_USER_DEFINED_TRAP_ATTR_TRAP_GROUP"] = attr.value.oid + attrs["trap_group"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_hostif(client, + type=None, + obj_id=None, + name=None, + genetlink_mcgrp_name=None, + oper_status=None, + queue=None, + vlan_tag=None, + custom_attribute=None): + """ + sai_create_hostif() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of hostif CREATE attributes. + + Returns: + sai_thrift_object_id_t: hostif_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if obj_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=obj_id) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_OBJ_ID, + value=attribute_value) + attr_list.append(attribute) + + if name is not None: + attribute_value = sai_thrift_attribute_value_t(chardata=name) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_NAME, + value=attribute_value) + attr_list.append(attribute) + + if genetlink_mcgrp_name is not None: + attribute_value = sai_thrift_attribute_value_t(chardata=genetlink_mcgrp_name) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME, + value=attribute_value) + attr_list.append(attribute) + + if oper_status is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=oper_status) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_OPER_STATUS, + value=attribute_value) + attr_list.append(attribute) + + if queue is not None: + attribute_value = sai_thrift_attribute_value_t(u32=queue) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_QUEUE, + value=attribute_value) + attr_list.append(attribute) + + if vlan_tag is not None: + attribute_value = sai_thrift_attribute_value_t(s32=vlan_tag) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_VLAN_TAG, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_hostif(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_hostif(client, + hostif_oid): + """ + sai_remove_hostif() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_hostif(hostif_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_hostif_attribute(client, + hostif_oid, + oper_status=None, + queue=None, + vlan_tag=None, + custom_attribute=None): + """ + sai_set_hostif_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if oper_status is not None: + attr_value = sai_thrift_attribute_value_t(booldata=oper_status) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_OPER_STATUS, + value=attr_value) + client.sai_thrift_set_hostif_attribute(hostif_oid, attr) + + if queue is not None: + attr_value = sai_thrift_attribute_value_t(u32=queue) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_QUEUE, + value=attr_value) + client.sai_thrift_set_hostif_attribute(hostif_oid, attr) + + if vlan_tag is not None: + attr_value = sai_thrift_attribute_value_t(s32=vlan_tag) + attr = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_VLAN_TAG, + value=attr_value) + client.sai_thrift_set_hostif_attribute(hostif_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_hostif_attribute(hostif_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_hostif_attribute(client, + hostif_oid, + type=None, + obj_id=None, + name=None, + oper_status=None, + queue=None, + vlan_tag=None, + genetlink_mcgrp_name=None, + custom_attribute=None): + """ + sai_get_hostif_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_TYPE) + attr_list.append(attribute) + + if obj_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_OBJ_ID) + attr_list.append(attribute) + + if name is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_NAME) + attr_list.append(attribute) + + if oper_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_OPER_STATUS) + attr_list.append(attribute) + + if queue is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_QUEUE) + attr_list.append(attribute) + + if vlan_tag is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_VLAN_TAG) + attr_list.append(attribute) + + if genetlink_mcgrp_name is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_hostif_attribute(hostif_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_HOSTIF_ATTR_TYPE: + attrs["SAI_HOSTIF_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_ATTR_OBJ_ID: + attrs["SAI_HOSTIF_ATTR_OBJ_ID"] = attr.value.oid + attrs["obj_id"] = attr.value.oid + + if attr.id == SAI_HOSTIF_ATTR_NAME: + attrs["SAI_HOSTIF_ATTR_NAME"] = attr.value.chardata + attrs["name"] = attr.value.chardata + + if attr.id == SAI_HOSTIF_ATTR_OPER_STATUS: + attrs["SAI_HOSTIF_ATTR_OPER_STATUS"] = attr.value.booldata + attrs["oper_status"] = attr.value.booldata + + if attr.id == SAI_HOSTIF_ATTR_QUEUE: + attrs["SAI_HOSTIF_ATTR_QUEUE"] = attr.value.u32 + attrs["queue"] = attr.value.u32 + + if attr.id == SAI_HOSTIF_ATTR_VLAN_TAG: + attrs["SAI_HOSTIF_ATTR_VLAN_TAG"] = attr.value.s32 + attrs["vlan_tag"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME: + attrs["SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME"] = attr.value.chardata + attrs["genetlink_mcgrp_name"] = attr.value.chardata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_hostif_table_entry(client, + type=None, + obj_id=None, + trap_id=None, + channel_type=None, + host_if=None, + custom_attribute=None): + """ + sai_create_hostif_table_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of hostif_table_entry CREATE attributes. + + Returns: + sai_thrift_object_id_t: hostif_table_entry_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if obj_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=obj_id) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_OBJ_ID, + value=attribute_value) + attr_list.append(attribute) + + if trap_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=trap_id) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID, + value=attribute_value) + attr_list.append(attribute) + + if channel_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=channel_type) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if host_if is not None: + attribute_value = sai_thrift_attribute_value_t(oid=host_if) + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_hostif_table_entry(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_hostif_table_entry(client, + hostif_table_entry_oid): + """ + sai_remove_hostif_table_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + hostif_table_entry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_hostif_table_entry(hostif_table_entry_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_hostif_table_entry_attribute(client, + hostif_table_entry_oid, + custom_attribute=None): + """ + sai_set_hostif_table_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + hostif_table_entry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del hostif_table_entry_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_hostif_table_entry_attribute(client, + hostif_table_entry_oid, + type=None, + obj_id=None, + trap_id=None, + channel_type=None, + host_if=None, + custom_attribute=None): + """ + sai_get_hostif_table_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + hostif_table_entry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of hostif_table_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE) + attr_list.append(attribute) + + if obj_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_OBJ_ID) + attr_list.append(attribute) + + if trap_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID) + attr_list.append(attribute) + + if channel_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE) + attr_list.append(attribute) + + if host_if is not None: + attribute = sai_thrift_attribute_t(id=SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_hostif_table_entry_attribute(hostif_table_entry_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE: + attrs["SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_TABLE_ENTRY_ATTR_OBJ_ID: + attrs["SAI_HOSTIF_TABLE_ENTRY_ATTR_OBJ_ID"] = attr.value.oid + attrs["obj_id"] = attr.value.oid + + if attr.id == SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID: + attrs["SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID"] = attr.value.oid + attrs["trap_id"] = attr.value.oid + + if attr.id == SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE: + attrs["SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE"] = attr.value.s32 + attrs["channel_type"] = attr.value.s32 + + if attr.id == SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF: + attrs["SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF"] = attr.value.oid + attrs["host_if"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_recv_hostif_packet(client, + hostif_oid, + buffer_size, + buffer): + """ + sai_recv_hostif_packet() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + buffer_size(sai_thrift_size_t): size IN/OUT argument + buffer(str): buffer OUT argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del hostif_oid + del buffer_size + del buffer + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_send_hostif_packet(client, + hostif_oid, + buffer_size, + buffer): + """ + sai_send_hostif_packet() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + buffer_size(sai_thrift_size_t): size IN argument + buffer(str): buffer IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del hostif_oid + del buffer_size + del buffer + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_allocate_hostif_packet(client, + hostif_oid, + buffer_size): + """ + sai_allocate_hostif_packet() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + buffer_size(sai_thrift_size_t): size IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del hostif_oid + del buffer_size + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_free_hostif_packet(client, + hostif_oid, + buffer): + """ + sai_free_hostif_packet() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + hostif_oid(sai_thrift_object_id_t): object_id IN argument + buffer(str): buffer IN/OUT argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del hostif_oid + del buffer + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +# ipmc API + +def sai_thrift_create_ipmc_entry(client, + ipmc_entry, + packet_action=None, + rpf_group_id=None, + output_group_id=None, + custom_attribute=None): + """ + sai_create_ipmc_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipmc_entry(sai_thrift_ipmc_entry_t): ipmc_entry IN argument + + For the other parameters, see documentation of ipmc_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if rpf_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=rpf_group_id) + attribute = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_RPF_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if output_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=output_group_id) + attribute = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_OUTPUT_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_ipmc_entry(ipmc_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_ipmc_entry(client, + ipmc_entry): + """ + sai_remove_ipmc_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipmc_entry(sai_thrift_ipmc_entry_t): ipmc_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ipmc_entry(ipmc_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ipmc_entry_attribute(client, + ipmc_entry, + packet_action=None, + output_group_id=None, + rpf_group_id=None, + custom_attribute=None): + """ + sai_set_ipmc_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ipmc_entry(sai_thrift_ipmc_entry_t): ipmc_entry IN argument + + For the other parameters, see documentation of ipmc_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_ipmc_entry_attribute(ipmc_entry, attr) + + if output_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=output_group_id) + attr = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_OUTPUT_GROUP_ID, + value=attr_value) + client.sai_thrift_set_ipmc_entry_attribute(ipmc_entry, attr) + + if rpf_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=rpf_group_id) + attr = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_RPF_GROUP_ID, + value=attr_value) + client.sai_thrift_set_ipmc_entry_attribute(ipmc_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_ipmc_entry_attribute(ipmc_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_ipmc_entry_attribute(client, + ipmc_entry, + packet_action=None, + output_group_id=None, + rpf_group_id=None, + custom_attribute=None): + """ + sai_get_ipmc_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ipmc_entry(sai_thrift_ipmc_entry_t): ipmc_entry IN argument + + For the other parameters, see documentation of ipmc_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if output_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_OUTPUT_GROUP_ID) + attr_list.append(attribute) + + if rpf_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPMC_ENTRY_ATTR_RPF_GROUP_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ipmc_entry_attribute(ipmc_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_IPMC_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_IPMC_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_IPMC_ENTRY_ATTR_OUTPUT_GROUP_ID: + attrs["SAI_IPMC_ENTRY_ATTR_OUTPUT_GROUP_ID"] = attr.value.oid + attrs["output_group_id"] = attr.value.oid + + if attr.id == SAI_IPMC_ENTRY_ATTR_RPF_GROUP_ID: + attrs["SAI_IPMC_ENTRY_ATTR_RPF_GROUP_ID"] = attr.value.oid + attrs["rpf_group_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# ipmc_group API + +def sai_thrift_create_ipmc_group(client, + custom_attribute=None): + """ + sai_create_ipmc_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + sai_thrift_object_id_t: ipmc_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_ipmc_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_ipmc_group(client, + ipmc_group_oid): + """ + sai_remove_ipmc_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipmc_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ipmc_group(ipmc_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ipmc_group_attribute(client, + ipmc_group_oid, + custom_attribute=None): + """ + sai_set_ipmc_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ipmc_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del ipmc_group_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_ipmc_group_attribute(client, + ipmc_group_oid, + ipmc_output_count=None, + ipmc_member_list=None, + custom_attribute=None): + """ + sai_get_ipmc_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ipmc_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipmc_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ipmc_output_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPMC_GROUP_ATTR_IPMC_OUTPUT_COUNT) + attr_list.append(attribute) + + if ipmc_member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ipmc_member_list) + attribute = sai_thrift_attribute_t(id=SAI_IPMC_GROUP_ATTR_IPMC_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ipmc_group_attribute(ipmc_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_IPMC_GROUP_ATTR_IPMC_OUTPUT_COUNT: + attrs["SAI_IPMC_GROUP_ATTR_IPMC_OUTPUT_COUNT"] = attr.value.u32 + attrs["ipmc_output_count"] = attr.value.u32 + + if attr.id == SAI_IPMC_GROUP_ATTR_IPMC_MEMBER_LIST: + attrs["SAI_IPMC_GROUP_ATTR_IPMC_MEMBER_LIST"] = attr.value.objlist + attrs["ipmc_member_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_ipmc_group_member(client, + ipmc_group_id=None, + ipmc_output_id=None, + custom_attribute=None): + """ + sai_create_ipmc_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of ipmc_group_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: ipmc_group_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ipmc_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ipmc_group_id) + attribute = sai_thrift_attribute_t(id=SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if ipmc_output_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ipmc_output_id) + attribute = sai_thrift_attribute_t(id=SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_OUTPUT_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_ipmc_group_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_ipmc_group_member(client, + ipmc_group_member_oid): + """ + sai_remove_ipmc_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipmc_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ipmc_group_member(ipmc_group_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ipmc_group_member_attribute(client, + ipmc_group_member_oid, + custom_attribute=None): + """ + sai_set_ipmc_group_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ipmc_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del ipmc_group_member_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_ipmc_group_member_attribute(client, + ipmc_group_member_oid, + ipmc_group_id=None, + ipmc_output_id=None, + custom_attribute=None): + """ + sai_get_ipmc_group_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ipmc_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipmc_group_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ipmc_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_GROUP_ID) + attr_list.append(attribute) + + if ipmc_output_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_OUTPUT_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ipmc_group_member_attribute(ipmc_group_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_GROUP_ID: + attrs["SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_GROUP_ID"] = attr.value.oid + attrs["ipmc_group_id"] = attr.value.oid + + if attr.id == SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_OUTPUT_ID: + attrs["SAI_IPMC_GROUP_MEMBER_ATTR_IPMC_OUTPUT_ID"] = attr.value.oid + attrs["ipmc_output_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# ipsec API + +def sai_thrift_create_ipsec(client, + external_sa_index_enable=None, + warm_boot_enable=None, + ctag_tpid=None, + stag_tpid=None, + max_vlan_tags_parsed=None, + octet_count_high_watermark=None, + octet_count_low_watermark=None, + stats_mode=None, + custom_attribute=None): + """ + sai_create_ipsec() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of ipsec CREATE attributes. + + Returns: + sai_thrift_object_id_t: ipsec_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if external_sa_index_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=external_sa_index_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_EXTERNAL_SA_INDEX_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if warm_boot_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=warm_boot_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_WARM_BOOT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if ctag_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=ctag_tpid) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_CTAG_TPID, + value=attribute_value) + attr_list.append(attribute) + + if stag_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=stag_tpid) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STAG_TPID, + value=attribute_value) + attr_list.append(attribute) + + if max_vlan_tags_parsed is not None: + attribute_value = sai_thrift_attribute_value_t(u8=max_vlan_tags_parsed) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_MAX_VLAN_TAGS_PARSED, + value=attribute_value) + attr_list.append(attribute) + + if octet_count_high_watermark is not None: + attribute_value = sai_thrift_attribute_value_t(u64=octet_count_high_watermark) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_OCTET_COUNT_HIGH_WATERMARK, + value=attribute_value) + attr_list.append(attribute) + + if octet_count_low_watermark is not None: + attribute_value = sai_thrift_attribute_value_t(u64=octet_count_low_watermark) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_OCTET_COUNT_LOW_WATERMARK, + value=attribute_value) + attr_list.append(attribute) + + if stats_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=stats_mode) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STATS_MODE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_ipsec(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_ipsec(client, + ipsec_oid): + """ + sai_remove_ipsec() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ipsec(ipsec_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ipsec_attribute(client, + ipsec_oid, + warm_boot_enable=None, + ctag_tpid=None, + stag_tpid=None, + max_vlan_tags_parsed=None, + octet_count_high_watermark=None, + octet_count_low_watermark=None, + stats_mode=None, + custom_attribute=None): + """ + sai_set_ipsec_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ipsec_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipsec SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if warm_boot_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=warm_boot_enable) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_WARM_BOOT_ENABLE, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if ctag_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=ctag_tpid) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_CTAG_TPID, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if stag_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=stag_tpid) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STAG_TPID, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if max_vlan_tags_parsed is not None: + attr_value = sai_thrift_attribute_value_t(u8=max_vlan_tags_parsed) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_MAX_VLAN_TAGS_PARSED, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if octet_count_high_watermark is not None: + attr_value = sai_thrift_attribute_value_t(u64=octet_count_high_watermark) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_OCTET_COUNT_HIGH_WATERMARK, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if octet_count_low_watermark is not None: + attr_value = sai_thrift_attribute_value_t(u64=octet_count_low_watermark) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_OCTET_COUNT_LOW_WATERMARK, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if stats_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=stats_mode) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STATS_MODE, + value=attr_value) + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_ipsec_attribute(ipsec_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_ipsec_attribute(client, + ipsec_oid, + term_remote_ip_match_supported=None, + switching_mode_cut_through_supported=None, + switching_mode_store_and_forward_supported=None, + stats_mode_read_supported=None, + stats_mode_read_clear_supported=None, + sn_32bit_supported=None, + esn_64bit_supported=None, + supported_cipher_list=None, + system_side_mtu=None, + warm_boot_supported=None, + warm_boot_enable=None, + external_sa_index_enable=None, + ctag_tpid=None, + stag_tpid=None, + max_vlan_tags_parsed=None, + octet_count_high_watermark=None, + octet_count_low_watermark=None, + stats_mode=None, + available_ipsec_sa=None, + sa_list=None, + custom_attribute=None): + """ + sai_get_ipsec_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ipsec_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipsec GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if term_remote_ip_match_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_TERM_REMOTE_IP_MATCH_SUPPORTED) + attr_list.append(attribute) + + if switching_mode_cut_through_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_SWITCHING_MODE_CUT_THROUGH_SUPPORTED) + attr_list.append(attribute) + + if switching_mode_store_and_forward_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_SWITCHING_MODE_STORE_AND_FORWARD_SUPPORTED) + attr_list.append(attribute) + + if stats_mode_read_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STATS_MODE_READ_SUPPORTED) + attr_list.append(attribute) + + if stats_mode_read_clear_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STATS_MODE_READ_CLEAR_SUPPORTED) + attr_list.append(attribute) + + if sn_32bit_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_SN_32BIT_SUPPORTED) + attr_list.append(attribute) + + if esn_64bit_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_ESN_64BIT_SUPPORTED) + attr_list.append(attribute) + + if supported_cipher_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_cipher_list) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_SUPPORTED_CIPHER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if system_side_mtu is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_SYSTEM_SIDE_MTU) + attr_list.append(attribute) + + if warm_boot_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_WARM_BOOT_SUPPORTED) + attr_list.append(attribute) + + if warm_boot_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_WARM_BOOT_ENABLE) + attr_list.append(attribute) + + if external_sa_index_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_EXTERNAL_SA_INDEX_ENABLE) + attr_list.append(attribute) + + if ctag_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_CTAG_TPID) + attr_list.append(attribute) + + if stag_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STAG_TPID) + attr_list.append(attribute) + + if max_vlan_tags_parsed is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_MAX_VLAN_TAGS_PARSED) + attr_list.append(attribute) + + if octet_count_high_watermark is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_OCTET_COUNT_HIGH_WATERMARK) + attr_list.append(attribute) + + if octet_count_low_watermark is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_OCTET_COUNT_LOW_WATERMARK) + attr_list.append(attribute) + + if stats_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_STATS_MODE) + attr_list.append(attribute) + + if available_ipsec_sa is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_AVAILABLE_IPSEC_SA) + attr_list.append(attribute) + + if sa_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=sa_list) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_ATTR_SA_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ipsec_attribute(ipsec_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_IPSEC_ATTR_TERM_REMOTE_IP_MATCH_SUPPORTED: + attrs["SAI_IPSEC_ATTR_TERM_REMOTE_IP_MATCH_SUPPORTED"] = attr.value.booldata + attrs["term_remote_ip_match_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_SWITCHING_MODE_CUT_THROUGH_SUPPORTED: + attrs["SAI_IPSEC_ATTR_SWITCHING_MODE_CUT_THROUGH_SUPPORTED"] = attr.value.booldata + attrs["switching_mode_cut_through_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_SWITCHING_MODE_STORE_AND_FORWARD_SUPPORTED: + attrs["SAI_IPSEC_ATTR_SWITCHING_MODE_STORE_AND_FORWARD_SUPPORTED"] = attr.value.booldata + attrs["switching_mode_store_and_forward_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_STATS_MODE_READ_SUPPORTED: + attrs["SAI_IPSEC_ATTR_STATS_MODE_READ_SUPPORTED"] = attr.value.booldata + attrs["stats_mode_read_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_STATS_MODE_READ_CLEAR_SUPPORTED: + attrs["SAI_IPSEC_ATTR_STATS_MODE_READ_CLEAR_SUPPORTED"] = attr.value.booldata + attrs["stats_mode_read_clear_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_SN_32BIT_SUPPORTED: + attrs["SAI_IPSEC_ATTR_SN_32BIT_SUPPORTED"] = attr.value.booldata + attrs["sn_32bit_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_ESN_64BIT_SUPPORTED: + attrs["SAI_IPSEC_ATTR_ESN_64BIT_SUPPORTED"] = attr.value.booldata + attrs["esn_64bit_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_SUPPORTED_CIPHER_LIST: + attrs["SAI_IPSEC_ATTR_SUPPORTED_CIPHER_LIST"] = attr.value.s32list + attrs["supported_cipher_list"] = attr.value.s32list + + if attr.id == SAI_IPSEC_ATTR_SYSTEM_SIDE_MTU: + attrs["SAI_IPSEC_ATTR_SYSTEM_SIDE_MTU"] = attr.value.u16 + attrs["system_side_mtu"] = attr.value.u16 + + if attr.id == SAI_IPSEC_ATTR_WARM_BOOT_SUPPORTED: + attrs["SAI_IPSEC_ATTR_WARM_BOOT_SUPPORTED"] = attr.value.booldata + attrs["warm_boot_supported"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_WARM_BOOT_ENABLE: + attrs["SAI_IPSEC_ATTR_WARM_BOOT_ENABLE"] = attr.value.booldata + attrs["warm_boot_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_EXTERNAL_SA_INDEX_ENABLE: + attrs["SAI_IPSEC_ATTR_EXTERNAL_SA_INDEX_ENABLE"] = attr.value.booldata + attrs["external_sa_index_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_ATTR_CTAG_TPID: + attrs["SAI_IPSEC_ATTR_CTAG_TPID"] = attr.value.u16 + attrs["ctag_tpid"] = attr.value.u16 + + if attr.id == SAI_IPSEC_ATTR_STAG_TPID: + attrs["SAI_IPSEC_ATTR_STAG_TPID"] = attr.value.u16 + attrs["stag_tpid"] = attr.value.u16 + + if attr.id == SAI_IPSEC_ATTR_MAX_VLAN_TAGS_PARSED: + attrs["SAI_IPSEC_ATTR_MAX_VLAN_TAGS_PARSED"] = attr.value.u8 + attrs["max_vlan_tags_parsed"] = attr.value.u8 + + if attr.id == SAI_IPSEC_ATTR_OCTET_COUNT_HIGH_WATERMARK: + attrs["SAI_IPSEC_ATTR_OCTET_COUNT_HIGH_WATERMARK"] = attr.value.u64 + attrs["octet_count_high_watermark"] = attr.value.u64 + + if attr.id == SAI_IPSEC_ATTR_OCTET_COUNT_LOW_WATERMARK: + attrs["SAI_IPSEC_ATTR_OCTET_COUNT_LOW_WATERMARK"] = attr.value.u64 + attrs["octet_count_low_watermark"] = attr.value.u64 + + if attr.id == SAI_IPSEC_ATTR_STATS_MODE: + attrs["SAI_IPSEC_ATTR_STATS_MODE"] = attr.value.s32 + attrs["stats_mode"] = attr.value.s32 + + if attr.id == SAI_IPSEC_ATTR_AVAILABLE_IPSEC_SA: + attrs["SAI_IPSEC_ATTR_AVAILABLE_IPSEC_SA"] = attr.value.u32 + attrs["available_ipsec_sa"] = attr.value.u32 + + if attr.id == SAI_IPSEC_ATTR_SA_LIST: + attrs["SAI_IPSEC_ATTR_SA_LIST"] = attr.value.objlist + attrs["sa_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_ipsec_port(client, + port_id=None, + native_vlan_id=None, + ctag_enable=None, + stag_enable=None, + vrf_from_packet_vlan_enable=None, + switch_switching_mode=None, + custom_attribute=None): + """ + sai_create_ipsec_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of ipsec_port CREATE attributes. + + Returns: + sai_thrift_object_id_t: ipsec_port_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if native_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=native_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_NATIVE_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if ctag_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ctag_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_CTAG_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if stag_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=stag_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_STAG_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if vrf_from_packet_vlan_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=vrf_from_packet_vlan_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_VRF_FROM_PACKET_VLAN_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if switch_switching_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=switch_switching_mode) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_SWITCH_SWITCHING_MODE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_ipsec_port(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_ipsec_port(client, + ipsec_port_oid): + """ + sai_remove_ipsec_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ipsec_port(ipsec_port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ipsec_port_attribute(client, + ipsec_port_oid, + ctag_enable=None, + stag_enable=None, + vrf_from_packet_vlan_enable=None, + switch_switching_mode=None, + custom_attribute=None): + """ + sai_set_ipsec_port_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ipsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipsec_port SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if ctag_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ctag_enable) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_CTAG_ENABLE, + value=attr_value) + client.sai_thrift_set_ipsec_port_attribute(ipsec_port_oid, attr) + + if stag_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=stag_enable) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_STAG_ENABLE, + value=attr_value) + client.sai_thrift_set_ipsec_port_attribute(ipsec_port_oid, attr) + + if vrf_from_packet_vlan_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=vrf_from_packet_vlan_enable) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_VRF_FROM_PACKET_VLAN_ENABLE, + value=attr_value) + client.sai_thrift_set_ipsec_port_attribute(ipsec_port_oid, attr) + + if switch_switching_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=switch_switching_mode) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_SWITCH_SWITCHING_MODE, + value=attr_value) + client.sai_thrift_set_ipsec_port_attribute(ipsec_port_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_ipsec_port_attribute(ipsec_port_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_ipsec_port_attribute(client, + ipsec_port_oid, + port_id=None, + ctag_enable=None, + stag_enable=None, + native_vlan_id=None, + vrf_from_packet_vlan_enable=None, + switch_switching_mode=None, + custom_attribute=None): + """ + sai_get_ipsec_port_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ipsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipsec_port GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_PORT_ID) + attr_list.append(attribute) + + if ctag_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_CTAG_ENABLE) + attr_list.append(attribute) + + if stag_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_STAG_ENABLE) + attr_list.append(attribute) + + if native_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_NATIVE_VLAN_ID) + attr_list.append(attribute) + + if vrf_from_packet_vlan_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_VRF_FROM_PACKET_VLAN_ENABLE) + attr_list.append(attribute) + + if switch_switching_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_PORT_ATTR_SWITCH_SWITCHING_MODE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ipsec_port_attribute(ipsec_port_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_IPSEC_PORT_ATTR_PORT_ID: + attrs["SAI_IPSEC_PORT_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_IPSEC_PORT_ATTR_CTAG_ENABLE: + attrs["SAI_IPSEC_PORT_ATTR_CTAG_ENABLE"] = attr.value.booldata + attrs["ctag_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_PORT_ATTR_STAG_ENABLE: + attrs["SAI_IPSEC_PORT_ATTR_STAG_ENABLE"] = attr.value.booldata + attrs["stag_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_PORT_ATTR_NATIVE_VLAN_ID: + attrs["SAI_IPSEC_PORT_ATTR_NATIVE_VLAN_ID"] = attr.value.u16 + attrs["native_vlan_id"] = attr.value.u16 + + if attr.id == SAI_IPSEC_PORT_ATTR_VRF_FROM_PACKET_VLAN_ENABLE: + attrs["SAI_IPSEC_PORT_ATTR_VRF_FROM_PACKET_VLAN_ENABLE"] = attr.value.booldata + attrs["vrf_from_packet_vlan_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_PORT_ATTR_SWITCH_SWITCHING_MODE: + attrs["SAI_IPSEC_PORT_ATTR_SWITCH_SWITCHING_MODE"] = attr.value.s32 + attrs["switch_switching_mode"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_ipsec_port_stats(client, + ipsec_port_oid): + """ + sai_get_ipsec_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_ERROR_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_NON_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_ERROR_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_NON_IPSEC_PKTS) + + counters = [0] * 6 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_ipsec_port_stats(ipsec_port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_IPSEC_PORT_STAT_TX_ERROR_PKTS"] = counters[0] + stats["SAI_IPSEC_PORT_STAT_TX_IPSEC_PKTS"] = counters[1] + stats["SAI_IPSEC_PORT_STAT_TX_NON_IPSEC_PKTS"] = counters[2] + stats["SAI_IPSEC_PORT_STAT_RX_ERROR_PKTS"] = counters[3] + stats["SAI_IPSEC_PORT_STAT_RX_IPSEC_PKTS"] = counters[4] + stats["SAI_IPSEC_PORT_STAT_RX_NON_IPSEC_PKTS"] = counters[5] + + return stats + + +def sai_thrift_get_ipsec_port_stats_ext(client, + ipsec_port_oid, + mode): + """ + sai_get_ipsec_port_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_port_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_ERROR_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_NON_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_ERROR_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_NON_IPSEC_PKTS) + + counters = [0] * 6 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_ipsec_port_stats_ext(ipsec_port_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_IPSEC_PORT_STAT_TX_ERROR_PKTS"] = counters[0] + stats["SAI_IPSEC_PORT_STAT_TX_IPSEC_PKTS"] = counters[1] + stats["SAI_IPSEC_PORT_STAT_TX_NON_IPSEC_PKTS"] = counters[2] + stats["SAI_IPSEC_PORT_STAT_RX_ERROR_PKTS"] = counters[3] + stats["SAI_IPSEC_PORT_STAT_RX_IPSEC_PKTS"] = counters[4] + stats["SAI_IPSEC_PORT_STAT_RX_NON_IPSEC_PKTS"] = counters[5] + + return stats + + +def sai_thrift_clear_ipsec_port_stats(client, + ipsec_port_oid): + """ + sai_clear_ipsec_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_ERROR_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_TX_NON_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_ERROR_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_IPSEC_PKTS) + counter_ids.append(SAI_IPSEC_PORT_STAT_RX_NON_IPSEC_PKTS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_ipsec_port_stats(ipsec_port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_ipsec_sa(client, + ipsec_direction=None, + ipsec_id=None, + ipsec_spi=None, + encrypt_key=None, + salt=None, + auth_key=None, + term_dst_ip=None, + term_vlan_id=None, + term_src_ip=None, + external_sa_index=None, + ipsec_port_list=None, + ipsec_esn_enable=None, + ipsec_cipher=None, + ipsec_replay_protection_enable=None, + ipsec_replay_protection_window=None, + term_vlan_id_enable=None, + term_src_ip_enable=None, + egress_esn=None, + minimum_ingress_esn=None, + custom_attribute=None): + """ + sai_create_ipsec_sa() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of ipsec_sa CREATE attributes. + + Returns: + sai_thrift_object_id_t: ipsec_sa_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ipsec_direction is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ipsec_direction) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_DIRECTION, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ipsec_id) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_ID, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_spi is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ipsec_spi) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_SPI, + value=attribute_value) + attr_list.append(attribute) + + if encrypt_key is not None: + attribute_value = sai_thrift_attribute_value_t(encrypt_key=encrypt_key) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_ENCRYPT_KEY, + value=attribute_value) + attr_list.append(attribute) + + if salt is not None: + attribute_value = sai_thrift_attribute_value_t(u32=salt) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_SALT, + value=attribute_value) + attr_list.append(attribute) + + if auth_key is not None: + attribute_value = sai_thrift_attribute_value_t(authkey=auth_key) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_AUTH_KEY, + value=attribute_value) + attr_list.append(attribute) + + if term_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=term_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if term_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=term_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if term_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=term_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if external_sa_index is not None: + attribute_value = sai_thrift_attribute_value_t(u32=external_sa_index) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_EXTERNAL_SA_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ipsec_port_list) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_esn_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ipsec_esn_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_ESN_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_cipher is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ipsec_cipher) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_CIPHER, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_replay_protection_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ipsec_replay_protection_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_replay_protection_window is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ipsec_replay_protection_window) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_WINDOW, + value=attribute_value) + attr_list.append(attribute) + + if term_vlan_id_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=term_vlan_id_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_VLAN_ID_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if term_src_ip_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=term_src_ip_enable) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_SRC_IP_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if egress_esn is not None: + attribute_value = sai_thrift_attribute_value_t(u64=egress_esn) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_EGRESS_ESN, + value=attribute_value) + attr_list.append(attribute) + + if minimum_ingress_esn is not None: + attribute_value = sai_thrift_attribute_value_t(u64=minimum_ingress_esn) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_MINIMUM_INGRESS_ESN, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_ipsec_sa(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_ipsec_sa(client, + ipsec_sa_oid): + """ + sai_remove_ipsec_sa() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_ipsec_sa(ipsec_sa_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_ipsec_sa_attribute(client, + ipsec_sa_oid, + external_sa_index=None, + ipsec_port_list=None, + ipsec_replay_protection_enable=None, + ipsec_replay_protection_window=None, + egress_esn=None, + minimum_ingress_esn=None, + custom_attribute=None): + """ + sai_set_ipsec_sa_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + ipsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipsec_sa SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if external_sa_index is not None: + attr_value = sai_thrift_attribute_value_t(u32=external_sa_index) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_EXTERNAL_SA_INDEX, + value=attr_value) + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + if ipsec_port_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=ipsec_port_list) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_PORT_LIST, + value=attr_value) + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + if ipsec_replay_protection_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ipsec_replay_protection_enable) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_ENABLE, + value=attr_value) + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + if ipsec_replay_protection_window is not None: + attr_value = sai_thrift_attribute_value_t(u32=ipsec_replay_protection_window) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_WINDOW, + value=attr_value) + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + if egress_esn is not None: + attr_value = sai_thrift_attribute_value_t(u64=egress_esn) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_EGRESS_ESN, + value=attr_value) + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + if minimum_ingress_esn is not None: + attr_value = sai_thrift_attribute_value_t(u64=minimum_ingress_esn) + attr = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_MINIMUM_INGRESS_ESN, + value=attr_value) + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_ipsec_sa_attribute(ipsec_sa_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_ipsec_sa_attribute(client, + ipsec_sa_oid, + ipsec_direction=None, + ipsec_id=None, + octet_count_status=None, + external_sa_index=None, + sa_index=None, + ipsec_port_list=None, + ipsec_spi=None, + ipsec_esn_enable=None, + ipsec_cipher=None, + encrypt_key=None, + salt=None, + auth_key=None, + ipsec_replay_protection_enable=None, + ipsec_replay_protection_window=None, + term_dst_ip=None, + term_vlan_id_enable=None, + term_vlan_id=None, + term_src_ip_enable=None, + term_src_ip=None, + egress_esn=None, + minimum_ingress_esn=None, + custom_attribute=None): + """ + sai_get_ipsec_sa_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + ipsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of ipsec_sa GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ipsec_direction is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_DIRECTION) + attr_list.append(attribute) + + if ipsec_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_ID) + attr_list.append(attribute) + + if octet_count_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_OCTET_COUNT_STATUS) + attr_list.append(attribute) + + if external_sa_index is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_EXTERNAL_SA_INDEX) + attr_list.append(attribute) + + if sa_index is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_SA_INDEX) + attr_list.append(attribute) + + if ipsec_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ipsec_port_list) + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_spi is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_SPI) + attr_list.append(attribute) + + if ipsec_esn_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_ESN_ENABLE) + attr_list.append(attribute) + + if ipsec_cipher is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_CIPHER) + attr_list.append(attribute) + + if encrypt_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_ENCRYPT_KEY) + attr_list.append(attribute) + + if salt is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_SALT) + attr_list.append(attribute) + + if auth_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_AUTH_KEY) + attr_list.append(attribute) + + if ipsec_replay_protection_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_ENABLE) + attr_list.append(attribute) + + if ipsec_replay_protection_window is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_WINDOW) + attr_list.append(attribute) + + if term_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_DST_IP) + attr_list.append(attribute) + + if term_vlan_id_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_VLAN_ID_ENABLE) + attr_list.append(attribute) + + if term_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_VLAN_ID) + attr_list.append(attribute) + + if term_src_ip_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_SRC_IP_ENABLE) + attr_list.append(attribute) + + if term_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_TERM_SRC_IP) + attr_list.append(attribute) + + if egress_esn is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_EGRESS_ESN) + attr_list.append(attribute) + + if minimum_ingress_esn is not None: + attribute = sai_thrift_attribute_t(id=SAI_IPSEC_SA_ATTR_MINIMUM_INGRESS_ESN) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_ipsec_sa_attribute(ipsec_sa_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_DIRECTION: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_DIRECTION"] = attr.value.s32 + attrs["ipsec_direction"] = attr.value.s32 + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_ID: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_ID"] = attr.value.oid + attrs["ipsec_id"] = attr.value.oid + + if attr.id == SAI_IPSEC_SA_ATTR_OCTET_COUNT_STATUS: + attrs["SAI_IPSEC_SA_ATTR_OCTET_COUNT_STATUS"] = attr.value.s32 + attrs["octet_count_status"] = attr.value.s32 + + if attr.id == SAI_IPSEC_SA_ATTR_EXTERNAL_SA_INDEX: + attrs["SAI_IPSEC_SA_ATTR_EXTERNAL_SA_INDEX"] = attr.value.u32 + attrs["external_sa_index"] = attr.value.u32 + + if attr.id == SAI_IPSEC_SA_ATTR_SA_INDEX: + attrs["SAI_IPSEC_SA_ATTR_SA_INDEX"] = attr.value.u32 + attrs["sa_index"] = attr.value.u32 + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_PORT_LIST: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_PORT_LIST"] = attr.value.objlist + attrs["ipsec_port_list"] = attr.value.objlist + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_SPI: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_SPI"] = attr.value.u32 + attrs["ipsec_spi"] = attr.value.u32 + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_ESN_ENABLE: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_ESN_ENABLE"] = attr.value.booldata + attrs["ipsec_esn_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_CIPHER: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_CIPHER"] = attr.value.s32 + attrs["ipsec_cipher"] = attr.value.s32 + + if attr.id == SAI_IPSEC_SA_ATTR_ENCRYPT_KEY: + attrs["SAI_IPSEC_SA_ATTR_ENCRYPT_KEY"] = attr.value.encrypt_key + attrs["encrypt_key"] = attr.value.encrypt_key + + if attr.id == SAI_IPSEC_SA_ATTR_SALT: + attrs["SAI_IPSEC_SA_ATTR_SALT"] = attr.value.u32 + attrs["salt"] = attr.value.u32 + + if attr.id == SAI_IPSEC_SA_ATTR_AUTH_KEY: + attrs["SAI_IPSEC_SA_ATTR_AUTH_KEY"] = attr.value.authkey + attrs["auth_key"] = attr.value.authkey + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_ENABLE: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_ENABLE"] = attr.value.booldata + attrs["ipsec_replay_protection_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_WINDOW: + attrs["SAI_IPSEC_SA_ATTR_IPSEC_REPLAY_PROTECTION_WINDOW"] = attr.value.u32 + attrs["ipsec_replay_protection_window"] = attr.value.u32 + + if attr.id == SAI_IPSEC_SA_ATTR_TERM_DST_IP: + attrs["SAI_IPSEC_SA_ATTR_TERM_DST_IP"] = attr.value.ipaddr + attrs["term_dst_ip"] = attr.value.ipaddr + + if attr.id == SAI_IPSEC_SA_ATTR_TERM_VLAN_ID_ENABLE: + attrs["SAI_IPSEC_SA_ATTR_TERM_VLAN_ID_ENABLE"] = attr.value.booldata + attrs["term_vlan_id_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_SA_ATTR_TERM_VLAN_ID: + attrs["SAI_IPSEC_SA_ATTR_TERM_VLAN_ID"] = attr.value.u16 + attrs["term_vlan_id"] = attr.value.u16 + + if attr.id == SAI_IPSEC_SA_ATTR_TERM_SRC_IP_ENABLE: + attrs["SAI_IPSEC_SA_ATTR_TERM_SRC_IP_ENABLE"] = attr.value.booldata + attrs["term_src_ip_enable"] = attr.value.booldata + + if attr.id == SAI_IPSEC_SA_ATTR_TERM_SRC_IP: + attrs["SAI_IPSEC_SA_ATTR_TERM_SRC_IP"] = attr.value.ipaddr + attrs["term_src_ip"] = attr.value.ipaddr + + if attr.id == SAI_IPSEC_SA_ATTR_EGRESS_ESN: + attrs["SAI_IPSEC_SA_ATTR_EGRESS_ESN"] = attr.value.u64 + attrs["egress_esn"] = attr.value.u64 + + if attr.id == SAI_IPSEC_SA_ATTR_MINIMUM_INGRESS_ESN: + attrs["SAI_IPSEC_SA_ATTR_MINIMUM_INGRESS_ESN"] = attr.value.u64 + attrs["minimum_ingress_esn"] = attr.value.u64 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_ipsec_sa_stats(client, + ipsec_sa_oid): + """ + sai_get_ipsec_sa_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_IPSEC_SA_STAT_PROTECTED_OCTETS) + counter_ids.append(SAI_IPSEC_SA_STAT_PROTECTED_PKTS) + counter_ids.append(SAI_IPSEC_SA_STAT_GOOD_PKTS) + counter_ids.append(SAI_IPSEC_SA_STAT_BAD_HEADER_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_REPLAYED_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_LATE_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_BAD_TRAILER_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_AUTH_FAIL_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_DUMMY_DROPPED_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_OTHER_DROPPED_PKTS) + + counters = [0] * 10 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_ipsec_sa_stats(ipsec_sa_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_IPSEC_SA_STAT_PROTECTED_OCTETS"] = counters[0] + stats["SAI_IPSEC_SA_STAT_PROTECTED_PKTS"] = counters[1] + stats["SAI_IPSEC_SA_STAT_GOOD_PKTS"] = counters[2] + stats["SAI_IPSEC_SA_STAT_BAD_HEADER_PKTS_IN"] = counters[3] + stats["SAI_IPSEC_SA_STAT_REPLAYED_PKTS_IN"] = counters[4] + stats["SAI_IPSEC_SA_STAT_LATE_PKTS_IN"] = counters[5] + stats["SAI_IPSEC_SA_STAT_BAD_TRAILER_PKTS_IN"] = counters[6] + stats["SAI_IPSEC_SA_STAT_AUTH_FAIL_PKTS_IN"] = counters[7] + stats["SAI_IPSEC_SA_STAT_DUMMY_DROPPED_PKTS_IN"] = counters[8] + stats["SAI_IPSEC_SA_STAT_OTHER_DROPPED_PKTS"] = counters[9] + + return stats + + +def sai_thrift_get_ipsec_sa_stats_ext(client, + ipsec_sa_oid, + mode): + """ + sai_get_ipsec_sa_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_IPSEC_SA_STAT_PROTECTED_OCTETS) + counter_ids.append(SAI_IPSEC_SA_STAT_PROTECTED_PKTS) + counter_ids.append(SAI_IPSEC_SA_STAT_GOOD_PKTS) + counter_ids.append(SAI_IPSEC_SA_STAT_BAD_HEADER_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_REPLAYED_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_LATE_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_BAD_TRAILER_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_AUTH_FAIL_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_DUMMY_DROPPED_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_OTHER_DROPPED_PKTS) + + counters = [0] * 10 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_ipsec_sa_stats_ext(ipsec_sa_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_IPSEC_SA_STAT_PROTECTED_OCTETS"] = counters[0] + stats["SAI_IPSEC_SA_STAT_PROTECTED_PKTS"] = counters[1] + stats["SAI_IPSEC_SA_STAT_GOOD_PKTS"] = counters[2] + stats["SAI_IPSEC_SA_STAT_BAD_HEADER_PKTS_IN"] = counters[3] + stats["SAI_IPSEC_SA_STAT_REPLAYED_PKTS_IN"] = counters[4] + stats["SAI_IPSEC_SA_STAT_LATE_PKTS_IN"] = counters[5] + stats["SAI_IPSEC_SA_STAT_BAD_TRAILER_PKTS_IN"] = counters[6] + stats["SAI_IPSEC_SA_STAT_AUTH_FAIL_PKTS_IN"] = counters[7] + stats["SAI_IPSEC_SA_STAT_DUMMY_DROPPED_PKTS_IN"] = counters[8] + stats["SAI_IPSEC_SA_STAT_OTHER_DROPPED_PKTS"] = counters[9] + + return stats + + +def sai_thrift_clear_ipsec_sa_stats(client, + ipsec_sa_oid): + """ + sai_clear_ipsec_sa_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + ipsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_IPSEC_SA_STAT_PROTECTED_OCTETS) + counter_ids.append(SAI_IPSEC_SA_STAT_PROTECTED_PKTS) + counter_ids.append(SAI_IPSEC_SA_STAT_GOOD_PKTS) + counter_ids.append(SAI_IPSEC_SA_STAT_BAD_HEADER_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_REPLAYED_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_LATE_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_BAD_TRAILER_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_AUTH_FAIL_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_DUMMY_DROPPED_PKTS_IN) + counter_ids.append(SAI_IPSEC_SA_STAT_OTHER_DROPPED_PKTS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_ipsec_sa_stats(ipsec_sa_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# isolation_group API + +def sai_thrift_create_isolation_group(client, + type=None, + custom_attribute=None): + """ + sai_create_isolation_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of isolation_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: isolation_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_isolation_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_isolation_group(client, + isolation_group_oid): + """ + sai_remove_isolation_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + isolation_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_isolation_group(isolation_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_isolation_group_attribute(client, + isolation_group_oid, + custom_attribute=None): + """ + sai_set_isolation_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + isolation_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del isolation_group_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_isolation_group_attribute(client, + isolation_group_oid, + type=None, + isolation_member_list=None, + custom_attribute=None): + """ + sai_get_isolation_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + isolation_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of isolation_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_ATTR_TYPE) + attr_list.append(attribute) + + if isolation_member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=isolation_member_list) + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_ATTR_ISOLATION_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_isolation_group_attribute(isolation_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ISOLATION_GROUP_ATTR_TYPE: + attrs["SAI_ISOLATION_GROUP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_ISOLATION_GROUP_ATTR_ISOLATION_MEMBER_LIST: + attrs["SAI_ISOLATION_GROUP_ATTR_ISOLATION_MEMBER_LIST"] = attr.value.objlist + attrs["isolation_member_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_isolation_group_member(client, + isolation_group_id=None, + isolation_object=None, + custom_attribute=None): + """ + sai_create_isolation_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of isolation_group_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: isolation_group_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if isolation_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=isolation_group_id) + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if isolation_object is not None: + attribute_value = sai_thrift_attribute_value_t(oid=isolation_object) + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_isolation_group_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_isolation_group_member(client, + isolation_group_member_oid): + """ + sai_remove_isolation_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + isolation_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_isolation_group_member(isolation_group_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_isolation_group_member_attribute(client, + isolation_group_member_oid, + custom_attribute=None): + """ + sai_set_isolation_group_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + isolation_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del isolation_group_member_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_isolation_group_member_attribute(client, + isolation_group_member_oid, + isolation_group_id=None, + isolation_object=None, + custom_attribute=None): + """ + sai_get_isolation_group_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + isolation_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of isolation_group_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if isolation_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_GROUP_ID) + attr_list.append(attribute) + + if isolation_object is not None: + attribute = sai_thrift_attribute_t(id=SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_OBJECT) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_isolation_group_member_attribute(isolation_group_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_GROUP_ID: + attrs["SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_GROUP_ID"] = attr.value.oid + attrs["isolation_group_id"] = attr.value.oid + + if attr.id == SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_OBJECT: + attrs["SAI_ISOLATION_GROUP_MEMBER_ATTR_ISOLATION_OBJECT"] = attr.value.oid + attrs["isolation_object"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# l2mc API + +def sai_thrift_create_l2mc_entry(client, + l2mc_entry, + packet_action=None, + output_group_id=None, + custom_attribute=None): + """ + sai_create_l2mc_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + l2mc_entry(sai_thrift_l2mc_entry_t): l2mc_entry IN argument + + For the other parameters, see documentation of l2mc_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_L2MC_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if output_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=output_group_id) + attribute = sai_thrift_attribute_t(id=SAI_L2MC_ENTRY_ATTR_OUTPUT_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_l2mc_entry(l2mc_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_l2mc_entry(client, + l2mc_entry): + """ + sai_remove_l2mc_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + l2mc_entry(sai_thrift_l2mc_entry_t): l2mc_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_l2mc_entry(l2mc_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_l2mc_entry_attribute(client, + l2mc_entry, + packet_action=None, + output_group_id=None, + custom_attribute=None): + """ + sai_set_l2mc_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + l2mc_entry(sai_thrift_l2mc_entry_t): l2mc_entry IN argument + + For the other parameters, see documentation of l2mc_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_L2MC_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_l2mc_entry_attribute(l2mc_entry, attr) + + if output_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=output_group_id) + attr = sai_thrift_attribute_t(id=SAI_L2MC_ENTRY_ATTR_OUTPUT_GROUP_ID, + value=attr_value) + client.sai_thrift_set_l2mc_entry_attribute(l2mc_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_l2mc_entry_attribute(l2mc_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_l2mc_entry_attribute(client, + l2mc_entry, + packet_action=None, + output_group_id=None, + custom_attribute=None): + """ + sai_get_l2mc_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + l2mc_entry(sai_thrift_l2mc_entry_t): l2mc_entry IN argument + + For the other parameters, see documentation of l2mc_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_L2MC_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if output_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_L2MC_ENTRY_ATTR_OUTPUT_GROUP_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_l2mc_entry_attribute(l2mc_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_L2MC_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_L2MC_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_L2MC_ENTRY_ATTR_OUTPUT_GROUP_ID: + attrs["SAI_L2MC_ENTRY_ATTR_OUTPUT_GROUP_ID"] = attr.value.oid + attrs["output_group_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# l2mc_group API + +def sai_thrift_create_l2mc_group(client, + custom_attribute=None): + """ + sai_create_l2mc_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + sai_thrift_object_id_t: l2mc_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_l2mc_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_l2mc_group(client, + l2mc_group_oid): + """ + sai_remove_l2mc_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + l2mc_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_l2mc_group(l2mc_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_l2mc_group_attribute(client, + l2mc_group_oid, + custom_attribute=None): + """ + sai_set_l2mc_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + l2mc_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del l2mc_group_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_l2mc_group_attribute(client, + l2mc_group_oid, + l2mc_output_count=None, + l2mc_member_list=None, + custom_attribute=None): + """ + sai_get_l2mc_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + l2mc_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of l2mc_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if l2mc_output_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_ATTR_L2MC_OUTPUT_COUNT) + attr_list.append(attribute) + + if l2mc_member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=l2mc_member_list) + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_ATTR_L2MC_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_l2mc_group_attribute(l2mc_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_L2MC_GROUP_ATTR_L2MC_OUTPUT_COUNT: + attrs["SAI_L2MC_GROUP_ATTR_L2MC_OUTPUT_COUNT"] = attr.value.u32 + attrs["l2mc_output_count"] = attr.value.u32 + + if attr.id == SAI_L2MC_GROUP_ATTR_L2MC_MEMBER_LIST: + attrs["SAI_L2MC_GROUP_ATTR_L2MC_MEMBER_LIST"] = attr.value.objlist + attrs["l2mc_member_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_l2mc_group_member(client, + l2mc_group_id=None, + l2mc_output_id=None, + l2mc_endpoint_ip=None, + custom_attribute=None): + """ + sai_create_l2mc_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of l2mc_group_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: l2mc_group_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if l2mc_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=l2mc_group_id) + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if l2mc_output_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=l2mc_output_id) + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_OUTPUT_ID, + value=attribute_value) + attr_list.append(attribute) + + if l2mc_endpoint_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=l2mc_endpoint_ip) + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_ENDPOINT_IP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_l2mc_group_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_l2mc_group_member(client, + l2mc_group_member_oid): + """ + sai_remove_l2mc_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + l2mc_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_l2mc_group_member(l2mc_group_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_l2mc_group_member_attribute(client, + l2mc_group_member_oid, + custom_attribute=None): + """ + sai_set_l2mc_group_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + l2mc_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del l2mc_group_member_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_l2mc_group_member_attribute(client, + l2mc_group_member_oid, + l2mc_group_id=None, + l2mc_output_id=None, + l2mc_endpoint_ip=None, + custom_attribute=None): + """ + sai_get_l2mc_group_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + l2mc_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of l2mc_group_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if l2mc_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_GROUP_ID) + attr_list.append(attribute) + + if l2mc_output_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_OUTPUT_ID) + attr_list.append(attribute) + + if l2mc_endpoint_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_ENDPOINT_IP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_l2mc_group_member_attribute(l2mc_group_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_GROUP_ID: + attrs["SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_GROUP_ID"] = attr.value.oid + attrs["l2mc_group_id"] = attr.value.oid + + if attr.id == SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_OUTPUT_ID: + attrs["SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_OUTPUT_ID"] = attr.value.oid + attrs["l2mc_output_id"] = attr.value.oid + + if attr.id == SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_ENDPOINT_IP: + attrs["SAI_L2MC_GROUP_MEMBER_ATTR_L2MC_ENDPOINT_IP"] = attr.value.ipaddr + attrs["l2mc_endpoint_ip"] = attr.value.ipaddr + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# lag API + +def sai_thrift_create_lag(client, + ingress_acl=None, + egress_acl=None, + port_vlan_id=None, + default_vlan_priority=None, + drop_untagged=None, + drop_tagged=None, + tpid=None, + system_port_aggregate_id=None, + label=None, + custom_attribute=None): + """ + sai_create_lag() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of lag CREATE attributes. + + Returns: + sai_thrift_object_id_t: lag_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if ingress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_INGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if egress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_acl) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_EGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if port_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=port_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_PORT_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if default_vlan_priority is not None: + attribute_value = sai_thrift_attribute_value_t(u8=default_vlan_priority) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if drop_untagged is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=drop_untagged) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DROP_UNTAGGED, + value=attribute_value) + attr_list.append(attribute) + + if drop_tagged is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=drop_tagged) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DROP_TAGGED, + value=attribute_value) + attr_list.append(attribute) + + if tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=tpid) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_TPID, + value=attribute_value) + attr_list.append(attribute) + + if system_port_aggregate_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=system_port_aggregate_id) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID, + value=attribute_value) + attr_list.append(attribute) + + if label is not None: + attribute_value = sai_thrift_attribute_value_t(chardata=label) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_lag(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_lag(client, + lag_oid): + """ + sai_remove_lag() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + lag_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_lag(lag_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_lag_attribute(client, + lag_oid, + ingress_acl=None, + egress_acl=None, + port_vlan_id=None, + default_vlan_priority=None, + drop_untagged=None, + drop_tagged=None, + tpid=None, + label=None, + custom_attribute=None): + """ + sai_set_lag_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + lag_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of lag SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if ingress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_INGRESS_ACL, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if egress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_acl) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_EGRESS_ACL, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if port_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(u16=port_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_PORT_VLAN_ID, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if default_vlan_priority is not None: + attr_value = sai_thrift_attribute_value_t(u8=default_vlan_priority) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if drop_untagged is not None: + attr_value = sai_thrift_attribute_value_t(booldata=drop_untagged) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DROP_UNTAGGED, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if drop_tagged is not None: + attr_value = sai_thrift_attribute_value_t(booldata=drop_tagged) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DROP_TAGGED, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=tpid) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_TPID, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if label is not None: + attr_value = sai_thrift_attribute_value_t(chardata=label) + attr = sai_thrift_attribute_t(id=SAI_LAG_ATTR_LABEL, + value=attr_value) + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_lag_attribute(lag_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_lag_attribute(client, + lag_oid, + port_list=None, + ingress_acl=None, + egress_acl=None, + port_vlan_id=None, + default_vlan_priority=None, + drop_untagged=None, + drop_tagged=None, + tpid=None, + system_port_aggregate_id=None, + label=None, + custom_attribute=None): + """ + sai_get_lag_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + lag_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of lag GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=port_list) + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_INGRESS_ACL) + attr_list.append(attribute) + + if egress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_EGRESS_ACL) + attr_list.append(attribute) + + if port_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_PORT_VLAN_ID) + attr_list.append(attribute) + + if default_vlan_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY) + attr_list.append(attribute) + + if drop_untagged is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DROP_UNTAGGED) + attr_list.append(attribute) + + if drop_tagged is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_DROP_TAGGED) + attr_list.append(attribute) + + if tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_TPID) + attr_list.append(attribute) + + if system_port_aggregate_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID) + attr_list.append(attribute) + + if label is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_ATTR_LABEL) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_lag_attribute(lag_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_LAG_ATTR_PORT_LIST: + attrs["SAI_LAG_ATTR_PORT_LIST"] = attr.value.objlist + attrs["port_list"] = attr.value.objlist + + if attr.id == SAI_LAG_ATTR_INGRESS_ACL: + attrs["SAI_LAG_ATTR_INGRESS_ACL"] = attr.value.oid + attrs["ingress_acl"] = attr.value.oid + + if attr.id == SAI_LAG_ATTR_EGRESS_ACL: + attrs["SAI_LAG_ATTR_EGRESS_ACL"] = attr.value.oid + attrs["egress_acl"] = attr.value.oid + + if attr.id == SAI_LAG_ATTR_PORT_VLAN_ID: + attrs["SAI_LAG_ATTR_PORT_VLAN_ID"] = attr.value.u16 + attrs["port_vlan_id"] = attr.value.u16 + + if attr.id == SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY: + attrs["SAI_LAG_ATTR_DEFAULT_VLAN_PRIORITY"] = attr.value.u8 + attrs["default_vlan_priority"] = attr.value.u8 + + if attr.id == SAI_LAG_ATTR_DROP_UNTAGGED: + attrs["SAI_LAG_ATTR_DROP_UNTAGGED"] = attr.value.booldata + attrs["drop_untagged"] = attr.value.booldata + + if attr.id == SAI_LAG_ATTR_DROP_TAGGED: + attrs["SAI_LAG_ATTR_DROP_TAGGED"] = attr.value.booldata + attrs["drop_tagged"] = attr.value.booldata + + if attr.id == SAI_LAG_ATTR_TPID: + attrs["SAI_LAG_ATTR_TPID"] = attr.value.u16 + attrs["tpid"] = attr.value.u16 + + if attr.id == SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID: + attrs["SAI_LAG_ATTR_SYSTEM_PORT_AGGREGATE_ID"] = attr.value.u32 + attrs["system_port_aggregate_id"] = attr.value.u32 + + if attr.id == SAI_LAG_ATTR_LABEL: + attrs["SAI_LAG_ATTR_LABEL"] = attr.value.chardata + attrs["label"] = attr.value.chardata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_lag_member(client, + lag_id=None, + port_id=None, + egress_disable=None, + ingress_disable=None, + custom_attribute=None): + """ + sai_create_lag_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of lag_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: lag_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if lag_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=lag_id) + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_LAG_ID, + value=attribute_value) + attr_list.append(attribute) + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if egress_disable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=egress_disable) + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE, + value=attribute_value) + attr_list.append(attribute) + + if ingress_disable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ingress_disable) + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_lag_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_lag_member(client, + lag_member_oid): + """ + sai_remove_lag_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + lag_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_lag_member(lag_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_lag_member_attribute(client, + lag_member_oid, + egress_disable=None, + ingress_disable=None, + custom_attribute=None): + """ + sai_set_lag_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + lag_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of lag_member SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if egress_disable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=egress_disable) + attr = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE, + value=attr_value) + client.sai_thrift_set_lag_member_attribute(lag_member_oid, attr) + + if ingress_disable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ingress_disable) + attr = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE, + value=attr_value) + client.sai_thrift_set_lag_member_attribute(lag_member_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_lag_member_attribute(lag_member_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_lag_member_attribute(client, + lag_member_oid, + lag_id=None, + port_id=None, + egress_disable=None, + ingress_disable=None, + custom_attribute=None): + """ + sai_get_lag_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + lag_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of lag_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if lag_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_LAG_ID) + attr_list.append(attribute) + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_PORT_ID) + attr_list.append(attribute) + + if egress_disable is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE) + attr_list.append(attribute) + + if ingress_disable is not None: + attribute = sai_thrift_attribute_t(id=SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_lag_member_attribute(lag_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_LAG_MEMBER_ATTR_LAG_ID: + attrs["SAI_LAG_MEMBER_ATTR_LAG_ID"] = attr.value.oid + attrs["lag_id"] = attr.value.oid + + if attr.id == SAI_LAG_MEMBER_ATTR_PORT_ID: + attrs["SAI_LAG_MEMBER_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE: + attrs["SAI_LAG_MEMBER_ATTR_EGRESS_DISABLE"] = attr.value.booldata + attrs["egress_disable"] = attr.value.booldata + + if attr.id == SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE: + attrs["SAI_LAG_MEMBER_ATTR_INGRESS_DISABLE"] = attr.value.booldata + attrs["ingress_disable"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# macsec API + +def sai_thrift_create_macsec(client, + direction=None, + warm_boot_enable=None, + ctag_tpid=None, + stag_tpid=None, + max_vlan_tags_parsed=None, + stats_mode=None, + physical_bypass_enable=None, + custom_attribute=None): + """ + sai_create_macsec() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of macsec CREATE attributes. + + Returns: + sai_thrift_object_id_t: macsec_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if direction is not None: + attribute_value = sai_thrift_attribute_value_t(s32=direction) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_DIRECTION, + value=attribute_value) + attr_list.append(attribute) + + if warm_boot_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=warm_boot_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_WARM_BOOT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if ctag_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=ctag_tpid) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_CTAG_TPID, + value=attribute_value) + attr_list.append(attribute) + + if stag_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=stag_tpid) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STAG_TPID, + value=attribute_value) + attr_list.append(attribute) + + if max_vlan_tags_parsed is not None: + attribute_value = sai_thrift_attribute_value_t(u8=max_vlan_tags_parsed) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_MAX_VLAN_TAGS_PARSED, + value=attribute_value) + attr_list.append(attribute) + + if stats_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=stats_mode) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STATS_MODE, + value=attribute_value) + attr_list.append(attribute) + + if physical_bypass_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=physical_bypass_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_PHYSICAL_BYPASS_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_macsec(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_macsec(client, + macsec_oid): + """ + sai_remove_macsec() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_macsec(macsec_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_macsec_attribute(client, + macsec_oid, + warm_boot_enable=None, + ctag_tpid=None, + stag_tpid=None, + max_vlan_tags_parsed=None, + stats_mode=None, + physical_bypass_enable=None, + custom_attribute=None): + """ + sai_set_macsec_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + macsec_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if warm_boot_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=warm_boot_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_WARM_BOOT_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + if ctag_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=ctag_tpid) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_CTAG_TPID, + value=attr_value) + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + if stag_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=stag_tpid) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STAG_TPID, + value=attr_value) + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + if max_vlan_tags_parsed is not None: + attr_value = sai_thrift_attribute_value_t(u8=max_vlan_tags_parsed) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_MAX_VLAN_TAGS_PARSED, + value=attr_value) + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + if stats_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=stats_mode) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STATS_MODE, + value=attr_value) + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + if physical_bypass_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=physical_bypass_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_PHYSICAL_BYPASS_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_macsec_attribute(macsec_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_macsec_attribute(client, + macsec_oid, + direction=None, + switching_mode_cut_through_supported=None, + switching_mode_store_and_forward_supported=None, + stats_mode_read_supported=None, + stats_mode_read_clear_supported=None, + sci_in_ingress_macsec_acl=None, + supported_cipher_suite_list=None, + pn_32bit_supported=None, + xpn_64bit_supported=None, + gcm_aes128_supported=None, + gcm_aes256_supported=None, + sectag_offsets_supported=None, + system_side_mtu=None, + warm_boot_supported=None, + warm_boot_enable=None, + ctag_tpid=None, + stag_tpid=None, + max_vlan_tags_parsed=None, + stats_mode=None, + physical_bypass_enable=None, + supported_port_list=None, + available_macsec_flow=None, + flow_list=None, + available_macsec_sc=None, + available_macsec_sa=None, + max_secure_associations_per_sc=None, + custom_attribute=None): + """ + sai_get_macsec_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + macsec_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if direction is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_DIRECTION) + attr_list.append(attribute) + + if switching_mode_cut_through_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SWITCHING_MODE_CUT_THROUGH_SUPPORTED) + attr_list.append(attribute) + + if switching_mode_store_and_forward_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SWITCHING_MODE_STORE_AND_FORWARD_SUPPORTED) + attr_list.append(attribute) + + if stats_mode_read_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STATS_MODE_READ_SUPPORTED) + attr_list.append(attribute) + + if stats_mode_read_clear_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STATS_MODE_READ_CLEAR_SUPPORTED) + attr_list.append(attribute) + + if sci_in_ingress_macsec_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SCI_IN_INGRESS_MACSEC_ACL) + attr_list.append(attribute) + + if supported_cipher_suite_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_cipher_suite_list) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SUPPORTED_CIPHER_SUITE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if pn_32bit_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_PN_32BIT_SUPPORTED) + attr_list.append(attribute) + + if xpn_64bit_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_XPN_64BIT_SUPPORTED) + attr_list.append(attribute) + + if gcm_aes128_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_GCM_AES128_SUPPORTED) + attr_list.append(attribute) + + if gcm_aes256_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_GCM_AES256_SUPPORTED) + attr_list.append(attribute) + + if sectag_offsets_supported is not None: + attribute_value = sai_thrift_attribute_value_t(u8list=sectag_offsets_supported) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SECTAG_OFFSETS_SUPPORTED, + value=attribute_value) + attr_list.append(attribute) + + if system_side_mtu is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SYSTEM_SIDE_MTU) + attr_list.append(attribute) + + if warm_boot_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_WARM_BOOT_SUPPORTED) + attr_list.append(attribute) + + if warm_boot_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_WARM_BOOT_ENABLE) + attr_list.append(attribute) + + if ctag_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_CTAG_TPID) + attr_list.append(attribute) + + if stag_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STAG_TPID) + attr_list.append(attribute) + + if max_vlan_tags_parsed is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_MAX_VLAN_TAGS_PARSED) + attr_list.append(attribute) + + if stats_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_STATS_MODE) + attr_list.append(attribute) + + if physical_bypass_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_PHYSICAL_BYPASS_ENABLE) + attr_list.append(attribute) + + if supported_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=supported_port_list) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_SUPPORTED_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if available_macsec_flow is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_AVAILABLE_MACSEC_FLOW) + attr_list.append(attribute) + + if flow_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=flow_list) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_FLOW_LIST, + value=attribute_value) + attr_list.append(attribute) + + if available_macsec_sc is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_AVAILABLE_MACSEC_SC) + attr_list.append(attribute) + + if available_macsec_sa is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_AVAILABLE_MACSEC_SA) + attr_list.append(attribute) + + if max_secure_associations_per_sc is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_ATTR_MAX_SECURE_ASSOCIATIONS_PER_SC) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_macsec_attribute(macsec_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MACSEC_ATTR_DIRECTION: + attrs["SAI_MACSEC_ATTR_DIRECTION"] = attr.value.s32 + attrs["direction"] = attr.value.s32 + + if attr.id == SAI_MACSEC_ATTR_SWITCHING_MODE_CUT_THROUGH_SUPPORTED: + attrs["SAI_MACSEC_ATTR_SWITCHING_MODE_CUT_THROUGH_SUPPORTED"] = attr.value.booldata + attrs["switching_mode_cut_through_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_SWITCHING_MODE_STORE_AND_FORWARD_SUPPORTED: + attrs["SAI_MACSEC_ATTR_SWITCHING_MODE_STORE_AND_FORWARD_SUPPORTED"] = attr.value.booldata + attrs["switching_mode_store_and_forward_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_STATS_MODE_READ_SUPPORTED: + attrs["SAI_MACSEC_ATTR_STATS_MODE_READ_SUPPORTED"] = attr.value.booldata + attrs["stats_mode_read_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_STATS_MODE_READ_CLEAR_SUPPORTED: + attrs["SAI_MACSEC_ATTR_STATS_MODE_READ_CLEAR_SUPPORTED"] = attr.value.booldata + attrs["stats_mode_read_clear_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_SCI_IN_INGRESS_MACSEC_ACL: + attrs["SAI_MACSEC_ATTR_SCI_IN_INGRESS_MACSEC_ACL"] = attr.value.booldata + attrs["sci_in_ingress_macsec_acl"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_SUPPORTED_CIPHER_SUITE_LIST: + attrs["SAI_MACSEC_ATTR_SUPPORTED_CIPHER_SUITE_LIST"] = attr.value.s32list + attrs["supported_cipher_suite_list"] = attr.value.s32list + + if attr.id == SAI_MACSEC_ATTR_PN_32BIT_SUPPORTED: + attrs["SAI_MACSEC_ATTR_PN_32BIT_SUPPORTED"] = attr.value.booldata + attrs["pn_32bit_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_XPN_64BIT_SUPPORTED: + attrs["SAI_MACSEC_ATTR_XPN_64BIT_SUPPORTED"] = attr.value.booldata + attrs["xpn_64bit_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_GCM_AES128_SUPPORTED: + attrs["SAI_MACSEC_ATTR_GCM_AES128_SUPPORTED"] = attr.value.booldata + attrs["gcm_aes128_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_GCM_AES256_SUPPORTED: + attrs["SAI_MACSEC_ATTR_GCM_AES256_SUPPORTED"] = attr.value.booldata + attrs["gcm_aes256_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_SECTAG_OFFSETS_SUPPORTED: + attrs["SAI_MACSEC_ATTR_SECTAG_OFFSETS_SUPPORTED"] = attr.value.u8list + attrs["sectag_offsets_supported"] = attr.value.u8list + + if attr.id == SAI_MACSEC_ATTR_SYSTEM_SIDE_MTU: + attrs["SAI_MACSEC_ATTR_SYSTEM_SIDE_MTU"] = attr.value.u16 + attrs["system_side_mtu"] = attr.value.u16 + + if attr.id == SAI_MACSEC_ATTR_WARM_BOOT_SUPPORTED: + attrs["SAI_MACSEC_ATTR_WARM_BOOT_SUPPORTED"] = attr.value.booldata + attrs["warm_boot_supported"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_WARM_BOOT_ENABLE: + attrs["SAI_MACSEC_ATTR_WARM_BOOT_ENABLE"] = attr.value.booldata + attrs["warm_boot_enable"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_CTAG_TPID: + attrs["SAI_MACSEC_ATTR_CTAG_TPID"] = attr.value.u16 + attrs["ctag_tpid"] = attr.value.u16 + + if attr.id == SAI_MACSEC_ATTR_STAG_TPID: + attrs["SAI_MACSEC_ATTR_STAG_TPID"] = attr.value.u16 + attrs["stag_tpid"] = attr.value.u16 + + if attr.id == SAI_MACSEC_ATTR_MAX_VLAN_TAGS_PARSED: + attrs["SAI_MACSEC_ATTR_MAX_VLAN_TAGS_PARSED"] = attr.value.u8 + attrs["max_vlan_tags_parsed"] = attr.value.u8 + + if attr.id == SAI_MACSEC_ATTR_STATS_MODE: + attrs["SAI_MACSEC_ATTR_STATS_MODE"] = attr.value.s32 + attrs["stats_mode"] = attr.value.s32 + + if attr.id == SAI_MACSEC_ATTR_PHYSICAL_BYPASS_ENABLE: + attrs["SAI_MACSEC_ATTR_PHYSICAL_BYPASS_ENABLE"] = attr.value.booldata + attrs["physical_bypass_enable"] = attr.value.booldata + + if attr.id == SAI_MACSEC_ATTR_SUPPORTED_PORT_LIST: + attrs["SAI_MACSEC_ATTR_SUPPORTED_PORT_LIST"] = attr.value.objlist + attrs["supported_port_list"] = attr.value.objlist + + if attr.id == SAI_MACSEC_ATTR_AVAILABLE_MACSEC_FLOW: + attrs["SAI_MACSEC_ATTR_AVAILABLE_MACSEC_FLOW"] = attr.value.u32 + attrs["available_macsec_flow"] = attr.value.u32 + + if attr.id == SAI_MACSEC_ATTR_FLOW_LIST: + attrs["SAI_MACSEC_ATTR_FLOW_LIST"] = attr.value.objlist + attrs["flow_list"] = attr.value.objlist + + if attr.id == SAI_MACSEC_ATTR_AVAILABLE_MACSEC_SC: + attrs["SAI_MACSEC_ATTR_AVAILABLE_MACSEC_SC"] = attr.value.u32 + attrs["available_macsec_sc"] = attr.value.u32 + + if attr.id == SAI_MACSEC_ATTR_AVAILABLE_MACSEC_SA: + attrs["SAI_MACSEC_ATTR_AVAILABLE_MACSEC_SA"] = attr.value.u32 + attrs["available_macsec_sa"] = attr.value.u32 + + if attr.id == SAI_MACSEC_ATTR_MAX_SECURE_ASSOCIATIONS_PER_SC: + attrs["SAI_MACSEC_ATTR_MAX_SECURE_ASSOCIATIONS_PER_SC"] = attr.value.s32 + attrs["max_secure_associations_per_sc"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_macsec_port(client, + macsec_direction=None, + port_id=None, + ctag_enable=None, + stag_enable=None, + switch_switching_mode=None, + custom_attribute=None): + """ + sai_create_macsec_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of macsec_port CREATE attributes. + + Returns: + sai_thrift_object_id_t: macsec_port_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute_value = sai_thrift_attribute_value_t(s32=macsec_direction) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_MACSEC_DIRECTION, + value=attribute_value) + attr_list.append(attribute) + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if ctag_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ctag_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_CTAG_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if stag_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=stag_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_STAG_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if switch_switching_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=switch_switching_mode) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_SWITCH_SWITCHING_MODE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_macsec_port(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_macsec_port(client, + macsec_port_oid): + """ + sai_remove_macsec_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_macsec_port(macsec_port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_macsec_port_attribute(client, + macsec_port_oid, + ctag_enable=None, + stag_enable=None, + switch_switching_mode=None, + custom_attribute=None): + """ + sai_set_macsec_port_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + macsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_port SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if ctag_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ctag_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_CTAG_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_port_attribute(macsec_port_oid, attr) + + if stag_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=stag_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_STAG_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_port_attribute(macsec_port_oid, attr) + + if switch_switching_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=switch_switching_mode) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_SWITCH_SWITCHING_MODE, + value=attr_value) + client.sai_thrift_set_macsec_port_attribute(macsec_port_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_macsec_port_attribute(macsec_port_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_macsec_port_attribute(client, + macsec_port_oid, + macsec_direction=None, + port_id=None, + ctag_enable=None, + stag_enable=None, + switch_switching_mode=None, + custom_attribute=None): + """ + sai_get_macsec_port_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + macsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_port GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_MACSEC_DIRECTION) + attr_list.append(attribute) + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_PORT_ID) + attr_list.append(attribute) + + if ctag_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_CTAG_ENABLE) + attr_list.append(attribute) + + if stag_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_STAG_ENABLE) + attr_list.append(attribute) + + if switch_switching_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_PORT_ATTR_SWITCH_SWITCHING_MODE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_macsec_port_attribute(macsec_port_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MACSEC_PORT_ATTR_MACSEC_DIRECTION: + attrs["SAI_MACSEC_PORT_ATTR_MACSEC_DIRECTION"] = attr.value.s32 + attrs["macsec_direction"] = attr.value.s32 + + if attr.id == SAI_MACSEC_PORT_ATTR_PORT_ID: + attrs["SAI_MACSEC_PORT_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_MACSEC_PORT_ATTR_CTAG_ENABLE: + attrs["SAI_MACSEC_PORT_ATTR_CTAG_ENABLE"] = attr.value.booldata + attrs["ctag_enable"] = attr.value.booldata + + if attr.id == SAI_MACSEC_PORT_ATTR_STAG_ENABLE: + attrs["SAI_MACSEC_PORT_ATTR_STAG_ENABLE"] = attr.value.booldata + attrs["stag_enable"] = attr.value.booldata + + if attr.id == SAI_MACSEC_PORT_ATTR_SWITCH_SWITCHING_MODE: + attrs["SAI_MACSEC_PORT_ATTR_SWITCH_SWITCHING_MODE"] = attr.value.s32 + attrs["switch_switching_mode"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_macsec_port_stats(client, + macsec_port_oid): + """ + sai_get_macsec_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_PORT_STAT_PRE_MACSEC_DROP_PKTS) + counter_ids.append(SAI_MACSEC_PORT_STAT_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_PORT_STAT_DATA_PKTS) + + counters = [0] * 3 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_port_stats(macsec_port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_PORT_STAT_PRE_MACSEC_DROP_PKTS"] = counters[0] + stats["SAI_MACSEC_PORT_STAT_CONTROL_PKTS"] = counters[1] + stats["SAI_MACSEC_PORT_STAT_DATA_PKTS"] = counters[2] + + return stats + + +def sai_thrift_get_macsec_port_stats_ext(client, + macsec_port_oid, + mode): + """ + sai_get_macsec_port_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_port_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_PORT_STAT_PRE_MACSEC_DROP_PKTS) + counter_ids.append(SAI_MACSEC_PORT_STAT_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_PORT_STAT_DATA_PKTS) + + counters = [0] * 3 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_port_stats_ext(macsec_port_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_PORT_STAT_PRE_MACSEC_DROP_PKTS"] = counters[0] + stats["SAI_MACSEC_PORT_STAT_CONTROL_PKTS"] = counters[1] + stats["SAI_MACSEC_PORT_STAT_DATA_PKTS"] = counters[2] + + return stats + + +def sai_thrift_clear_macsec_port_stats(client, + macsec_port_oid): + """ + sai_clear_macsec_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_PORT_STAT_PRE_MACSEC_DROP_PKTS) + counter_ids.append(SAI_MACSEC_PORT_STAT_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_PORT_STAT_DATA_PKTS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_macsec_port_stats(macsec_port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_macsec_flow(client, + macsec_direction=None, + custom_attribute=None): + """ + sai_create_macsec_flow() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of macsec_flow CREATE attributes. + + Returns: + sai_thrift_object_id_t: macsec_flow_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute_value = sai_thrift_attribute_value_t(s32=macsec_direction) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_FLOW_ATTR_MACSEC_DIRECTION, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_macsec_flow(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_macsec_flow(client, + macsec_flow_oid): + """ + sai_remove_macsec_flow() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_flow_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_macsec_flow(macsec_flow_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_macsec_flow_attribute(client, + macsec_flow_oid, + custom_attribute=None): + """ + sai_set_macsec_flow_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + macsec_flow_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del macsec_flow_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_macsec_flow_attribute(client, + macsec_flow_oid, + macsec_direction=None, + acl_entry_list=None, + sc_list=None, + custom_attribute=None): + """ + sai_get_macsec_flow_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + macsec_flow_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_flow GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_FLOW_ATTR_MACSEC_DIRECTION) + attr_list.append(attribute) + + if acl_entry_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=acl_entry_list) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_FLOW_ATTR_ACL_ENTRY_LIST, + value=attribute_value) + attr_list.append(attribute) + + if sc_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=sc_list) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_FLOW_ATTR_SC_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_macsec_flow_attribute(macsec_flow_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MACSEC_FLOW_ATTR_MACSEC_DIRECTION: + attrs["SAI_MACSEC_FLOW_ATTR_MACSEC_DIRECTION"] = attr.value.s32 + attrs["macsec_direction"] = attr.value.s32 + + if attr.id == SAI_MACSEC_FLOW_ATTR_ACL_ENTRY_LIST: + attrs["SAI_MACSEC_FLOW_ATTR_ACL_ENTRY_LIST"] = attr.value.objlist + attrs["acl_entry_list"] = attr.value.objlist + + if attr.id == SAI_MACSEC_FLOW_ATTR_SC_LIST: + attrs["SAI_MACSEC_FLOW_ATTR_SC_LIST"] = attr.value.objlist + attrs["sc_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_macsec_flow_stats(client, + macsec_flow_oid): + """ + sai_get_macsec_flow_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_flow_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_FLOW_STAT_OTHER_ERR) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OUT_OCTETS_COMMON) + counter_ids.append(SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_TAGGED_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OUT_PKTS_TOO_LONG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_TAG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_BAD_TAG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_SCI) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_UNKNOWN_SCI) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_OVERRUN) + + counters = [0] * 19 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_flow_stats(macsec_flow_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_FLOW_STAT_OTHER_ERR"] = counters[0] + stats["SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED"] = counters[1] + stats["SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED"] = counters[2] + stats["SAI_MACSEC_FLOW_STAT_OUT_OCTETS_COMMON"] = counters[3] + stats["SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED"] = counters[4] + stats["SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED"] = counters[5] + stats["SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED"] = counters[6] + stats["SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED"] = counters[7] + stats["SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED"] = counters[8] + stats["SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED"] = counters[9] + stats["SAI_MACSEC_FLOW_STAT_CONTROL_PKTS"] = counters[10] + stats["SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED"] = counters[11] + stats["SAI_MACSEC_FLOW_STAT_IN_TAGGED_CONTROL_PKTS"] = counters[12] + stats["SAI_MACSEC_FLOW_STAT_OUT_PKTS_TOO_LONG"] = counters[13] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_TAG"] = counters[14] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_BAD_TAG"] = counters[15] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_SCI"] = counters[16] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_UNKNOWN_SCI"] = counters[17] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_OVERRUN"] = counters[18] + + return stats + + +def sai_thrift_get_macsec_flow_stats_ext(client, + macsec_flow_oid, + mode): + """ + sai_get_macsec_flow_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_flow_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_FLOW_STAT_OTHER_ERR) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OUT_OCTETS_COMMON) + counter_ids.append(SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_TAGGED_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OUT_PKTS_TOO_LONG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_TAG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_BAD_TAG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_SCI) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_UNKNOWN_SCI) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_OVERRUN) + + counters = [0] * 19 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_flow_stats_ext(macsec_flow_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_FLOW_STAT_OTHER_ERR"] = counters[0] + stats["SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED"] = counters[1] + stats["SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED"] = counters[2] + stats["SAI_MACSEC_FLOW_STAT_OUT_OCTETS_COMMON"] = counters[3] + stats["SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED"] = counters[4] + stats["SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED"] = counters[5] + stats["SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED"] = counters[6] + stats["SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED"] = counters[7] + stats["SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED"] = counters[8] + stats["SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED"] = counters[9] + stats["SAI_MACSEC_FLOW_STAT_CONTROL_PKTS"] = counters[10] + stats["SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED"] = counters[11] + stats["SAI_MACSEC_FLOW_STAT_IN_TAGGED_CONTROL_PKTS"] = counters[12] + stats["SAI_MACSEC_FLOW_STAT_OUT_PKTS_TOO_LONG"] = counters[13] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_TAG"] = counters[14] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_BAD_TAG"] = counters[15] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_SCI"] = counters[16] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_UNKNOWN_SCI"] = counters[17] + stats["SAI_MACSEC_FLOW_STAT_IN_PKTS_OVERRUN"] = counters[18] + + return stats + + +def sai_thrift_clear_macsec_flow_stats(client, + macsec_flow_oid): + """ + sai_clear_macsec_flow_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_flow_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_FLOW_STAT_OTHER_ERR) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OCTETS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OCTETS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OUT_OCTETS_COMMON) + counter_ids.append(SAI_MACSEC_FLOW_STAT_UCAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_UCAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_MULTICAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_UNCONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_BROADCAST_PKTS_CONTROLLED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_TAGGED_CONTROL_PKTS) + counter_ids.append(SAI_MACSEC_FLOW_STAT_OUT_PKTS_TOO_LONG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_TAG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_BAD_TAG) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_NO_SCI) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_UNKNOWN_SCI) + counter_ids.append(SAI_MACSEC_FLOW_STAT_IN_PKTS_OVERRUN) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_macsec_flow_stats(macsec_flow_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_macsec_sc(client, + macsec_direction=None, + flow_id=None, + macsec_sci=None, + macsec_cipher_suite=None, + macsec_explicit_sci_enable=None, + macsec_sectag_offset=None, + macsec_replay_protection_enable=None, + macsec_replay_protection_window=None, + encryption_enable=None, + custom_attribute=None): + """ + sai_create_macsec_sc() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of macsec_sc CREATE attributes. + + Returns: + sai_thrift_object_id_t: macsec_sc_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute_value = sai_thrift_attribute_value_t(s32=macsec_direction) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_DIRECTION, + value=attribute_value) + attr_list.append(attribute) + + if flow_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=flow_id) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_FLOW_ID, + value=attribute_value) + attr_list.append(attribute) + + if macsec_sci is not None: + attribute_value = sai_thrift_attribute_value_t(u64=macsec_sci) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_SCI, + value=attribute_value) + attr_list.append(attribute) + + if macsec_cipher_suite is not None: + attribute_value = sai_thrift_attribute_value_t(s32=macsec_cipher_suite) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_CIPHER_SUITE, + value=attribute_value) + attr_list.append(attribute) + + if macsec_explicit_sci_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=macsec_explicit_sci_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_EXPLICIT_SCI_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if macsec_sectag_offset is not None: + attribute_value = sai_thrift_attribute_value_t(u8=macsec_sectag_offset) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_SECTAG_OFFSET, + value=attribute_value) + attr_list.append(attribute) + + if macsec_replay_protection_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=macsec_replay_protection_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if macsec_replay_protection_window is not None: + attribute_value = sai_thrift_attribute_value_t(u32=macsec_replay_protection_window) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_WINDOW, + value=attribute_value) + attr_list.append(attribute) + + if encryption_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=encryption_enable) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_ENCRYPTION_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_macsec_sc(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_macsec_sc(client, + macsec_sc_oid): + """ + sai_remove_macsec_sc() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sc_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_macsec_sc(macsec_sc_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_macsec_sc_attribute(client, + macsec_sc_oid, + macsec_explicit_sci_enable=None, + macsec_sectag_offset=None, + macsec_replay_protection_enable=None, + macsec_replay_protection_window=None, + macsec_cipher_suite=None, + encryption_enable=None, + custom_attribute=None): + """ + sai_set_macsec_sc_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + macsec_sc_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_sc SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if macsec_explicit_sci_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=macsec_explicit_sci_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_EXPLICIT_SCI_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + if macsec_sectag_offset is not None: + attr_value = sai_thrift_attribute_value_t(u8=macsec_sectag_offset) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_SECTAG_OFFSET, + value=attr_value) + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + if macsec_replay_protection_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=macsec_replay_protection_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + if macsec_replay_protection_window is not None: + attr_value = sai_thrift_attribute_value_t(u32=macsec_replay_protection_window) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_WINDOW, + value=attr_value) + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + if macsec_cipher_suite is not None: + attr_value = sai_thrift_attribute_value_t(s32=macsec_cipher_suite) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_CIPHER_SUITE, + value=attr_value) + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + if encryption_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=encryption_enable) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_ENCRYPTION_ENABLE, + value=attr_value) + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_macsec_sc_attribute(macsec_sc_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_macsec_sc_attribute(client, + macsec_sc_oid, + macsec_direction=None, + flow_id=None, + macsec_sci=None, + macsec_explicit_sci_enable=None, + macsec_sectag_offset=None, + active_egress_sa_id=None, + macsec_replay_protection_enable=None, + macsec_replay_protection_window=None, + sa_list=None, + macsec_cipher_suite=None, + encryption_enable=None, + custom_attribute=None): + """ + sai_get_macsec_sc_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + macsec_sc_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_sc GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_DIRECTION) + attr_list.append(attribute) + + if flow_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_FLOW_ID) + attr_list.append(attribute) + + if macsec_sci is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_SCI) + attr_list.append(attribute) + + if macsec_explicit_sci_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_EXPLICIT_SCI_ENABLE) + attr_list.append(attribute) + + if macsec_sectag_offset is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_SECTAG_OFFSET) + attr_list.append(attribute) + + if active_egress_sa_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_ACTIVE_EGRESS_SA_ID) + attr_list.append(attribute) + + if macsec_replay_protection_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_ENABLE) + attr_list.append(attribute) + + if macsec_replay_protection_window is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_WINDOW) + attr_list.append(attribute) + + if sa_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=sa_list) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_SA_LIST, + value=attribute_value) + attr_list.append(attribute) + + if macsec_cipher_suite is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_MACSEC_CIPHER_SUITE) + attr_list.append(attribute) + + if encryption_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SC_ATTR_ENCRYPTION_ENABLE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_macsec_sc_attribute(macsec_sc_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_DIRECTION: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_DIRECTION"] = attr.value.s32 + attrs["macsec_direction"] = attr.value.s32 + + if attr.id == SAI_MACSEC_SC_ATTR_FLOW_ID: + attrs["SAI_MACSEC_SC_ATTR_FLOW_ID"] = attr.value.oid + attrs["flow_id"] = attr.value.oid + + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_SCI: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_SCI"] = attr.value.u64 + attrs["macsec_sci"] = attr.value.u64 + + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_EXPLICIT_SCI_ENABLE: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_EXPLICIT_SCI_ENABLE"] = attr.value.booldata + attrs["macsec_explicit_sci_enable"] = attr.value.booldata + + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_SECTAG_OFFSET: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_SECTAG_OFFSET"] = attr.value.u8 + attrs["macsec_sectag_offset"] = attr.value.u8 + + if attr.id == SAI_MACSEC_SC_ATTR_ACTIVE_EGRESS_SA_ID: + attrs["SAI_MACSEC_SC_ATTR_ACTIVE_EGRESS_SA_ID"] = attr.value.oid + attrs["active_egress_sa_id"] = attr.value.oid + + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_ENABLE: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_ENABLE"] = attr.value.booldata + attrs["macsec_replay_protection_enable"] = attr.value.booldata + + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_WINDOW: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_REPLAY_PROTECTION_WINDOW"] = attr.value.u32 + attrs["macsec_replay_protection_window"] = attr.value.u32 + + if attr.id == SAI_MACSEC_SC_ATTR_SA_LIST: + attrs["SAI_MACSEC_SC_ATTR_SA_LIST"] = attr.value.objlist + attrs["sa_list"] = attr.value.objlist + + if attr.id == SAI_MACSEC_SC_ATTR_MACSEC_CIPHER_SUITE: + attrs["SAI_MACSEC_SC_ATTR_MACSEC_CIPHER_SUITE"] = attr.value.s32 + attrs["macsec_cipher_suite"] = attr.value.s32 + + if attr.id == SAI_MACSEC_SC_ATTR_ENCRYPTION_ENABLE: + attrs["SAI_MACSEC_SC_ATTR_ENCRYPTION_ENABLE"] = attr.value.booldata + attrs["encryption_enable"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_macsec_sc_stats(client, + macsec_sc_oid): + """ + sai_get_macsec_sc_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sc_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_SC_STAT_SA_NOT_IN_USE) + + counters = [0] * 2 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_sc_stats(macsec_sc_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_SC_STAT_SA_NOT_IN_USE"] = counters[0] + + return stats + + +def sai_thrift_get_macsec_sc_stats_ext(client, + macsec_sc_oid, + mode): + """ + sai_get_macsec_sc_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sc_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_SC_STAT_SA_NOT_IN_USE) + + counters = [0] * 2 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_sc_stats_ext(macsec_sc_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_SC_STAT_SA_NOT_IN_USE"] = counters[0] + + return stats + + +def sai_thrift_clear_macsec_sc_stats(client, + macsec_sc_oid): + """ + sai_clear_macsec_sc_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sc_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_SC_STAT_SA_NOT_IN_USE) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_macsec_sc_stats(macsec_sc_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_macsec_sa(client, + macsec_direction=None, + sc_id=None, + an=None, + sak=None, + salt=None, + auth_key=None, + macsec_ssci=None, + configured_egress_xpn=None, + minimum_ingress_xpn=None, + custom_attribute=None): + """ + sai_create_macsec_sa() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of macsec_sa CREATE attributes. + + Returns: + sai_thrift_object_id_t: macsec_sa_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute_value = sai_thrift_attribute_value_t(s32=macsec_direction) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MACSEC_DIRECTION, + value=attribute_value) + attr_list.append(attribute) + + if sc_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=sc_id) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_SC_ID, + value=attribute_value) + attr_list.append(attribute) + + if an is not None: + attribute_value = sai_thrift_attribute_value_t(u8=an) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_AN, + value=attribute_value) + attr_list.append(attribute) + + if sak is not None: + attribute_value = sai_thrift_attribute_value_t(macsecsak=sak) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_SAK, + value=attribute_value) + attr_list.append(attribute) + + if salt is not None: + attribute_value = sai_thrift_attribute_value_t(macsecsalt=salt) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_SALT, + value=attribute_value) + attr_list.append(attribute) + + if auth_key is not None: + attribute_value = sai_thrift_attribute_value_t(macsecauthkey=auth_key) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_AUTH_KEY, + value=attribute_value) + attr_list.append(attribute) + + if macsec_ssci is not None: + attribute_value = sai_thrift_attribute_value_t(u32=macsec_ssci) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MACSEC_SSCI, + value=attribute_value) + attr_list.append(attribute) + + if configured_egress_xpn is not None: + attribute_value = sai_thrift_attribute_value_t(u64=configured_egress_xpn) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN, + value=attribute_value) + attr_list.append(attribute) + + if minimum_ingress_xpn is not None: + attribute_value = sai_thrift_attribute_value_t(u64=minimum_ingress_xpn) + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MINIMUM_INGRESS_XPN, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_macsec_sa(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_macsec_sa(client, + macsec_sa_oid): + """ + sai_remove_macsec_sa() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_macsec_sa(macsec_sa_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_macsec_sa_attribute(client, + macsec_sa_oid, + configured_egress_xpn=None, + minimum_ingress_xpn=None, + custom_attribute=None): + """ + sai_set_macsec_sa_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + macsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_sa SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if configured_egress_xpn is not None: + attr_value = sai_thrift_attribute_value_t(u64=configured_egress_xpn) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN, + value=attr_value) + client.sai_thrift_set_macsec_sa_attribute(macsec_sa_oid, attr) + + if minimum_ingress_xpn is not None: + attr_value = sai_thrift_attribute_value_t(u64=minimum_ingress_xpn) + attr = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MINIMUM_INGRESS_XPN, + value=attr_value) + client.sai_thrift_set_macsec_sa_attribute(macsec_sa_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_macsec_sa_attribute(macsec_sa_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_macsec_sa_attribute(client, + macsec_sa_oid, + macsec_direction=None, + sc_id=None, + an=None, + sak=None, + salt=None, + auth_key=None, + configured_egress_xpn=None, + current_xpn=None, + minimum_ingress_xpn=None, + macsec_ssci=None, + custom_attribute=None): + """ + sai_get_macsec_sa_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + macsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of macsec_sa GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if macsec_direction is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MACSEC_DIRECTION) + attr_list.append(attribute) + + if sc_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_SC_ID) + attr_list.append(attribute) + + if an is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_AN) + attr_list.append(attribute) + + if sak is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_SAK) + attr_list.append(attribute) + + if salt is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_SALT) + attr_list.append(attribute) + + if auth_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_AUTH_KEY) + attr_list.append(attribute) + + if configured_egress_xpn is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN) + attr_list.append(attribute) + + if current_xpn is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_CURRENT_XPN) + attr_list.append(attribute) + + if minimum_ingress_xpn is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MINIMUM_INGRESS_XPN) + attr_list.append(attribute) + + if macsec_ssci is not None: + attribute = sai_thrift_attribute_t(id=SAI_MACSEC_SA_ATTR_MACSEC_SSCI) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_macsec_sa_attribute(macsec_sa_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MACSEC_SA_ATTR_MACSEC_DIRECTION: + attrs["SAI_MACSEC_SA_ATTR_MACSEC_DIRECTION"] = attr.value.s32 + attrs["macsec_direction"] = attr.value.s32 + + if attr.id == SAI_MACSEC_SA_ATTR_SC_ID: + attrs["SAI_MACSEC_SA_ATTR_SC_ID"] = attr.value.oid + attrs["sc_id"] = attr.value.oid + + if attr.id == SAI_MACSEC_SA_ATTR_AN: + attrs["SAI_MACSEC_SA_ATTR_AN"] = attr.value.u8 + attrs["an"] = attr.value.u8 + + if attr.id == SAI_MACSEC_SA_ATTR_SAK: + attrs["SAI_MACSEC_SA_ATTR_SAK"] = attr.value.macsecsak + attrs["sak"] = attr.value.macsecsak + + if attr.id == SAI_MACSEC_SA_ATTR_SALT: + attrs["SAI_MACSEC_SA_ATTR_SALT"] = attr.value.macsecsalt + attrs["salt"] = attr.value.macsecsalt + + if attr.id == SAI_MACSEC_SA_ATTR_AUTH_KEY: + attrs["SAI_MACSEC_SA_ATTR_AUTH_KEY"] = attr.value.macsecauthkey + attrs["auth_key"] = attr.value.macsecauthkey + + if attr.id == SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN: + attrs["SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN"] = attr.value.u64 + attrs["configured_egress_xpn"] = attr.value.u64 + + if attr.id == SAI_MACSEC_SA_ATTR_CURRENT_XPN: + attrs["SAI_MACSEC_SA_ATTR_CURRENT_XPN"] = attr.value.u64 + attrs["current_xpn"] = attr.value.u64 + + if attr.id == SAI_MACSEC_SA_ATTR_MINIMUM_INGRESS_XPN: + attrs["SAI_MACSEC_SA_ATTR_MINIMUM_INGRESS_XPN"] = attr.value.u64 + attrs["minimum_ingress_xpn"] = attr.value.u64 + + if attr.id == SAI_MACSEC_SA_ATTR_MACSEC_SSCI: + attrs["SAI_MACSEC_SA_ATTR_MACSEC_SSCI"] = attr.value.u32 + attrs["macsec_ssci"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_macsec_sa_stats(client, + macsec_sa_oid): + """ + sai_get_macsec_sa_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OCTETS_PROTECTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OUT_PKTS_ENCRYPTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OUT_PKTS_PROTECTED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_UNCHECKED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_DELAYED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_LATE) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_INVALID) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_NOT_VALID) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_NOT_USING_SA) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_UNUSED_SA) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_OK) + + counters = [0] * 12 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_sa_stats(macsec_sa_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED"] = counters[0] + stats["SAI_MACSEC_SA_STAT_OCTETS_PROTECTED"] = counters[1] + stats["SAI_MACSEC_SA_STAT_OUT_PKTS_ENCRYPTED"] = counters[2] + stats["SAI_MACSEC_SA_STAT_OUT_PKTS_PROTECTED"] = counters[3] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_UNCHECKED"] = counters[4] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_DELAYED"] = counters[5] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_LATE"] = counters[6] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_INVALID"] = counters[7] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_NOT_VALID"] = counters[8] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_NOT_USING_SA"] = counters[9] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_UNUSED_SA"] = counters[10] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_OK"] = counters[11] + + return stats + + +def sai_thrift_get_macsec_sa_stats_ext(client, + macsec_sa_oid, + mode): + """ + sai_get_macsec_sa_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OCTETS_PROTECTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OUT_PKTS_ENCRYPTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OUT_PKTS_PROTECTED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_UNCHECKED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_DELAYED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_LATE) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_INVALID) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_NOT_VALID) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_NOT_USING_SA) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_UNUSED_SA) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_OK) + + counters = [0] * 12 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_macsec_sa_stats_ext(macsec_sa_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED"] = counters[0] + stats["SAI_MACSEC_SA_STAT_OCTETS_PROTECTED"] = counters[1] + stats["SAI_MACSEC_SA_STAT_OUT_PKTS_ENCRYPTED"] = counters[2] + stats["SAI_MACSEC_SA_STAT_OUT_PKTS_PROTECTED"] = counters[3] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_UNCHECKED"] = counters[4] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_DELAYED"] = counters[5] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_LATE"] = counters[6] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_INVALID"] = counters[7] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_NOT_VALID"] = counters[8] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_NOT_USING_SA"] = counters[9] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_UNUSED_SA"] = counters[10] + stats["SAI_MACSEC_SA_STAT_IN_PKTS_OK"] = counters[11] + + return stats + + +def sai_thrift_clear_macsec_sa_stats(client, + macsec_sa_oid): + """ + sai_clear_macsec_sa_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + macsec_sa_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OCTETS_PROTECTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OUT_PKTS_ENCRYPTED) + counter_ids.append(SAI_MACSEC_SA_STAT_OUT_PKTS_PROTECTED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_UNCHECKED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_DELAYED) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_LATE) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_INVALID) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_NOT_VALID) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_NOT_USING_SA) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_UNUSED_SA) + counter_ids.append(SAI_MACSEC_SA_STAT_IN_PKTS_OK) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_macsec_sa_stats(macsec_sa_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# mcast_fdb API + +def sai_thrift_create_mcast_fdb_entry(client, + mcast_fdb_entry, + group_id=None, + packet_action=None, + meta_data=None, + custom_attribute=None): + """ + sai_create_mcast_fdb_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + mcast_fdb_entry(sai_thrift_mcast_fdb_entry_t): mcast_fdb_entry IN argument + + For the other parameters, see documentation of mcast_fdb_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=group_id) + attribute = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(u32=meta_data) + attribute = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_mcast_fdb_entry(mcast_fdb_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_mcast_fdb_entry(client, + mcast_fdb_entry): + """ + sai_remove_mcast_fdb_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + mcast_fdb_entry(sai_thrift_mcast_fdb_entry_t): mcast_fdb_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_mcast_fdb_entry(mcast_fdb_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_mcast_fdb_entry_attribute(client, + mcast_fdb_entry, + group_id=None, + packet_action=None, + meta_data=None, + custom_attribute=None): + """ + sai_set_mcast_fdb_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + mcast_fdb_entry(sai_thrift_mcast_fdb_entry_t): mcast_fdb_entry IN argument + + For the other parameters, see documentation of mcast_fdb_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=group_id) + attr = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_GROUP_ID, + value=attr_value) + client.sai_thrift_set_mcast_fdb_entry_attribute(mcast_fdb_entry, attr) + + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_mcast_fdb_entry_attribute(mcast_fdb_entry, attr) + + if meta_data is not None: + attr_value = sai_thrift_attribute_value_t(u32=meta_data) + attr = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_META_DATA, + value=attr_value) + client.sai_thrift_set_mcast_fdb_entry_attribute(mcast_fdb_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_mcast_fdb_entry_attribute(mcast_fdb_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_mcast_fdb_entry_attribute(client, + mcast_fdb_entry, + group_id=None, + packet_action=None, + meta_data=None, + custom_attribute=None): + """ + sai_get_mcast_fdb_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + mcast_fdb_entry(sai_thrift_mcast_fdb_entry_t): mcast_fdb_entry IN argument + + For the other parameters, see documentation of mcast_fdb_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_GROUP_ID) + attr_list.append(attribute) + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_MCAST_FDB_ENTRY_ATTR_META_DATA) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_mcast_fdb_entry_attribute(mcast_fdb_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MCAST_FDB_ENTRY_ATTR_GROUP_ID: + attrs["SAI_MCAST_FDB_ENTRY_ATTR_GROUP_ID"] = attr.value.oid + attrs["group_id"] = attr.value.oid + + if attr.id == SAI_MCAST_FDB_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_MCAST_FDB_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_MCAST_FDB_ENTRY_ATTR_META_DATA: + attrs["SAI_MCAST_FDB_ENTRY_ATTR_META_DATA"] = attr.value.u32 + attrs["meta_data"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# mirror API + +def sai_thrift_create_mirror_session(client, + type=None, + monitor_port=None, + erspan_encapsulation_type=None, + iphdr_version=None, + tos=None, + src_ip_address=None, + dst_ip_address=None, + src_mac_address=None, + dst_mac_address=None, + gre_protocol_type=None, + monitor_portlist=None, + udp_src_port=None, + udp_dst_port=None, + truncate_size=None, + sample_rate=None, + congestion_mode=None, + tc=None, + vlan_tpid=None, + vlan_id=None, + vlan_pri=None, + vlan_cfi=None, + vlan_header_valid=None, + ttl=None, + monitor_portlist_valid=None, + policer=None, + counter_id=None, + custom_attribute=None): + """ + sai_create_mirror_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of mirror_session CREATE attributes. + + Returns: + sai_thrift_object_id_t: mirror_session_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if monitor_port is not None: + attribute_value = sai_thrift_attribute_value_t(oid=monitor_port) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORT, + value=attribute_value) + attr_list.append(attribute) + + if erspan_encapsulation_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=erspan_encapsulation_type) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if iphdr_version is not None: + attribute_value = sai_thrift_attribute_value_t(u8=iphdr_version) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION, + value=attribute_value) + attr_list.append(attribute) + + if tos is not None: + attribute_value = sai_thrift_attribute_value_t(u8=tos) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TOS, + value=attribute_value) + attr_list.append(attribute) + + if src_ip_address is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=src_ip_address) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip_address is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=dst_ip_address) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if dst_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=dst_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if gre_protocol_type is not None: + attribute_value = sai_thrift_attribute_value_t(u16=gre_protocol_type) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if monitor_portlist is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=monitor_portlist) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST, + value=attribute_value) + attr_list.append(attribute) + + if udp_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(u16=udp_src_port) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_UDP_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if udp_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(u16=udp_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_UDP_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if truncate_size is not None: + attribute_value = sai_thrift_attribute_value_t(u16=truncate_size) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TRUNCATE_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if sample_rate is not None: + attribute_value = sai_thrift_attribute_value_t(u32=sample_rate) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SAMPLE_RATE, + value=attribute_value) + attr_list.append(attribute) + + if congestion_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=congestion_mode) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_CONGESTION_MODE, + value=attribute_value) + attr_list.append(attribute) + + if tc is not None: + attribute_value = sai_thrift_attribute_value_t(u8=tc) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TC, + value=attribute_value) + attr_list.append(attribute) + + if vlan_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_tpid) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_TPID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_pri is not None: + attribute_value = sai_thrift_attribute_value_t(u8=vlan_pri) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_PRI, + value=attribute_value) + attr_list.append(attribute) + + if vlan_cfi is not None: + attribute_value = sai_thrift_attribute_value_t(u8=vlan_cfi) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_CFI, + value=attribute_value) + attr_list.append(attribute) + + if vlan_header_valid is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=vlan_header_valid) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID, + value=attribute_value) + attr_list.append(attribute) + + if ttl is not None: + attribute_value = sai_thrift_attribute_value_t(u8=ttl) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TTL, + value=attribute_value) + attr_list.append(attribute) + + if monitor_portlist_valid is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=monitor_portlist_valid) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST_VALID, + value=attribute_value) + attr_list.append(attribute) + + if policer is not None: + attribute_value = sai_thrift_attribute_value_t(oid=policer) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_POLICER, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_mirror_session(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_mirror_session(client, + mirror_session_oid): + """ + sai_remove_mirror_session() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + mirror_session_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_mirror_session(mirror_session_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_mirror_session_attribute(client, + mirror_session_oid, + monitor_port=None, + truncate_size=None, + sample_rate=None, + congestion_mode=None, + tc=None, + vlan_tpid=None, + vlan_id=None, + vlan_pri=None, + vlan_cfi=None, + vlan_header_valid=None, + iphdr_version=None, + tos=None, + ttl=None, + src_ip_address=None, + dst_ip_address=None, + src_mac_address=None, + dst_mac_address=None, + gre_protocol_type=None, + monitor_portlist=None, + policer=None, + udp_src_port=None, + udp_dst_port=None, + counter_id=None, + custom_attribute=None): + """ + sai_set_mirror_session_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + mirror_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of mirror_session SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if monitor_port is not None: + attr_value = sai_thrift_attribute_value_t(oid=monitor_port) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORT, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if truncate_size is not None: + attr_value = sai_thrift_attribute_value_t(u16=truncate_size) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TRUNCATE_SIZE, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if sample_rate is not None: + attr_value = sai_thrift_attribute_value_t(u32=sample_rate) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SAMPLE_RATE, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if congestion_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=congestion_mode) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_CONGESTION_MODE, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if tc is not None: + attr_value = sai_thrift_attribute_value_t(u8=tc) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TC, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if vlan_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=vlan_tpid) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_TPID, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(u16=vlan_id) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_ID, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if vlan_pri is not None: + attr_value = sai_thrift_attribute_value_t(u8=vlan_pri) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_PRI, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if vlan_cfi is not None: + attr_value = sai_thrift_attribute_value_t(u8=vlan_cfi) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_CFI, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if vlan_header_valid is not None: + attr_value = sai_thrift_attribute_value_t(booldata=vlan_header_valid) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if iphdr_version is not None: + attr_value = sai_thrift_attribute_value_t(u8=iphdr_version) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if tos is not None: + attr_value = sai_thrift_attribute_value_t(u8=tos) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TOS, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if ttl is not None: + attr_value = sai_thrift_attribute_value_t(u8=ttl) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TTL, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if src_ip_address is not None: + attr_value = sai_thrift_attribute_value_t(ipaddr=src_ip_address) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if dst_ip_address is not None: + attr_value = sai_thrift_attribute_value_t(ipaddr=dst_ip_address) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if src_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if dst_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=dst_mac_address) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if gre_protocol_type is not None: + attr_value = sai_thrift_attribute_value_t(u16=gre_protocol_type) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if monitor_portlist is not None: + attr_value = sai_thrift_attribute_value_t(objlist=monitor_portlist) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if policer is not None: + attr_value = sai_thrift_attribute_value_t(oid=policer) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_POLICER, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if udp_src_port is not None: + attr_value = sai_thrift_attribute_value_t(u16=udp_src_port) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_UDP_SRC_PORT, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if udp_dst_port is not None: + attr_value = sai_thrift_attribute_value_t(u16=udp_dst_port) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_UDP_DST_PORT, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_mirror_session_attribute(mirror_session_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_mirror_session_attribute(client, + mirror_session_oid, + type=None, + monitor_port=None, + truncate_size=None, + sample_rate=None, + congestion_mode=None, + tc=None, + vlan_tpid=None, + vlan_id=None, + vlan_pri=None, + vlan_cfi=None, + vlan_header_valid=None, + erspan_encapsulation_type=None, + iphdr_version=None, + tos=None, + ttl=None, + src_ip_address=None, + dst_ip_address=None, + src_mac_address=None, + dst_mac_address=None, + gre_protocol_type=None, + monitor_portlist_valid=None, + monitor_portlist=None, + policer=None, + udp_src_port=None, + udp_dst_port=None, + counter_id=None, + custom_attribute=None): + """ + sai_get_mirror_session_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + mirror_session_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of mirror_session GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TYPE) + attr_list.append(attribute) + + if monitor_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORT) + attr_list.append(attribute) + + if truncate_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TRUNCATE_SIZE) + attr_list.append(attribute) + + if sample_rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SAMPLE_RATE) + attr_list.append(attribute) + + if congestion_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_CONGESTION_MODE) + attr_list.append(attribute) + + if tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TC) + attr_list.append(attribute) + + if vlan_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_TPID) + attr_list.append(attribute) + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_ID) + attr_list.append(attribute) + + if vlan_pri is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_PRI) + attr_list.append(attribute) + + if vlan_cfi is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_CFI) + attr_list.append(attribute) + + if vlan_header_valid is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID) + attr_list.append(attribute) + + if erspan_encapsulation_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE) + attr_list.append(attribute) + + if iphdr_version is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION) + attr_list.append(attribute) + + if tos is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TOS) + attr_list.append(attribute) + + if ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_TTL) + attr_list.append(attribute) + + if src_ip_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS) + attr_list.append(attribute) + + if dst_ip_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS) + attr_list.append(attribute) + + if dst_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS) + attr_list.append(attribute) + + if gre_protocol_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE) + attr_list.append(attribute) + + if monitor_portlist_valid is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST_VALID) + attr_list.append(attribute) + + if monitor_portlist is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=monitor_portlist) + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST, + value=attribute_value) + attr_list.append(attribute) + + if policer is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_POLICER) + attr_list.append(attribute) + + if udp_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_UDP_SRC_PORT) + attr_list.append(attribute) + + if udp_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_UDP_DST_PORT) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MIRROR_SESSION_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_mirror_session_attribute(mirror_session_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MIRROR_SESSION_ATTR_TYPE: + attrs["SAI_MIRROR_SESSION_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_MIRROR_SESSION_ATTR_MONITOR_PORT: + attrs["SAI_MIRROR_SESSION_ATTR_MONITOR_PORT"] = attr.value.oid + attrs["monitor_port"] = attr.value.oid + + if attr.id == SAI_MIRROR_SESSION_ATTR_TRUNCATE_SIZE: + attrs["SAI_MIRROR_SESSION_ATTR_TRUNCATE_SIZE"] = attr.value.u16 + attrs["truncate_size"] = attr.value.u16 + + if attr.id == SAI_MIRROR_SESSION_ATTR_SAMPLE_RATE: + attrs["SAI_MIRROR_SESSION_ATTR_SAMPLE_RATE"] = attr.value.u32 + attrs["sample_rate"] = attr.value.u32 + + if attr.id == SAI_MIRROR_SESSION_ATTR_CONGESTION_MODE: + attrs["SAI_MIRROR_SESSION_ATTR_CONGESTION_MODE"] = attr.value.s32 + attrs["congestion_mode"] = attr.value.s32 + + if attr.id == SAI_MIRROR_SESSION_ATTR_TC: + attrs["SAI_MIRROR_SESSION_ATTR_TC"] = attr.value.u8 + attrs["tc"] = attr.value.u8 + + if attr.id == SAI_MIRROR_SESSION_ATTR_VLAN_TPID: + attrs["SAI_MIRROR_SESSION_ATTR_VLAN_TPID"] = attr.value.u16 + attrs["vlan_tpid"] = attr.value.u16 + + if attr.id == SAI_MIRROR_SESSION_ATTR_VLAN_ID: + attrs["SAI_MIRROR_SESSION_ATTR_VLAN_ID"] = attr.value.u16 + attrs["vlan_id"] = attr.value.u16 + + if attr.id == SAI_MIRROR_SESSION_ATTR_VLAN_PRI: + attrs["SAI_MIRROR_SESSION_ATTR_VLAN_PRI"] = attr.value.u8 + attrs["vlan_pri"] = attr.value.u8 + + if attr.id == SAI_MIRROR_SESSION_ATTR_VLAN_CFI: + attrs["SAI_MIRROR_SESSION_ATTR_VLAN_CFI"] = attr.value.u8 + attrs["vlan_cfi"] = attr.value.u8 + + if attr.id == SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID: + attrs["SAI_MIRROR_SESSION_ATTR_VLAN_HEADER_VALID"] = attr.value.booldata + attrs["vlan_header_valid"] = attr.value.booldata + + if attr.id == SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE: + attrs["SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE"] = attr.value.s32 + attrs["erspan_encapsulation_type"] = attr.value.s32 + + if attr.id == SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION: + attrs["SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION"] = attr.value.u8 + attrs["iphdr_version"] = attr.value.u8 + + if attr.id == SAI_MIRROR_SESSION_ATTR_TOS: + attrs["SAI_MIRROR_SESSION_ATTR_TOS"] = attr.value.u8 + attrs["tos"] = attr.value.u8 + + if attr.id == SAI_MIRROR_SESSION_ATTR_TTL: + attrs["SAI_MIRROR_SESSION_ATTR_TTL"] = attr.value.u8 + attrs["ttl"] = attr.value.u8 + + if attr.id == SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS: + attrs["SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS"] = attr.value.ipaddr + attrs["src_ip_address"] = attr.value.ipaddr + + if attr.id == SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS: + attrs["SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS"] = attr.value.ipaddr + attrs["dst_ip_address"] = attr.value.ipaddr + + if attr.id == SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS: + attrs["SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS"] = attr.value.mac + attrs["src_mac_address"] = attr.value.mac + + if attr.id == SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS: + attrs["SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS"] = attr.value.mac + attrs["dst_mac_address"] = attr.value.mac + + if attr.id == SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE: + attrs["SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE"] = attr.value.u16 + attrs["gre_protocol_type"] = attr.value.u16 + + if attr.id == SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST_VALID: + attrs["SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST_VALID"] = attr.value.booldata + attrs["monitor_portlist_valid"] = attr.value.booldata + + if attr.id == SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST: + attrs["SAI_MIRROR_SESSION_ATTR_MONITOR_PORTLIST"] = attr.value.objlist + attrs["monitor_portlist"] = attr.value.objlist + + if attr.id == SAI_MIRROR_SESSION_ATTR_POLICER: + attrs["SAI_MIRROR_SESSION_ATTR_POLICER"] = attr.value.oid + attrs["policer"] = attr.value.oid + + if attr.id == SAI_MIRROR_SESSION_ATTR_UDP_SRC_PORT: + attrs["SAI_MIRROR_SESSION_ATTR_UDP_SRC_PORT"] = attr.value.u16 + attrs["udp_src_port"] = attr.value.u16 + + if attr.id == SAI_MIRROR_SESSION_ATTR_UDP_DST_PORT: + attrs["SAI_MIRROR_SESSION_ATTR_UDP_DST_PORT"] = attr.value.u16 + attrs["udp_dst_port"] = attr.value.u16 + + if attr.id == SAI_MIRROR_SESSION_ATTR_COUNTER_ID: + attrs["SAI_MIRROR_SESSION_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# mpls API + +def sai_thrift_create_inseg_entry(client, + inseg_entry, + num_of_pop=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + psc_type=None, + qos_tc=None, + mpls_exp_to_tc_map=None, + mpls_exp_to_color_map=None, + pop_ttl_mode=None, + pop_qos_mode=None, + counter_id=None, + custom_attribute=None): + """ + sai_create_inseg_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + inseg_entry(sai_thrift_inseg_entry_t): inseg_entry IN argument + + For the other parameters, see documentation of inseg_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if num_of_pop is not None: + attribute_value = sai_thrift_attribute_value_t(u8=num_of_pop) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_NUM_OF_POP, + value=attribute_value) + attr_list.append(attribute) + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if trap_priority is not None: + attribute_value = sai_thrift_attribute_value_t(u8=trap_priority) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_TRAP_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_NEXT_HOP_ID, + value=attribute_value) + attr_list.append(attribute) + + if psc_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=psc_type) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_PSC_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc is not None: + attribute_value = sai_thrift_attribute_value_t(u8=qos_tc) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_QOS_TC, + value=attribute_value) + attr_list.append(attribute) + + if mpls_exp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=mpls_exp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if mpls_exp_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=mpls_exp_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if pop_ttl_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=pop_ttl_mode) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_POP_TTL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if pop_qos_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=pop_qos_mode) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_POP_QOS_MODE, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_inseg_entry(inseg_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_inseg_entry(client, + inseg_entry): + """ + sai_remove_inseg_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + inseg_entry(sai_thrift_inseg_entry_t): inseg_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_inseg_entry(inseg_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_inseg_entry_attribute(client, + inseg_entry, + num_of_pop=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + psc_type=None, + qos_tc=None, + mpls_exp_to_tc_map=None, + mpls_exp_to_color_map=None, + pop_ttl_mode=None, + pop_qos_mode=None, + counter_id=None, + custom_attribute=None): + """ + sai_set_inseg_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + inseg_entry(sai_thrift_inseg_entry_t): inseg_entry IN argument + + For the other parameters, see documentation of inseg_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if num_of_pop is not None: + attr_value = sai_thrift_attribute_value_t(u8=num_of_pop) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_NUM_OF_POP, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if trap_priority is not None: + attr_value = sai_thrift_attribute_value_t(u8=trap_priority) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_TRAP_PRIORITY, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if next_hop_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_NEXT_HOP_ID, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if psc_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=psc_type) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_PSC_TYPE, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if qos_tc is not None: + attr_value = sai_thrift_attribute_value_t(u8=qos_tc) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_QOS_TC, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if mpls_exp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=mpls_exp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if mpls_exp_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=mpls_exp_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if pop_ttl_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=pop_ttl_mode) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_POP_TTL_MODE, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if pop_qos_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=pop_qos_mode) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_POP_QOS_MODE, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_inseg_entry_attribute(inseg_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_inseg_entry_attribute(client, + inseg_entry, + num_of_pop=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + psc_type=None, + qos_tc=None, + mpls_exp_to_tc_map=None, + mpls_exp_to_color_map=None, + pop_ttl_mode=None, + pop_qos_mode=None, + counter_id=None, + custom_attribute=None): + """ + sai_get_inseg_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + inseg_entry(sai_thrift_inseg_entry_t): inseg_entry IN argument + + For the other parameters, see documentation of inseg_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if num_of_pop is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_NUM_OF_POP) + attr_list.append(attribute) + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if trap_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_TRAP_PRIORITY) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_NEXT_HOP_ID) + attr_list.append(attribute) + + if psc_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_PSC_TYPE) + attr_list.append(attribute) + + if qos_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_QOS_TC) + attr_list.append(attribute) + + if mpls_exp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_TC_MAP) + attr_list.append(attribute) + + if mpls_exp_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_COLOR_MAP) + attr_list.append(attribute) + + if pop_ttl_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_POP_TTL_MODE) + attr_list.append(attribute) + + if pop_qos_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_POP_QOS_MODE) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_INSEG_ENTRY_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_inseg_entry_attribute(inseg_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_INSEG_ENTRY_ATTR_NUM_OF_POP: + attrs["SAI_INSEG_ENTRY_ATTR_NUM_OF_POP"] = attr.value.u8 + attrs["num_of_pop"] = attr.value.u8 + + if attr.id == SAI_INSEG_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_INSEG_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_INSEG_ENTRY_ATTR_TRAP_PRIORITY: + attrs["SAI_INSEG_ENTRY_ATTR_TRAP_PRIORITY"] = attr.value.u8 + attrs["trap_priority"] = attr.value.u8 + + if attr.id == SAI_INSEG_ENTRY_ATTR_NEXT_HOP_ID: + attrs["SAI_INSEG_ENTRY_ATTR_NEXT_HOP_ID"] = attr.value.oid + attrs["next_hop_id"] = attr.value.oid + + if attr.id == SAI_INSEG_ENTRY_ATTR_PSC_TYPE: + attrs["SAI_INSEG_ENTRY_ATTR_PSC_TYPE"] = attr.value.s32 + attrs["psc_type"] = attr.value.s32 + + if attr.id == SAI_INSEG_ENTRY_ATTR_QOS_TC: + attrs["SAI_INSEG_ENTRY_ATTR_QOS_TC"] = attr.value.u8 + attrs["qos_tc"] = attr.value.u8 + + if attr.id == SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_TC_MAP: + attrs["SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_TC_MAP"] = attr.value.oid + attrs["mpls_exp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_COLOR_MAP: + attrs["SAI_INSEG_ENTRY_ATTR_MPLS_EXP_TO_COLOR_MAP"] = attr.value.oid + attrs["mpls_exp_to_color_map"] = attr.value.oid + + if attr.id == SAI_INSEG_ENTRY_ATTR_POP_TTL_MODE: + attrs["SAI_INSEG_ENTRY_ATTR_POP_TTL_MODE"] = attr.value.s32 + attrs["pop_ttl_mode"] = attr.value.s32 + + if attr.id == SAI_INSEG_ENTRY_ATTR_POP_QOS_MODE: + attrs["SAI_INSEG_ENTRY_ATTR_POP_QOS_MODE"] = attr.value.s32 + attrs["pop_qos_mode"] = attr.value.s32 + + if attr.id == SAI_INSEG_ENTRY_ATTR_COUNTER_ID: + attrs["SAI_INSEG_ENTRY_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_bulk_create_inseg_entry(client, + inseg_entry, + attr_count, + mode, + num_of_pop=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + psc_type=None, + qos_tc=None, + mpls_exp_to_tc_map=None, + mpls_exp_to_color_map=None, + pop_ttl_mode=None, + pop_qos_mode=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_create_inseg_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + inseg_entry(List[sai_thrift_inseg_entry_t]): inseg_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of inseg_entry CREATE attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del inseg_entry + del attr_count + del mode + + # No function call - delete all attributes + del num_of_pop + del packet_action + del trap_priority + del next_hop_id + del psc_type + del qos_tc + del mpls_exp_to_tc_map + del mpls_exp_to_color_map + del pop_ttl_mode + del pop_qos_mode + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_remove_inseg_entry(client, + inseg_entry, + mode): + """ + sai_bulk_remove_inseg_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + inseg_entry(List[sai_thrift_inseg_entry_t]): inseg_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del inseg_entry + del mode + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_set_inseg_entry_attribute(client, + inseg_entry, + mode, + num_of_pop=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + psc_type=None, + qos_tc=None, + mpls_exp_to_tc_map=None, + mpls_exp_to_color_map=None, + pop_ttl_mode=None, + pop_qos_mode=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_set_inseg_entry_attribute() - UNSUPPORTED + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + inseg_entry(List[sai_thrift_inseg_entry_t]): inseg_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of inseg_entry SET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del inseg_entry + del mode + + # No function call - delete all attributes + del num_of_pop + del packet_action + del trap_priority + del next_hop_id + del psc_type + del qos_tc + del mpls_exp_to_tc_map + del mpls_exp_to_color_map + del pop_ttl_mode + del pop_qos_mode + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_get_inseg_entry_attribute(client, + inseg_entry, + attr_count, + mode, + object_statuses, + num_of_pop=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + psc_type=None, + qos_tc=None, + mpls_exp_to_tc_map=None, + mpls_exp_to_color_map=None, + pop_ttl_mode=None, + pop_qos_mode=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_get_inseg_entry_attribute() - UNSUPPORTED + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + inseg_entry(List[sai_thrift_inseg_entry_t]): inseg_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + object_statuses(List[sai_thrift_status_t]): status_list OUT argument + + For the other parameters, see documentation of inseg_entry GET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del inseg_entry + del attr_count + del mode + del object_statuses + + # No function call - delete all attributes + del num_of_pop + del packet_action + del trap_priority + del next_hop_id + del psc_type + del qos_tc + del mpls_exp_to_tc_map + del mpls_exp_to_color_map + del pop_ttl_mode + del pop_qos_mode + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +# my_mac API + +def sai_thrift_create_my_mac(client, + priority=None, + port_id=None, + vlan_id=None, + mac_address=None, + mac_address_mask=None, + custom_attribute=None): + """ + sai_create_my_mac() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of my_mac CREATE attributes. + + Returns: + sai_thrift_object_id_t: my_mac_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if priority is not None: + attribute_value = sai_thrift_attribute_value_t(u32=priority) + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=mac_address) + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if mac_address_mask is not None: + attribute_value = sai_thrift_attribute_value_t(mac=mac_address_mask) + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_MAC_ADDRESS_MASK, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_my_mac(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_my_mac(client, + my_mac_oid): + """ + sai_remove_my_mac() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + my_mac_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_my_mac(my_mac_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_my_mac_attribute(client, + my_mac_oid, + priority=None, + custom_attribute=None): + """ + sai_set_my_mac_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + my_mac_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of my_mac SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if priority is not None: + attr_value = sai_thrift_attribute_value_t(u32=priority) + attr = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_PRIORITY, + value=attr_value) + client.sai_thrift_set_my_mac_attribute(my_mac_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_my_mac_attribute(my_mac_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_my_mac_attribute(client, + my_mac_oid, + priority=None, + port_id=None, + vlan_id=None, + mac_address=None, + mac_address_mask=None, + custom_attribute=None): + """ + sai_get_my_mac_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + my_mac_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of my_mac GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_PRIORITY) + attr_list.append(attribute) + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_PORT_ID) + attr_list.append(attribute) + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_VLAN_ID) + attr_list.append(attribute) + + if mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_MAC_ADDRESS) + attr_list.append(attribute) + + if mac_address_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_MAC_ATTR_MAC_ADDRESS_MASK) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_my_mac_attribute(my_mac_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MY_MAC_ATTR_PRIORITY: + attrs["SAI_MY_MAC_ATTR_PRIORITY"] = attr.value.u32 + attrs["priority"] = attr.value.u32 + + if attr.id == SAI_MY_MAC_ATTR_PORT_ID: + attrs["SAI_MY_MAC_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_MY_MAC_ATTR_VLAN_ID: + attrs["SAI_MY_MAC_ATTR_VLAN_ID"] = attr.value.u16 + attrs["vlan_id"] = attr.value.u16 + + if attr.id == SAI_MY_MAC_ATTR_MAC_ADDRESS: + attrs["SAI_MY_MAC_ATTR_MAC_ADDRESS"] = attr.value.mac + attrs["mac_address"] = attr.value.mac + + if attr.id == SAI_MY_MAC_ATTR_MAC_ADDRESS_MASK: + attrs["SAI_MY_MAC_ATTR_MAC_ADDRESS_MASK"] = attr.value.mac + attrs["mac_address_mask"] = attr.value.mac + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# nat API + +def sai_thrift_create_nat_entry(client, + nat_entry, + nat_type=None, + src_ip=None, + src_ip_mask=None, + vr_id=None, + dst_ip=None, + dst_ip_mask=None, + l4_src_port=None, + l4_dst_port=None, + enable_packet_count=None, + packet_count=None, + enable_byte_count=None, + byte_count=None, + hit_bit_cor=None, + hit_bit=None, + aging_time=None, + custom_attribute=None): + """ + sai_create_nat_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + nat_entry(sai_thrift_nat_entry_t): nat_entry IN argument + + For the other parameters, see documentation of nat_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if nat_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=nat_type) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_NAT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ip4=src_ip) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if src_ip_mask is not None: + attribute_value = sai_thrift_attribute_value_t(ip4=src_ip_mask) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_SRC_IP_MASK, + value=attribute_value) + attr_list.append(attribute) + + if vr_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=vr_id) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_VR_ID, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ip4=dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip_mask is not None: + attribute_value = sai_thrift_attribute_value_t(ip4=dst_ip_mask) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_DST_IP_MASK, + value=attribute_value) + attr_list.append(attribute) + + if l4_src_port is not None: + attribute_value = sai_thrift_attribute_value_t(u16=l4_src_port) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_L4_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if l4_dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(u16=l4_dst_port) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_L4_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if enable_packet_count is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_packet_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_ENABLE_PACKET_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if packet_count is not None: + attribute_value = sai_thrift_attribute_value_t(u64=packet_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_PACKET_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if enable_byte_count is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_byte_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_ENABLE_BYTE_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if byte_count is not None: + attribute_value = sai_thrift_attribute_value_t(u64=byte_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_BYTE_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if hit_bit_cor is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=hit_bit_cor) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_HIT_BIT_COR, + value=attribute_value) + attr_list.append(attribute) + + if hit_bit is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=hit_bit) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_HIT_BIT, + value=attribute_value) + attr_list.append(attribute) + + if aging_time is not None: + attribute_value = sai_thrift_attribute_value_t(u32=aging_time) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_AGING_TIME, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_nat_entry(nat_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_nat_entry(client, + nat_entry): + """ + sai_remove_nat_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + nat_entry(sai_thrift_nat_entry_t): nat_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_nat_entry(nat_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_nat_entry_attribute(client, + nat_entry, + nat_type=None, + src_ip=None, + src_ip_mask=None, + vr_id=None, + dst_ip=None, + dst_ip_mask=None, + l4_src_port=None, + l4_dst_port=None, + enable_packet_count=None, + packet_count=None, + enable_byte_count=None, + byte_count=None, + hit_bit_cor=None, + hit_bit=None, + aging_time=None, + custom_attribute=None): + """ + sai_set_nat_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + nat_entry(sai_thrift_nat_entry_t): nat_entry IN argument + + For the other parameters, see documentation of nat_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if nat_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=nat_type) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_NAT_TYPE, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if src_ip is not None: + attr_value = sai_thrift_attribute_value_t(ip4=src_ip) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_SRC_IP, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if src_ip_mask is not None: + attr_value = sai_thrift_attribute_value_t(ip4=src_ip_mask) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_SRC_IP_MASK, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if vr_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=vr_id) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_VR_ID, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if dst_ip is not None: + attr_value = sai_thrift_attribute_value_t(ip4=dst_ip) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_DST_IP, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if dst_ip_mask is not None: + attr_value = sai_thrift_attribute_value_t(ip4=dst_ip_mask) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_DST_IP_MASK, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if l4_src_port is not None: + attr_value = sai_thrift_attribute_value_t(u16=l4_src_port) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_L4_SRC_PORT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if l4_dst_port is not None: + attr_value = sai_thrift_attribute_value_t(u16=l4_dst_port) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_L4_DST_PORT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if enable_packet_count is not None: + attr_value = sai_thrift_attribute_value_t(booldata=enable_packet_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_ENABLE_PACKET_COUNT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if packet_count is not None: + attr_value = sai_thrift_attribute_value_t(u64=packet_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_PACKET_COUNT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if enable_byte_count is not None: + attr_value = sai_thrift_attribute_value_t(booldata=enable_byte_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_ENABLE_BYTE_COUNT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if byte_count is not None: + attr_value = sai_thrift_attribute_value_t(u64=byte_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_BYTE_COUNT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if hit_bit_cor is not None: + attr_value = sai_thrift_attribute_value_t(booldata=hit_bit_cor) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_HIT_BIT_COR, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if hit_bit is not None: + attr_value = sai_thrift_attribute_value_t(booldata=hit_bit) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_HIT_BIT, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if aging_time is not None: + attr_value = sai_thrift_attribute_value_t(u32=aging_time) + attr = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_AGING_TIME, + value=attr_value) + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_nat_entry_attribute(nat_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_nat_entry_attribute(client, + nat_entry, + nat_type=None, + src_ip=None, + src_ip_mask=None, + vr_id=None, + dst_ip=None, + dst_ip_mask=None, + l4_src_port=None, + l4_dst_port=None, + enable_packet_count=None, + packet_count=None, + enable_byte_count=None, + byte_count=None, + hit_bit_cor=None, + hit_bit=None, + aging_time=None, + custom_attribute=None): + """ + sai_get_nat_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + nat_entry(sai_thrift_nat_entry_t): nat_entry IN argument + + For the other parameters, see documentation of nat_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if nat_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_NAT_TYPE) + attr_list.append(attribute) + + if src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_SRC_IP) + attr_list.append(attribute) + + if src_ip_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_SRC_IP_MASK) + attr_list.append(attribute) + + if vr_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_VR_ID) + attr_list.append(attribute) + + if dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_DST_IP) + attr_list.append(attribute) + + if dst_ip_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_DST_IP_MASK) + attr_list.append(attribute) + + if l4_src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_L4_SRC_PORT) + attr_list.append(attribute) + + if l4_dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_L4_DST_PORT) + attr_list.append(attribute) + + if enable_packet_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_ENABLE_PACKET_COUNT) + attr_list.append(attribute) + + if packet_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_PACKET_COUNT) + attr_list.append(attribute) + + if enable_byte_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_ENABLE_BYTE_COUNT) + attr_list.append(attribute) + + if byte_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_BYTE_COUNT) + attr_list.append(attribute) + + if hit_bit_cor is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_HIT_BIT_COR) + attr_list.append(attribute) + + if hit_bit is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_HIT_BIT) + attr_list.append(attribute) + + if aging_time is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ENTRY_ATTR_AGING_TIME) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_nat_entry_attribute(nat_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NAT_ENTRY_ATTR_NAT_TYPE: + attrs["SAI_NAT_ENTRY_ATTR_NAT_TYPE"] = attr.value.s32 + attrs["nat_type"] = attr.value.s32 + + if attr.id == SAI_NAT_ENTRY_ATTR_SRC_IP: + attrs["SAI_NAT_ENTRY_ATTR_SRC_IP"] = attr.value.ip4 + attrs["src_ip"] = attr.value.ip4 + + if attr.id == SAI_NAT_ENTRY_ATTR_SRC_IP_MASK: + attrs["SAI_NAT_ENTRY_ATTR_SRC_IP_MASK"] = attr.value.ip4 + attrs["src_ip_mask"] = attr.value.ip4 + + if attr.id == SAI_NAT_ENTRY_ATTR_VR_ID: + attrs["SAI_NAT_ENTRY_ATTR_VR_ID"] = attr.value.oid + attrs["vr_id"] = attr.value.oid + + if attr.id == SAI_NAT_ENTRY_ATTR_DST_IP: + attrs["SAI_NAT_ENTRY_ATTR_DST_IP"] = attr.value.ip4 + attrs["dst_ip"] = attr.value.ip4 + + if attr.id == SAI_NAT_ENTRY_ATTR_DST_IP_MASK: + attrs["SAI_NAT_ENTRY_ATTR_DST_IP_MASK"] = attr.value.ip4 + attrs["dst_ip_mask"] = attr.value.ip4 + + if attr.id == SAI_NAT_ENTRY_ATTR_L4_SRC_PORT: + attrs["SAI_NAT_ENTRY_ATTR_L4_SRC_PORT"] = attr.value.u16 + attrs["l4_src_port"] = attr.value.u16 + + if attr.id == SAI_NAT_ENTRY_ATTR_L4_DST_PORT: + attrs["SAI_NAT_ENTRY_ATTR_L4_DST_PORT"] = attr.value.u16 + attrs["l4_dst_port"] = attr.value.u16 + + if attr.id == SAI_NAT_ENTRY_ATTR_ENABLE_PACKET_COUNT: + attrs["SAI_NAT_ENTRY_ATTR_ENABLE_PACKET_COUNT"] = attr.value.booldata + attrs["enable_packet_count"] = attr.value.booldata + + if attr.id == SAI_NAT_ENTRY_ATTR_PACKET_COUNT: + attrs["SAI_NAT_ENTRY_ATTR_PACKET_COUNT"] = attr.value.u64 + attrs["packet_count"] = attr.value.u64 + + if attr.id == SAI_NAT_ENTRY_ATTR_ENABLE_BYTE_COUNT: + attrs["SAI_NAT_ENTRY_ATTR_ENABLE_BYTE_COUNT"] = attr.value.booldata + attrs["enable_byte_count"] = attr.value.booldata + + if attr.id == SAI_NAT_ENTRY_ATTR_BYTE_COUNT: + attrs["SAI_NAT_ENTRY_ATTR_BYTE_COUNT"] = attr.value.u64 + attrs["byte_count"] = attr.value.u64 + + if attr.id == SAI_NAT_ENTRY_ATTR_HIT_BIT_COR: + attrs["SAI_NAT_ENTRY_ATTR_HIT_BIT_COR"] = attr.value.booldata + attrs["hit_bit_cor"] = attr.value.booldata + + if attr.id == SAI_NAT_ENTRY_ATTR_HIT_BIT: + attrs["SAI_NAT_ENTRY_ATTR_HIT_BIT"] = attr.value.booldata + attrs["hit_bit"] = attr.value.booldata + + if attr.id == SAI_NAT_ENTRY_ATTR_AGING_TIME: + attrs["SAI_NAT_ENTRY_ATTR_AGING_TIME"] = attr.value.u32 + attrs["aging_time"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_bulk_create_nat_entry(client, + nat_entry, + attr_count, + mode, + nat_type=None, + src_ip=None, + src_ip_mask=None, + vr_id=None, + dst_ip=None, + dst_ip_mask=None, + l4_src_port=None, + l4_dst_port=None, + enable_packet_count=None, + packet_count=None, + enable_byte_count=None, + byte_count=None, + hit_bit_cor=None, + hit_bit=None, + aging_time=None, + custom_attribute=None): + """ + sai_bulk_create_nat_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + nat_entry(List[sai_thrift_nat_entry_t]): nat_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of nat_entry CREATE attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del nat_entry + del attr_count + del mode + + # No function call - delete all attributes + del nat_type + del src_ip + del src_ip_mask + del vr_id + del dst_ip + del dst_ip_mask + del l4_src_port + del l4_dst_port + del enable_packet_count + del packet_count + del enable_byte_count + del byte_count + del hit_bit_cor + del hit_bit + del aging_time + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_remove_nat_entry(client, + nat_entry, + mode): + """ + sai_bulk_remove_nat_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + nat_entry(List[sai_thrift_nat_entry_t]): nat_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del nat_entry + del mode + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_set_nat_entry_attribute(client, + nat_entry, + mode, + nat_type=None, + src_ip=None, + src_ip_mask=None, + vr_id=None, + dst_ip=None, + dst_ip_mask=None, + l4_src_port=None, + l4_dst_port=None, + enable_packet_count=None, + packet_count=None, + enable_byte_count=None, + byte_count=None, + hit_bit_cor=None, + hit_bit=None, + aging_time=None, + custom_attribute=None): + """ + sai_bulk_set_nat_entry_attribute() - UNSUPPORTED + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + nat_entry(List[sai_thrift_nat_entry_t]): nat_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of nat_entry SET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del nat_entry + del mode + + # No function call - delete all attributes + del nat_type + del src_ip + del src_ip_mask + del vr_id + del dst_ip + del dst_ip_mask + del l4_src_port + del l4_dst_port + del enable_packet_count + del packet_count + del enable_byte_count + del byte_count + del hit_bit_cor + del hit_bit + del aging_time + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_get_nat_entry_attribute(client, + nat_entry, + attr_count, + mode, + object_statuses, + nat_type=None, + src_ip=None, + src_ip_mask=None, + vr_id=None, + dst_ip=None, + dst_ip_mask=None, + l4_src_port=None, + l4_dst_port=None, + enable_packet_count=None, + packet_count=None, + enable_byte_count=None, + byte_count=None, + hit_bit_cor=None, + hit_bit=None, + aging_time=None, + custom_attribute=None): + """ + sai_bulk_get_nat_entry_attribute() - UNSUPPORTED + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + nat_entry(List[sai_thrift_nat_entry_t]): nat_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + object_statuses(List[sai_thrift_status_t]): status_list OUT argument + + For the other parameters, see documentation of nat_entry GET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del nat_entry + del attr_count + del mode + del object_statuses + + # No function call - delete all attributes + del nat_type + del src_ip + del src_ip_mask + del vr_id + del dst_ip + del dst_ip_mask + del l4_src_port + del l4_dst_port + del enable_packet_count + del packet_count + del enable_byte_count + del byte_count + del hit_bit_cor + del hit_bit + del aging_time + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_create_nat_zone_counter(client, + nat_type=None, + zone_id=None, + enable_discard=None, + discard_packet_count=None, + enable_translation_needed=None, + translation_needed_packet_count=None, + enable_translations=None, + translations_packet_count=None, + custom_attribute=None): + """ + sai_create_nat_zone_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of nat_zone_counter CREATE attributes. + + Returns: + sai_thrift_object_id_t: nat_zone_counter_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if nat_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=nat_type) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_NAT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if zone_id is not None: + attribute_value = sai_thrift_attribute_value_t(u8=zone_id) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ZONE_ID, + value=attribute_value) + attr_list.append(attribute) + + if enable_discard is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_discard) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_DISCARD, + value=attribute_value) + attr_list.append(attribute) + + if discard_packet_count is not None: + attribute_value = sai_thrift_attribute_value_t(u64=discard_packet_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_DISCARD_PACKET_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if enable_translation_needed is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_translation_needed) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATION_NEEDED, + value=attribute_value) + attr_list.append(attribute) + + if translation_needed_packet_count is not None: + attribute_value = sai_thrift_attribute_value_t(u64=translation_needed_packet_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATION_NEEDED_PACKET_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if enable_translations is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_translations) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATIONS, + value=attribute_value) + attr_list.append(attribute) + + if translations_packet_count is not None: + attribute_value = sai_thrift_attribute_value_t(u64=translations_packet_count) + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATIONS_PACKET_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_nat_zone_counter(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_nat_zone_counter(client, + nat_zone_counter_oid): + """ + sai_remove_nat_zone_counter() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + nat_zone_counter_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_nat_zone_counter(nat_zone_counter_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_nat_zone_counter_attribute(client, + nat_zone_counter_oid, + nat_type=None, + zone_id=None, + discard_packet_count=None, + translation_needed_packet_count=None, + translations_packet_count=None, + custom_attribute=None): + """ + sai_set_nat_zone_counter_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + nat_zone_counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of nat_zone_counter SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if nat_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=nat_type) + attr = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_NAT_TYPE, + value=attr_value) + client.sai_thrift_set_nat_zone_counter_attribute(nat_zone_counter_oid, attr) + + if zone_id is not None: + attr_value = sai_thrift_attribute_value_t(u8=zone_id) + attr = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ZONE_ID, + value=attr_value) + client.sai_thrift_set_nat_zone_counter_attribute(nat_zone_counter_oid, attr) + + if discard_packet_count is not None: + attr_value = sai_thrift_attribute_value_t(u64=discard_packet_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_DISCARD_PACKET_COUNT, + value=attr_value) + client.sai_thrift_set_nat_zone_counter_attribute(nat_zone_counter_oid, attr) + + if translation_needed_packet_count is not None: + attr_value = sai_thrift_attribute_value_t(u64=translation_needed_packet_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATION_NEEDED_PACKET_COUNT, + value=attr_value) + client.sai_thrift_set_nat_zone_counter_attribute(nat_zone_counter_oid, attr) + + if translations_packet_count is not None: + attr_value = sai_thrift_attribute_value_t(u64=translations_packet_count) + attr = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATIONS_PACKET_COUNT, + value=attr_value) + client.sai_thrift_set_nat_zone_counter_attribute(nat_zone_counter_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_nat_zone_counter_attribute(nat_zone_counter_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_nat_zone_counter_attribute(client, + nat_zone_counter_oid, + nat_type=None, + zone_id=None, + enable_discard=None, + discard_packet_count=None, + enable_translation_needed=None, + translation_needed_packet_count=None, + enable_translations=None, + translations_packet_count=None, + custom_attribute=None): + """ + sai_get_nat_zone_counter_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + nat_zone_counter_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of nat_zone_counter GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if nat_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_NAT_TYPE) + attr_list.append(attribute) + + if zone_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ZONE_ID) + attr_list.append(attribute) + + if enable_discard is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_DISCARD) + attr_list.append(attribute) + + if discard_packet_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_DISCARD_PACKET_COUNT) + attr_list.append(attribute) + + if enable_translation_needed is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATION_NEEDED) + attr_list.append(attribute) + + if translation_needed_packet_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATION_NEEDED_PACKET_COUNT) + attr_list.append(attribute) + + if enable_translations is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATIONS) + attr_list.append(attribute) + + if translations_packet_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATIONS_PACKET_COUNT) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_nat_zone_counter_attribute(nat_zone_counter_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_NAT_TYPE: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_NAT_TYPE"] = attr.value.s32 + attrs["nat_type"] = attr.value.s32 + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_ZONE_ID: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_ZONE_ID"] = attr.value.u8 + attrs["zone_id"] = attr.value.u8 + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_DISCARD: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_DISCARD"] = attr.value.booldata + attrs["enable_discard"] = attr.value.booldata + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_DISCARD_PACKET_COUNT: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_DISCARD_PACKET_COUNT"] = attr.value.u64 + attrs["discard_packet_count"] = attr.value.u64 + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATION_NEEDED: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATION_NEEDED"] = attr.value.booldata + attrs["enable_translation_needed"] = attr.value.booldata + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATION_NEEDED_PACKET_COUNT: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATION_NEEDED_PACKET_COUNT"] = attr.value.u64 + attrs["translation_needed_packet_count"] = attr.value.u64 + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATIONS: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_ENABLE_TRANSLATIONS"] = attr.value.booldata + attrs["enable_translations"] = attr.value.booldata + + if attr.id == SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATIONS_PACKET_COUNT: + attrs["SAI_NAT_ZONE_COUNTER_ATTR_TRANSLATIONS_PACKET_COUNT"] = attr.value.u64 + attrs["translations_packet_count"] = attr.value.u64 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# neighbor API + +def sai_thrift_create_neighbor_entry(client, + neighbor_entry, + dst_mac_address=None, + packet_action=None, + user_trap_id=None, + no_host_route=None, + meta_data=None, + counter_id=None, + encap_index=None, + encap_impose_index=None, + is_local=None, + custom_attribute=None): + """ + sai_create_neighbor_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + neighbor_entry(sai_thrift_neighbor_entry_t): neighbor_entry IN argument + + For the other parameters, see documentation of neighbor_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if dst_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=dst_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if user_trap_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=user_trap_id) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_USER_TRAP_ID, + value=attribute_value) + attr_list.append(attribute) + + if no_host_route is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=no_host_route) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE, + value=attribute_value) + attr_list.append(attribute) + + if meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(u32=meta_data) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if encap_index is not None: + attribute_value = sai_thrift_attribute_value_t(u32=encap_index) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if encap_impose_index is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=encap_impose_index) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if is_local is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=is_local) + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_neighbor_entry(neighbor_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_neighbor_entry(client, + neighbor_entry): + """ + sai_remove_neighbor_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + neighbor_entry(sai_thrift_neighbor_entry_t): neighbor_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_neighbor_entry(neighbor_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_neighbor_entry_attribute(client, + neighbor_entry, + dst_mac_address=None, + packet_action=None, + user_trap_id=None, + no_host_route=None, + meta_data=None, + counter_id=None, + encap_index=None, + encap_impose_index=None, + is_local=None, + custom_attribute=None): + """ + sai_set_neighbor_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + neighbor_entry(sai_thrift_neighbor_entry_t): neighbor_entry IN argument + + For the other parameters, see documentation of neighbor_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if dst_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=dst_mac_address) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if user_trap_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=user_trap_id) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_USER_TRAP_ID, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if no_host_route is not None: + attr_value = sai_thrift_attribute_value_t(booldata=no_host_route) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if meta_data is not None: + attr_value = sai_thrift_attribute_value_t(u32=meta_data) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_META_DATA, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if encap_index is not None: + attr_value = sai_thrift_attribute_value_t(u32=encap_index) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if encap_impose_index is not None: + attr_value = sai_thrift_attribute_value_t(booldata=encap_impose_index) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if is_local is not None: + attr_value = sai_thrift_attribute_value_t(booldata=is_local) + attr = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL, + value=attr_value) + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_neighbor_entry_attribute(neighbor_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_neighbor_entry_attribute(client, + neighbor_entry, + dst_mac_address=None, + packet_action=None, + user_trap_id=None, + no_host_route=None, + meta_data=None, + counter_id=None, + encap_index=None, + encap_impose_index=None, + is_local=None, + ip_addr_family=None, + custom_attribute=None): + """ + sai_get_neighbor_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + neighbor_entry(sai_thrift_neighbor_entry_t): neighbor_entry IN argument + + For the other parameters, see documentation of neighbor_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if dst_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS) + attr_list.append(attribute) + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if user_trap_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_USER_TRAP_ID) + attr_list.append(attribute) + + if no_host_route is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE) + attr_list.append(attribute) + + if meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_META_DATA) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if encap_index is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX) + attr_list.append(attribute) + + if encap_impose_index is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX) + attr_list.append(attribute) + + if is_local is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL) + attr_list.append(attribute) + + if ip_addr_family is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEIGHBOR_ENTRY_ATTR_IP_ADDR_FAMILY) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_neighbor_entry_attribute(neighbor_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS"] = attr.value.mac + attrs["dst_mac_address"] = attr.value.mac + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_USER_TRAP_ID: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_USER_TRAP_ID"] = attr.value.oid + attrs["user_trap_id"] = attr.value.oid + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE"] = attr.value.booldata + attrs["no_host_route"] = attr.value.booldata + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_META_DATA: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_META_DATA"] = attr.value.u32 + attrs["meta_data"] = attr.value.u32 + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_COUNTER_ID: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX"] = attr.value.u32 + attrs["encap_index"] = attr.value.u32 + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX"] = attr.value.booldata + attrs["encap_impose_index"] = attr.value.booldata + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL"] = attr.value.booldata + attrs["is_local"] = attr.value.booldata + + if attr.id == SAI_NEIGHBOR_ENTRY_ATTR_IP_ADDR_FAMILY: + attrs["SAI_NEIGHBOR_ENTRY_ATTR_IP_ADDR_FAMILY"] = attr.value.s32 + attrs["ip_addr_family"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_remove_all_neighbor_entries(client): + """ + sai_remove_all_neighbor_entries() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_all_neighbor_entries() + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# next_hop API + +def sai_thrift_create_next_hop(client, + type=None, + ip=None, + router_interface_id=None, + tunnel_id=None, + srv6_sidlist_id=None, + labelstack=None, + tunnel_vni=None, + tunnel_mac=None, + counter_id=None, + disable_decrement_ttl=None, + outseg_type=None, + outseg_ttl_mode=None, + outseg_ttl_value=None, + outseg_exp_mode=None, + outseg_exp_value=None, + qos_tc_and_color_to_mpls_exp_map=None, + custom_attribute=None): + """ + sai_create_next_hop() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of next_hop CREATE attributes. + + Returns: + sai_thrift_object_id_t: next_hop_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=ip) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_IP, + value=attribute_value) + attr_list.append(attribute) + + if router_interface_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=router_interface_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=tunnel_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_ID, + value=attribute_value) + attr_list.append(attribute) + + if srv6_sidlist_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=srv6_sidlist_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_SRV6_SIDLIST_ID, + value=attribute_value) + attr_list.append(attribute) + + if labelstack is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=labelstack) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_LABELSTACK, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_vni is not None: + attribute_value = sai_thrift_attribute_value_t(u32=tunnel_vni) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_VNI, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_mac is not None: + attribute_value = sai_thrift_attribute_value_t(mac=tunnel_mac) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_MAC, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if disable_decrement_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=disable_decrement_ttl) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_DISABLE_DECREMENT_TTL, + value=attribute_value) + attr_list.append(attribute) + + if outseg_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=outseg_type) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if outseg_ttl_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=outseg_ttl_mode) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TTL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if outseg_ttl_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=outseg_ttl_value) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TTL_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if outseg_exp_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=outseg_exp_mode) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_EXP_MODE, + value=attribute_value) + attr_list.append(attribute) + + if outseg_exp_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=outseg_exp_value) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_EXP_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_mpls_exp_map) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_next_hop(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_next_hop(client, + next_hop_oid): + """ + sai_remove_next_hop() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + next_hop_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_next_hop(next_hop_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_next_hop_attribute(client, + next_hop_oid, + tunnel_vni=None, + tunnel_mac=None, + counter_id=None, + disable_decrement_ttl=None, + outseg_type=None, + outseg_ttl_mode=None, + outseg_ttl_value=None, + outseg_exp_mode=None, + outseg_exp_value=None, + qos_tc_and_color_to_mpls_exp_map=None, + custom_attribute=None): + """ + sai_set_next_hop_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + next_hop_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if tunnel_vni is not None: + attr_value = sai_thrift_attribute_value_t(u32=tunnel_vni) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_VNI, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if tunnel_mac is not None: + attr_value = sai_thrift_attribute_value_t(mac=tunnel_mac) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_MAC, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if disable_decrement_ttl is not None: + attr_value = sai_thrift_attribute_value_t(booldata=disable_decrement_ttl) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_DISABLE_DECREMENT_TTL, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if outseg_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=outseg_type) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TYPE, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if outseg_ttl_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=outseg_ttl_mode) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TTL_MODE, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if outseg_ttl_value is not None: + attr_value = sai_thrift_attribute_value_t(u8=outseg_ttl_value) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TTL_VALUE, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if outseg_exp_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=outseg_exp_mode) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_EXP_MODE, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if outseg_exp_value is not None: + attr_value = sai_thrift_attribute_value_t(u8=outseg_exp_value) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_EXP_VALUE, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_mpls_exp_map) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP, + value=attr_value) + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_next_hop_attribute(next_hop_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_next_hop_attribute(client, + next_hop_oid, + type=None, + ip=None, + router_interface_id=None, + tunnel_id=None, + tunnel_vni=None, + tunnel_mac=None, + srv6_sidlist_id=None, + labelstack=None, + counter_id=None, + disable_decrement_ttl=None, + outseg_type=None, + outseg_ttl_mode=None, + outseg_ttl_value=None, + outseg_exp_mode=None, + outseg_exp_value=None, + qos_tc_and_color_to_mpls_exp_map=None, + custom_attribute=None): + """ + sai_get_next_hop_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + next_hop_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TYPE) + attr_list.append(attribute) + + if ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_IP) + attr_list.append(attribute) + + if router_interface_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID) + attr_list.append(attribute) + + if tunnel_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_ID) + attr_list.append(attribute) + + if tunnel_vni is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_VNI) + attr_list.append(attribute) + + if tunnel_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_TUNNEL_MAC) + attr_list.append(attribute) + + if srv6_sidlist_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_SRV6_SIDLIST_ID) + attr_list.append(attribute) + + if labelstack is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=labelstack) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_LABELSTACK, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if disable_decrement_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_DISABLE_DECREMENT_TTL) + attr_list.append(attribute) + + if outseg_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TYPE) + attr_list.append(attribute) + + if outseg_ttl_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TTL_MODE) + attr_list.append(attribute) + + if outseg_ttl_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_TTL_VALUE) + attr_list.append(attribute) + + if outseg_exp_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_EXP_MODE) + attr_list.append(attribute) + + if outseg_exp_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_OUTSEG_EXP_VALUE) + attr_list.append(attribute) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_next_hop_attribute(next_hop_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NEXT_HOP_ATTR_TYPE: + attrs["SAI_NEXT_HOP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_ATTR_IP: + attrs["SAI_NEXT_HOP_ATTR_IP"] = attr.value.ipaddr + attrs["ip"] = attr.value.ipaddr + + if attr.id == SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID: + attrs["SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID"] = attr.value.oid + attrs["router_interface_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_ATTR_TUNNEL_ID: + attrs["SAI_NEXT_HOP_ATTR_TUNNEL_ID"] = attr.value.oid + attrs["tunnel_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_ATTR_TUNNEL_VNI: + attrs["SAI_NEXT_HOP_ATTR_TUNNEL_VNI"] = attr.value.u32 + attrs["tunnel_vni"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_ATTR_TUNNEL_MAC: + attrs["SAI_NEXT_HOP_ATTR_TUNNEL_MAC"] = attr.value.mac + attrs["tunnel_mac"] = attr.value.mac + + if attr.id == SAI_NEXT_HOP_ATTR_SRV6_SIDLIST_ID: + attrs["SAI_NEXT_HOP_ATTR_SRV6_SIDLIST_ID"] = attr.value.oid + attrs["srv6_sidlist_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_ATTR_LABELSTACK: + attrs["SAI_NEXT_HOP_ATTR_LABELSTACK"] = attr.value.u32list + attrs["labelstack"] = attr.value.u32list + + if attr.id == SAI_NEXT_HOP_ATTR_COUNTER_ID: + attrs["SAI_NEXT_HOP_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_ATTR_DISABLE_DECREMENT_TTL: + attrs["SAI_NEXT_HOP_ATTR_DISABLE_DECREMENT_TTL"] = attr.value.booldata + attrs["disable_decrement_ttl"] = attr.value.booldata + + if attr.id == SAI_NEXT_HOP_ATTR_OUTSEG_TYPE: + attrs["SAI_NEXT_HOP_ATTR_OUTSEG_TYPE"] = attr.value.s32 + attrs["outseg_type"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_ATTR_OUTSEG_TTL_MODE: + attrs["SAI_NEXT_HOP_ATTR_OUTSEG_TTL_MODE"] = attr.value.s32 + attrs["outseg_ttl_mode"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_ATTR_OUTSEG_TTL_VALUE: + attrs["SAI_NEXT_HOP_ATTR_OUTSEG_TTL_VALUE"] = attr.value.u8 + attrs["outseg_ttl_value"] = attr.value.u8 + + if attr.id == SAI_NEXT_HOP_ATTR_OUTSEG_EXP_MODE: + attrs["SAI_NEXT_HOP_ATTR_OUTSEG_EXP_MODE"] = attr.value.s32 + attrs["outseg_exp_mode"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_ATTR_OUTSEG_EXP_VALUE: + attrs["SAI_NEXT_HOP_ATTR_OUTSEG_EXP_VALUE"] = attr.value.u8 + attrs["outseg_exp_value"] = attr.value.u8 + + if attr.id == SAI_NEXT_HOP_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP: + attrs["SAI_NEXT_HOP_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_mpls_exp_map"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# next_hop_group API + +def sai_thrift_create_next_hop_group(client, + type=None, + set_switchover=None, + counter_id=None, + configured_size=None, + selection_map=None, + custom_attribute=None): + """ + sai_create_next_hop_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of next_hop_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: next_hop_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if set_switchover is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=set_switchover) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if configured_size is not None: + attribute_value = sai_thrift_attribute_value_t(u32=configured_size) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_CONFIGURED_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if selection_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=selection_map) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_SELECTION_MAP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_next_hop_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_next_hop_group(client, + next_hop_group_oid): + """ + sai_remove_next_hop_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + next_hop_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_next_hop_group(next_hop_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_next_hop_group_attribute(client, + next_hop_group_oid, + set_switchover=None, + counter_id=None, + selection_map=None, + custom_attribute=None): + """ + sai_set_next_hop_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + next_hop_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop_group SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if set_switchover is not None: + attr_value = sai_thrift_attribute_value_t(booldata=set_switchover) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER, + value=attr_value) + client.sai_thrift_set_next_hop_group_attribute(next_hop_group_oid, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_next_hop_group_attribute(next_hop_group_oid, attr) + + if selection_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=selection_map) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_SELECTION_MAP, + value=attr_value) + client.sai_thrift_set_next_hop_group_attribute(next_hop_group_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_next_hop_group_attribute(next_hop_group_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_next_hop_group_attribute(client, + next_hop_group_oid, + next_hop_count=None, + next_hop_member_list=None, + type=None, + set_switchover=None, + counter_id=None, + configured_size=None, + real_size=None, + selection_map=None, + custom_attribute=None): + """ + sai_get_next_hop_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + next_hop_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if next_hop_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_COUNT) + attr_list.append(attribute) + + if next_hop_member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=next_hop_member_list) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_TYPE) + attr_list.append(attribute) + + if set_switchover is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if configured_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_CONFIGURED_SIZE) + attr_list.append(attribute) + + if real_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_REAL_SIZE) + attr_list.append(attribute) + + if selection_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_ATTR_SELECTION_MAP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_next_hop_group_attribute(next_hop_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_COUNT: + attrs["SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_COUNT"] = attr.value.u32 + attrs["next_hop_count"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_MEMBER_LIST: + attrs["SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_MEMBER_LIST"] = attr.value.objlist + attrs["next_hop_member_list"] = attr.value.objlist + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_TYPE: + attrs["SAI_NEXT_HOP_GROUP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER: + attrs["SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER"] = attr.value.booldata + attrs["set_switchover"] = attr.value.booldata + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_COUNTER_ID: + attrs["SAI_NEXT_HOP_GROUP_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_CONFIGURED_SIZE: + attrs["SAI_NEXT_HOP_GROUP_ATTR_CONFIGURED_SIZE"] = attr.value.u32 + attrs["configured_size"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_REAL_SIZE: + attrs["SAI_NEXT_HOP_GROUP_ATTR_REAL_SIZE"] = attr.value.u32 + attrs["real_size"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_GROUP_ATTR_SELECTION_MAP: + attrs["SAI_NEXT_HOP_GROUP_ATTR_SELECTION_MAP"] = attr.value.oid + attrs["selection_map"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_next_hop_group_member(client, + next_hop_group_id=None, + next_hop_id=None, + weight=None, + configured_role=None, + monitored_object=None, + index=None, + sequence_id=None, + counter_id=None, + custom_attribute=None): + """ + sai_create_next_hop_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of next_hop_group_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: next_hop_group_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if next_hop_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=next_hop_group_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID, + value=attribute_value) + attr_list.append(attribute) + + if weight is not None: + attribute_value = sai_thrift_attribute_value_t(u32=weight) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT, + value=attribute_value) + attr_list.append(attribute) + + if configured_role is not None: + attribute_value = sai_thrift_attribute_value_t(s32=configured_role) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_CONFIGURED_ROLE, + value=attribute_value) + attr_list.append(attribute) + + if monitored_object is not None: + attribute_value = sai_thrift_attribute_value_t(oid=monitored_object) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_MONITORED_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if index is not None: + attribute_value = sai_thrift_attribute_value_t(u32=index) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if sequence_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=sequence_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_next_hop_group_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_next_hop_group_member(client, + next_hop_group_member_oid): + """ + sai_remove_next_hop_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + next_hop_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_next_hop_group_member(next_hop_group_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_next_hop_group_member_attribute(client, + next_hop_group_member_oid, + next_hop_id=None, + weight=None, + monitored_object=None, + sequence_id=None, + counter_id=None, + custom_attribute=None): + """ + sai_set_next_hop_group_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + next_hop_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop_group_member SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if next_hop_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID, + value=attr_value) + client.sai_thrift_set_next_hop_group_member_attribute(next_hop_group_member_oid, attr) + + if weight is not None: + attr_value = sai_thrift_attribute_value_t(u32=weight) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT, + value=attr_value) + client.sai_thrift_set_next_hop_group_member_attribute(next_hop_group_member_oid, attr) + + if monitored_object is not None: + attr_value = sai_thrift_attribute_value_t(oid=monitored_object) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_MONITORED_OBJECT, + value=attr_value) + client.sai_thrift_set_next_hop_group_member_attribute(next_hop_group_member_oid, attr) + + if sequence_id is not None: + attr_value = sai_thrift_attribute_value_t(u32=sequence_id) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID, + value=attr_value) + client.sai_thrift_set_next_hop_group_member_attribute(next_hop_group_member_oid, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_next_hop_group_member_attribute(next_hop_group_member_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_next_hop_group_member_attribute(next_hop_group_member_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_next_hop_group_member_attribute(client, + next_hop_group_member_oid, + next_hop_group_id=None, + next_hop_id=None, + weight=None, + configured_role=None, + observed_role=None, + monitored_object=None, + index=None, + sequence_id=None, + counter_id=None, + custom_attribute=None): + """ + sai_get_next_hop_group_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + next_hop_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop_group_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if next_hop_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID) + attr_list.append(attribute) + + if weight is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT) + attr_list.append(attribute) + + if configured_role is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_CONFIGURED_ROLE) + attr_list.append(attribute) + + if observed_role is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_OBSERVED_ROLE) + attr_list.append(attribute) + + if monitored_object is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_MONITORED_OBJECT) + attr_list.append(attribute) + + if index is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_INDEX) + attr_list.append(attribute) + + if sequence_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MEMBER_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_next_hop_group_member_attribute(next_hop_group_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] = attr.value.oid + attrs["next_hop_group_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"] = attr.value.oid + attrs["next_hop_id"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT"] = attr.value.u32 + attrs["weight"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_CONFIGURED_ROLE: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_CONFIGURED_ROLE"] = attr.value.s32 + attrs["configured_role"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_OBSERVED_ROLE: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_OBSERVED_ROLE"] = attr.value.s32 + attrs["observed_role"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_MONITORED_OBJECT: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_MONITORED_OBJECT"] = attr.value.oid + attrs["monitored_object"] = attr.value.oid + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_INDEX: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_INDEX"] = attr.value.u32 + attrs["index"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID"] = attr.value.u32 + attrs["sequence_id"] = attr.value.u32 + + if attr.id == SAI_NEXT_HOP_GROUP_MEMBER_ATTR_COUNTER_ID: + attrs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_next_hop_group_map(client, + type=None, + map_to_value_list=None, + custom_attribute=None): + """ + sai_create_next_hop_group_map() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of next_hop_group_map CREATE attributes. + + Returns: + sai_thrift_object_id_t: next_hop_group_map_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MAP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if map_to_value_list is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=map_to_value_list) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MAP_ATTR_MAP_TO_VALUE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_next_hop_group_map(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_next_hop_group_map(client, + next_hop_group_map_oid): + """ + sai_remove_next_hop_group_map() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + next_hop_group_map_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_next_hop_group_map(next_hop_group_map_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_next_hop_group_map_attribute(client, + next_hop_group_map_oid, + map_to_value_list=None, + custom_attribute=None): + """ + sai_set_next_hop_group_map_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + next_hop_group_map_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop_group_map SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if map_to_value_list is not None: + attr_value = sai_thrift_attribute_value_t(maplist=map_to_value_list) + attr = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MAP_ATTR_MAP_TO_VALUE_LIST, + value=attr_value) + client.sai_thrift_set_next_hop_group_map_attribute(next_hop_group_map_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_next_hop_group_map_attribute(next_hop_group_map_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_next_hop_group_map_attribute(client, + next_hop_group_map_oid, + type=None, + map_to_value_list=None, + custom_attribute=None): + """ + sai_get_next_hop_group_map_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + next_hop_group_map_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of next_hop_group_map GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MAP_ATTR_TYPE) + attr_list.append(attribute) + + if map_to_value_list is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=map_to_value_list) + attribute = sai_thrift_attribute_t(id=SAI_NEXT_HOP_GROUP_MAP_ATTR_MAP_TO_VALUE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_next_hop_group_map_attribute(next_hop_group_map_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_NEXT_HOP_GROUP_MAP_ATTR_TYPE: + attrs["SAI_NEXT_HOP_GROUP_MAP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_NEXT_HOP_GROUP_MAP_ATTR_MAP_TO_VALUE_LIST: + attrs["SAI_NEXT_HOP_GROUP_MAP_ATTR_MAP_TO_VALUE_LIST"] = attr.value.maplist + attrs["map_to_value_list"] = attr.value.maplist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# policer API + +def sai_thrift_create_policer(client, + meter_type=None, + mode=None, + color_source=None, + cbs=None, + cir=None, + pbs=None, + pir=None, + green_packet_action=None, + yellow_packet_action=None, + red_packet_action=None, + enable_counter_packet_action_list=None, + custom_attribute=None): + """ + sai_create_policer() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of policer CREATE attributes. + + Returns: + sai_thrift_object_id_t: policer_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if meter_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=meter_type) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_METER_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=mode) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_MODE, + value=attribute_value) + attr_list.append(attribute) + + if color_source is not None: + attribute_value = sai_thrift_attribute_value_t(s32=color_source) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_COLOR_SOURCE, + value=attribute_value) + attr_list.append(attribute) + + if cbs is not None: + attribute_value = sai_thrift_attribute_value_t(u64=cbs) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_CBS, + value=attribute_value) + attr_list.append(attribute) + + if cir is not None: + attribute_value = sai_thrift_attribute_value_t(u64=cir) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_CIR, + value=attribute_value) + attr_list.append(attribute) + + if pbs is not None: + attribute_value = sai_thrift_attribute_value_t(u64=pbs) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_PBS, + value=attribute_value) + attr_list.append(attribute) + + if pir is not None: + attribute_value = sai_thrift_attribute_value_t(u64=pir) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_PIR, + value=attribute_value) + attr_list.append(attribute) + + if green_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=green_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_GREEN_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if yellow_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=yellow_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_YELLOW_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if red_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=red_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_RED_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if enable_counter_packet_action_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=enable_counter_packet_action_list) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_ENABLE_COUNTER_PACKET_ACTION_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_policer(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_policer(client, + policer_oid): + """ + sai_remove_policer() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + policer_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_policer(policer_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_policer_attribute(client, + policer_oid, + cbs=None, + cir=None, + pbs=None, + pir=None, + green_packet_action=None, + yellow_packet_action=None, + red_packet_action=None, + enable_counter_packet_action_list=None, + custom_attribute=None): + """ + sai_set_policer_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + policer_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of policer SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if cbs is not None: + attr_value = sai_thrift_attribute_value_t(u64=cbs) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_CBS, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if cir is not None: + attr_value = sai_thrift_attribute_value_t(u64=cir) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_CIR, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if pbs is not None: + attr_value = sai_thrift_attribute_value_t(u64=pbs) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_PBS, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if pir is not None: + attr_value = sai_thrift_attribute_value_t(u64=pir) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_PIR, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if green_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=green_packet_action) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_GREEN_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if yellow_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=yellow_packet_action) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_YELLOW_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if red_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=red_packet_action) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_RED_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if enable_counter_packet_action_list is not None: + attr_value = sai_thrift_attribute_value_t(s32list=enable_counter_packet_action_list) + attr = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_ENABLE_COUNTER_PACKET_ACTION_LIST, + value=attr_value) + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_policer_attribute(policer_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_policer_attribute(client, + policer_oid, + meter_type=None, + mode=None, + color_source=None, + cbs=None, + cir=None, + pbs=None, + pir=None, + green_packet_action=None, + yellow_packet_action=None, + red_packet_action=None, + enable_counter_packet_action_list=None, + custom_attribute=None): + """ + sai_get_policer_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + policer_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of policer GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if meter_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_METER_TYPE) + attr_list.append(attribute) + + if mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_MODE) + attr_list.append(attribute) + + if color_source is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_COLOR_SOURCE) + attr_list.append(attribute) + + if cbs is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_CBS) + attr_list.append(attribute) + + if cir is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_CIR) + attr_list.append(attribute) + + if pbs is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_PBS) + attr_list.append(attribute) + + if pir is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_PIR) + attr_list.append(attribute) + + if green_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_GREEN_PACKET_ACTION) + attr_list.append(attribute) + + if yellow_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_YELLOW_PACKET_ACTION) + attr_list.append(attribute) + + if red_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_RED_PACKET_ACTION) + attr_list.append(attribute) + + if enable_counter_packet_action_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=enable_counter_packet_action_list) + attribute = sai_thrift_attribute_t(id=SAI_POLICER_ATTR_ENABLE_COUNTER_PACKET_ACTION_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_policer_attribute(policer_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_POLICER_ATTR_METER_TYPE: + attrs["SAI_POLICER_ATTR_METER_TYPE"] = attr.value.s32 + attrs["meter_type"] = attr.value.s32 + + if attr.id == SAI_POLICER_ATTR_MODE: + attrs["SAI_POLICER_ATTR_MODE"] = attr.value.s32 + attrs["mode"] = attr.value.s32 + + if attr.id == SAI_POLICER_ATTR_COLOR_SOURCE: + attrs["SAI_POLICER_ATTR_COLOR_SOURCE"] = attr.value.s32 + attrs["color_source"] = attr.value.s32 + + if attr.id == SAI_POLICER_ATTR_CBS: + attrs["SAI_POLICER_ATTR_CBS"] = attr.value.u64 + attrs["cbs"] = attr.value.u64 + + if attr.id == SAI_POLICER_ATTR_CIR: + attrs["SAI_POLICER_ATTR_CIR"] = attr.value.u64 + attrs["cir"] = attr.value.u64 + + if attr.id == SAI_POLICER_ATTR_PBS: + attrs["SAI_POLICER_ATTR_PBS"] = attr.value.u64 + attrs["pbs"] = attr.value.u64 + + if attr.id == SAI_POLICER_ATTR_PIR: + attrs["SAI_POLICER_ATTR_PIR"] = attr.value.u64 + attrs["pir"] = attr.value.u64 + + if attr.id == SAI_POLICER_ATTR_GREEN_PACKET_ACTION: + attrs["SAI_POLICER_ATTR_GREEN_PACKET_ACTION"] = attr.value.s32 + attrs["green_packet_action"] = attr.value.s32 + + if attr.id == SAI_POLICER_ATTR_YELLOW_PACKET_ACTION: + attrs["SAI_POLICER_ATTR_YELLOW_PACKET_ACTION"] = attr.value.s32 + attrs["yellow_packet_action"] = attr.value.s32 + + if attr.id == SAI_POLICER_ATTR_RED_PACKET_ACTION: + attrs["SAI_POLICER_ATTR_RED_PACKET_ACTION"] = attr.value.s32 + attrs["red_packet_action"] = attr.value.s32 + + if attr.id == SAI_POLICER_ATTR_ENABLE_COUNTER_PACKET_ACTION_LIST: + attrs["SAI_POLICER_ATTR_ENABLE_COUNTER_PACKET_ACTION_LIST"] = attr.value.s32list + attrs["enable_counter_packet_action_list"] = attr.value.s32list + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_policer_stats(client, + policer_oid): + """ + sai_get_policer_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + policer_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_POLICER_STAT_PACKETS) + counter_ids.append(SAI_POLICER_STAT_ATTR_BYTES) + counter_ids.append(SAI_POLICER_STAT_GREEN_PACKETS) + counter_ids.append(SAI_POLICER_STAT_GREEN_BYTES) + counter_ids.append(SAI_POLICER_STAT_YELLOW_PACKETS) + counter_ids.append(SAI_POLICER_STAT_YELLOW_BYTES) + counter_ids.append(SAI_POLICER_STAT_RED_PACKETS) + counter_ids.append(SAI_POLICER_STAT_RED_BYTES) + counter_ids.append(SAI_POLICER_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 9 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_policer_stats(policer_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_POLICER_STAT_PACKETS"] = counters[0] + stats["SAI_POLICER_STAT_ATTR_BYTES"] = counters[1] + stats["SAI_POLICER_STAT_GREEN_PACKETS"] = counters[2] + stats["SAI_POLICER_STAT_GREEN_BYTES"] = counters[3] + stats["SAI_POLICER_STAT_YELLOW_PACKETS"] = counters[4] + stats["SAI_POLICER_STAT_YELLOW_BYTES"] = counters[5] + stats["SAI_POLICER_STAT_RED_PACKETS"] = counters[6] + stats["SAI_POLICER_STAT_RED_BYTES"] = counters[7] + stats["SAI_POLICER_STAT_CUSTOM_RANGE_BASE"] = counters[8] + + return stats + + +def sai_thrift_get_policer_stats_ext(client, + policer_oid, + mode): + """ + sai_get_policer_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + policer_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_POLICER_STAT_PACKETS) + counter_ids.append(SAI_POLICER_STAT_ATTR_BYTES) + counter_ids.append(SAI_POLICER_STAT_GREEN_PACKETS) + counter_ids.append(SAI_POLICER_STAT_GREEN_BYTES) + counter_ids.append(SAI_POLICER_STAT_YELLOW_PACKETS) + counter_ids.append(SAI_POLICER_STAT_YELLOW_BYTES) + counter_ids.append(SAI_POLICER_STAT_RED_PACKETS) + counter_ids.append(SAI_POLICER_STAT_RED_BYTES) + counter_ids.append(SAI_POLICER_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 9 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_policer_stats_ext(policer_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_POLICER_STAT_PACKETS"] = counters[0] + stats["SAI_POLICER_STAT_ATTR_BYTES"] = counters[1] + stats["SAI_POLICER_STAT_GREEN_PACKETS"] = counters[2] + stats["SAI_POLICER_STAT_GREEN_BYTES"] = counters[3] + stats["SAI_POLICER_STAT_YELLOW_PACKETS"] = counters[4] + stats["SAI_POLICER_STAT_YELLOW_BYTES"] = counters[5] + stats["SAI_POLICER_STAT_RED_PACKETS"] = counters[6] + stats["SAI_POLICER_STAT_RED_BYTES"] = counters[7] + stats["SAI_POLICER_STAT_CUSTOM_RANGE_BASE"] = counters[8] + + return stats + + +def sai_thrift_clear_policer_stats(client, + policer_oid): + """ + sai_clear_policer_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + policer_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_POLICER_STAT_PACKETS) + counter_ids.append(SAI_POLICER_STAT_ATTR_BYTES) + counter_ids.append(SAI_POLICER_STAT_GREEN_PACKETS) + counter_ids.append(SAI_POLICER_STAT_GREEN_BYTES) + counter_ids.append(SAI_POLICER_STAT_YELLOW_PACKETS) + counter_ids.append(SAI_POLICER_STAT_YELLOW_BYTES) + counter_ids.append(SAI_POLICER_STAT_RED_PACKETS) + counter_ids.append(SAI_POLICER_STAT_RED_BYTES) + counter_ids.append(SAI_POLICER_STAT_CUSTOM_RANGE_BASE) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_policer_stats(policer_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# port API + +def sai_thrift_create_port(client, + hw_lane_list=None, + speed=None, + full_duplex_mode=None, + auto_neg_mode=None, + admin_state=None, + media_type=None, + advertised_speed=None, + advertised_fec_mode=None, + advertised_fec_mode_extended=None, + advertised_half_duplex_speed=None, + advertised_auto_neg_mode=None, + advertised_flow_control_mode=None, + advertised_asymmetric_pause_mode=None, + advertised_media_type=None, + advertised_oui_code=None, + port_vlan_id=None, + default_vlan_priority=None, + drop_untagged=None, + drop_tagged=None, + internal_loopback_mode=None, + use_extended_fec=None, + fec_mode=None, + fec_mode_extended=None, + update_dscp=None, + mtu=None, + flood_storm_control_policer_id=None, + broadcast_storm_control_policer_id=None, + multicast_storm_control_policer_id=None, + global_flow_control_mode=None, + ingress_acl=None, + egress_acl=None, + ingress_macsec_acl=None, + egress_macsec_acl=None, + ingress_mirror_session=None, + egress_mirror_session=None, + ingress_samplepacket_enable=None, + egress_samplepacket_enable=None, + ingress_sample_mirror_session=None, + egress_sample_mirror_session=None, + policer_id=None, + qos_default_tc=None, + qos_dot1p_to_tc_map=None, + qos_dot1p_to_color_map=None, + qos_dscp_to_tc_map=None, + qos_dscp_to_color_map=None, + qos_tc_to_queue_map=None, + qos_tc_and_color_to_dot1p_map=None, + qos_tc_and_color_to_dscp_map=None, + qos_tc_to_priority_group_map=None, + qos_pfc_priority_to_priority_group_map=None, + qos_pfc_priority_to_queue_map=None, + qos_scheduler_profile_id=None, + qos_ingress_buffer_profile_list=None, + qos_egress_buffer_profile_list=None, + priority_flow_control_mode=None, + priority_flow_control=None, + priority_flow_control_rx=None, + priority_flow_control_tx=None, + meta_data=None, + egress_block_port_list=None, + hw_profile_id=None, + eee_enable=None, + eee_idle_time=None, + eee_wake_time=None, + isolation_group=None, + pkt_tx_enable=None, + tam_object=None, + serdes_preemphasis=None, + serdes_idriver=None, + serdes_ipredriver=None, + link_training_enable=None, + ptp_mode=None, + interface_type=None, + advertised_interface_type=None, + reference_clock=None, + prbs_polynomial=None, + prbs_config=None, + disable_decrement_ttl=None, + qos_mpls_exp_to_tc_map=None, + qos_mpls_exp_to_color_map=None, + qos_tc_and_color_to_mpls_exp_map=None, + tpid=None, + auto_neg_fec_mode_override=None, + loopback_mode=None, + mdix_mode_config=None, + auto_neg_config_mode=None, + _1000x_sgmii_slave_autodetect=None, + module_type=None, + dual_media=None, + ipg=None, + global_flow_control_forward=None, + priority_flow_control_forward=None, + qos_dscp_to_forwarding_class_map=None, + qos_mpls_exp_to_forwarding_class_map=None, + pfc_tc_dld_interval=None, + pfc_tc_dlr_interval=None, + custom_attribute=None): + """ + sai_create_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of port CREATE attributes. + + Returns: + sai_thrift_object_id_t: port_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if hw_lane_list is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=hw_lane_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_HW_LANE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32=speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if full_duplex_mode is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=full_duplex_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FULL_DUPLEX_MODE, + value=attribute_value) + attr_list.append(attribute) + + if auto_neg_mode is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=auto_neg_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_MODE, + value=attribute_value) + attr_list.append(attribute) + + if admin_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_state) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADMIN_STATE, + value=attribute_value) + attr_list.append(attribute) + + if media_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=media_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MEDIA_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=advertised_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if advertised_fec_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=advertised_fec_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FEC_MODE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_fec_mode_extended is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=advertised_fec_mode_extended) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FEC_MODE_EXTENDED, + value=attribute_value) + attr_list.append(attribute) + + if advertised_half_duplex_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=advertised_half_duplex_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_HALF_DUPLEX_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if advertised_auto_neg_mode is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=advertised_auto_neg_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_AUTO_NEG_MODE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_flow_control_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=advertised_flow_control_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FLOW_CONTROL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_asymmetric_pause_mode is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=advertised_asymmetric_pause_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_ASYMMETRIC_PAUSE_MODE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_media_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=advertised_media_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_MEDIA_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_oui_code is not None: + attribute_value = sai_thrift_attribute_value_t(u32=advertised_oui_code) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_OUI_CODE, + value=attribute_value) + attr_list.append(attribute) + + if port_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=port_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PORT_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if default_vlan_priority is not None: + attribute_value = sai_thrift_attribute_value_t(u8=default_vlan_priority) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if drop_untagged is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=drop_untagged) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DROP_UNTAGGED, + value=attribute_value) + attr_list.append(attribute) + + if drop_tagged is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=drop_tagged) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DROP_TAGGED, + value=attribute_value) + attr_list.append(attribute) + + if internal_loopback_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=internal_loopback_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INTERNAL_LOOPBACK_MODE, + value=attribute_value) + attr_list.append(attribute) + + if use_extended_fec is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=use_extended_fec) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_USE_EXTENDED_FEC, + value=attribute_value) + attr_list.append(attribute) + + if fec_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fec_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FEC_MODE, + value=attribute_value) + attr_list.append(attribute) + + if fec_mode_extended is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fec_mode_extended) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FEC_MODE_EXTENDED, + value=attribute_value) + attr_list.append(attribute) + + if update_dscp is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=update_dscp) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_UPDATE_DSCP, + value=attribute_value) + attr_list.append(attribute) + + if mtu is not None: + attribute_value = sai_thrift_attribute_value_t(u32=mtu) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MTU, + value=attribute_value) + attr_list.append(attribute) + + if flood_storm_control_policer_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=flood_storm_control_policer_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID, + value=attribute_value) + attr_list.append(attribute) + + if broadcast_storm_control_policer_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=broadcast_storm_control_policer_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID, + value=attribute_value) + attr_list.append(attribute) + + if multicast_storm_control_policer_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=multicast_storm_control_policer_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID, + value=attribute_value) + attr_list.append(attribute) + + if global_flow_control_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=global_flow_control_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if egress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_acl) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if ingress_macsec_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_macsec_acl) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_MACSEC_ACL, + value=attribute_value) + attr_list.append(attribute) + + if egress_macsec_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_macsec_acl) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_MACSEC_ACL, + value=attribute_value) + attr_list.append(attribute) + + if ingress_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ingress_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if egress_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=egress_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if ingress_samplepacket_enable is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_samplepacket_enable) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if egress_samplepacket_enable is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_samplepacket_enable) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if ingress_sample_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ingress_sample_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if egress_sample_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=egress_sample_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_SAMPLE_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if policer_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=policer_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_POLICER_ID, + value=attribute_value) + attr_list.append(attribute) + + if qos_default_tc is not None: + attribute_value = sai_thrift_attribute_value_t(u8=qos_default_tc) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DEFAULT_TC, + value=attribute_value) + attr_list.append(attribute) + + if qos_dot1p_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DOT1P_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_dot1p_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DOT1P_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_dscp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_dscp_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_to_queue_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_to_queue_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_TO_QUEUE_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_dot1p_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dot1p_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_dscp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dscp_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_to_priority_group_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_to_priority_group_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_TO_PRIORITY_GROUP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_pfc_priority_to_priority_group_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_pfc_priority_to_priority_group_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_pfc_priority_to_queue_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_pfc_priority_to_queue_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_QUEUE_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_scheduler_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_scheduler_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_SCHEDULER_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if qos_ingress_buffer_profile_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_ingress_buffer_profile_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_INGRESS_BUFFER_PROFILE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_egress_buffer_profile_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_egress_buffer_profile_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_EGRESS_BUFFER_PROFILE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if priority_flow_control_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=priority_flow_control_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if priority_flow_control is not None: + attribute_value = sai_thrift_attribute_value_t(u8=priority_flow_control) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL, + value=attribute_value) + attr_list.append(attribute) + + if priority_flow_control_rx is not None: + attribute_value = sai_thrift_attribute_value_t(u8=priority_flow_control_rx) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX, + value=attribute_value) + attr_list.append(attribute) + + if priority_flow_control_tx is not None: + attribute_value = sai_thrift_attribute_value_t(u8=priority_flow_control_tx) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX, + value=attribute_value) + attr_list.append(attribute) + + if meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(u32=meta_data) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if egress_block_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=egress_block_port_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_BLOCK_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if hw_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(u64=hw_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_HW_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if eee_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=eee_enable) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if eee_idle_time is not None: + attribute_value = sai_thrift_attribute_value_t(u16=eee_idle_time) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_IDLE_TIME, + value=attribute_value) + attr_list.append(attribute) + + if eee_wake_time is not None: + attribute_value = sai_thrift_attribute_value_t(u16=eee_wake_time) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_WAKE_TIME, + value=attribute_value) + attr_list.append(attribute) + + if isolation_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=isolation_group) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ISOLATION_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if pkt_tx_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=pkt_tx_enable) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PKT_TX_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if tam_object is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TAM_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if serdes_preemphasis is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=serdes_preemphasis) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_PREEMPHASIS, + value=attribute_value) + attr_list.append(attribute) + + if serdes_idriver is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=serdes_idriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_IDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if serdes_ipredriver is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=serdes_ipredriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_IPREDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if link_training_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=link_training_enable) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LINK_TRAINING_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if ptp_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ptp_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PTP_MODE, + value=attribute_value) + attr_list.append(attribute) + + if interface_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=interface_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INTERFACE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_interface_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=advertised_interface_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_INTERFACE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if reference_clock is not None: + attribute_value = sai_thrift_attribute_value_t(u64=reference_clock) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REFERENCE_CLOCK, + value=attribute_value) + attr_list.append(attribute) + + if prbs_polynomial is not None: + attribute_value = sai_thrift_attribute_value_t(u32=prbs_polynomial) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_POLYNOMIAL, + value=attribute_value) + attr_list.append(attribute) + + if prbs_config is not None: + attribute_value = sai_thrift_attribute_value_t(s32=prbs_config) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_CONFIG, + value=attribute_value) + attr_list.append(attribute) + + if disable_decrement_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=disable_decrement_ttl) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DISABLE_DECREMENT_TTL, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_mpls_exp_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=tpid) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TPID, + value=attribute_value) + attr_list.append(attribute) + + if auto_neg_fec_mode_override is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=auto_neg_fec_mode_override) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE, + value=attribute_value) + attr_list.append(attribute) + + if loopback_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=loopback_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LOOPBACK_MODE, + value=attribute_value) + attr_list.append(attribute) + + if mdix_mode_config is not None: + attribute_value = sai_thrift_attribute_value_t(s32=mdix_mode_config) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MDIX_MODE_CONFIG, + value=attribute_value) + attr_list.append(attribute) + + if auto_neg_config_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=auto_neg_config_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_CONFIG_MODE, + value=attribute_value) + attr_list.append(attribute) + + if _1000x_sgmii_slave_autodetect is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=_1000x_sgmii_slave_autodetect) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_1000X_SGMII_SLAVE_AUTODETECT, + value=attribute_value) + attr_list.append(attribute) + + if module_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=module_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MODULE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if dual_media is not None: + attribute_value = sai_thrift_attribute_value_t(s32=dual_media) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DUAL_MEDIA, + value=attribute_value) + attr_list.append(attribute) + + if ipg is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ipg) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_IPG, + value=attribute_value) + attr_list.append(attribute) + + if global_flow_control_forward is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=global_flow_control_forward) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_FORWARD, + value=attribute_value) + attr_list.append(attribute) + + if priority_flow_control_forward is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=priority_flow_control_forward) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_FORWARD, + value=attribute_value) + attr_list.append(attribute) + + if qos_dscp_to_forwarding_class_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_forwarding_class_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_forwarding_class_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_forwarding_class_map) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP, + value=attribute_value) + attr_list.append(attribute) + + if pfc_tc_dld_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dld_interval) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if pfc_tc_dlr_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dlr_interval) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_port(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_port(client, + port_oid): + """ + sai_remove_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_port(port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_port_attribute(client, + port_oid, + speed=None, + auto_neg_mode=None, + admin_state=None, + media_type=None, + advertised_speed=None, + advertised_fec_mode=None, + advertised_fec_mode_extended=None, + advertised_half_duplex_speed=None, + advertised_auto_neg_mode=None, + advertised_flow_control_mode=None, + advertised_asymmetric_pause_mode=None, + advertised_media_type=None, + advertised_oui_code=None, + port_vlan_id=None, + default_vlan_priority=None, + drop_untagged=None, + drop_tagged=None, + internal_loopback_mode=None, + use_extended_fec=None, + fec_mode=None, + fec_mode_extended=None, + update_dscp=None, + mtu=None, + flood_storm_control_policer_id=None, + broadcast_storm_control_policer_id=None, + multicast_storm_control_policer_id=None, + global_flow_control_mode=None, + ingress_acl=None, + egress_acl=None, + ingress_macsec_acl=None, + egress_macsec_acl=None, + ingress_mirror_session=None, + egress_mirror_session=None, + ingress_samplepacket_enable=None, + egress_samplepacket_enable=None, + ingress_sample_mirror_session=None, + egress_sample_mirror_session=None, + policer_id=None, + qos_default_tc=None, + qos_dot1p_to_tc_map=None, + qos_dot1p_to_color_map=None, + qos_dscp_to_tc_map=None, + qos_dscp_to_color_map=None, + qos_tc_to_queue_map=None, + qos_tc_and_color_to_dot1p_map=None, + qos_tc_and_color_to_dscp_map=None, + qos_tc_to_priority_group_map=None, + qos_pfc_priority_to_priority_group_map=None, + qos_pfc_priority_to_queue_map=None, + qos_scheduler_profile_id=None, + qos_ingress_buffer_profile_list=None, + qos_egress_buffer_profile_list=None, + priority_flow_control_mode=None, + priority_flow_control=None, + priority_flow_control_rx=None, + priority_flow_control_tx=None, + meta_data=None, + egress_block_port_list=None, + hw_profile_id=None, + eee_enable=None, + eee_idle_time=None, + eee_wake_time=None, + isolation_group=None, + pkt_tx_enable=None, + tam_object=None, + serdes_preemphasis=None, + serdes_idriver=None, + serdes_ipredriver=None, + link_training_enable=None, + ptp_mode=None, + interface_type=None, + advertised_interface_type=None, + prbs_polynomial=None, + prbs_config=None, + disable_decrement_ttl=None, + qos_mpls_exp_to_tc_map=None, + qos_mpls_exp_to_color_map=None, + qos_tc_and_color_to_mpls_exp_map=None, + tpid=None, + auto_neg_fec_mode_override=None, + loopback_mode=None, + mdix_mode_config=None, + auto_neg_config_mode=None, + _1000x_sgmii_slave_autodetect=None, + module_type=None, + dual_media=None, + ipg=None, + global_flow_control_forward=None, + priority_flow_control_forward=None, + qos_dscp_to_forwarding_class_map=None, + qos_mpls_exp_to_forwarding_class_map=None, + pfc_tc_dld_interval=None, + pfc_tc_dlr_interval=None, + custom_attribute=None): + """ + sai_set_port_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if speed is not None: + attr_value = sai_thrift_attribute_value_t(u32=speed) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SPEED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if auto_neg_mode is not None: + attr_value = sai_thrift_attribute_value_t(booldata=auto_neg_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if admin_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_state) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADMIN_STATE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if media_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=media_type) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MEDIA_TYPE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_speed is not None: + attr_value = sai_thrift_attribute_value_t(u32list=advertised_speed) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_SPEED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_fec_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32list=advertised_fec_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FEC_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_fec_mode_extended is not None: + attr_value = sai_thrift_attribute_value_t(s32list=advertised_fec_mode_extended) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FEC_MODE_EXTENDED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_half_duplex_speed is not None: + attr_value = sai_thrift_attribute_value_t(u32list=advertised_half_duplex_speed) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_HALF_DUPLEX_SPEED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_auto_neg_mode is not None: + attr_value = sai_thrift_attribute_value_t(booldata=advertised_auto_neg_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_AUTO_NEG_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_flow_control_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=advertised_flow_control_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FLOW_CONTROL_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_asymmetric_pause_mode is not None: + attr_value = sai_thrift_attribute_value_t(booldata=advertised_asymmetric_pause_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_ASYMMETRIC_PAUSE_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_media_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=advertised_media_type) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_MEDIA_TYPE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_oui_code is not None: + attr_value = sai_thrift_attribute_value_t(u32=advertised_oui_code) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_OUI_CODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if port_vlan_id is not None: + attr_value = sai_thrift_attribute_value_t(u16=port_vlan_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PORT_VLAN_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if default_vlan_priority is not None: + attr_value = sai_thrift_attribute_value_t(u8=default_vlan_priority) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if drop_untagged is not None: + attr_value = sai_thrift_attribute_value_t(booldata=drop_untagged) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DROP_UNTAGGED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if drop_tagged is not None: + attr_value = sai_thrift_attribute_value_t(booldata=drop_tagged) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DROP_TAGGED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if internal_loopback_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=internal_loopback_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INTERNAL_LOOPBACK_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if use_extended_fec is not None: + attr_value = sai_thrift_attribute_value_t(booldata=use_extended_fec) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_USE_EXTENDED_FEC, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if fec_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=fec_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FEC_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if fec_mode_extended is not None: + attr_value = sai_thrift_attribute_value_t(s32=fec_mode_extended) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FEC_MODE_EXTENDED, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if update_dscp is not None: + attr_value = sai_thrift_attribute_value_t(booldata=update_dscp) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_UPDATE_DSCP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if mtu is not None: + attr_value = sai_thrift_attribute_value_t(u32=mtu) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MTU, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if flood_storm_control_policer_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=flood_storm_control_policer_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if broadcast_storm_control_policer_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=broadcast_storm_control_policer_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if multicast_storm_control_policer_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=multicast_storm_control_policer_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if global_flow_control_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=global_flow_control_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ingress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_ACL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if egress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_acl) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_ACL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ingress_macsec_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_macsec_acl) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_MACSEC_ACL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if egress_macsec_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_macsec_acl) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_MACSEC_ACL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ingress_mirror_session is not None: + attr_value = sai_thrift_attribute_value_t(objlist=ingress_mirror_session) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_MIRROR_SESSION, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if egress_mirror_session is not None: + attr_value = sai_thrift_attribute_value_t(objlist=egress_mirror_session) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_MIRROR_SESSION, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ingress_samplepacket_enable is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_samplepacket_enable) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if egress_samplepacket_enable is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_samplepacket_enable) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ingress_sample_mirror_session is not None: + attr_value = sai_thrift_attribute_value_t(objlist=ingress_sample_mirror_session) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSION, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if egress_sample_mirror_session is not None: + attr_value = sai_thrift_attribute_value_t(objlist=egress_sample_mirror_session) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_SAMPLE_MIRROR_SESSION, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if policer_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=policer_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_POLICER_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_default_tc is not None: + attr_value = sai_thrift_attribute_value_t(u8=qos_default_tc) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DEFAULT_TC, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_dot1p_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DOT1P_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_dot1p_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DOT1P_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_dscp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_dscp_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_tc_to_queue_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_to_queue_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_TO_QUEUE_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_tc_and_color_to_dot1p_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dot1p_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_tc_and_color_to_dscp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dscp_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_tc_to_priority_group_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_to_priority_group_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_TO_PRIORITY_GROUP_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_pfc_priority_to_priority_group_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_pfc_priority_to_priority_group_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_pfc_priority_to_queue_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_pfc_priority_to_queue_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_QUEUE_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_scheduler_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_scheduler_profile_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_SCHEDULER_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_ingress_buffer_profile_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=qos_ingress_buffer_profile_list) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_INGRESS_BUFFER_PROFILE_LIST, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_egress_buffer_profile_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=qos_egress_buffer_profile_list) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_EGRESS_BUFFER_PROFILE_LIST, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if priority_flow_control_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=priority_flow_control_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if priority_flow_control is not None: + attr_value = sai_thrift_attribute_value_t(u8=priority_flow_control) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if priority_flow_control_rx is not None: + attr_value = sai_thrift_attribute_value_t(u8=priority_flow_control_rx) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if priority_flow_control_tx is not None: + attr_value = sai_thrift_attribute_value_t(u8=priority_flow_control_tx) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if meta_data is not None: + attr_value = sai_thrift_attribute_value_t(u32=meta_data) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_META_DATA, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if egress_block_port_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=egress_block_port_list) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_BLOCK_PORT_LIST, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if hw_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(u64=hw_profile_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_HW_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if eee_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=eee_enable) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_ENABLE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if eee_idle_time is not None: + attr_value = sai_thrift_attribute_value_t(u16=eee_idle_time) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_IDLE_TIME, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if eee_wake_time is not None: + attr_value = sai_thrift_attribute_value_t(u16=eee_wake_time) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_WAKE_TIME, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if isolation_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=isolation_group) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ISOLATION_GROUP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if pkt_tx_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=pkt_tx_enable) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PKT_TX_ENABLE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if tam_object is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam_object) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TAM_OBJECT, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if serdes_preemphasis is not None: + attr_value = sai_thrift_attribute_value_t(u32list=serdes_preemphasis) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_PREEMPHASIS, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if serdes_idriver is not None: + attr_value = sai_thrift_attribute_value_t(u32list=serdes_idriver) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_IDRIVER, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if serdes_ipredriver is not None: + attr_value = sai_thrift_attribute_value_t(u32list=serdes_ipredriver) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_IPREDRIVER, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if link_training_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=link_training_enable) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LINK_TRAINING_ENABLE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ptp_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=ptp_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PTP_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if interface_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=interface_type) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INTERFACE_TYPE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if advertised_interface_type is not None: + attr_value = sai_thrift_attribute_value_t(s32list=advertised_interface_type) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_INTERFACE_TYPE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if prbs_polynomial is not None: + attr_value = sai_thrift_attribute_value_t(u32=prbs_polynomial) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_POLYNOMIAL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if prbs_config is not None: + attr_value = sai_thrift_attribute_value_t(s32=prbs_config) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_CONFIG, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if disable_decrement_ttl is not None: + attr_value = sai_thrift_attribute_value_t(booldata=disable_decrement_ttl) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DISABLE_DECREMENT_TTL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_mpls_exp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_mpls_exp_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_mpls_exp_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=tpid) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TPID, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if auto_neg_fec_mode_override is not None: + attr_value = sai_thrift_attribute_value_t(booldata=auto_neg_fec_mode_override) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if loopback_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=loopback_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LOOPBACK_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if mdix_mode_config is not None: + attr_value = sai_thrift_attribute_value_t(s32=mdix_mode_config) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MDIX_MODE_CONFIG, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if auto_neg_config_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=auto_neg_config_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_CONFIG_MODE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if _1000x_sgmii_slave_autodetect is not None: + attr_value = sai_thrift_attribute_value_t(booldata=_1000x_sgmii_slave_autodetect) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_1000X_SGMII_SLAVE_AUTODETECT, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if module_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=module_type) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MODULE_TYPE, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if dual_media is not None: + attr_value = sai_thrift_attribute_value_t(s32=dual_media) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DUAL_MEDIA, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if ipg is not None: + attr_value = sai_thrift_attribute_value_t(u32=ipg) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_IPG, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if global_flow_control_forward is not None: + attr_value = sai_thrift_attribute_value_t(booldata=global_flow_control_forward) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_FORWARD, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if priority_flow_control_forward is not None: + attr_value = sai_thrift_attribute_value_t(booldata=priority_flow_control_forward) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_FORWARD, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_dscp_to_forwarding_class_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_forwarding_class_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if qos_mpls_exp_to_forwarding_class_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_forwarding_class_map) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if pfc_tc_dld_interval is not None: + attr_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dld_interval) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if pfc_tc_dlr_interval is not None: + attr_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dlr_interval) + attr = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL, + value=attr_value) + client.sai_thrift_set_port_attribute(port_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_port_attribute(port_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_port_attribute(client, + port_oid, + type=None, + oper_status=None, + supported_breakout_mode_type=None, + current_breakout_mode_type=None, + qos_number_of_queues=None, + qos_queue_list=None, + qos_number_of_scheduler_groups=None, + qos_scheduler_group_list=None, + qos_maximum_headroom_size=None, + supported_speed=None, + supported_fec_mode=None, + supported_fec_mode_extended=None, + supported_half_duplex_speed=None, + supported_auto_neg_mode=None, + supported_flow_control_mode=None, + supported_asymmetric_pause_mode=None, + supported_media_type=None, + remote_advertised_speed=None, + remote_advertised_fec_mode=None, + remote_advertised_fec_mode_extended=None, + remote_advertised_half_duplex_speed=None, + remote_advertised_auto_neg_mode=None, + remote_advertised_flow_control_mode=None, + remote_advertised_asymmetric_pause_mode=None, + remote_advertised_media_type=None, + remote_advertised_oui_code=None, + number_of_ingress_priority_groups=None, + ingress_priority_group_list=None, + eye_values=None, + oper_speed=None, + hw_lane_list=None, + speed=None, + full_duplex_mode=None, + auto_neg_mode=None, + admin_state=None, + media_type=None, + advertised_speed=None, + advertised_fec_mode=None, + advertised_fec_mode_extended=None, + advertised_half_duplex_speed=None, + advertised_auto_neg_mode=None, + advertised_flow_control_mode=None, + advertised_asymmetric_pause_mode=None, + advertised_media_type=None, + advertised_oui_code=None, + port_vlan_id=None, + default_vlan_priority=None, + drop_untagged=None, + drop_tagged=None, + internal_loopback_mode=None, + use_extended_fec=None, + fec_mode=None, + fec_mode_extended=None, + update_dscp=None, + mtu=None, + flood_storm_control_policer_id=None, + broadcast_storm_control_policer_id=None, + multicast_storm_control_policer_id=None, + global_flow_control_mode=None, + ingress_acl=None, + egress_acl=None, + ingress_macsec_acl=None, + egress_macsec_acl=None, + macsec_port_list=None, + ingress_mirror_session=None, + egress_mirror_session=None, + ingress_samplepacket_enable=None, + egress_samplepacket_enable=None, + ingress_sample_mirror_session=None, + egress_sample_mirror_session=None, + policer_id=None, + qos_default_tc=None, + qos_dot1p_to_tc_map=None, + qos_dot1p_to_color_map=None, + qos_dscp_to_tc_map=None, + qos_dscp_to_color_map=None, + qos_tc_to_queue_map=None, + qos_tc_and_color_to_dot1p_map=None, + qos_tc_and_color_to_dscp_map=None, + qos_tc_to_priority_group_map=None, + qos_pfc_priority_to_priority_group_map=None, + qos_pfc_priority_to_queue_map=None, + qos_scheduler_profile_id=None, + qos_ingress_buffer_profile_list=None, + qos_egress_buffer_profile_list=None, + priority_flow_control_mode=None, + priority_flow_control=None, + priority_flow_control_rx=None, + priority_flow_control_tx=None, + meta_data=None, + egress_block_port_list=None, + hw_profile_id=None, + eee_enable=None, + eee_idle_time=None, + eee_wake_time=None, + port_pool_list=None, + isolation_group=None, + pkt_tx_enable=None, + tam_object=None, + serdes_preemphasis=None, + serdes_idriver=None, + serdes_ipredriver=None, + link_training_enable=None, + ptp_mode=None, + interface_type=None, + advertised_interface_type=None, + reference_clock=None, + prbs_polynomial=None, + port_serdes_id=None, + link_training_failure_status=None, + link_training_rx_status=None, + prbs_config=None, + prbs_lock_status=None, + prbs_lock_loss_status=None, + prbs_rx_status=None, + prbs_rx_state=None, + auto_neg_status=None, + disable_decrement_ttl=None, + qos_mpls_exp_to_tc_map=None, + qos_mpls_exp_to_color_map=None, + qos_tc_and_color_to_mpls_exp_map=None, + tpid=None, + err_status_list=None, + fabric_attached=None, + fabric_attached_switch_type=None, + fabric_attached_switch_id=None, + fabric_attached_port_index=None, + fabric_reachability=None, + system_port=None, + auto_neg_fec_mode_override=None, + loopback_mode=None, + mdix_mode_status=None, + mdix_mode_config=None, + auto_neg_config_mode=None, + _1000x_sgmii_slave_autodetect=None, + module_type=None, + dual_media=None, + auto_neg_fec_mode_extended=None, + ipg=None, + global_flow_control_forward=None, + priority_flow_control_forward=None, + qos_dscp_to_forwarding_class_map=None, + qos_mpls_exp_to_forwarding_class_map=None, + ipsec_port=None, + pfc_tc_dld_interval_range=None, + pfc_tc_dld_interval=None, + pfc_tc_dlr_interval_range=None, + pfc_tc_dlr_interval=None, + custom_attribute=None): + """ + sai_get_port_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TYPE) + attr_list.append(attribute) + + if oper_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_OPER_STATUS) + attr_list.append(attribute) + + if supported_breakout_mode_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_breakout_mode_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_BREAKOUT_MODE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if current_breakout_mode_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_CURRENT_BREAKOUT_MODE_TYPE) + attr_list.append(attribute) + + if qos_number_of_queues is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_NUMBER_OF_QUEUES) + attr_list.append(attribute) + + if qos_queue_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_queue_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_QUEUE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_number_of_scheduler_groups is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_NUMBER_OF_SCHEDULER_GROUPS) + attr_list.append(attribute) + + if qos_scheduler_group_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_scheduler_group_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_SCHEDULER_GROUP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_maximum_headroom_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MAXIMUM_HEADROOM_SIZE) + attr_list.append(attribute) + + if supported_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=supported_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if supported_fec_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_fec_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_FEC_MODE, + value=attribute_value) + attr_list.append(attribute) + + if supported_fec_mode_extended is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_fec_mode_extended) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_FEC_MODE_EXTENDED, + value=attribute_value) + attr_list.append(attribute) + + if supported_half_duplex_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=supported_half_duplex_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_HALF_DUPLEX_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if supported_auto_neg_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_AUTO_NEG_MODE) + attr_list.append(attribute) + + if supported_flow_control_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_FLOW_CONTROL_MODE) + attr_list.append(attribute) + + if supported_asymmetric_pause_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_ASYMMETRIC_PAUSE_MODE) + attr_list.append(attribute) + + if supported_media_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SUPPORTED_MEDIA_TYPE) + attr_list.append(attribute) + + if remote_advertised_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=remote_advertised_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if remote_advertised_fec_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=remote_advertised_fec_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_FEC_MODE, + value=attribute_value) + attr_list.append(attribute) + + if remote_advertised_fec_mode_extended is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=remote_advertised_fec_mode_extended) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_FEC_MODE_EXTENDED, + value=attribute_value) + attr_list.append(attribute) + + if remote_advertised_half_duplex_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=remote_advertised_half_duplex_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_HALF_DUPLEX_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if remote_advertised_auto_neg_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_AUTO_NEG_MODE) + attr_list.append(attribute) + + if remote_advertised_flow_control_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_FLOW_CONTROL_MODE) + attr_list.append(attribute) + + if remote_advertised_asymmetric_pause_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_ASYMMETRIC_PAUSE_MODE) + attr_list.append(attribute) + + if remote_advertised_media_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_MEDIA_TYPE) + attr_list.append(attribute) + + if remote_advertised_oui_code is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REMOTE_ADVERTISED_OUI_CODE) + attr_list.append(attribute) + + if number_of_ingress_priority_groups is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_NUMBER_OF_INGRESS_PRIORITY_GROUPS) + attr_list.append(attribute) + + if ingress_priority_group_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ingress_priority_group_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_PRIORITY_GROUP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if eye_values is not None: + attribute_value = sai_thrift_attribute_value_t(porteyevalues=eye_values) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EYE_VALUES, + value=attribute_value) + attr_list.append(attribute) + + if oper_speed is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_OPER_SPEED) + attr_list.append(attribute) + + if hw_lane_list is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=hw_lane_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_HW_LANE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if speed is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SPEED) + attr_list.append(attribute) + + if full_duplex_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FULL_DUPLEX_MODE) + attr_list.append(attribute) + + if auto_neg_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_MODE) + attr_list.append(attribute) + + if admin_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADMIN_STATE) + attr_list.append(attribute) + + if media_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MEDIA_TYPE) + attr_list.append(attribute) + + if advertised_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=advertised_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if advertised_fec_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=advertised_fec_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FEC_MODE, + value=attribute_value) + attr_list.append(attribute) + + if advertised_fec_mode_extended is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=advertised_fec_mode_extended) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FEC_MODE_EXTENDED, + value=attribute_value) + attr_list.append(attribute) + + if advertised_half_duplex_speed is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=advertised_half_duplex_speed) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_HALF_DUPLEX_SPEED, + value=attribute_value) + attr_list.append(attribute) + + if advertised_auto_neg_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_AUTO_NEG_MODE) + attr_list.append(attribute) + + if advertised_flow_control_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_FLOW_CONTROL_MODE) + attr_list.append(attribute) + + if advertised_asymmetric_pause_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_ASYMMETRIC_PAUSE_MODE) + attr_list.append(attribute) + + if advertised_media_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_MEDIA_TYPE) + attr_list.append(attribute) + + if advertised_oui_code is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_OUI_CODE) + attr_list.append(attribute) + + if port_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PORT_VLAN_ID) + attr_list.append(attribute) + + if default_vlan_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY) + attr_list.append(attribute) + + if drop_untagged is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DROP_UNTAGGED) + attr_list.append(attribute) + + if drop_tagged is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DROP_TAGGED) + attr_list.append(attribute) + + if internal_loopback_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INTERNAL_LOOPBACK_MODE) + attr_list.append(attribute) + + if use_extended_fec is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_USE_EXTENDED_FEC) + attr_list.append(attribute) + + if fec_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FEC_MODE) + attr_list.append(attribute) + + if fec_mode_extended is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FEC_MODE_EXTENDED) + attr_list.append(attribute) + + if update_dscp is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_UPDATE_DSCP) + attr_list.append(attribute) + + if mtu is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MTU) + attr_list.append(attribute) + + if flood_storm_control_policer_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID) + attr_list.append(attribute) + + if broadcast_storm_control_policer_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID) + attr_list.append(attribute) + + if multicast_storm_control_policer_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID) + attr_list.append(attribute) + + if global_flow_control_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_MODE) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_ACL) + attr_list.append(attribute) + + if egress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_ACL) + attr_list.append(attribute) + + if ingress_macsec_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_MACSEC_ACL) + attr_list.append(attribute) + + if egress_macsec_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_MACSEC_ACL) + attr_list.append(attribute) + + if macsec_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=macsec_port_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MACSEC_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if ingress_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ingress_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if egress_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=egress_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if ingress_samplepacket_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE) + attr_list.append(attribute) + + if egress_samplepacket_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE) + attr_list.append(attribute) + + if ingress_sample_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ingress_sample_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if egress_sample_mirror_session is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=egress_sample_mirror_session) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_SAMPLE_MIRROR_SESSION, + value=attribute_value) + attr_list.append(attribute) + + if policer_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_POLICER_ID) + attr_list.append(attribute) + + if qos_default_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DEFAULT_TC) + attr_list.append(attribute) + + if qos_dot1p_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DOT1P_TO_TC_MAP) + attr_list.append(attribute) + + if qos_dot1p_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DOT1P_TO_COLOR_MAP) + attr_list.append(attribute) + + if qos_dscp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_TC_MAP) + attr_list.append(attribute) + + if qos_dscp_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_COLOR_MAP) + attr_list.append(attribute) + + if qos_tc_to_queue_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_TO_QUEUE_MAP) + attr_list.append(attribute) + + if qos_tc_and_color_to_dot1p_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP) + attr_list.append(attribute) + + if qos_tc_and_color_to_dscp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP) + attr_list.append(attribute) + + if qos_tc_to_priority_group_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_TO_PRIORITY_GROUP_MAP) + attr_list.append(attribute) + + if qos_pfc_priority_to_priority_group_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP) + attr_list.append(attribute) + + if qos_pfc_priority_to_queue_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_QUEUE_MAP) + attr_list.append(attribute) + + if qos_scheduler_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_SCHEDULER_PROFILE_ID) + attr_list.append(attribute) + + if qos_ingress_buffer_profile_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_ingress_buffer_profile_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_INGRESS_BUFFER_PROFILE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_egress_buffer_profile_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_egress_buffer_profile_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_EGRESS_BUFFER_PROFILE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if priority_flow_control_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE) + attr_list.append(attribute) + + if priority_flow_control is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL) + attr_list.append(attribute) + + if priority_flow_control_rx is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX) + attr_list.append(attribute) + + if priority_flow_control_tx is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX) + attr_list.append(attribute) + + if meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_META_DATA) + attr_list.append(attribute) + + if egress_block_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=egress_block_port_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EGRESS_BLOCK_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if hw_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_HW_PROFILE_ID) + attr_list.append(attribute) + + if eee_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_ENABLE) + attr_list.append(attribute) + + if eee_idle_time is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_IDLE_TIME) + attr_list.append(attribute) + + if eee_wake_time is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_EEE_WAKE_TIME) + attr_list.append(attribute) + + if port_pool_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=port_pool_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PORT_POOL_LIST, + value=attribute_value) + attr_list.append(attribute) + + if isolation_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ISOLATION_GROUP) + attr_list.append(attribute) + + if pkt_tx_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PKT_TX_ENABLE) + attr_list.append(attribute) + + if tam_object is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TAM_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if serdes_preemphasis is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=serdes_preemphasis) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_PREEMPHASIS, + value=attribute_value) + attr_list.append(attribute) + + if serdes_idriver is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=serdes_idriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_IDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if serdes_ipredriver is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=serdes_ipredriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SERDES_IPREDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if link_training_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LINK_TRAINING_ENABLE) + attr_list.append(attribute) + + if ptp_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PTP_MODE) + attr_list.append(attribute) + + if interface_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_INTERFACE_TYPE) + attr_list.append(attribute) + + if advertised_interface_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=advertised_interface_type) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ADVERTISED_INTERFACE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if reference_clock is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_REFERENCE_CLOCK) + attr_list.append(attribute) + + if prbs_polynomial is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_POLYNOMIAL) + attr_list.append(attribute) + + if port_serdes_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PORT_SERDES_ID) + attr_list.append(attribute) + + if link_training_failure_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LINK_TRAINING_FAILURE_STATUS) + attr_list.append(attribute) + + if link_training_rx_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LINK_TRAINING_RX_STATUS) + attr_list.append(attribute) + + if prbs_config is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_CONFIG) + attr_list.append(attribute) + + if prbs_lock_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_LOCK_STATUS) + attr_list.append(attribute) + + if prbs_lock_loss_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_LOCK_LOSS_STATUS) + attr_list.append(attribute) + + if prbs_rx_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_RX_STATUS) + attr_list.append(attribute) + + if prbs_rx_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRBS_RX_STATE) + attr_list.append(attribute) + + if auto_neg_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_STATUS) + attr_list.append(attribute) + + if disable_decrement_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DISABLE_DECREMENT_TTL) + attr_list.append(attribute) + + if qos_mpls_exp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP) + attr_list.append(attribute) + + if qos_mpls_exp_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP) + attr_list.append(attribute) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP) + attr_list.append(attribute) + + if tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_TPID) + attr_list.append(attribute) + + if err_status_list is not None: + attribute_value = sai_thrift_attribute_value_t(porterror=err_status_list) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_ERR_STATUS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if fabric_attached is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FABRIC_ATTACHED) + attr_list.append(attribute) + + if fabric_attached_switch_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_TYPE) + attr_list.append(attribute) + + if fabric_attached_switch_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_ID) + attr_list.append(attribute) + + if fabric_attached_port_index is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX) + attr_list.append(attribute) + + if fabric_reachability is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_FABRIC_REACHABILITY) + attr_list.append(attribute) + + if system_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_SYSTEM_PORT) + attr_list.append(attribute) + + if auto_neg_fec_mode_override is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE) + attr_list.append(attribute) + + if loopback_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_LOOPBACK_MODE) + attr_list.append(attribute) + + if mdix_mode_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MDIX_MODE_STATUS) + attr_list.append(attribute) + + if mdix_mode_config is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MDIX_MODE_CONFIG) + attr_list.append(attribute) + + if auto_neg_config_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_CONFIG_MODE) + attr_list.append(attribute) + + if _1000x_sgmii_slave_autodetect is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_1000X_SGMII_SLAVE_AUTODETECT) + attr_list.append(attribute) + + if module_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_MODULE_TYPE) + attr_list.append(attribute) + + if dual_media is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_DUAL_MEDIA) + attr_list.append(attribute) + + if auto_neg_fec_mode_extended is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_EXTENDED) + attr_list.append(attribute) + + if ipg is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_IPG) + attr_list.append(attribute) + + if global_flow_control_forward is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_FORWARD) + attr_list.append(attribute) + + if priority_flow_control_forward is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_FORWARD) + attr_list.append(attribute) + + if qos_dscp_to_forwarding_class_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP) + attr_list.append(attribute) + + if qos_mpls_exp_to_forwarding_class_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP) + attr_list.append(attribute) + + if ipsec_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_IPSEC_PORT) + attr_list.append(attribute) + + if pfc_tc_dld_interval_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL_RANGE) + attr_list.append(attribute) + + if pfc_tc_dld_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dld_interval) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if pfc_tc_dlr_interval_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL_RANGE) + attr_list.append(attribute) + + if pfc_tc_dlr_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dlr_interval) + attribute = sai_thrift_attribute_t(id=SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_port_attribute(port_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_PORT_ATTR_TYPE: + attrs["SAI_PORT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_OPER_STATUS: + attrs["SAI_PORT_ATTR_OPER_STATUS"] = attr.value.s32 + attrs["oper_status"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_SUPPORTED_BREAKOUT_MODE_TYPE: + attrs["SAI_PORT_ATTR_SUPPORTED_BREAKOUT_MODE_TYPE"] = attr.value.s32list + attrs["supported_breakout_mode_type"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_CURRENT_BREAKOUT_MODE_TYPE: + attrs["SAI_PORT_ATTR_CURRENT_BREAKOUT_MODE_TYPE"] = attr.value.s32 + attrs["current_breakout_mode_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_QOS_NUMBER_OF_QUEUES: + attrs["SAI_PORT_ATTR_QOS_NUMBER_OF_QUEUES"] = attr.value.u32 + attrs["qos_number_of_queues"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_QOS_QUEUE_LIST: + attrs["SAI_PORT_ATTR_QOS_QUEUE_LIST"] = attr.value.objlist + attrs["qos_queue_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_QOS_NUMBER_OF_SCHEDULER_GROUPS: + attrs["SAI_PORT_ATTR_QOS_NUMBER_OF_SCHEDULER_GROUPS"] = attr.value.u32 + attrs["qos_number_of_scheduler_groups"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_QOS_SCHEDULER_GROUP_LIST: + attrs["SAI_PORT_ATTR_QOS_SCHEDULER_GROUP_LIST"] = attr.value.objlist + attrs["qos_scheduler_group_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_QOS_MAXIMUM_HEADROOM_SIZE: + attrs["SAI_PORT_ATTR_QOS_MAXIMUM_HEADROOM_SIZE"] = attr.value.u32 + attrs["qos_maximum_headroom_size"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_SUPPORTED_SPEED: + attrs["SAI_PORT_ATTR_SUPPORTED_SPEED"] = attr.value.u32list + attrs["supported_speed"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_SUPPORTED_FEC_MODE: + attrs["SAI_PORT_ATTR_SUPPORTED_FEC_MODE"] = attr.value.s32list + attrs["supported_fec_mode"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_SUPPORTED_FEC_MODE_EXTENDED: + attrs["SAI_PORT_ATTR_SUPPORTED_FEC_MODE_EXTENDED"] = attr.value.s32list + attrs["supported_fec_mode_extended"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_SUPPORTED_HALF_DUPLEX_SPEED: + attrs["SAI_PORT_ATTR_SUPPORTED_HALF_DUPLEX_SPEED"] = attr.value.u32list + attrs["supported_half_duplex_speed"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_SUPPORTED_AUTO_NEG_MODE: + attrs["SAI_PORT_ATTR_SUPPORTED_AUTO_NEG_MODE"] = attr.value.booldata + attrs["supported_auto_neg_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_SUPPORTED_FLOW_CONTROL_MODE: + attrs["SAI_PORT_ATTR_SUPPORTED_FLOW_CONTROL_MODE"] = attr.value.s32 + attrs["supported_flow_control_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_SUPPORTED_ASYMMETRIC_PAUSE_MODE: + attrs["SAI_PORT_ATTR_SUPPORTED_ASYMMETRIC_PAUSE_MODE"] = attr.value.booldata + attrs["supported_asymmetric_pause_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_SUPPORTED_MEDIA_TYPE: + attrs["SAI_PORT_ATTR_SUPPORTED_MEDIA_TYPE"] = attr.value.s32 + attrs["supported_media_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_SPEED: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_SPEED"] = attr.value.u32list + attrs["remote_advertised_speed"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_FEC_MODE: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_FEC_MODE"] = attr.value.s32list + attrs["remote_advertised_fec_mode"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_FEC_MODE_EXTENDED: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_FEC_MODE_EXTENDED"] = attr.value.s32list + attrs["remote_advertised_fec_mode_extended"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_HALF_DUPLEX_SPEED: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_HALF_DUPLEX_SPEED"] = attr.value.u32list + attrs["remote_advertised_half_duplex_speed"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_AUTO_NEG_MODE: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_AUTO_NEG_MODE"] = attr.value.booldata + attrs["remote_advertised_auto_neg_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_FLOW_CONTROL_MODE: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_FLOW_CONTROL_MODE"] = attr.value.s32 + attrs["remote_advertised_flow_control_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_ASYMMETRIC_PAUSE_MODE: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_ASYMMETRIC_PAUSE_MODE"] = attr.value.booldata + attrs["remote_advertised_asymmetric_pause_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_MEDIA_TYPE: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_MEDIA_TYPE"] = attr.value.s32 + attrs["remote_advertised_media_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_REMOTE_ADVERTISED_OUI_CODE: + attrs["SAI_PORT_ATTR_REMOTE_ADVERTISED_OUI_CODE"] = attr.value.u32 + attrs["remote_advertised_oui_code"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_NUMBER_OF_INGRESS_PRIORITY_GROUPS: + attrs["SAI_PORT_ATTR_NUMBER_OF_INGRESS_PRIORITY_GROUPS"] = attr.value.u32 + attrs["number_of_ingress_priority_groups"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_INGRESS_PRIORITY_GROUP_LIST: + attrs["SAI_PORT_ATTR_INGRESS_PRIORITY_GROUP_LIST"] = attr.value.objlist + attrs["ingress_priority_group_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_EYE_VALUES: + attrs["SAI_PORT_ATTR_EYE_VALUES"] = attr.value.porteyevalues + attrs["eye_values"] = attr.value.porteyevalues + + if attr.id == SAI_PORT_ATTR_OPER_SPEED: + attrs["SAI_PORT_ATTR_OPER_SPEED"] = attr.value.u32 + attrs["oper_speed"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_HW_LANE_LIST: + attrs["SAI_PORT_ATTR_HW_LANE_LIST"] = attr.value.u32list + attrs["hw_lane_list"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_SPEED: + attrs["SAI_PORT_ATTR_SPEED"] = attr.value.u32 + attrs["speed"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_FULL_DUPLEX_MODE: + attrs["SAI_PORT_ATTR_FULL_DUPLEX_MODE"] = attr.value.booldata + attrs["full_duplex_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_AUTO_NEG_MODE: + attrs["SAI_PORT_ATTR_AUTO_NEG_MODE"] = attr.value.booldata + attrs["auto_neg_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_ADMIN_STATE: + attrs["SAI_PORT_ATTR_ADMIN_STATE"] = attr.value.booldata + attrs["admin_state"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_MEDIA_TYPE: + attrs["SAI_PORT_ATTR_MEDIA_TYPE"] = attr.value.s32 + attrs["media_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_ADVERTISED_SPEED: + attrs["SAI_PORT_ATTR_ADVERTISED_SPEED"] = attr.value.u32list + attrs["advertised_speed"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_ADVERTISED_FEC_MODE: + attrs["SAI_PORT_ATTR_ADVERTISED_FEC_MODE"] = attr.value.s32list + attrs["advertised_fec_mode"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_ADVERTISED_FEC_MODE_EXTENDED: + attrs["SAI_PORT_ATTR_ADVERTISED_FEC_MODE_EXTENDED"] = attr.value.s32list + attrs["advertised_fec_mode_extended"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_ADVERTISED_HALF_DUPLEX_SPEED: + attrs["SAI_PORT_ATTR_ADVERTISED_HALF_DUPLEX_SPEED"] = attr.value.u32list + attrs["advertised_half_duplex_speed"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_ADVERTISED_AUTO_NEG_MODE: + attrs["SAI_PORT_ATTR_ADVERTISED_AUTO_NEG_MODE"] = attr.value.booldata + attrs["advertised_auto_neg_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_ADVERTISED_FLOW_CONTROL_MODE: + attrs["SAI_PORT_ATTR_ADVERTISED_FLOW_CONTROL_MODE"] = attr.value.s32 + attrs["advertised_flow_control_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_ADVERTISED_ASYMMETRIC_PAUSE_MODE: + attrs["SAI_PORT_ATTR_ADVERTISED_ASYMMETRIC_PAUSE_MODE"] = attr.value.booldata + attrs["advertised_asymmetric_pause_mode"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_ADVERTISED_MEDIA_TYPE: + attrs["SAI_PORT_ATTR_ADVERTISED_MEDIA_TYPE"] = attr.value.s32 + attrs["advertised_media_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_ADVERTISED_OUI_CODE: + attrs["SAI_PORT_ATTR_ADVERTISED_OUI_CODE"] = attr.value.u32 + attrs["advertised_oui_code"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_PORT_VLAN_ID: + attrs["SAI_PORT_ATTR_PORT_VLAN_ID"] = attr.value.u16 + attrs["port_vlan_id"] = attr.value.u16 + + if attr.id == SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY: + attrs["SAI_PORT_ATTR_DEFAULT_VLAN_PRIORITY"] = attr.value.u8 + attrs["default_vlan_priority"] = attr.value.u8 + + if attr.id == SAI_PORT_ATTR_DROP_UNTAGGED: + attrs["SAI_PORT_ATTR_DROP_UNTAGGED"] = attr.value.booldata + attrs["drop_untagged"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_DROP_TAGGED: + attrs["SAI_PORT_ATTR_DROP_TAGGED"] = attr.value.booldata + attrs["drop_tagged"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_INTERNAL_LOOPBACK_MODE: + attrs["SAI_PORT_ATTR_INTERNAL_LOOPBACK_MODE"] = attr.value.s32 + attrs["internal_loopback_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_USE_EXTENDED_FEC: + attrs["SAI_PORT_ATTR_USE_EXTENDED_FEC"] = attr.value.booldata + attrs["use_extended_fec"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_FEC_MODE: + attrs["SAI_PORT_ATTR_FEC_MODE"] = attr.value.s32 + attrs["fec_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_FEC_MODE_EXTENDED: + attrs["SAI_PORT_ATTR_FEC_MODE_EXTENDED"] = attr.value.s32 + attrs["fec_mode_extended"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_UPDATE_DSCP: + attrs["SAI_PORT_ATTR_UPDATE_DSCP"] = attr.value.booldata + attrs["update_dscp"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_MTU: + attrs["SAI_PORT_ATTR_MTU"] = attr.value.u32 + attrs["mtu"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID: + attrs["SAI_PORT_ATTR_FLOOD_STORM_CONTROL_POLICER_ID"] = attr.value.oid + attrs["flood_storm_control_policer_id"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID: + attrs["SAI_PORT_ATTR_BROADCAST_STORM_CONTROL_POLICER_ID"] = attr.value.oid + attrs["broadcast_storm_control_policer_id"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID: + attrs["SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID"] = attr.value.oid + attrs["multicast_storm_control_policer_id"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_MODE: + attrs["SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_MODE"] = attr.value.s32 + attrs["global_flow_control_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_INGRESS_ACL: + attrs["SAI_PORT_ATTR_INGRESS_ACL"] = attr.value.oid + attrs["ingress_acl"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_EGRESS_ACL: + attrs["SAI_PORT_ATTR_EGRESS_ACL"] = attr.value.oid + attrs["egress_acl"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_INGRESS_MACSEC_ACL: + attrs["SAI_PORT_ATTR_INGRESS_MACSEC_ACL"] = attr.value.oid + attrs["ingress_macsec_acl"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_EGRESS_MACSEC_ACL: + attrs["SAI_PORT_ATTR_EGRESS_MACSEC_ACL"] = attr.value.oid + attrs["egress_macsec_acl"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_MACSEC_PORT_LIST: + attrs["SAI_PORT_ATTR_MACSEC_PORT_LIST"] = attr.value.objlist + attrs["macsec_port_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_INGRESS_MIRROR_SESSION: + attrs["SAI_PORT_ATTR_INGRESS_MIRROR_SESSION"] = attr.value.objlist + attrs["ingress_mirror_session"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_EGRESS_MIRROR_SESSION: + attrs["SAI_PORT_ATTR_EGRESS_MIRROR_SESSION"] = attr.value.objlist + attrs["egress_mirror_session"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE: + attrs["SAI_PORT_ATTR_INGRESS_SAMPLEPACKET_ENABLE"] = attr.value.oid + attrs["ingress_samplepacket_enable"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE: + attrs["SAI_PORT_ATTR_EGRESS_SAMPLEPACKET_ENABLE"] = attr.value.oid + attrs["egress_samplepacket_enable"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSION: + attrs["SAI_PORT_ATTR_INGRESS_SAMPLE_MIRROR_SESSION"] = attr.value.objlist + attrs["ingress_sample_mirror_session"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_EGRESS_SAMPLE_MIRROR_SESSION: + attrs["SAI_PORT_ATTR_EGRESS_SAMPLE_MIRROR_SESSION"] = attr.value.objlist + attrs["egress_sample_mirror_session"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_POLICER_ID: + attrs["SAI_PORT_ATTR_POLICER_ID"] = attr.value.oid + attrs["policer_id"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_DEFAULT_TC: + attrs["SAI_PORT_ATTR_QOS_DEFAULT_TC"] = attr.value.u8 + attrs["qos_default_tc"] = attr.value.u8 + + if attr.id == SAI_PORT_ATTR_QOS_DOT1P_TO_TC_MAP: + attrs["SAI_PORT_ATTR_QOS_DOT1P_TO_TC_MAP"] = attr.value.oid + attrs["qos_dot1p_to_tc_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_DOT1P_TO_COLOR_MAP: + attrs["SAI_PORT_ATTR_QOS_DOT1P_TO_COLOR_MAP"] = attr.value.oid + attrs["qos_dot1p_to_color_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_DSCP_TO_TC_MAP: + attrs["SAI_PORT_ATTR_QOS_DSCP_TO_TC_MAP"] = attr.value.oid + attrs["qos_dscp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_DSCP_TO_COLOR_MAP: + attrs["SAI_PORT_ATTR_QOS_DSCP_TO_COLOR_MAP"] = attr.value.oid + attrs["qos_dscp_to_color_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_TC_TO_QUEUE_MAP: + attrs["SAI_PORT_ATTR_QOS_TC_TO_QUEUE_MAP"] = attr.value.oid + attrs["qos_tc_to_queue_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP: + attrs["SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_dot1p_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP: + attrs["SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_dscp_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_TC_TO_PRIORITY_GROUP_MAP: + attrs["SAI_PORT_ATTR_QOS_TC_TO_PRIORITY_GROUP_MAP"] = attr.value.oid + attrs["qos_tc_to_priority_group_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP: + attrs["SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP"] = attr.value.oid + attrs["qos_pfc_priority_to_priority_group_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_QUEUE_MAP: + attrs["SAI_PORT_ATTR_QOS_PFC_PRIORITY_TO_QUEUE_MAP"] = attr.value.oid + attrs["qos_pfc_priority_to_queue_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_SCHEDULER_PROFILE_ID: + attrs["SAI_PORT_ATTR_QOS_SCHEDULER_PROFILE_ID"] = attr.value.oid + attrs["qos_scheduler_profile_id"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_INGRESS_BUFFER_PROFILE_LIST: + attrs["SAI_PORT_ATTR_QOS_INGRESS_BUFFER_PROFILE_LIST"] = attr.value.objlist + attrs["qos_ingress_buffer_profile_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_QOS_EGRESS_BUFFER_PROFILE_LIST: + attrs["SAI_PORT_ATTR_QOS_EGRESS_BUFFER_PROFILE_LIST"] = attr.value.objlist + attrs["qos_egress_buffer_profile_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE: + attrs["SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE"] = attr.value.s32 + attrs["priority_flow_control_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL: + attrs["SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL"] = attr.value.u8 + attrs["priority_flow_control"] = attr.value.u8 + + if attr.id == SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX: + attrs["SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX"] = attr.value.u8 + attrs["priority_flow_control_rx"] = attr.value.u8 + + if attr.id == SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX: + attrs["SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX"] = attr.value.u8 + attrs["priority_flow_control_tx"] = attr.value.u8 + + if attr.id == SAI_PORT_ATTR_META_DATA: + attrs["SAI_PORT_ATTR_META_DATA"] = attr.value.u32 + attrs["meta_data"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_EGRESS_BLOCK_PORT_LIST: + attrs["SAI_PORT_ATTR_EGRESS_BLOCK_PORT_LIST"] = attr.value.objlist + attrs["egress_block_port_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_HW_PROFILE_ID: + attrs["SAI_PORT_ATTR_HW_PROFILE_ID"] = attr.value.u64 + attrs["hw_profile_id"] = attr.value.u64 + + if attr.id == SAI_PORT_ATTR_EEE_ENABLE: + attrs["SAI_PORT_ATTR_EEE_ENABLE"] = attr.value.booldata + attrs["eee_enable"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_EEE_IDLE_TIME: + attrs["SAI_PORT_ATTR_EEE_IDLE_TIME"] = attr.value.u16 + attrs["eee_idle_time"] = attr.value.u16 + + if attr.id == SAI_PORT_ATTR_EEE_WAKE_TIME: + attrs["SAI_PORT_ATTR_EEE_WAKE_TIME"] = attr.value.u16 + attrs["eee_wake_time"] = attr.value.u16 + + if attr.id == SAI_PORT_ATTR_PORT_POOL_LIST: + attrs["SAI_PORT_ATTR_PORT_POOL_LIST"] = attr.value.objlist + attrs["port_pool_list"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_ISOLATION_GROUP: + attrs["SAI_PORT_ATTR_ISOLATION_GROUP"] = attr.value.oid + attrs["isolation_group"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_PKT_TX_ENABLE: + attrs["SAI_PORT_ATTR_PKT_TX_ENABLE"] = attr.value.booldata + attrs["pkt_tx_enable"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_TAM_OBJECT: + attrs["SAI_PORT_ATTR_TAM_OBJECT"] = attr.value.objlist + attrs["tam_object"] = attr.value.objlist + + if attr.id == SAI_PORT_ATTR_SERDES_PREEMPHASIS: + attrs["SAI_PORT_ATTR_SERDES_PREEMPHASIS"] = attr.value.u32list + attrs["serdes_preemphasis"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_SERDES_IDRIVER: + attrs["SAI_PORT_ATTR_SERDES_IDRIVER"] = attr.value.u32list + attrs["serdes_idriver"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_SERDES_IPREDRIVER: + attrs["SAI_PORT_ATTR_SERDES_IPREDRIVER"] = attr.value.u32list + attrs["serdes_ipredriver"] = attr.value.u32list + + if attr.id == SAI_PORT_ATTR_LINK_TRAINING_ENABLE: + attrs["SAI_PORT_ATTR_LINK_TRAINING_ENABLE"] = attr.value.booldata + attrs["link_training_enable"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_PTP_MODE: + attrs["SAI_PORT_ATTR_PTP_MODE"] = attr.value.s32 + attrs["ptp_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_INTERFACE_TYPE: + attrs["SAI_PORT_ATTR_INTERFACE_TYPE"] = attr.value.s32 + attrs["interface_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_ADVERTISED_INTERFACE_TYPE: + attrs["SAI_PORT_ATTR_ADVERTISED_INTERFACE_TYPE"] = attr.value.s32list + attrs["advertised_interface_type"] = attr.value.s32list + + if attr.id == SAI_PORT_ATTR_REFERENCE_CLOCK: + attrs["SAI_PORT_ATTR_REFERENCE_CLOCK"] = attr.value.u64 + attrs["reference_clock"] = attr.value.u64 + + if attr.id == SAI_PORT_ATTR_PRBS_POLYNOMIAL: + attrs["SAI_PORT_ATTR_PRBS_POLYNOMIAL"] = attr.value.u32 + attrs["prbs_polynomial"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_PORT_SERDES_ID: + attrs["SAI_PORT_ATTR_PORT_SERDES_ID"] = attr.value.oid + attrs["port_serdes_id"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_LINK_TRAINING_FAILURE_STATUS: + attrs["SAI_PORT_ATTR_LINK_TRAINING_FAILURE_STATUS"] = attr.value.s32 + attrs["link_training_failure_status"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_LINK_TRAINING_RX_STATUS: + attrs["SAI_PORT_ATTR_LINK_TRAINING_RX_STATUS"] = attr.value.s32 + attrs["link_training_rx_status"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_PRBS_CONFIG: + attrs["SAI_PORT_ATTR_PRBS_CONFIG"] = attr.value.s32 + attrs["prbs_config"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_PRBS_LOCK_STATUS: + attrs["SAI_PORT_ATTR_PRBS_LOCK_STATUS"] = attr.value.booldata + attrs["prbs_lock_status"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_PRBS_LOCK_LOSS_STATUS: + attrs["SAI_PORT_ATTR_PRBS_LOCK_LOSS_STATUS"] = attr.value.booldata + attrs["prbs_lock_loss_status"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_PRBS_RX_STATUS: + attrs["SAI_PORT_ATTR_PRBS_RX_STATUS"] = attr.value.s32 + attrs["prbs_rx_status"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_PRBS_RX_STATE: + attrs["SAI_PORT_ATTR_PRBS_RX_STATE"] = attr.value.rx_state + attrs["prbs_rx_state"] = attr.value.rx_state + + if attr.id == SAI_PORT_ATTR_AUTO_NEG_STATUS: + attrs["SAI_PORT_ATTR_AUTO_NEG_STATUS"] = attr.value.booldata + attrs["auto_neg_status"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_DISABLE_DECREMENT_TTL: + attrs["SAI_PORT_ATTR_DISABLE_DECREMENT_TTL"] = attr.value.booldata + attrs["disable_decrement_ttl"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP: + attrs["SAI_PORT_ATTR_QOS_MPLS_EXP_TO_TC_MAP"] = attr.value.oid + attrs["qos_mpls_exp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP: + attrs["SAI_PORT_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP"] = attr.value.oid + attrs["qos_mpls_exp_to_color_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP: + attrs["SAI_PORT_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_mpls_exp_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_TPID: + attrs["SAI_PORT_ATTR_TPID"] = attr.value.u16 + attrs["tpid"] = attr.value.u16 + + if attr.id == SAI_PORT_ATTR_ERR_STATUS_LIST: + attrs["SAI_PORT_ATTR_ERR_STATUS_LIST"] = attr.value.porterror + attrs["err_status_list"] = attr.value.porterror + + if attr.id == SAI_PORT_ATTR_FABRIC_ATTACHED: + attrs["SAI_PORT_ATTR_FABRIC_ATTACHED"] = attr.value.booldata + attrs["fabric_attached"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_TYPE: + attrs["SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_TYPE"] = attr.value.s32 + attrs["fabric_attached_switch_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_ID: + attrs["SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_ID"] = attr.value.u32 + attrs["fabric_attached_switch_id"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX: + attrs["SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX"] = attr.value.u32 + attrs["fabric_attached_port_index"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_FABRIC_REACHABILITY: + attrs["SAI_PORT_ATTR_FABRIC_REACHABILITY"] = attr.value.reachability + attrs["fabric_reachability"] = attr.value.reachability + + if attr.id == SAI_PORT_ATTR_SYSTEM_PORT: + attrs["SAI_PORT_ATTR_SYSTEM_PORT"] = attr.value.oid + attrs["system_port"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE: + attrs["SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE"] = attr.value.booldata + attrs["auto_neg_fec_mode_override"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_LOOPBACK_MODE: + attrs["SAI_PORT_ATTR_LOOPBACK_MODE"] = attr.value.s32 + attrs["loopback_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_MDIX_MODE_STATUS: + attrs["SAI_PORT_ATTR_MDIX_MODE_STATUS"] = attr.value.s32 + attrs["mdix_mode_status"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_MDIX_MODE_CONFIG: + attrs["SAI_PORT_ATTR_MDIX_MODE_CONFIG"] = attr.value.s32 + attrs["mdix_mode_config"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_AUTO_NEG_CONFIG_MODE: + attrs["SAI_PORT_ATTR_AUTO_NEG_CONFIG_MODE"] = attr.value.s32 + attrs["auto_neg_config_mode"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_1000X_SGMII_SLAVE_AUTODETECT: + attrs["SAI_PORT_ATTR_1000X_SGMII_SLAVE_AUTODETECT"] = attr.value.booldata + attrs["_1000x_sgmii_slave_autodetect"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_MODULE_TYPE: + attrs["SAI_PORT_ATTR_MODULE_TYPE"] = attr.value.s32 + attrs["module_type"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_DUAL_MEDIA: + attrs["SAI_PORT_ATTR_DUAL_MEDIA"] = attr.value.s32 + attrs["dual_media"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_EXTENDED: + attrs["SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_EXTENDED"] = attr.value.s32 + attrs["auto_neg_fec_mode_extended"] = attr.value.s32 + + if attr.id == SAI_PORT_ATTR_IPG: + attrs["SAI_PORT_ATTR_IPG"] = attr.value.u32 + attrs["ipg"] = attr.value.u32 + + if attr.id == SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_FORWARD: + attrs["SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_FORWARD"] = attr.value.booldata + attrs["global_flow_control_forward"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_FORWARD: + attrs["SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_FORWARD"] = attr.value.booldata + attrs["priority_flow_control_forward"] = attr.value.booldata + + if attr.id == SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP: + attrs["SAI_PORT_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP"] = attr.value.oid + attrs["qos_dscp_to_forwarding_class_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP: + attrs["SAI_PORT_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP"] = attr.value.oid + attrs["qos_mpls_exp_to_forwarding_class_map"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_IPSEC_PORT: + attrs["SAI_PORT_ATTR_IPSEC_PORT"] = attr.value.oid + attrs["ipsec_port"] = attr.value.oid + + if attr.id == SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL_RANGE: + attrs["SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL_RANGE"] = attr.value.u32range + attrs["pfc_tc_dld_interval_range"] = attr.value.u32range + + if attr.id == SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL: + attrs["SAI_PORT_ATTR_PFC_TC_DLD_INTERVAL"] = attr.value.maplist + attrs["pfc_tc_dld_interval"] = attr.value.maplist + + if attr.id == SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL_RANGE: + attrs["SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL_RANGE"] = attr.value.u32range + attrs["pfc_tc_dlr_interval_range"] = attr.value.u32range + + if attr.id == SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL: + attrs["SAI_PORT_ATTR_PFC_TC_DLR_INTERVAL"] = attr.value.maplist + attrs["pfc_tc_dlr_interval"] = attr.value.maplist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_port_stats(client, + port_oid): + """ + sai_get_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_PORT_STAT_IF_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IF_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_IN_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS) + counter_ids.append(SAI_PORT_STAT_IF_IN_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_VLAN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_QLEN) + counter_ids.append(SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_FRAGMENTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_JABBERS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS) + counter_ids.append(SAI_PORT_STAT_IP_IN_RECEIVES) + counter_ids.append(SAI_PORT_STAT_IP_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IP_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_RECEIVES) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_MCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_IN_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_PAUSE_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PAUSE_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_0_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_ALIGNMENT_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_FCS_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SINGLE_COLLISION_FRAMES) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_MULTIPLE_COLLISION_FRAMES) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SQE_TEST_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_DEFERRED_TRANSMISSIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_LATE_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_EXCESSIVE_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_TRANSMIT_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_CARRIER_SENSE_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_FRAME_TOO_LONGS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_RECEIVE_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SYMBOL_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_CONTROL_IN_UNKNOWN_OPCODES) + counter_ids.append(SAI_PORT_STAT_EEE_TX_EVENT_COUNT) + counter_ids.append(SAI_PORT_STAT_EEE_RX_EVENT_COUNT) + counter_ids.append(SAI_PORT_STAT_EEE_TX_DURATION) + counter_ids.append(SAI_PORT_STAT_EEE_RX_DURATION) + counter_ids.append(SAI_PORT_STAT_PRBS_ERROR_COUNT) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS) + counter_ids.append(SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + + counters = [0] * 201 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_port_stats(port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_PORT_STAT_IF_IN_OCTETS"] = counters[0] + stats["SAI_PORT_STAT_IF_IN_UCAST_PKTS"] = counters[1] + stats["SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS"] = counters[2] + stats["SAI_PORT_STAT_IF_IN_DISCARDS"] = counters[3] + stats["SAI_PORT_STAT_IF_IN_ERRORS"] = counters[4] + stats["SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS"] = counters[5] + stats["SAI_PORT_STAT_IF_IN_BROADCAST_PKTS"] = counters[6] + stats["SAI_PORT_STAT_IF_IN_MULTICAST_PKTS"] = counters[7] + stats["SAI_PORT_STAT_IF_IN_VLAN_DISCARDS"] = counters[8] + stats["SAI_PORT_STAT_IF_OUT_OCTETS"] = counters[9] + stats["SAI_PORT_STAT_IF_OUT_UCAST_PKTS"] = counters[10] + stats["SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS"] = counters[11] + stats["SAI_PORT_STAT_IF_OUT_DISCARDS"] = counters[12] + stats["SAI_PORT_STAT_IF_OUT_ERRORS"] = counters[13] + stats["SAI_PORT_STAT_IF_OUT_QLEN"] = counters[14] + stats["SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS"] = counters[15] + stats["SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS"] = counters[16] + stats["SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS"] = counters[17] + stats["SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS"] = counters[18] + stats["SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS"] = counters[19] + stats["SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS"] = counters[20] + stats["SAI_PORT_STAT_ETHER_STATS_FRAGMENTS"] = counters[21] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS"] = counters[22] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS"] = counters[23] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS"] = counters[24] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS"] = counters[25] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS"] = counters[26] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS"] = counters[27] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_1519_TO_2047_OCTETS"] = counters[28] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_2048_TO_4095_OCTETS"] = counters[29] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS"] = counters[30] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_9217_TO_16383_OCTETS"] = counters[31] + stats["SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS"] = counters[32] + stats["SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS"] = counters[33] + stats["SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS"] = counters[34] + stats["SAI_PORT_STAT_ETHER_STATS_JABBERS"] = counters[35] + stats["SAI_PORT_STAT_ETHER_STATS_OCTETS"] = counters[36] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS"] = counters[37] + stats["SAI_PORT_STAT_ETHER_STATS_COLLISIONS"] = counters[38] + stats["SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS"] = counters[39] + stats["SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS"] = counters[40] + stats["SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS"] = counters[41] + stats["SAI_PORT_STAT_IP_IN_RECEIVES"] = counters[42] + stats["SAI_PORT_STAT_IP_IN_OCTETS"] = counters[43] + stats["SAI_PORT_STAT_IP_IN_UCAST_PKTS"] = counters[44] + stats["SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS"] = counters[45] + stats["SAI_PORT_STAT_IP_IN_DISCARDS"] = counters[46] + stats["SAI_PORT_STAT_IP_OUT_OCTETS"] = counters[47] + stats["SAI_PORT_STAT_IP_OUT_UCAST_PKTS"] = counters[48] + stats["SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS"] = counters[49] + stats["SAI_PORT_STAT_IP_OUT_DISCARDS"] = counters[50] + stats["SAI_PORT_STAT_IPV6_IN_RECEIVES"] = counters[51] + stats["SAI_PORT_STAT_IPV6_IN_OCTETS"] = counters[52] + stats["SAI_PORT_STAT_IPV6_IN_UCAST_PKTS"] = counters[53] + stats["SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS"] = counters[54] + stats["SAI_PORT_STAT_IPV6_IN_MCAST_PKTS"] = counters[55] + stats["SAI_PORT_STAT_IPV6_IN_DISCARDS"] = counters[56] + stats["SAI_PORT_STAT_IPV6_OUT_OCTETS"] = counters[57] + stats["SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS"] = counters[58] + stats["SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS"] = counters[59] + stats["SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS"] = counters[60] + stats["SAI_PORT_STAT_IPV6_OUT_DISCARDS"] = counters[61] + stats["SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[62] + stats["SAI_PORT_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[63] + stats["SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[64] + stats["SAI_PORT_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[65] + stats["SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS"] = counters[66] + stats["SAI_PORT_STAT_RED_WRED_DROPPED_BYTES"] = counters[67] + stats["SAI_PORT_STAT_WRED_DROPPED_PACKETS"] = counters[68] + stats["SAI_PORT_STAT_WRED_DROPPED_BYTES"] = counters[69] + stats["SAI_PORT_STAT_ECN_MARKED_PACKETS"] = counters[70] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_64_OCTETS"] = counters[71] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_65_TO_127_OCTETS"] = counters[72] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS"] = counters[73] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_256_TO_511_OCTETS"] = counters[74] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_512_TO_1023_OCTETS"] = counters[75] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_1024_TO_1518_OCTETS"] = counters[76] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_1519_TO_2047_OCTETS"] = counters[77] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_2048_TO_4095_OCTETS"] = counters[78] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_4096_TO_9216_OCTETS"] = counters[79] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_9217_TO_16383_OCTETS"] = counters[80] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_64_OCTETS"] = counters[81] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_65_TO_127_OCTETS"] = counters[82] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_128_TO_255_OCTETS"] = counters[83] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_256_TO_511_OCTETS"] = counters[84] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_512_TO_1023_OCTETS"] = counters[85] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_1024_TO_1518_OCTETS"] = counters[86] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_1519_TO_2047_OCTETS"] = counters[87] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_2048_TO_4095_OCTETS"] = counters[88] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_4096_TO_9216_OCTETS"] = counters[89] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_9217_TO_16383_OCTETS"] = counters[90] + stats["SAI_PORT_STAT_IN_CURR_OCCUPANCY_BYTES"] = counters[91] + stats["SAI_PORT_STAT_IN_WATERMARK_BYTES"] = counters[92] + stats["SAI_PORT_STAT_IN_SHARED_CURR_OCCUPANCY_BYTES"] = counters[93] + stats["SAI_PORT_STAT_IN_SHARED_WATERMARK_BYTES"] = counters[94] + stats["SAI_PORT_STAT_OUT_CURR_OCCUPANCY_BYTES"] = counters[95] + stats["SAI_PORT_STAT_OUT_WATERMARK_BYTES"] = counters[96] + stats["SAI_PORT_STAT_OUT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[97] + stats["SAI_PORT_STAT_OUT_SHARED_WATERMARK_BYTES"] = counters[98] + stats["SAI_PORT_STAT_IN_DROPPED_PKTS"] = counters[99] + stats["SAI_PORT_STAT_OUT_DROPPED_PKTS"] = counters[100] + stats["SAI_PORT_STAT_PAUSE_RX_PKTS"] = counters[101] + stats["SAI_PORT_STAT_PAUSE_TX_PKTS"] = counters[102] + stats["SAI_PORT_STAT_PFC_0_RX_PKTS"] = counters[103] + stats["SAI_PORT_STAT_PFC_0_TX_PKTS"] = counters[104] + stats["SAI_PORT_STAT_PFC_1_RX_PKTS"] = counters[105] + stats["SAI_PORT_STAT_PFC_1_TX_PKTS"] = counters[106] + stats["SAI_PORT_STAT_PFC_2_RX_PKTS"] = counters[107] + stats["SAI_PORT_STAT_PFC_2_TX_PKTS"] = counters[108] + stats["SAI_PORT_STAT_PFC_3_RX_PKTS"] = counters[109] + stats["SAI_PORT_STAT_PFC_3_TX_PKTS"] = counters[110] + stats["SAI_PORT_STAT_PFC_4_RX_PKTS"] = counters[111] + stats["SAI_PORT_STAT_PFC_4_TX_PKTS"] = counters[112] + stats["SAI_PORT_STAT_PFC_5_RX_PKTS"] = counters[113] + stats["SAI_PORT_STAT_PFC_5_TX_PKTS"] = counters[114] + stats["SAI_PORT_STAT_PFC_6_RX_PKTS"] = counters[115] + stats["SAI_PORT_STAT_PFC_6_TX_PKTS"] = counters[116] + stats["SAI_PORT_STAT_PFC_7_RX_PKTS"] = counters[117] + stats["SAI_PORT_STAT_PFC_7_TX_PKTS"] = counters[118] + stats["SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION"] = counters[119] + stats["SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION"] = counters[120] + stats["SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION"] = counters[121] + stats["SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION"] = counters[122] + stats["SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION"] = counters[123] + stats["SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION"] = counters[124] + stats["SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION"] = counters[125] + stats["SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION"] = counters[126] + stats["SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION"] = counters[127] + stats["SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION"] = counters[128] + stats["SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION"] = counters[129] + stats["SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION"] = counters[130] + stats["SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION"] = counters[131] + stats["SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION"] = counters[132] + stats["SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION"] = counters[133] + stats["SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION"] = counters[134] + stats["SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION_US"] = counters[135] + stats["SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION_US"] = counters[136] + stats["SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION_US"] = counters[137] + stats["SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION_US"] = counters[138] + stats["SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION_US"] = counters[139] + stats["SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION_US"] = counters[140] + stats["SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION_US"] = counters[141] + stats["SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION_US"] = counters[142] + stats["SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION_US"] = counters[143] + stats["SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION_US"] = counters[144] + stats["SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION_US"] = counters[145] + stats["SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION_US"] = counters[146] + stats["SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION_US"] = counters[147] + stats["SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION_US"] = counters[148] + stats["SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION_US"] = counters[149] + stats["SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION_US"] = counters[150] + stats["SAI_PORT_STAT_PFC_0_ON2OFF_RX_PKTS"] = counters[151] + stats["SAI_PORT_STAT_PFC_1_ON2OFF_RX_PKTS"] = counters[152] + stats["SAI_PORT_STAT_PFC_2_ON2OFF_RX_PKTS"] = counters[153] + stats["SAI_PORT_STAT_PFC_3_ON2OFF_RX_PKTS"] = counters[154] + stats["SAI_PORT_STAT_PFC_4_ON2OFF_RX_PKTS"] = counters[155] + stats["SAI_PORT_STAT_PFC_5_ON2OFF_RX_PKTS"] = counters[156] + stats["SAI_PORT_STAT_PFC_6_ON2OFF_RX_PKTS"] = counters[157] + stats["SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS"] = counters[158] + stats["SAI_PORT_STAT_DOT3_STATS_ALIGNMENT_ERRORS"] = counters[159] + stats["SAI_PORT_STAT_DOT3_STATS_FCS_ERRORS"] = counters[160] + stats["SAI_PORT_STAT_DOT3_STATS_SINGLE_COLLISION_FRAMES"] = counters[161] + stats["SAI_PORT_STAT_DOT3_STATS_MULTIPLE_COLLISION_FRAMES"] = counters[162] + stats["SAI_PORT_STAT_DOT3_STATS_SQE_TEST_ERRORS"] = counters[163] + stats["SAI_PORT_STAT_DOT3_STATS_DEFERRED_TRANSMISSIONS"] = counters[164] + stats["SAI_PORT_STAT_DOT3_STATS_LATE_COLLISIONS"] = counters[165] + stats["SAI_PORT_STAT_DOT3_STATS_EXCESSIVE_COLLISIONS"] = counters[166] + stats["SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_TRANSMIT_ERRORS"] = counters[167] + stats["SAI_PORT_STAT_DOT3_STATS_CARRIER_SENSE_ERRORS"] = counters[168] + stats["SAI_PORT_STAT_DOT3_STATS_FRAME_TOO_LONGS"] = counters[169] + stats["SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_RECEIVE_ERRORS"] = counters[170] + stats["SAI_PORT_STAT_DOT3_STATS_SYMBOL_ERRORS"] = counters[171] + stats["SAI_PORT_STAT_DOT3_CONTROL_IN_UNKNOWN_OPCODES"] = counters[172] + stats["SAI_PORT_STAT_EEE_TX_EVENT_COUNT"] = counters[173] + stats["SAI_PORT_STAT_EEE_RX_EVENT_COUNT"] = counters[174] + stats["SAI_PORT_STAT_EEE_TX_DURATION"] = counters[175] + stats["SAI_PORT_STAT_EEE_RX_DURATION"] = counters[176] + stats["SAI_PORT_STAT_PRBS_ERROR_COUNT"] = counters[177] + stats["SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES"] = counters[178] + stats["SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES"] = counters[179] + stats["SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS"] = counters[180] + stats["SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS"] = counters[181] + stats["SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS"] = counters[182] + stats["SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE"] = counters[183] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[184] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[185] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[186] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[187] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[188] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[189] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[190] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[191] + stats["SAI_PORT_STAT_OUT_DROP_REASON_RANGE_BASE"] = counters[192] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[193] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[194] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[195] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[196] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[197] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[198] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[199] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[200] + + return stats + + +def sai_thrift_get_port_stats_ext(client, + port_oid, + mode): + """ + sai_get_port_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_PORT_STAT_IF_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IF_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_IN_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS) + counter_ids.append(SAI_PORT_STAT_IF_IN_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_VLAN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_QLEN) + counter_ids.append(SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_FRAGMENTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_JABBERS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS) + counter_ids.append(SAI_PORT_STAT_IP_IN_RECEIVES) + counter_ids.append(SAI_PORT_STAT_IP_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IP_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_RECEIVES) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_MCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_IN_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_PAUSE_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PAUSE_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_0_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_ALIGNMENT_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_FCS_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SINGLE_COLLISION_FRAMES) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_MULTIPLE_COLLISION_FRAMES) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SQE_TEST_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_DEFERRED_TRANSMISSIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_LATE_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_EXCESSIVE_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_TRANSMIT_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_CARRIER_SENSE_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_FRAME_TOO_LONGS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_RECEIVE_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SYMBOL_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_CONTROL_IN_UNKNOWN_OPCODES) + counter_ids.append(SAI_PORT_STAT_EEE_TX_EVENT_COUNT) + counter_ids.append(SAI_PORT_STAT_EEE_RX_EVENT_COUNT) + counter_ids.append(SAI_PORT_STAT_EEE_TX_DURATION) + counter_ids.append(SAI_PORT_STAT_EEE_RX_DURATION) + counter_ids.append(SAI_PORT_STAT_PRBS_ERROR_COUNT) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS) + counter_ids.append(SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + + counters = [0] * 201 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_port_stats_ext(port_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_PORT_STAT_IF_IN_OCTETS"] = counters[0] + stats["SAI_PORT_STAT_IF_IN_UCAST_PKTS"] = counters[1] + stats["SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS"] = counters[2] + stats["SAI_PORT_STAT_IF_IN_DISCARDS"] = counters[3] + stats["SAI_PORT_STAT_IF_IN_ERRORS"] = counters[4] + stats["SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS"] = counters[5] + stats["SAI_PORT_STAT_IF_IN_BROADCAST_PKTS"] = counters[6] + stats["SAI_PORT_STAT_IF_IN_MULTICAST_PKTS"] = counters[7] + stats["SAI_PORT_STAT_IF_IN_VLAN_DISCARDS"] = counters[8] + stats["SAI_PORT_STAT_IF_OUT_OCTETS"] = counters[9] + stats["SAI_PORT_STAT_IF_OUT_UCAST_PKTS"] = counters[10] + stats["SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS"] = counters[11] + stats["SAI_PORT_STAT_IF_OUT_DISCARDS"] = counters[12] + stats["SAI_PORT_STAT_IF_OUT_ERRORS"] = counters[13] + stats["SAI_PORT_STAT_IF_OUT_QLEN"] = counters[14] + stats["SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS"] = counters[15] + stats["SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS"] = counters[16] + stats["SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS"] = counters[17] + stats["SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS"] = counters[18] + stats["SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS"] = counters[19] + stats["SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS"] = counters[20] + stats["SAI_PORT_STAT_ETHER_STATS_FRAGMENTS"] = counters[21] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS"] = counters[22] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS"] = counters[23] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS"] = counters[24] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS"] = counters[25] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS"] = counters[26] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS"] = counters[27] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_1519_TO_2047_OCTETS"] = counters[28] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_2048_TO_4095_OCTETS"] = counters[29] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS"] = counters[30] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS_9217_TO_16383_OCTETS"] = counters[31] + stats["SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS"] = counters[32] + stats["SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS"] = counters[33] + stats["SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS"] = counters[34] + stats["SAI_PORT_STAT_ETHER_STATS_JABBERS"] = counters[35] + stats["SAI_PORT_STAT_ETHER_STATS_OCTETS"] = counters[36] + stats["SAI_PORT_STAT_ETHER_STATS_PKTS"] = counters[37] + stats["SAI_PORT_STAT_ETHER_STATS_COLLISIONS"] = counters[38] + stats["SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS"] = counters[39] + stats["SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS"] = counters[40] + stats["SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS"] = counters[41] + stats["SAI_PORT_STAT_IP_IN_RECEIVES"] = counters[42] + stats["SAI_PORT_STAT_IP_IN_OCTETS"] = counters[43] + stats["SAI_PORT_STAT_IP_IN_UCAST_PKTS"] = counters[44] + stats["SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS"] = counters[45] + stats["SAI_PORT_STAT_IP_IN_DISCARDS"] = counters[46] + stats["SAI_PORT_STAT_IP_OUT_OCTETS"] = counters[47] + stats["SAI_PORT_STAT_IP_OUT_UCAST_PKTS"] = counters[48] + stats["SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS"] = counters[49] + stats["SAI_PORT_STAT_IP_OUT_DISCARDS"] = counters[50] + stats["SAI_PORT_STAT_IPV6_IN_RECEIVES"] = counters[51] + stats["SAI_PORT_STAT_IPV6_IN_OCTETS"] = counters[52] + stats["SAI_PORT_STAT_IPV6_IN_UCAST_PKTS"] = counters[53] + stats["SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS"] = counters[54] + stats["SAI_PORT_STAT_IPV6_IN_MCAST_PKTS"] = counters[55] + stats["SAI_PORT_STAT_IPV6_IN_DISCARDS"] = counters[56] + stats["SAI_PORT_STAT_IPV6_OUT_OCTETS"] = counters[57] + stats["SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS"] = counters[58] + stats["SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS"] = counters[59] + stats["SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS"] = counters[60] + stats["SAI_PORT_STAT_IPV6_OUT_DISCARDS"] = counters[61] + stats["SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[62] + stats["SAI_PORT_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[63] + stats["SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[64] + stats["SAI_PORT_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[65] + stats["SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS"] = counters[66] + stats["SAI_PORT_STAT_RED_WRED_DROPPED_BYTES"] = counters[67] + stats["SAI_PORT_STAT_WRED_DROPPED_PACKETS"] = counters[68] + stats["SAI_PORT_STAT_WRED_DROPPED_BYTES"] = counters[69] + stats["SAI_PORT_STAT_ECN_MARKED_PACKETS"] = counters[70] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_64_OCTETS"] = counters[71] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_65_TO_127_OCTETS"] = counters[72] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS"] = counters[73] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_256_TO_511_OCTETS"] = counters[74] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_512_TO_1023_OCTETS"] = counters[75] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_1024_TO_1518_OCTETS"] = counters[76] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_1519_TO_2047_OCTETS"] = counters[77] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_2048_TO_4095_OCTETS"] = counters[78] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_4096_TO_9216_OCTETS"] = counters[79] + stats["SAI_PORT_STAT_ETHER_IN_PKTS_9217_TO_16383_OCTETS"] = counters[80] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_64_OCTETS"] = counters[81] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_65_TO_127_OCTETS"] = counters[82] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_128_TO_255_OCTETS"] = counters[83] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_256_TO_511_OCTETS"] = counters[84] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_512_TO_1023_OCTETS"] = counters[85] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_1024_TO_1518_OCTETS"] = counters[86] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_1519_TO_2047_OCTETS"] = counters[87] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_2048_TO_4095_OCTETS"] = counters[88] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_4096_TO_9216_OCTETS"] = counters[89] + stats["SAI_PORT_STAT_ETHER_OUT_PKTS_9217_TO_16383_OCTETS"] = counters[90] + stats["SAI_PORT_STAT_IN_CURR_OCCUPANCY_BYTES"] = counters[91] + stats["SAI_PORT_STAT_IN_WATERMARK_BYTES"] = counters[92] + stats["SAI_PORT_STAT_IN_SHARED_CURR_OCCUPANCY_BYTES"] = counters[93] + stats["SAI_PORT_STAT_IN_SHARED_WATERMARK_BYTES"] = counters[94] + stats["SAI_PORT_STAT_OUT_CURR_OCCUPANCY_BYTES"] = counters[95] + stats["SAI_PORT_STAT_OUT_WATERMARK_BYTES"] = counters[96] + stats["SAI_PORT_STAT_OUT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[97] + stats["SAI_PORT_STAT_OUT_SHARED_WATERMARK_BYTES"] = counters[98] + stats["SAI_PORT_STAT_IN_DROPPED_PKTS"] = counters[99] + stats["SAI_PORT_STAT_OUT_DROPPED_PKTS"] = counters[100] + stats["SAI_PORT_STAT_PAUSE_RX_PKTS"] = counters[101] + stats["SAI_PORT_STAT_PAUSE_TX_PKTS"] = counters[102] + stats["SAI_PORT_STAT_PFC_0_RX_PKTS"] = counters[103] + stats["SAI_PORT_STAT_PFC_0_TX_PKTS"] = counters[104] + stats["SAI_PORT_STAT_PFC_1_RX_PKTS"] = counters[105] + stats["SAI_PORT_STAT_PFC_1_TX_PKTS"] = counters[106] + stats["SAI_PORT_STAT_PFC_2_RX_PKTS"] = counters[107] + stats["SAI_PORT_STAT_PFC_2_TX_PKTS"] = counters[108] + stats["SAI_PORT_STAT_PFC_3_RX_PKTS"] = counters[109] + stats["SAI_PORT_STAT_PFC_3_TX_PKTS"] = counters[110] + stats["SAI_PORT_STAT_PFC_4_RX_PKTS"] = counters[111] + stats["SAI_PORT_STAT_PFC_4_TX_PKTS"] = counters[112] + stats["SAI_PORT_STAT_PFC_5_RX_PKTS"] = counters[113] + stats["SAI_PORT_STAT_PFC_5_TX_PKTS"] = counters[114] + stats["SAI_PORT_STAT_PFC_6_RX_PKTS"] = counters[115] + stats["SAI_PORT_STAT_PFC_6_TX_PKTS"] = counters[116] + stats["SAI_PORT_STAT_PFC_7_RX_PKTS"] = counters[117] + stats["SAI_PORT_STAT_PFC_7_TX_PKTS"] = counters[118] + stats["SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION"] = counters[119] + stats["SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION"] = counters[120] + stats["SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION"] = counters[121] + stats["SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION"] = counters[122] + stats["SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION"] = counters[123] + stats["SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION"] = counters[124] + stats["SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION"] = counters[125] + stats["SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION"] = counters[126] + stats["SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION"] = counters[127] + stats["SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION"] = counters[128] + stats["SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION"] = counters[129] + stats["SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION"] = counters[130] + stats["SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION"] = counters[131] + stats["SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION"] = counters[132] + stats["SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION"] = counters[133] + stats["SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION"] = counters[134] + stats["SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION_US"] = counters[135] + stats["SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION_US"] = counters[136] + stats["SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION_US"] = counters[137] + stats["SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION_US"] = counters[138] + stats["SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION_US"] = counters[139] + stats["SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION_US"] = counters[140] + stats["SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION_US"] = counters[141] + stats["SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION_US"] = counters[142] + stats["SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION_US"] = counters[143] + stats["SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION_US"] = counters[144] + stats["SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION_US"] = counters[145] + stats["SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION_US"] = counters[146] + stats["SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION_US"] = counters[147] + stats["SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION_US"] = counters[148] + stats["SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION_US"] = counters[149] + stats["SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION_US"] = counters[150] + stats["SAI_PORT_STAT_PFC_0_ON2OFF_RX_PKTS"] = counters[151] + stats["SAI_PORT_STAT_PFC_1_ON2OFF_RX_PKTS"] = counters[152] + stats["SAI_PORT_STAT_PFC_2_ON2OFF_RX_PKTS"] = counters[153] + stats["SAI_PORT_STAT_PFC_3_ON2OFF_RX_PKTS"] = counters[154] + stats["SAI_PORT_STAT_PFC_4_ON2OFF_RX_PKTS"] = counters[155] + stats["SAI_PORT_STAT_PFC_5_ON2OFF_RX_PKTS"] = counters[156] + stats["SAI_PORT_STAT_PFC_6_ON2OFF_RX_PKTS"] = counters[157] + stats["SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS"] = counters[158] + stats["SAI_PORT_STAT_DOT3_STATS_ALIGNMENT_ERRORS"] = counters[159] + stats["SAI_PORT_STAT_DOT3_STATS_FCS_ERRORS"] = counters[160] + stats["SAI_PORT_STAT_DOT3_STATS_SINGLE_COLLISION_FRAMES"] = counters[161] + stats["SAI_PORT_STAT_DOT3_STATS_MULTIPLE_COLLISION_FRAMES"] = counters[162] + stats["SAI_PORT_STAT_DOT3_STATS_SQE_TEST_ERRORS"] = counters[163] + stats["SAI_PORT_STAT_DOT3_STATS_DEFERRED_TRANSMISSIONS"] = counters[164] + stats["SAI_PORT_STAT_DOT3_STATS_LATE_COLLISIONS"] = counters[165] + stats["SAI_PORT_STAT_DOT3_STATS_EXCESSIVE_COLLISIONS"] = counters[166] + stats["SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_TRANSMIT_ERRORS"] = counters[167] + stats["SAI_PORT_STAT_DOT3_STATS_CARRIER_SENSE_ERRORS"] = counters[168] + stats["SAI_PORT_STAT_DOT3_STATS_FRAME_TOO_LONGS"] = counters[169] + stats["SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_RECEIVE_ERRORS"] = counters[170] + stats["SAI_PORT_STAT_DOT3_STATS_SYMBOL_ERRORS"] = counters[171] + stats["SAI_PORT_STAT_DOT3_CONTROL_IN_UNKNOWN_OPCODES"] = counters[172] + stats["SAI_PORT_STAT_EEE_TX_EVENT_COUNT"] = counters[173] + stats["SAI_PORT_STAT_EEE_RX_EVENT_COUNT"] = counters[174] + stats["SAI_PORT_STAT_EEE_TX_DURATION"] = counters[175] + stats["SAI_PORT_STAT_EEE_RX_DURATION"] = counters[176] + stats["SAI_PORT_STAT_PRBS_ERROR_COUNT"] = counters[177] + stats["SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES"] = counters[178] + stats["SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES"] = counters[179] + stats["SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS"] = counters[180] + stats["SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS"] = counters[181] + stats["SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS"] = counters[182] + stats["SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE"] = counters[183] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[184] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[185] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[186] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[187] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[188] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[189] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[190] + stats["SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[191] + stats["SAI_PORT_STAT_OUT_DROP_REASON_RANGE_BASE"] = counters[192] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[193] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[194] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[195] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[196] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[197] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[198] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[199] + stats["SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[200] + + return stats + + +def sai_thrift_clear_port_stats(client, + port_oid): + """ + sai_clear_port_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_PORT_STAT_IF_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IF_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_IN_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS) + counter_ids.append(SAI_PORT_STAT_IF_IN_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_IN_VLAN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_QLEN) + counter_ids.append(SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_FRAGMENTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_JABBERS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_PKTS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS) + counter_ids.append(SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS) + counter_ids.append(SAI_PORT_STAT_IP_IN_RECEIVES) + counter_ids.append(SAI_PORT_STAT_IP_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IP_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IP_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_RECEIVES) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_OCTETS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_MCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_IN_DISCARDS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_OCTETS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS) + counter_ids.append(SAI_PORT_STAT_IPV6_OUT_DISCARDS) + counter_ids.append(SAI_PORT_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_STAT_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_IN_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_64_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_65_TO_127_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_128_TO_255_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_256_TO_511_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_512_TO_1023_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_1024_TO_1518_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_1519_TO_2047_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_2048_TO_4095_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_4096_TO_9216_OCTETS) + counter_ids.append(SAI_PORT_STAT_ETHER_OUT_PKTS_9217_TO_16383_OCTETS) + counter_ids.append(SAI_PORT_STAT_IN_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_STAT_OUT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_STAT_IN_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_PAUSE_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PAUSE_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION) + counter_ids.append(SAI_PORT_STAT_PFC_0_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_0_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_1_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_1_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_2_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_2_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_3_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_3_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_4_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_4_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_5_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_5_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_6_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_6_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_7_RX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_7_TX_PAUSE_DURATION_US) + counter_ids.append(SAI_PORT_STAT_PFC_0_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_1_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_2_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_3_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_4_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_5_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_6_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_PFC_7_ON2OFF_RX_PKTS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_ALIGNMENT_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_FCS_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SINGLE_COLLISION_FRAMES) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_MULTIPLE_COLLISION_FRAMES) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SQE_TEST_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_DEFERRED_TRANSMISSIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_LATE_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_EXCESSIVE_COLLISIONS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_TRANSMIT_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_CARRIER_SENSE_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_FRAME_TOO_LONGS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_INTERNAL_MAC_RECEIVE_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_STATS_SYMBOL_ERRORS) + counter_ids.append(SAI_PORT_STAT_DOT3_CONTROL_IN_UNKNOWN_OPCODES) + counter_ids.append(SAI_PORT_STAT_EEE_TX_EVENT_COUNT) + counter_ids.append(SAI_PORT_STAT_EEE_RX_EVENT_COUNT) + counter_ids.append(SAI_PORT_STAT_EEE_TX_DURATION) + counter_ids.append(SAI_PORT_STAT_EEE_RX_DURATION) + counter_ids.append(SAI_PORT_STAT_PRBS_ERROR_COUNT) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES) + counter_ids.append(SAI_PORT_STAT_IF_IN_FEC_SYMBOL_ERRORS) + counter_ids.append(SAI_PORT_STAT_IF_IN_FABRIC_DATA_UNITS) + counter_ids.append(SAI_PORT_STAT_IF_OUT_FABRIC_DATA_UNITS) + counter_ids.append(SAI_PORT_STAT_IN_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_PORT_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_port_stats(port_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_clear_port_all_stats(client, + port_oid): + """ + sai_clear_port_all_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_port_all_stats(port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_port_pool(client, + port_id=None, + buffer_pool_id=None, + qos_wred_profile_id=None, + custom_attribute=None): + """ + sai_create_port_pool() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of port_pool CREATE attributes. + + Returns: + sai_thrift_object_id_t: port_pool_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if buffer_pool_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=buffer_pool_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_BUFFER_POOL_ID, + value=attribute_value) + attr_list.append(attribute) + + if qos_wred_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_wred_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_QOS_WRED_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_port_pool(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_port_pool(client, + port_pool_oid): + """ + sai_remove_port_pool() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_pool_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_port_pool(port_pool_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_port_pool_attribute(client, + port_pool_oid, + qos_wred_profile_id=None, + custom_attribute=None): + """ + sai_set_port_pool_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + port_pool_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port_pool SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if qos_wred_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_wred_profile_id) + attr = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_QOS_WRED_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_port_pool_attribute(port_pool_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_port_pool_attribute(port_pool_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_port_pool_attribute(client, + port_pool_oid, + port_id=None, + buffer_pool_id=None, + qos_wred_profile_id=None, + custom_attribute=None): + """ + sai_get_port_pool_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + port_pool_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port_pool GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_PORT_ID) + attr_list.append(attribute) + + if buffer_pool_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_BUFFER_POOL_ID) + attr_list.append(attribute) + + if qos_wred_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_POOL_ATTR_QOS_WRED_PROFILE_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_port_pool_attribute(port_pool_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_PORT_POOL_ATTR_PORT_ID: + attrs["SAI_PORT_POOL_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_PORT_POOL_ATTR_BUFFER_POOL_ID: + attrs["SAI_PORT_POOL_ATTR_BUFFER_POOL_ID"] = attr.value.oid + attrs["buffer_pool_id"] = attr.value.oid + + if attr.id == SAI_PORT_POOL_ATTR_QOS_WRED_PROFILE_ID: + attrs["SAI_PORT_POOL_ATTR_QOS_WRED_PROFILE_ID"] = attr.value.oid + attrs["qos_wred_profile_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_port_pool_stats(client, + port_pool_oid): + """ + sai_get_port_pool_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_pool_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_PORT_POOL_STAT_IF_OCTETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_DROPPED_PKTS) + + counters = [0] * 22 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_port_pool_stats(port_pool_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_PORT_POOL_STAT_IF_OCTETS"] = counters[0] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[1] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[2] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[3] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[4] + stats["SAI_PORT_POOL_STAT_RED_WRED_DROPPED_PACKETS"] = counters[5] + stats["SAI_PORT_POOL_STAT_RED_WRED_DROPPED_BYTES"] = counters[6] + stats["SAI_PORT_POOL_STAT_WRED_DROPPED_PACKETS"] = counters[7] + stats["SAI_PORT_POOL_STAT_WRED_DROPPED_BYTES"] = counters[8] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS"] = counters[9] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES"] = counters[10] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS"] = counters[11] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES"] = counters[12] + stats["SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS"] = counters[13] + stats["SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_BYTES"] = counters[14] + stats["SAI_PORT_POOL_STAT_WRED_ECN_MARKED_PACKETS"] = counters[15] + stats["SAI_PORT_POOL_STAT_WRED_ECN_MARKED_BYTES"] = counters[16] + stats["SAI_PORT_POOL_STAT_CURR_OCCUPANCY_BYTES"] = counters[17] + stats["SAI_PORT_POOL_STAT_WATERMARK_BYTES"] = counters[18] + stats["SAI_PORT_POOL_STAT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[19] + stats["SAI_PORT_POOL_STAT_SHARED_WATERMARK_BYTES"] = counters[20] + stats["SAI_PORT_POOL_STAT_DROPPED_PKTS"] = counters[21] + + return stats + + +def sai_thrift_get_port_pool_stats_ext(client, + port_pool_oid, + mode): + """ + sai_get_port_pool_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_pool_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_PORT_POOL_STAT_IF_OCTETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_DROPPED_PKTS) + + counters = [0] * 22 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_port_pool_stats_ext(port_pool_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_PORT_POOL_STAT_IF_OCTETS"] = counters[0] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[1] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[2] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[3] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[4] + stats["SAI_PORT_POOL_STAT_RED_WRED_DROPPED_PACKETS"] = counters[5] + stats["SAI_PORT_POOL_STAT_RED_WRED_DROPPED_BYTES"] = counters[6] + stats["SAI_PORT_POOL_STAT_WRED_DROPPED_PACKETS"] = counters[7] + stats["SAI_PORT_POOL_STAT_WRED_DROPPED_BYTES"] = counters[8] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS"] = counters[9] + stats["SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES"] = counters[10] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS"] = counters[11] + stats["SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES"] = counters[12] + stats["SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS"] = counters[13] + stats["SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_BYTES"] = counters[14] + stats["SAI_PORT_POOL_STAT_WRED_ECN_MARKED_PACKETS"] = counters[15] + stats["SAI_PORT_POOL_STAT_WRED_ECN_MARKED_BYTES"] = counters[16] + stats["SAI_PORT_POOL_STAT_CURR_OCCUPANCY_BYTES"] = counters[17] + stats["SAI_PORT_POOL_STAT_WATERMARK_BYTES"] = counters[18] + stats["SAI_PORT_POOL_STAT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[19] + stats["SAI_PORT_POOL_STAT_SHARED_WATERMARK_BYTES"] = counters[20] + stats["SAI_PORT_POOL_STAT_DROPPED_PKTS"] = counters[21] + + return stats + + +def sai_thrift_clear_port_pool_stats(client, + port_pool_oid): + """ + sai_clear_port_pool_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_pool_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_PORT_POOL_STAT_IF_OCTETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_PORT_POOL_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_PORT_POOL_STAT_DROPPED_PKTS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_port_pool_stats(port_pool_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_port_serdes(client, + port_id=None, + preemphasis=None, + idriver=None, + ipredriver=None, + tx_fir_pre1=None, + tx_fir_pre2=None, + tx_fir_pre3=None, + tx_fir_main=None, + tx_fir_post1=None, + tx_fir_post2=None, + tx_fir_post3=None, + tx_fir_attn=None, + custom_attribute=None): + """ + sai_create_port_serdes() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of port_serdes CREATE attributes. + + Returns: + sai_thrift_object_id_t: port_serdes_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if preemphasis is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=preemphasis) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_PREEMPHASIS, + value=attribute_value) + attr_list.append(attribute) + + if idriver is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=idriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_IDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if ipredriver is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=ipredriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_IPREDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_pre1 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_pre1) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_PRE1, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_pre2 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_pre2) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_PRE2, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_pre3 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_pre3) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_PRE3, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_main is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_main) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_MAIN, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_post1 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_post1) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_POST1, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_post2 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_post2) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_POST2, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_post3 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_post3) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_POST3, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_attn is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_attn) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_ATTN, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_port_serdes(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_port_serdes(client, + port_serdes_oid): + """ + sai_remove_port_serdes() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_serdes_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_port_serdes(port_serdes_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_port_serdes_attribute(client, + port_serdes_oid, + custom_attribute=None): + """ + sai_set_port_serdes_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + port_serdes_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del port_serdes_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_port_serdes_attribute(client, + port_serdes_oid, + port_id=None, + preemphasis=None, + idriver=None, + ipredriver=None, + tx_fir_pre1=None, + tx_fir_pre2=None, + tx_fir_pre3=None, + tx_fir_main=None, + tx_fir_post1=None, + tx_fir_post2=None, + tx_fir_post3=None, + tx_fir_attn=None, + custom_attribute=None): + """ + sai_get_port_serdes_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + port_serdes_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port_serdes GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_PORT_ID) + attr_list.append(attribute) + + if preemphasis is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=preemphasis) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_PREEMPHASIS, + value=attribute_value) + attr_list.append(attribute) + + if idriver is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=idriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_IDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if ipredriver is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=ipredriver) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_IPREDRIVER, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_pre1 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_pre1) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_PRE1, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_pre2 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_pre2) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_PRE2, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_pre3 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_pre3) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_PRE3, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_main is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_main) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_MAIN, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_post1 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_post1) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_POST1, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_post2 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_post2) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_POST2, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_post3 is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_post3) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_POST3, + value=attribute_value) + attr_list.append(attribute) + + if tx_fir_attn is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tx_fir_attn) + attribute = sai_thrift_attribute_t(id=SAI_PORT_SERDES_ATTR_TX_FIR_ATTN, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_port_serdes_attribute(port_serdes_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_PORT_SERDES_ATTR_PORT_ID: + attrs["SAI_PORT_SERDES_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_PORT_SERDES_ATTR_PREEMPHASIS: + attrs["SAI_PORT_SERDES_ATTR_PREEMPHASIS"] = attr.value.s32list + attrs["preemphasis"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_IDRIVER: + attrs["SAI_PORT_SERDES_ATTR_IDRIVER"] = attr.value.s32list + attrs["idriver"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_IPREDRIVER: + attrs["SAI_PORT_SERDES_ATTR_IPREDRIVER"] = attr.value.s32list + attrs["ipredriver"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_PRE1: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_PRE1"] = attr.value.s32list + attrs["tx_fir_pre1"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_PRE2: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_PRE2"] = attr.value.s32list + attrs["tx_fir_pre2"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_PRE3: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_PRE3"] = attr.value.s32list + attrs["tx_fir_pre3"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_MAIN: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_MAIN"] = attr.value.s32list + attrs["tx_fir_main"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_POST1: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_POST1"] = attr.value.s32list + attrs["tx_fir_post1"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_POST2: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_POST2"] = attr.value.s32list + attrs["tx_fir_post2"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_POST3: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_POST3"] = attr.value.s32list + attrs["tx_fir_post3"] = attr.value.s32list + + if attr.id == SAI_PORT_SERDES_ATTR_TX_FIR_ATTN: + attrs["SAI_PORT_SERDES_ATTR_TX_FIR_ATTN"] = attr.value.s32list + attrs["tx_fir_attn"] = attr.value.s32list + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_port_connector(client, + system_side_port_id=None, + line_side_port_id=None, + system_side_failover_port_id=None, + line_side_failover_port_id=None, + failover_mode=None, + custom_attribute=None): + """ + sai_create_port_connector() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of port_connector CREATE attributes. + + Returns: + sai_thrift_object_id_t: port_connector_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if system_side_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=system_side_port_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if line_side_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=line_side_port_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if system_side_failover_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=system_side_failover_port_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_FAILOVER_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if line_side_failover_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=line_side_failover_port_id) + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_FAILOVER_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if failover_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=failover_mode) + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_FAILOVER_MODE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_port_connector(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_port_connector(client, + port_connector_oid): + """ + sai_remove_port_connector() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + port_connector_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_port_connector(port_connector_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_port_connector_attribute(client, + port_connector_oid, + failover_mode=None, + custom_attribute=None): + """ + sai_set_port_connector_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + port_connector_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port_connector SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if failover_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=failover_mode) + attr = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_FAILOVER_MODE, + value=attr_value) + client.sai_thrift_set_port_connector_attribute(port_connector_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_port_connector_attribute(port_connector_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_port_connector_attribute(client, + port_connector_oid, + system_side_port_id=None, + line_side_port_id=None, + system_side_failover_port_id=None, + line_side_failover_port_id=None, + failover_mode=None, + custom_attribute=None): + """ + sai_get_port_connector_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + port_connector_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of port_connector GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if system_side_port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_PORT_ID) + attr_list.append(attribute) + + if line_side_port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_PORT_ID) + attr_list.append(attribute) + + if system_side_failover_port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_FAILOVER_PORT_ID) + attr_list.append(attribute) + + if line_side_failover_port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_FAILOVER_PORT_ID) + attr_list.append(attribute) + + if failover_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_PORT_CONNECTOR_ATTR_FAILOVER_MODE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_port_connector_attribute(port_connector_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_PORT_ID: + attrs["SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_PORT_ID"] = attr.value.oid + attrs["system_side_port_id"] = attr.value.oid + + if attr.id == SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_PORT_ID: + attrs["SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_PORT_ID"] = attr.value.oid + attrs["line_side_port_id"] = attr.value.oid + + if attr.id == SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_FAILOVER_PORT_ID: + attrs["SAI_PORT_CONNECTOR_ATTR_SYSTEM_SIDE_FAILOVER_PORT_ID"] = attr.value.oid + attrs["system_side_failover_port_id"] = attr.value.oid + + if attr.id == SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_FAILOVER_PORT_ID: + attrs["SAI_PORT_CONNECTOR_ATTR_LINE_SIDE_FAILOVER_PORT_ID"] = attr.value.oid + attrs["line_side_failover_port_id"] = attr.value.oid + + if attr.id == SAI_PORT_CONNECTOR_ATTR_FAILOVER_MODE: + attrs["SAI_PORT_CONNECTOR_ATTR_FAILOVER_MODE"] = attr.value.s32 + attrs["failover_mode"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# qos_map API + +def sai_thrift_create_qos_map(client, + type=None, + map_to_value_list=None, + custom_attribute=None): + """ + sai_create_qos_map() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of qos_map CREATE attributes. + + Returns: + sai_thrift_object_id_t: qos_map_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_QOS_MAP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if map_to_value_list is not None: + attribute_value = sai_thrift_attribute_value_t(qosmap=map_to_value_list) + attribute = sai_thrift_attribute_t(id=SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_qos_map(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_qos_map(client, + qos_map_oid): + """ + sai_remove_qos_map() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + qos_map_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_qos_map(qos_map_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_qos_map_attribute(client, + qos_map_oid, + map_to_value_list=None, + custom_attribute=None): + """ + sai_set_qos_map_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + qos_map_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of qos_map SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if map_to_value_list is not None: + attr_value = sai_thrift_attribute_value_t(qosmap=map_to_value_list) + attr = sai_thrift_attribute_t(id=SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST, + value=attr_value) + client.sai_thrift_set_qos_map_attribute(qos_map_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_qos_map_attribute(qos_map_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_qos_map_attribute(client, + qos_map_oid, + type=None, + map_to_value_list=None, + custom_attribute=None): + """ + sai_get_qos_map_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + qos_map_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of qos_map GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_QOS_MAP_ATTR_TYPE) + attr_list.append(attribute) + + if map_to_value_list is not None: + attribute_value = sai_thrift_attribute_value_t(qosmap=map_to_value_list) + attribute = sai_thrift_attribute_t(id=SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_qos_map_attribute(qos_map_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_QOS_MAP_ATTR_TYPE: + attrs["SAI_QOS_MAP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST: + attrs["SAI_QOS_MAP_ATTR_MAP_TO_VALUE_LIST"] = attr.value.qosmap + attrs["map_to_value_list"] = attr.value.qosmap + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# queue API + +def sai_thrift_create_queue(client, + type=None, + port=None, + index=None, + parent_scheduler_node=None, + wred_profile_id=None, + buffer_profile_id=None, + scheduler_profile_id=None, + enable_pfc_dldr=None, + pfc_dlr_init=None, + tam_object=None, + pfc_dlr_packet_action=None, + custom_attribute=None): + """ + sai_create_queue() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of queue CREATE attributes. + + Returns: + sai_thrift_object_id_t: queue_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if port is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PORT, + value=attribute_value) + attr_list.append(attribute) + + if index is not None: + attribute_value = sai_thrift_attribute_value_t(u8=index) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if parent_scheduler_node is not None: + attribute_value = sai_thrift_attribute_value_t(oid=parent_scheduler_node) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PARENT_SCHEDULER_NODE, + value=attribute_value) + attr_list.append(attribute) + + if wred_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=wred_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_WRED_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if buffer_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=buffer_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_BUFFER_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if scheduler_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=scheduler_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_SCHEDULER_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if enable_pfc_dldr is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=enable_pfc_dldr) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_ENABLE_PFC_DLDR, + value=attribute_value) + attr_list.append(attribute) + + if pfc_dlr_init is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=pfc_dlr_init) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_DLR_INIT, + value=attribute_value) + attr_list.append(attribute) + + if tam_object is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_TAM_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if pfc_dlr_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=pfc_dlr_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_DLR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_queue(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_queue(client, + queue_oid): + """ + sai_remove_queue() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + queue_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_queue(queue_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_queue_attribute(client, + queue_oid, + parent_scheduler_node=None, + wred_profile_id=None, + buffer_profile_id=None, + scheduler_profile_id=None, + enable_pfc_dldr=None, + pfc_dlr_init=None, + tam_object=None, + pfc_dlr_packet_action=None, + custom_attribute=None): + """ + sai_set_queue_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + queue_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of queue SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if parent_scheduler_node is not None: + attr_value = sai_thrift_attribute_value_t(oid=parent_scheduler_node) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PARENT_SCHEDULER_NODE, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if wred_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=wred_profile_id) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_WRED_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if buffer_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=buffer_profile_id) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_BUFFER_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if scheduler_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=scheduler_profile_id) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_SCHEDULER_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if enable_pfc_dldr is not None: + attr_value = sai_thrift_attribute_value_t(booldata=enable_pfc_dldr) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_ENABLE_PFC_DLDR, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if pfc_dlr_init is not None: + attr_value = sai_thrift_attribute_value_t(booldata=pfc_dlr_init) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_DLR_INIT, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if tam_object is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam_object) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_TAM_OBJECT, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if pfc_dlr_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=pfc_dlr_packet_action) + attr = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_DLR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_queue_attribute(queue_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_queue_attribute(client, + queue_oid, + type=None, + port=None, + index=None, + parent_scheduler_node=None, + wred_profile_id=None, + buffer_profile_id=None, + scheduler_profile_id=None, + pause_status=None, + enable_pfc_dldr=None, + pfc_dlr_init=None, + tam_object=None, + pfc_dlr_packet_action=None, + pfc_continuous_deadlock_state=None, + custom_attribute=None): + """ + sai_get_queue_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + queue_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of queue GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_TYPE) + attr_list.append(attribute) + + if port is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PORT) + attr_list.append(attribute) + + if index is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_INDEX) + attr_list.append(attribute) + + if parent_scheduler_node is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PARENT_SCHEDULER_NODE) + attr_list.append(attribute) + + if wred_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_WRED_PROFILE_ID) + attr_list.append(attribute) + + if buffer_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_BUFFER_PROFILE_ID) + attr_list.append(attribute) + + if scheduler_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_SCHEDULER_PROFILE_ID) + attr_list.append(attribute) + + if pause_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PAUSE_STATUS) + attr_list.append(attribute) + + if enable_pfc_dldr is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_ENABLE_PFC_DLDR) + attr_list.append(attribute) + + if pfc_dlr_init is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_DLR_INIT) + attr_list.append(attribute) + + if tam_object is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object) + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_TAM_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if pfc_dlr_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_DLR_PACKET_ACTION) + attr_list.append(attribute) + + if pfc_continuous_deadlock_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_QUEUE_ATTR_PFC_CONTINUOUS_DEADLOCK_STATE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_queue_attribute(queue_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_QUEUE_ATTR_TYPE: + attrs["SAI_QUEUE_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_QUEUE_ATTR_PORT: + attrs["SAI_QUEUE_ATTR_PORT"] = attr.value.oid + attrs["port"] = attr.value.oid + + if attr.id == SAI_QUEUE_ATTR_INDEX: + attrs["SAI_QUEUE_ATTR_INDEX"] = attr.value.u8 + attrs["index"] = attr.value.u8 + + if attr.id == SAI_QUEUE_ATTR_PARENT_SCHEDULER_NODE: + attrs["SAI_QUEUE_ATTR_PARENT_SCHEDULER_NODE"] = attr.value.oid + attrs["parent_scheduler_node"] = attr.value.oid + + if attr.id == SAI_QUEUE_ATTR_WRED_PROFILE_ID: + attrs["SAI_QUEUE_ATTR_WRED_PROFILE_ID"] = attr.value.oid + attrs["wred_profile_id"] = attr.value.oid + + if attr.id == SAI_QUEUE_ATTR_BUFFER_PROFILE_ID: + attrs["SAI_QUEUE_ATTR_BUFFER_PROFILE_ID"] = attr.value.oid + attrs["buffer_profile_id"] = attr.value.oid + + if attr.id == SAI_QUEUE_ATTR_SCHEDULER_PROFILE_ID: + attrs["SAI_QUEUE_ATTR_SCHEDULER_PROFILE_ID"] = attr.value.oid + attrs["scheduler_profile_id"] = attr.value.oid + + if attr.id == SAI_QUEUE_ATTR_PAUSE_STATUS: + attrs["SAI_QUEUE_ATTR_PAUSE_STATUS"] = attr.value.booldata + attrs["pause_status"] = attr.value.booldata + + if attr.id == SAI_QUEUE_ATTR_ENABLE_PFC_DLDR: + attrs["SAI_QUEUE_ATTR_ENABLE_PFC_DLDR"] = attr.value.booldata + attrs["enable_pfc_dldr"] = attr.value.booldata + + if attr.id == SAI_QUEUE_ATTR_PFC_DLR_INIT: + attrs["SAI_QUEUE_ATTR_PFC_DLR_INIT"] = attr.value.booldata + attrs["pfc_dlr_init"] = attr.value.booldata + + if attr.id == SAI_QUEUE_ATTR_TAM_OBJECT: + attrs["SAI_QUEUE_ATTR_TAM_OBJECT"] = attr.value.objlist + attrs["tam_object"] = attr.value.objlist + + if attr.id == SAI_QUEUE_ATTR_PFC_DLR_PACKET_ACTION: + attrs["SAI_QUEUE_ATTR_PFC_DLR_PACKET_ACTION"] = attr.value.s32 + attrs["pfc_dlr_packet_action"] = attr.value.s32 + + if attr.id == SAI_QUEUE_ATTR_PFC_CONTINUOUS_DEADLOCK_STATE: + attrs["SAI_QUEUE_ATTR_PFC_CONTINUOUS_DEADLOCK_STATE"] = attr.value.s32 + attrs["pfc_continuous_deadlock_state"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_queue_stats(client, + queue_oid): + """ + sai_get_queue_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + queue_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_QUEUE_STAT_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_BYTES) + counter_ids.append(SAI_QUEUE_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_QUEUE_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL) + counter_ids.append(SAI_QUEUE_STAT_WATERMARK_LEVEL) + counter_ids.append(SAI_QUEUE_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 39 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_queue_stats(queue_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_QUEUE_STAT_PACKETS"] = counters[0] + stats["SAI_QUEUE_STAT_BYTES"] = counters[1] + stats["SAI_QUEUE_STAT_DROPPED_PACKETS"] = counters[2] + stats["SAI_QUEUE_STAT_DROPPED_BYTES"] = counters[3] + stats["SAI_QUEUE_STAT_GREEN_PACKETS"] = counters[4] + stats["SAI_QUEUE_STAT_GREEN_BYTES"] = counters[5] + stats["SAI_QUEUE_STAT_GREEN_DROPPED_PACKETS"] = counters[6] + stats["SAI_QUEUE_STAT_GREEN_DROPPED_BYTES"] = counters[7] + stats["SAI_QUEUE_STAT_YELLOW_PACKETS"] = counters[8] + stats["SAI_QUEUE_STAT_YELLOW_BYTES"] = counters[9] + stats["SAI_QUEUE_STAT_YELLOW_DROPPED_PACKETS"] = counters[10] + stats["SAI_QUEUE_STAT_YELLOW_DROPPED_BYTES"] = counters[11] + stats["SAI_QUEUE_STAT_RED_PACKETS"] = counters[12] + stats["SAI_QUEUE_STAT_RED_BYTES"] = counters[13] + stats["SAI_QUEUE_STAT_RED_DROPPED_PACKETS"] = counters[14] + stats["SAI_QUEUE_STAT_RED_DROPPED_BYTES"] = counters[15] + stats["SAI_QUEUE_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[16] + stats["SAI_QUEUE_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[17] + stats["SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[18] + stats["SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[19] + stats["SAI_QUEUE_STAT_RED_WRED_DROPPED_PACKETS"] = counters[20] + stats["SAI_QUEUE_STAT_RED_WRED_DROPPED_BYTES"] = counters[21] + stats["SAI_QUEUE_STAT_WRED_DROPPED_PACKETS"] = counters[22] + stats["SAI_QUEUE_STAT_WRED_DROPPED_BYTES"] = counters[23] + stats["SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES"] = counters[24] + stats["SAI_QUEUE_STAT_WATERMARK_BYTES"] = counters[25] + stats["SAI_QUEUE_STAT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[26] + stats["SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES"] = counters[27] + stats["SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_PACKETS"] = counters[28] + stats["SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_BYTES"] = counters[29] + stats["SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_PACKETS"] = counters[30] + stats["SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_BYTES"] = counters[31] + stats["SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_PACKETS"] = counters[32] + stats["SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_BYTES"] = counters[33] + stats["SAI_QUEUE_STAT_WRED_ECN_MARKED_PACKETS"] = counters[34] + stats["SAI_QUEUE_STAT_WRED_ECN_MARKED_BYTES"] = counters[35] + stats["SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL"] = counters[36] + stats["SAI_QUEUE_STAT_WATERMARK_LEVEL"] = counters[37] + stats["SAI_QUEUE_STAT_CUSTOM_RANGE_BASE"] = counters[38] + + return stats + + +def sai_thrift_get_queue_stats_ext(client, + queue_oid, + mode): + """ + sai_get_queue_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + queue_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_QUEUE_STAT_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_BYTES) + counter_ids.append(SAI_QUEUE_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_QUEUE_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL) + counter_ids.append(SAI_QUEUE_STAT_WATERMARK_LEVEL) + counter_ids.append(SAI_QUEUE_STAT_CUSTOM_RANGE_BASE) + + counters = [0] * 39 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_queue_stats_ext(queue_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_QUEUE_STAT_PACKETS"] = counters[0] + stats["SAI_QUEUE_STAT_BYTES"] = counters[1] + stats["SAI_QUEUE_STAT_DROPPED_PACKETS"] = counters[2] + stats["SAI_QUEUE_STAT_DROPPED_BYTES"] = counters[3] + stats["SAI_QUEUE_STAT_GREEN_PACKETS"] = counters[4] + stats["SAI_QUEUE_STAT_GREEN_BYTES"] = counters[5] + stats["SAI_QUEUE_STAT_GREEN_DROPPED_PACKETS"] = counters[6] + stats["SAI_QUEUE_STAT_GREEN_DROPPED_BYTES"] = counters[7] + stats["SAI_QUEUE_STAT_YELLOW_PACKETS"] = counters[8] + stats["SAI_QUEUE_STAT_YELLOW_BYTES"] = counters[9] + stats["SAI_QUEUE_STAT_YELLOW_DROPPED_PACKETS"] = counters[10] + stats["SAI_QUEUE_STAT_YELLOW_DROPPED_BYTES"] = counters[11] + stats["SAI_QUEUE_STAT_RED_PACKETS"] = counters[12] + stats["SAI_QUEUE_STAT_RED_BYTES"] = counters[13] + stats["SAI_QUEUE_STAT_RED_DROPPED_PACKETS"] = counters[14] + stats["SAI_QUEUE_STAT_RED_DROPPED_BYTES"] = counters[15] + stats["SAI_QUEUE_STAT_GREEN_WRED_DROPPED_PACKETS"] = counters[16] + stats["SAI_QUEUE_STAT_GREEN_WRED_DROPPED_BYTES"] = counters[17] + stats["SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_PACKETS"] = counters[18] + stats["SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_BYTES"] = counters[19] + stats["SAI_QUEUE_STAT_RED_WRED_DROPPED_PACKETS"] = counters[20] + stats["SAI_QUEUE_STAT_RED_WRED_DROPPED_BYTES"] = counters[21] + stats["SAI_QUEUE_STAT_WRED_DROPPED_PACKETS"] = counters[22] + stats["SAI_QUEUE_STAT_WRED_DROPPED_BYTES"] = counters[23] + stats["SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES"] = counters[24] + stats["SAI_QUEUE_STAT_WATERMARK_BYTES"] = counters[25] + stats["SAI_QUEUE_STAT_SHARED_CURR_OCCUPANCY_BYTES"] = counters[26] + stats["SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES"] = counters[27] + stats["SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_PACKETS"] = counters[28] + stats["SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_BYTES"] = counters[29] + stats["SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_PACKETS"] = counters[30] + stats["SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_BYTES"] = counters[31] + stats["SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_PACKETS"] = counters[32] + stats["SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_BYTES"] = counters[33] + stats["SAI_QUEUE_STAT_WRED_ECN_MARKED_PACKETS"] = counters[34] + stats["SAI_QUEUE_STAT_WRED_ECN_MARKED_BYTES"] = counters[35] + stats["SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL"] = counters[36] + stats["SAI_QUEUE_STAT_WATERMARK_LEVEL"] = counters[37] + stats["SAI_QUEUE_STAT_CUSTOM_RANGE_BASE"] = counters[38] + + return stats + + +def sai_thrift_clear_queue_stats(client, + queue_oid): + """ + sai_clear_queue_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + queue_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_QUEUE_STAT_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_BYTES) + counter_ids.append(SAI_QUEUE_STAT_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WRED_DROPPED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_WRED_DROPPED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WATERMARK_BYTES) + counter_ids.append(SAI_QUEUE_STAT_SHARED_CURR_OCCUPANCY_BYTES) + counter_ids.append(SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_GREEN_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_YELLOW_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_RED_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_WRED_ECN_MARKED_PACKETS) + counter_ids.append(SAI_QUEUE_STAT_WRED_ECN_MARKED_BYTES) + counter_ids.append(SAI_QUEUE_STAT_CURR_OCCUPANCY_LEVEL) + counter_ids.append(SAI_QUEUE_STAT_WATERMARK_LEVEL) + counter_ids.append(SAI_QUEUE_STAT_CUSTOM_RANGE_BASE) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_queue_stats(queue_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# route API + +def sai_thrift_create_route_entry(client, + route_entry, + packet_action=None, + user_trap_id=None, + next_hop_id=None, + meta_data=None, + counter_id=None, + custom_attribute=None): + """ + sai_create_route_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + route_entry(sai_thrift_route_entry_t): route_entry IN argument + + For the other parameters, see documentation of route_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if user_trap_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=user_trap_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_USER_TRAP_ID, + value=attribute_value) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID, + value=attribute_value) + attr_list.append(attribute) + + if meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(u32=meta_data) + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_route_entry(route_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_route_entry(client, + route_entry): + """ + sai_remove_route_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + route_entry(sai_thrift_route_entry_t): route_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_route_entry(route_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_route_entry_attribute(client, + route_entry, + packet_action=None, + user_trap_id=None, + next_hop_id=None, + meta_data=None, + counter_id=None, + custom_attribute=None): + """ + sai_set_route_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + route_entry(sai_thrift_route_entry_t): route_entry IN argument + + For the other parameters, see documentation of route_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_route_entry_attribute(route_entry, attr) + + if user_trap_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=user_trap_id) + attr = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_USER_TRAP_ID, + value=attr_value) + client.sai_thrift_set_route_entry_attribute(route_entry, attr) + + if next_hop_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attr = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID, + value=attr_value) + client.sai_thrift_set_route_entry_attribute(route_entry, attr) + + if meta_data is not None: + attr_value = sai_thrift_attribute_value_t(u32=meta_data) + attr = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_META_DATA, + value=attr_value) + client.sai_thrift_set_route_entry_attribute(route_entry, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_route_entry_attribute(route_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_route_entry_attribute(route_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_route_entry_attribute(client, + route_entry, + packet_action=None, + user_trap_id=None, + next_hop_id=None, + meta_data=None, + ip_addr_family=None, + counter_id=None, + custom_attribute=None): + """ + sai_get_route_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + route_entry(sai_thrift_route_entry_t): route_entry IN argument + + For the other parameters, see documentation of route_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if user_trap_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_USER_TRAP_ID) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID) + attr_list.append(attribute) + + if meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_META_DATA) + attr_list.append(attribute) + + if ip_addr_family is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTE_ENTRY_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_route_entry_attribute(route_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_ROUTE_ENTRY_ATTR_USER_TRAP_ID: + attrs["SAI_ROUTE_ENTRY_ATTR_USER_TRAP_ID"] = attr.value.oid + attrs["user_trap_id"] = attr.value.oid + + if attr.id == SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID: + attrs["SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID"] = attr.value.oid + attrs["next_hop_id"] = attr.value.oid + + if attr.id == SAI_ROUTE_ENTRY_ATTR_META_DATA: + attrs["SAI_ROUTE_ENTRY_ATTR_META_DATA"] = attr.value.u32 + attrs["meta_data"] = attr.value.u32 + + if attr.id == SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY: + attrs["SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY"] = attr.value.s32 + attrs["ip_addr_family"] = attr.value.s32 + + if attr.id == SAI_ROUTE_ENTRY_ATTR_COUNTER_ID: + attrs["SAI_ROUTE_ENTRY_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_bulk_create_route_entry(client, + route_entry, + attr_count, + mode, + packet_action=None, + user_trap_id=None, + next_hop_id=None, + meta_data=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_create_route_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + route_entry(List[sai_thrift_route_entry_t]): route_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of route_entry CREATE attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del route_entry + del attr_count + del mode + + # No function call - delete all attributes + del packet_action + del user_trap_id + del next_hop_id + del meta_data + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_remove_route_entry(client, + route_entry, + mode): + """ + sai_bulk_remove_route_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + route_entry(List[sai_thrift_route_entry_t]): route_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del route_entry + del mode + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_set_route_entry_attribute(client, + route_entry, + mode, + packet_action=None, + user_trap_id=None, + next_hop_id=None, + meta_data=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_set_route_entry_attribute() - UNSUPPORTED + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + route_entry(List[sai_thrift_route_entry_t]): route_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of route_entry SET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del route_entry + del mode + + # No function call - delete all attributes + del packet_action + del user_trap_id + del next_hop_id + del meta_data + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_get_route_entry_attribute(client, + route_entry, + attr_count, + mode, + object_statuses, + packet_action=None, + user_trap_id=None, + next_hop_id=None, + meta_data=None, + ip_addr_family=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_get_route_entry_attribute() - UNSUPPORTED + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + route_entry(List[sai_thrift_route_entry_t]): route_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + object_statuses(List[sai_thrift_status_t]): status_list OUT argument + + For the other parameters, see documentation of route_entry GET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del route_entry + del attr_count + del mode + del object_statuses + + # No function call - delete all attributes + del packet_action + del user_trap_id + del next_hop_id + del meta_data + del ip_addr_family + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +# router_interface API + +def sai_thrift_create_router_interface(client, + virtual_router_id=None, + type=None, + port_id=None, + vlan_id=None, + outer_vlan_id=None, + inner_vlan_id=None, + bridge_id=None, + src_mac_address=None, + admin_v4_state=None, + admin_v6_state=None, + mtu=None, + ingress_acl=None, + egress_acl=None, + neighbor_miss_packet_action=None, + v4_mcast_enable=None, + v6_mcast_enable=None, + loopback_packet_action=None, + is_virtual=None, + nat_zone_id=None, + disable_decrement_ttl=None, + admin_mpls_state=None, + custom_attribute=None): + """ + sai_create_router_interface() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of router_interface CREATE attributes. + + Returns: + sai_thrift_object_id_t: router_interface_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if virtual_router_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=virtual_router_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if outer_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=outer_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if inner_vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=inner_vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_INNER_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if bridge_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_BRIDGE_ID, + value=attribute_value) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if admin_v4_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_v4_state) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE, + value=attribute_value) + attr_list.append(attribute) + + if admin_v6_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_v6_state) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE, + value=attribute_value) + attr_list.append(attribute) + + if mtu is not None: + attribute_value = sai_thrift_attribute_value_t(u32=mtu) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_MTU, + value=attribute_value) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_INGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if egress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_acl) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_EGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if neighbor_miss_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=neighbor_miss_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_NEIGHBOR_MISS_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if v4_mcast_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=v4_mcast_enable) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_V4_MCAST_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if v6_mcast_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=v6_mcast_enable) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_V6_MCAST_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if loopback_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=loopback_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if is_virtual is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=is_virtual) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_IS_VIRTUAL, + value=attribute_value) + attr_list.append(attribute) + + if nat_zone_id is not None: + attribute_value = sai_thrift_attribute_value_t(u8=nat_zone_id) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_NAT_ZONE_ID, + value=attribute_value) + attr_list.append(attribute) + + if disable_decrement_ttl is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=disable_decrement_ttl) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_DISABLE_DECREMENT_TTL, + value=attribute_value) + attr_list.append(attribute) + + if admin_mpls_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_mpls_state) + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_MPLS_STATE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_router_interface(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_router_interface(client, + router_interface_oid): + """ + sai_remove_router_interface() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + router_interface_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_router_interface(router_interface_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_router_interface_attribute(client, + router_interface_oid, + src_mac_address=None, + admin_v4_state=None, + admin_v6_state=None, + mtu=None, + ingress_acl=None, + egress_acl=None, + neighbor_miss_packet_action=None, + v4_mcast_enable=None, + v6_mcast_enable=None, + loopback_packet_action=None, + nat_zone_id=None, + disable_decrement_ttl=None, + admin_mpls_state=None, + custom_attribute=None): + """ + sai_set_router_interface_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + router_interface_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of router_interface SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if src_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if admin_v4_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_v4_state) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if admin_v6_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_v6_state) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if mtu is not None: + attr_value = sai_thrift_attribute_value_t(u32=mtu) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_MTU, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if ingress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_INGRESS_ACL, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if egress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_acl) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_EGRESS_ACL, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if neighbor_miss_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=neighbor_miss_packet_action) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_NEIGHBOR_MISS_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if v4_mcast_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=v4_mcast_enable) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_V4_MCAST_ENABLE, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if v6_mcast_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=v6_mcast_enable) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_V6_MCAST_ENABLE, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if loopback_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=loopback_packet_action) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if nat_zone_id is not None: + attr_value = sai_thrift_attribute_value_t(u8=nat_zone_id) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_NAT_ZONE_ID, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if disable_decrement_ttl is not None: + attr_value = sai_thrift_attribute_value_t(booldata=disable_decrement_ttl) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_DISABLE_DECREMENT_TTL, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if admin_mpls_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_mpls_state) + attr = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_MPLS_STATE, + value=attr_value) + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_router_interface_attribute(router_interface_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_router_interface_attribute(client, + router_interface_oid, + virtual_router_id=None, + type=None, + port_id=None, + vlan_id=None, + outer_vlan_id=None, + inner_vlan_id=None, + bridge_id=None, + src_mac_address=None, + admin_v4_state=None, + admin_v6_state=None, + mtu=None, + ingress_acl=None, + egress_acl=None, + neighbor_miss_packet_action=None, + v4_mcast_enable=None, + v6_mcast_enable=None, + loopback_packet_action=None, + is_virtual=None, + nat_zone_id=None, + disable_decrement_ttl=None, + admin_mpls_state=None, + custom_attribute=None): + """ + sai_get_router_interface_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + router_interface_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of router_interface GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if virtual_router_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_TYPE) + attr_list.append(attribute) + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_PORT_ID) + attr_list.append(attribute) + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_VLAN_ID) + attr_list.append(attribute) + + if outer_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID) + attr_list.append(attribute) + + if inner_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_INNER_VLAN_ID) + attr_list.append(attribute) + + if bridge_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_BRIDGE_ID) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS) + attr_list.append(attribute) + + if admin_v4_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE) + attr_list.append(attribute) + + if admin_v6_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE) + attr_list.append(attribute) + + if mtu is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_MTU) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_INGRESS_ACL) + attr_list.append(attribute) + + if egress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_EGRESS_ACL) + attr_list.append(attribute) + + if neighbor_miss_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_NEIGHBOR_MISS_PACKET_ACTION) + attr_list.append(attribute) + + if v4_mcast_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_V4_MCAST_ENABLE) + attr_list.append(attribute) + + if v6_mcast_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_V6_MCAST_ENABLE) + attr_list.append(attribute) + + if loopback_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION) + attr_list.append(attribute) + + if is_virtual is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_IS_VIRTUAL) + attr_list.append(attribute) + + if nat_zone_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_NAT_ZONE_ID) + attr_list.append(attribute) + + if disable_decrement_ttl is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_DISABLE_DECREMENT_TTL) + attr_list.append(attribute) + + if admin_mpls_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_ROUTER_INTERFACE_ATTR_ADMIN_MPLS_STATE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_router_interface_attribute(router_interface_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID"] = attr.value.oid + attrs["virtual_router_id"] = attr.value.oid + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_TYPE: + attrs["SAI_ROUTER_INTERFACE_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_PORT_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_VLAN_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_VLAN_ID"] = attr.value.oid + attrs["vlan_id"] = attr.value.oid + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID"] = attr.value.u16 + attrs["outer_vlan_id"] = attr.value.u16 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_INNER_VLAN_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_INNER_VLAN_ID"] = attr.value.u16 + attrs["inner_vlan_id"] = attr.value.u16 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_BRIDGE_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_BRIDGE_ID"] = attr.value.oid + attrs["bridge_id"] = attr.value.oid + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS: + attrs["SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS"] = attr.value.mac + attrs["src_mac_address"] = attr.value.mac + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE: + attrs["SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE"] = attr.value.booldata + attrs["admin_v4_state"] = attr.value.booldata + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE: + attrs["SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE"] = attr.value.booldata + attrs["admin_v6_state"] = attr.value.booldata + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_MTU: + attrs["SAI_ROUTER_INTERFACE_ATTR_MTU"] = attr.value.u32 + attrs["mtu"] = attr.value.u32 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_INGRESS_ACL: + attrs["SAI_ROUTER_INTERFACE_ATTR_INGRESS_ACL"] = attr.value.oid + attrs["ingress_acl"] = attr.value.oid + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_EGRESS_ACL: + attrs["SAI_ROUTER_INTERFACE_ATTR_EGRESS_ACL"] = attr.value.oid + attrs["egress_acl"] = attr.value.oid + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_NEIGHBOR_MISS_PACKET_ACTION: + attrs["SAI_ROUTER_INTERFACE_ATTR_NEIGHBOR_MISS_PACKET_ACTION"] = attr.value.s32 + attrs["neighbor_miss_packet_action"] = attr.value.s32 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_V4_MCAST_ENABLE: + attrs["SAI_ROUTER_INTERFACE_ATTR_V4_MCAST_ENABLE"] = attr.value.booldata + attrs["v4_mcast_enable"] = attr.value.booldata + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_V6_MCAST_ENABLE: + attrs["SAI_ROUTER_INTERFACE_ATTR_V6_MCAST_ENABLE"] = attr.value.booldata + attrs["v6_mcast_enable"] = attr.value.booldata + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION: + attrs["SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION"] = attr.value.s32 + attrs["loopback_packet_action"] = attr.value.s32 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_IS_VIRTUAL: + attrs["SAI_ROUTER_INTERFACE_ATTR_IS_VIRTUAL"] = attr.value.booldata + attrs["is_virtual"] = attr.value.booldata + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_NAT_ZONE_ID: + attrs["SAI_ROUTER_INTERFACE_ATTR_NAT_ZONE_ID"] = attr.value.u8 + attrs["nat_zone_id"] = attr.value.u8 + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_DISABLE_DECREMENT_TTL: + attrs["SAI_ROUTER_INTERFACE_ATTR_DISABLE_DECREMENT_TTL"] = attr.value.booldata + attrs["disable_decrement_ttl"] = attr.value.booldata + + if attr.id == SAI_ROUTER_INTERFACE_ATTR_ADMIN_MPLS_STATE: + attrs["SAI_ROUTER_INTERFACE_ATTR_ADMIN_MPLS_STATE"] = attr.value.booldata + attrs["admin_mpls_state"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_router_interface_stats(client, + router_interface_oid): + """ + sai_get_router_interface_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + router_interface_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS) + + counters = [0] * 8 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_router_interface_stats(router_interface_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_ROUTER_INTERFACE_STAT_IN_OCTETS"] = counters[0] + stats["SAI_ROUTER_INTERFACE_STAT_IN_PACKETS"] = counters[1] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS"] = counters[3] + stats["SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS"] = counters[4] + stats["SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS"] = counters[5] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS"] = counters[6] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS"] = counters[7] + + return stats + + +def sai_thrift_get_router_interface_stats_ext(client, + router_interface_oid, + mode): + """ + sai_get_router_interface_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + router_interface_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS) + + counters = [0] * 8 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_router_interface_stats_ext(router_interface_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_ROUTER_INTERFACE_STAT_IN_OCTETS"] = counters[0] + stats["SAI_ROUTER_INTERFACE_STAT_IN_PACKETS"] = counters[1] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS"] = counters[3] + stats["SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS"] = counters[4] + stats["SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS"] = counters[5] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS"] = counters[6] + stats["SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS"] = counters[7] + + return stats + + +def sai_thrift_clear_router_interface_stats(client, + router_interface_oid): + """ + sai_clear_router_interface_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + router_interface_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS) + counter_ids.append(SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_router_interface_stats(router_interface_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# rpf_group API + +def sai_thrift_create_rpf_group(client, + custom_attribute=None): + """ + sai_create_rpf_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + sai_thrift_object_id_t: rpf_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_rpf_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_rpf_group(client, + rpf_group_oid): + """ + sai_remove_rpf_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + rpf_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_rpf_group(rpf_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_rpf_group_attribute(client, + rpf_group_oid, + custom_attribute=None): + """ + sai_set_rpf_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + rpf_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del rpf_group_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_rpf_group_attribute(client, + rpf_group_oid, + rpf_interface_count=None, + rpf_member_list=None, + custom_attribute=None): + """ + sai_get_rpf_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + rpf_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of rpf_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if rpf_interface_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_RPF_GROUP_ATTR_RPF_INTERFACE_COUNT) + attr_list.append(attribute) + + if rpf_member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=rpf_member_list) + attribute = sai_thrift_attribute_t(id=SAI_RPF_GROUP_ATTR_RPF_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_rpf_group_attribute(rpf_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_RPF_GROUP_ATTR_RPF_INTERFACE_COUNT: + attrs["SAI_RPF_GROUP_ATTR_RPF_INTERFACE_COUNT"] = attr.value.u32 + attrs["rpf_interface_count"] = attr.value.u32 + + if attr.id == SAI_RPF_GROUP_ATTR_RPF_MEMBER_LIST: + attrs["SAI_RPF_GROUP_ATTR_RPF_MEMBER_LIST"] = attr.value.objlist + attrs["rpf_member_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_rpf_group_member(client, + rpf_group_id=None, + rpf_interface_id=None, + custom_attribute=None): + """ + sai_create_rpf_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of rpf_group_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: rpf_group_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if rpf_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=rpf_group_id) + attribute = sai_thrift_attribute_t(id=SAI_RPF_GROUP_MEMBER_ATTR_RPF_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if rpf_interface_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=rpf_interface_id) + attribute = sai_thrift_attribute_t(id=SAI_RPF_GROUP_MEMBER_ATTR_RPF_INTERFACE_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_rpf_group_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_rpf_group_member(client, + rpf_group_member_oid): + """ + sai_remove_rpf_group_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + rpf_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_rpf_group_member(rpf_group_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_rpf_group_member_attribute(client, + rpf_group_member_oid, + custom_attribute=None): + """ + sai_set_rpf_group_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + rpf_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del rpf_group_member_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_rpf_group_member_attribute(client, + rpf_group_member_oid, + rpf_group_id=None, + rpf_interface_id=None, + custom_attribute=None): + """ + sai_get_rpf_group_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + rpf_group_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of rpf_group_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if rpf_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_RPF_GROUP_MEMBER_ATTR_RPF_GROUP_ID) + attr_list.append(attribute) + + if rpf_interface_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_RPF_GROUP_MEMBER_ATTR_RPF_INTERFACE_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_rpf_group_member_attribute(rpf_group_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_RPF_GROUP_MEMBER_ATTR_RPF_GROUP_ID: + attrs["SAI_RPF_GROUP_MEMBER_ATTR_RPF_GROUP_ID"] = attr.value.oid + attrs["rpf_group_id"] = attr.value.oid + + if attr.id == SAI_RPF_GROUP_MEMBER_ATTR_RPF_INTERFACE_ID: + attrs["SAI_RPF_GROUP_MEMBER_ATTR_RPF_INTERFACE_ID"] = attr.value.oid + attrs["rpf_interface_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# samplepacket API + +def sai_thrift_create_samplepacket(client, + sample_rate=None, + type=None, + mode=None, + custom_attribute=None): + """ + sai_create_samplepacket() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of samplepacket CREATE attributes. + + Returns: + sai_thrift_object_id_t: samplepacket_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if sample_rate is not None: + attribute_value = sai_thrift_attribute_value_t(u32=sample_rate) + attribute = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=mode) + attribute = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_MODE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_samplepacket(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_samplepacket(client, + samplepacket_oid): + """ + sai_remove_samplepacket() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + samplepacket_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_samplepacket(samplepacket_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_samplepacket_attribute(client, + samplepacket_oid, + sample_rate=None, + custom_attribute=None): + """ + sai_set_samplepacket_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + samplepacket_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of samplepacket SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if sample_rate is not None: + attr_value = sai_thrift_attribute_value_t(u32=sample_rate) + attr = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE, + value=attr_value) + client.sai_thrift_set_samplepacket_attribute(samplepacket_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_samplepacket_attribute(samplepacket_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_samplepacket_attribute(client, + samplepacket_oid, + sample_rate=None, + type=None, + mode=None, + custom_attribute=None): + """ + sai_get_samplepacket_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + samplepacket_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of samplepacket GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if sample_rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_TYPE) + attr_list.append(attribute) + + if mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SAMPLEPACKET_ATTR_MODE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_samplepacket_attribute(samplepacket_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE: + attrs["SAI_SAMPLEPACKET_ATTR_SAMPLE_RATE"] = attr.value.u32 + attrs["sample_rate"] = attr.value.u32 + + if attr.id == SAI_SAMPLEPACKET_ATTR_TYPE: + attrs["SAI_SAMPLEPACKET_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_SAMPLEPACKET_ATTR_MODE: + attrs["SAI_SAMPLEPACKET_ATTR_MODE"] = attr.value.s32 + attrs["mode"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# scheduler API + +def sai_thrift_create_scheduler(client, + scheduling_type=None, + scheduling_weight=None, + meter_type=None, + min_bandwidth_rate=None, + min_bandwidth_burst_rate=None, + max_bandwidth_rate=None, + max_bandwidth_burst_rate=None, + custom_attribute=None): + """ + sai_create_scheduler() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of scheduler CREATE attributes. + + Returns: + sai_thrift_object_id_t: scheduler_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if scheduling_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=scheduling_type) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_SCHEDULING_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if scheduling_weight is not None: + attribute_value = sai_thrift_attribute_value_t(u8=scheduling_weight) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_SCHEDULING_WEIGHT, + value=attribute_value) + attr_list.append(attribute) + + if meter_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=meter_type) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_METER_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if min_bandwidth_rate is not None: + attribute_value = sai_thrift_attribute_value_t(u64=min_bandwidth_rate) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_RATE, + value=attribute_value) + attr_list.append(attribute) + + if min_bandwidth_burst_rate is not None: + attribute_value = sai_thrift_attribute_value_t(u64=min_bandwidth_burst_rate) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_BURST_RATE, + value=attribute_value) + attr_list.append(attribute) + + if max_bandwidth_rate is not None: + attribute_value = sai_thrift_attribute_value_t(u64=max_bandwidth_rate) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_RATE, + value=attribute_value) + attr_list.append(attribute) + + if max_bandwidth_burst_rate is not None: + attribute_value = sai_thrift_attribute_value_t(u64=max_bandwidth_burst_rate) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_BURST_RATE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_scheduler(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_scheduler(client, + scheduler_oid): + """ + sai_remove_scheduler() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + scheduler_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_scheduler(scheduler_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_scheduler_attribute(client, + scheduler_oid, + scheduling_type=None, + scheduling_weight=None, + meter_type=None, + min_bandwidth_rate=None, + min_bandwidth_burst_rate=None, + max_bandwidth_rate=None, + max_bandwidth_burst_rate=None, + custom_attribute=None): + """ + sai_set_scheduler_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + scheduler_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of scheduler SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if scheduling_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=scheduling_type) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_SCHEDULING_TYPE, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if scheduling_weight is not None: + attr_value = sai_thrift_attribute_value_t(u8=scheduling_weight) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_SCHEDULING_WEIGHT, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if meter_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=meter_type) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_METER_TYPE, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if min_bandwidth_rate is not None: + attr_value = sai_thrift_attribute_value_t(u64=min_bandwidth_rate) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_RATE, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if min_bandwidth_burst_rate is not None: + attr_value = sai_thrift_attribute_value_t(u64=min_bandwidth_burst_rate) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_BURST_RATE, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if max_bandwidth_rate is not None: + attr_value = sai_thrift_attribute_value_t(u64=max_bandwidth_rate) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_RATE, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if max_bandwidth_burst_rate is not None: + attr_value = sai_thrift_attribute_value_t(u64=max_bandwidth_burst_rate) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_BURST_RATE, + value=attr_value) + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_scheduler_attribute(scheduler_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_scheduler_attribute(client, + scheduler_oid, + scheduling_type=None, + scheduling_weight=None, + meter_type=None, + min_bandwidth_rate=None, + min_bandwidth_burst_rate=None, + max_bandwidth_rate=None, + max_bandwidth_burst_rate=None, + custom_attribute=None): + """ + sai_get_scheduler_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + scheduler_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of scheduler GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if scheduling_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_SCHEDULING_TYPE) + attr_list.append(attribute) + + if scheduling_weight is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_SCHEDULING_WEIGHT) + attr_list.append(attribute) + + if meter_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_METER_TYPE) + attr_list.append(attribute) + + if min_bandwidth_rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_RATE) + attr_list.append(attribute) + + if min_bandwidth_burst_rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_BURST_RATE) + attr_list.append(attribute) + + if max_bandwidth_rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_RATE) + attr_list.append(attribute) + + if max_bandwidth_burst_rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_BURST_RATE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_scheduler_attribute(scheduler_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SCHEDULER_ATTR_SCHEDULING_TYPE: + attrs["SAI_SCHEDULER_ATTR_SCHEDULING_TYPE"] = attr.value.s32 + attrs["scheduling_type"] = attr.value.s32 + + if attr.id == SAI_SCHEDULER_ATTR_SCHEDULING_WEIGHT: + attrs["SAI_SCHEDULER_ATTR_SCHEDULING_WEIGHT"] = attr.value.u8 + attrs["scheduling_weight"] = attr.value.u8 + + if attr.id == SAI_SCHEDULER_ATTR_METER_TYPE: + attrs["SAI_SCHEDULER_ATTR_METER_TYPE"] = attr.value.s32 + attrs["meter_type"] = attr.value.s32 + + if attr.id == SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_RATE: + attrs["SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_RATE"] = attr.value.u64 + attrs["min_bandwidth_rate"] = attr.value.u64 + + if attr.id == SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_BURST_RATE: + attrs["SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_BURST_RATE"] = attr.value.u64 + attrs["min_bandwidth_burst_rate"] = attr.value.u64 + + if attr.id == SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_RATE: + attrs["SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_RATE"] = attr.value.u64 + attrs["max_bandwidth_rate"] = attr.value.u64 + + if attr.id == SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_BURST_RATE: + attrs["SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_BURST_RATE"] = attr.value.u64 + attrs["max_bandwidth_burst_rate"] = attr.value.u64 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# scheduler_group API + +def sai_thrift_create_scheduler_group(client, + port_id=None, + level=None, + max_childs=None, + parent_node=None, + scheduler_profile_id=None, + custom_attribute=None): + """ + sai_create_scheduler_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of scheduler_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: scheduler_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=port_id) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if level is not None: + attribute_value = sai_thrift_attribute_value_t(u8=level) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_LEVEL, + value=attribute_value) + attr_list.append(attribute) + + if max_childs is not None: + attribute_value = sai_thrift_attribute_value_t(u8=max_childs) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_MAX_CHILDS, + value=attribute_value) + attr_list.append(attribute) + + if parent_node is not None: + attribute_value = sai_thrift_attribute_value_t(oid=parent_node) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_PARENT_NODE, + value=attribute_value) + attr_list.append(attribute) + + if scheduler_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=scheduler_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_scheduler_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_scheduler_group(client, + scheduler_group_oid): + """ + sai_remove_scheduler_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + scheduler_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_scheduler_group(scheduler_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_scheduler_group_attribute(client, + scheduler_group_oid, + scheduler_profile_id=None, + parent_node=None, + custom_attribute=None): + """ + sai_set_scheduler_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + scheduler_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of scheduler_group SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if scheduler_profile_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=scheduler_profile_id) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID, + value=attr_value) + client.sai_thrift_set_scheduler_group_attribute(scheduler_group_oid, attr) + + if parent_node is not None: + attr_value = sai_thrift_attribute_value_t(oid=parent_node) + attr = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_PARENT_NODE, + value=attr_value) + client.sai_thrift_set_scheduler_group_attribute(scheduler_group_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_scheduler_group_attribute(scheduler_group_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_scheduler_group_attribute(client, + scheduler_group_oid, + child_count=None, + child_list=None, + port_id=None, + level=None, + max_childs=None, + scheduler_profile_id=None, + parent_node=None, + custom_attribute=None): + """ + sai_get_scheduler_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + scheduler_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of scheduler_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if child_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_CHILD_COUNT) + attr_list.append(attribute) + + if child_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=child_list) + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_CHILD_LIST, + value=attribute_value) + attr_list.append(attribute) + + if port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_PORT_ID) + attr_list.append(attribute) + + if level is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_LEVEL) + attr_list.append(attribute) + + if max_childs is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_MAX_CHILDS) + attr_list.append(attribute) + + if scheduler_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID) + attr_list.append(attribute) + + if parent_node is not None: + attribute = sai_thrift_attribute_t(id=SAI_SCHEDULER_GROUP_ATTR_PARENT_NODE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_scheduler_group_attribute(scheduler_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SCHEDULER_GROUP_ATTR_CHILD_COUNT: + attrs["SAI_SCHEDULER_GROUP_ATTR_CHILD_COUNT"] = attr.value.u32 + attrs["child_count"] = attr.value.u32 + + if attr.id == SAI_SCHEDULER_GROUP_ATTR_CHILD_LIST: + attrs["SAI_SCHEDULER_GROUP_ATTR_CHILD_LIST"] = attr.value.objlist + attrs["child_list"] = attr.value.objlist + + if attr.id == SAI_SCHEDULER_GROUP_ATTR_PORT_ID: + attrs["SAI_SCHEDULER_GROUP_ATTR_PORT_ID"] = attr.value.oid + attrs["port_id"] = attr.value.oid + + if attr.id == SAI_SCHEDULER_GROUP_ATTR_LEVEL: + attrs["SAI_SCHEDULER_GROUP_ATTR_LEVEL"] = attr.value.u8 + attrs["level"] = attr.value.u8 + + if attr.id == SAI_SCHEDULER_GROUP_ATTR_MAX_CHILDS: + attrs["SAI_SCHEDULER_GROUP_ATTR_MAX_CHILDS"] = attr.value.u8 + attrs["max_childs"] = attr.value.u8 + + if attr.id == SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID: + attrs["SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID"] = attr.value.oid + attrs["scheduler_profile_id"] = attr.value.oid + + if attr.id == SAI_SCHEDULER_GROUP_ATTR_PARENT_NODE: + attrs["SAI_SCHEDULER_GROUP_ATTR_PARENT_NODE"] = attr.value.oid + attrs["parent_node"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# srv6 API + +def sai_thrift_create_srv6_sidlist(client, + type=None, + tlv_list=None, + segment_list=None, + custom_attribute=None): + """ + sai_create_srv6_sidlist() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of srv6_sidlist CREATE attributes. + + Returns: + sai_thrift_object_id_t: srv6_sidlist_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if tlv_list is not None: + attribute_value = sai_thrift_attribute_value_t(tlvlist=tlv_list) + attribute = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_TLV_LIST, + value=attribute_value) + attr_list.append(attribute) + + if segment_list is not None: + attribute_value = sai_thrift_attribute_value_t(segmentlist=segment_list) + attribute = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_srv6_sidlist(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_srv6_sidlist(client, + srv6_sidlist_oid): + """ + sai_remove_srv6_sidlist() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + srv6_sidlist_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_srv6_sidlist(srv6_sidlist_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_srv6_sidlist_attribute(client, + srv6_sidlist_oid, + tlv_list=None, + segment_list=None, + custom_attribute=None): + """ + sai_set_srv6_sidlist_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + srv6_sidlist_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of srv6_sidlist SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if tlv_list is not None: + attr_value = sai_thrift_attribute_value_t(tlvlist=tlv_list) + attr = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_TLV_LIST, + value=attr_value) + client.sai_thrift_set_srv6_sidlist_attribute(srv6_sidlist_oid, attr) + + if segment_list is not None: + attr_value = sai_thrift_attribute_value_t(segmentlist=segment_list) + attr = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST, + value=attr_value) + client.sai_thrift_set_srv6_sidlist_attribute(srv6_sidlist_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_srv6_sidlist_attribute(srv6_sidlist_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_srv6_sidlist_attribute(client, + srv6_sidlist_oid, + type=None, + tlv_list=None, + segment_list=None, + custom_attribute=None): + """ + sai_get_srv6_sidlist_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + srv6_sidlist_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of srv6_sidlist GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if tlv_list is not None: + attribute_value = sai_thrift_attribute_value_t(tlvlist=tlv_list) + attribute = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_TLV_LIST, + value=attribute_value) + attr_list.append(attribute) + + if segment_list is not None: + attribute_value = sai_thrift_attribute_value_t(segmentlist=segment_list) + attribute = sai_thrift_attribute_t(id=SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_srv6_sidlist_attribute(srv6_sidlist_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SRV6_SIDLIST_ATTR_TYPE: + attrs["SAI_SRV6_SIDLIST_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_SRV6_SIDLIST_ATTR_TLV_LIST: + attrs["SAI_SRV6_SIDLIST_ATTR_TLV_LIST"] = attr.value.tlvlist + attrs["tlv_list"] = attr.value.tlvlist + + if attr.id == SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST: + attrs["SAI_SRV6_SIDLIST_ATTR_SEGMENT_LIST"] = attr.value.segmentlist + attrs["segment_list"] = attr.value.segmentlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_my_sid_entry(client, + my_sid_entry, + endpoint_behavior=None, + endpoint_behavior_flavor=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + tunnel_id=None, + vrf=None, + counter_id=None, + custom_attribute=None): + """ + sai_create_my_sid_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + my_sid_entry(sai_thrift_my_sid_entry_t): my_sid_entry IN argument + + For the other parameters, see documentation of my_sid_entry CREATE attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if endpoint_behavior is not None: + attribute_value = sai_thrift_attribute_value_t(s32=endpoint_behavior) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR, + value=attribute_value) + attr_list.append(attribute) + + if endpoint_behavior_flavor is not None: + attribute_value = sai_thrift_attribute_value_t(s32=endpoint_behavior_flavor) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR_FLAVOR, + value=attribute_value) + attr_list.append(attribute) + + if packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=packet_action) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if trap_priority is not None: + attribute_value = sai_thrift_attribute_value_t(u8=trap_priority) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_TRAP_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_NEXT_HOP_ID, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=tunnel_id) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_TUNNEL_ID, + value=attribute_value) + attr_list.append(attribute) + + if vrf is not None: + attribute_value = sai_thrift_attribute_value_t(oid=vrf) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_VRF, + value=attribute_value) + attr_list.append(attribute) + + if counter_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=counter_id) + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_COUNTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_create_my_sid_entry(my_sid_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + return status + + +def sai_thrift_remove_my_sid_entry(client, + my_sid_entry): + """ + sai_remove_my_sid_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + my_sid_entry(sai_thrift_my_sid_entry_t): my_sid_entry IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_my_sid_entry(my_sid_entry) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_my_sid_entry_attribute(client, + my_sid_entry, + endpoint_behavior=None, + endpoint_behavior_flavor=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + tunnel_id=None, + vrf=None, + counter_id=None, + custom_attribute=None): + """ + sai_set_my_sid_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + my_sid_entry(sai_thrift_my_sid_entry_t): my_sid_entry IN argument + + For the other parameters, see documentation of my_sid_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if endpoint_behavior is not None: + attr_value = sai_thrift_attribute_value_t(s32=endpoint_behavior) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if endpoint_behavior_flavor is not None: + attr_value = sai_thrift_attribute_value_t(s32=endpoint_behavior_flavor) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR_FLAVOR, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=packet_action) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if trap_priority is not None: + attr_value = sai_thrift_attribute_value_t(u8=trap_priority) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_TRAP_PRIORITY, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if next_hop_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=next_hop_id) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_NEXT_HOP_ID, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if tunnel_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=tunnel_id) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_TUNNEL_ID, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if vrf is not None: + attr_value = sai_thrift_attribute_value_t(oid=vrf) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_VRF, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if counter_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=counter_id) + attr = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_COUNTER_ID, + value=attr_value) + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_my_sid_entry_attribute(my_sid_entry, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_my_sid_entry_attribute(client, + my_sid_entry, + endpoint_behavior=None, + endpoint_behavior_flavor=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + tunnel_id=None, + vrf=None, + counter_id=None, + custom_attribute=None): + """ + sai_get_my_sid_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + my_sid_entry(sai_thrift_my_sid_entry_t): my_sid_entry IN argument + + For the other parameters, see documentation of my_sid_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if endpoint_behavior is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR) + attr_list.append(attribute) + + if endpoint_behavior_flavor is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR_FLAVOR) + attr_list.append(attribute) + + if packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_PACKET_ACTION) + attr_list.append(attribute) + + if trap_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_TRAP_PRIORITY) + attr_list.append(attribute) + + if next_hop_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_NEXT_HOP_ID) + attr_list.append(attribute) + + if tunnel_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_TUNNEL_ID) + attr_list.append(attribute) + + if vrf is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_VRF) + attr_list.append(attribute) + + if counter_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_MY_SID_ENTRY_ATTR_COUNTER_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_my_sid_entry_attribute(my_sid_entry, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR: + attrs["SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR"] = attr.value.s32 + attrs["endpoint_behavior"] = attr.value.s32 + + if attr.id == SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR_FLAVOR: + attrs["SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR_FLAVOR"] = attr.value.s32 + attrs["endpoint_behavior_flavor"] = attr.value.s32 + + if attr.id == SAI_MY_SID_ENTRY_ATTR_PACKET_ACTION: + attrs["SAI_MY_SID_ENTRY_ATTR_PACKET_ACTION"] = attr.value.s32 + attrs["packet_action"] = attr.value.s32 + + if attr.id == SAI_MY_SID_ENTRY_ATTR_TRAP_PRIORITY: + attrs["SAI_MY_SID_ENTRY_ATTR_TRAP_PRIORITY"] = attr.value.u8 + attrs["trap_priority"] = attr.value.u8 + + if attr.id == SAI_MY_SID_ENTRY_ATTR_NEXT_HOP_ID: + attrs["SAI_MY_SID_ENTRY_ATTR_NEXT_HOP_ID"] = attr.value.oid + attrs["next_hop_id"] = attr.value.oid + + if attr.id == SAI_MY_SID_ENTRY_ATTR_TUNNEL_ID: + attrs["SAI_MY_SID_ENTRY_ATTR_TUNNEL_ID"] = attr.value.oid + attrs["tunnel_id"] = attr.value.oid + + if attr.id == SAI_MY_SID_ENTRY_ATTR_VRF: + attrs["SAI_MY_SID_ENTRY_ATTR_VRF"] = attr.value.oid + attrs["vrf"] = attr.value.oid + + if attr.id == SAI_MY_SID_ENTRY_ATTR_COUNTER_ID: + attrs["SAI_MY_SID_ENTRY_ATTR_COUNTER_ID"] = attr.value.oid + attrs["counter_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_bulk_create_my_sid_entry(client, + my_sid_entry, + attr_count, + mode, + endpoint_behavior=None, + endpoint_behavior_flavor=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + tunnel_id=None, + vrf=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_create_my_sid_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + my_sid_entry(List[sai_thrift_my_sid_entry_t]): my_sid_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of my_sid_entry CREATE attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del my_sid_entry + del attr_count + del mode + + # No function call - delete all attributes + del endpoint_behavior + del endpoint_behavior_flavor + del packet_action + del trap_priority + del next_hop_id + del tunnel_id + del vrf + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_remove_my_sid_entry(client, + my_sid_entry, + mode): + """ + sai_bulk_remove_my_sid_entry() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + my_sid_entry(List[sai_thrift_my_sid_entry_t]): my_sid_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del my_sid_entry + del mode + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_set_my_sid_entry_attribute(client, + my_sid_entry, + mode, + endpoint_behavior=None, + endpoint_behavior_flavor=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + tunnel_id=None, + vrf=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_set_my_sid_entry_attribute() - UNSUPPORTED + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + my_sid_entry(List[sai_thrift_my_sid_entry_t]): my_sid_entry_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + + For the other parameters, see documentation of my_sid_entry SET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del my_sid_entry + del mode + + # No function call - delete all attributes + del endpoint_behavior + del endpoint_behavior_flavor + del packet_action + del trap_priority + del next_hop_id + del tunnel_id + del vrf + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_bulk_get_my_sid_entry_attribute(client, + my_sid_entry, + attr_count, + mode, + object_statuses, + endpoint_behavior=None, + endpoint_behavior_flavor=None, + packet_action=None, + trap_priority=None, + next_hop_id=None, + tunnel_id=None, + vrf=None, + counter_id=None, + custom_attribute=None): + """ + sai_bulk_get_my_sid_entry_attribute() - UNSUPPORTED + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + my_sid_entry(List[sai_thrift_my_sid_entry_t]): my_sid_entry_list IN argument + attr_count(List[sai_thrift_uint32_t]): uint32_list IN argument + mode(sai_thrift_bulk_op_error_mode_t): bulk_op_error_mode IN argument + object_statuses(List[sai_thrift_status_t]): status_list OUT argument + + For the other parameters, see documentation of my_sid_entry GET attributes. + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del my_sid_entry + del attr_count + del mode + del object_statuses + + # No function call - delete all attributes + del endpoint_behavior + del endpoint_behavior_flavor + del packet_action + del trap_priority + del next_hop_id + del tunnel_id + del vrf + del counter_id + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +# stp API + +def sai_thrift_create_stp(client, + custom_attribute=None): + """ + sai_create_stp() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + sai_thrift_object_id_t: stp_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_stp(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_stp(client, + stp_oid): + """ + sai_remove_stp() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + stp_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_stp(stp_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_stp_attribute(client, + stp_oid, + custom_attribute=None): + """ + sai_set_stp_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + stp_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del stp_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_stp_attribute(client, + stp_oid, + vlan_list=None, + bridge_id=None, + port_list=None, + custom_attribute=None): + """ + sai_get_stp_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + stp_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of stp GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vlan_list is not None: + attribute_value = sai_thrift_attribute_value_t(vlanlist=vlan_list) + attribute = sai_thrift_attribute_t(id=SAI_STP_ATTR_VLAN_LIST, + value=attribute_value) + attr_list.append(attribute) + + if bridge_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_STP_ATTR_BRIDGE_ID) + attr_list.append(attribute) + + if port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=port_list) + attribute = sai_thrift_attribute_t(id=SAI_STP_ATTR_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_stp_attribute(stp_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_STP_ATTR_VLAN_LIST: + attrs["SAI_STP_ATTR_VLAN_LIST"] = attr.value.vlanlist + attrs["vlan_list"] = attr.value.vlanlist + + if attr.id == SAI_STP_ATTR_BRIDGE_ID: + attrs["SAI_STP_ATTR_BRIDGE_ID"] = attr.value.oid + attrs["bridge_id"] = attr.value.oid + + if attr.id == SAI_STP_ATTR_PORT_LIST: + attrs["SAI_STP_ATTR_PORT_LIST"] = attr.value.objlist + attrs["port_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_stp_port(client, + stp=None, + bridge_port=None, + state=None, + custom_attribute=None): + """ + sai_create_stp_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of stp_port CREATE attributes. + + Returns: + sai_thrift_object_id_t: stp_port_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if stp is not None: + attribute_value = sai_thrift_attribute_value_t(oid=stp) + attribute = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_STP, + value=attribute_value) + attr_list.append(attribute) + + if bridge_port is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_port) + attribute = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_BRIDGE_PORT, + value=attribute_value) + attr_list.append(attribute) + + if state is not None: + attribute_value = sai_thrift_attribute_value_t(s32=state) + attribute = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_STATE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_stp_port(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_stp_port(client, + stp_port_oid): + """ + sai_remove_stp_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + stp_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_stp_port(stp_port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_stp_port_attribute(client, + stp_port_oid, + state=None, + custom_attribute=None): + """ + sai_set_stp_port_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + stp_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of stp_port SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if state is not None: + attr_value = sai_thrift_attribute_value_t(s32=state) + attr = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_STATE, + value=attr_value) + client.sai_thrift_set_stp_port_attribute(stp_port_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_stp_port_attribute(stp_port_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_stp_port_attribute(client, + stp_port_oid, + stp=None, + bridge_port=None, + state=None, + custom_attribute=None): + """ + sai_get_stp_port_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + stp_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of stp_port GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if stp is not None: + attribute = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_STP) + attr_list.append(attribute) + + if bridge_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_BRIDGE_PORT) + attr_list.append(attribute) + + if state is not None: + attribute = sai_thrift_attribute_t(id=SAI_STP_PORT_ATTR_STATE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_stp_port_attribute(stp_port_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_STP_PORT_ATTR_STP: + attrs["SAI_STP_PORT_ATTR_STP"] = attr.value.oid + attrs["stp"] = attr.value.oid + + if attr.id == SAI_STP_PORT_ATTR_BRIDGE_PORT: + attrs["SAI_STP_PORT_ATTR_BRIDGE_PORT"] = attr.value.oid + attrs["bridge_port"] = attr.value.oid + + if attr.id == SAI_STP_PORT_ATTR_STATE: + attrs["SAI_STP_PORT_ATTR_STATE"] = attr.value.s32 + attrs["state"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# switch API + +def sai_thrift_switch_register_read(client, + platform_context, + device_addr, + start_reg_addr): + """ + sai_switch_register_read() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + platform_context(sai_thrift_uint64_t): uint64 IN argument + device_addr(sai_thrift_uint32_t): uint32 IN argument + start_reg_addr(sai_thrift_uint32_t): uint32 IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del platform_context + del device_addr + del start_reg_addr + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_switch_register_write(client, + platform_context, + device_addr, + start_reg_addr, + reg_val): + """ + sai_switch_register_write() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + platform_context(sai_thrift_uint64_t): uint64 IN argument + device_addr(sai_thrift_uint32_t): uint32 IN argument + start_reg_addr(sai_thrift_uint32_t): uint32 IN argument + reg_val(List[sai_thrift_uint32_t]): uint32_list IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del platform_context + del device_addr + del start_reg_addr + del reg_val + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_switch_mdio_read(client, + device_addr, + start_reg_addr): + """ + sai_switch_mdio_read() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + device_addr(sai_thrift_uint32_t): uint32 IN argument + start_reg_addr(sai_thrift_uint32_t): uint32 IN argument + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del device_addr + del start_reg_addr + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return None + else: + raise sai_thrift_exception(status) + + +def sai_thrift_switch_mdio_write(client, + device_addr, + start_reg_addr, + reg_val): + """ + sai_switch_mdio_write() - UNSUPPORTED + + Args: + client (Client): SAI RPC client + device_addr(sai_thrift_uint32_t): uint32 IN argument + start_reg_addr(sai_thrift_uint32_t): uint32 IN argument + reg_val(List[sai_thrift_uint32_t]): uint32_list IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # This function is UNSUPPORTED + + # No function call - delete all arguments + del client + del device_addr + del start_reg_addr + del reg_val + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_create_switch(client, + init_switch=None, + hardware_access_bus=None, + platfrom_context=None, + register_read=None, + register_write=None, + switch_id=None, + max_system_cores=None, + system_port_config_list=None, + ingress_acl=None, + egress_acl=None, + restart_warm=None, + warm_recover=None, + switching_mode=None, + bcast_cpu_flood_enable=None, + mcast_cpu_flood_enable=None, + src_mac_address=None, + max_learned_addresses=None, + fdb_aging_time=None, + fdb_unicast_miss_packet_action=None, + fdb_broadcast_miss_packet_action=None, + fdb_multicast_miss_packet_action=None, + ecmp_default_hash_algorithm=None, + ecmp_default_hash_seed=None, + ecmp_default_hash_offset=None, + ecmp_default_symmetric_hash=None, + ecmp_hash_ipv4=None, + ecmp_hash_ipv4_in_ipv4=None, + ecmp_hash_ipv6=None, + lag_default_hash_algorithm=None, + lag_default_hash_seed=None, + lag_default_hash_offset=None, + lag_default_symmetric_hash=None, + lag_hash_ipv4=None, + lag_hash_ipv4_in_ipv4=None, + lag_hash_ipv6=None, + counter_refresh_interval=None, + qos_default_tc=None, + qos_dot1p_to_tc_map=None, + qos_dot1p_to_color_map=None, + qos_dscp_to_tc_map=None, + qos_dscp_to_color_map=None, + qos_tc_to_queue_map=None, + qos_tc_and_color_to_dot1p_map=None, + qos_tc_and_color_to_dscp_map=None, + switch_shell_enable=None, + switch_profile_id=None, + switch_hardware_info=None, + firmware_path_name=None, + switch_state_change_notify=None, + switch_shutdown_request_notify=None, + fdb_event_notify=None, + port_state_change_notify=None, + packet_event_notify=None, + fast_api_enable=None, + mirror_tc=None, + queue_pfc_deadlock_notify=None, + pfc_dlr_packet_action=None, + pfc_tc_dld_interval=None, + pfc_tc_dlr_interval=None, + tpid_outer_vlan=None, + tpid_inner_vlan=None, + crc_check_enable=None, + crc_recalculation_enable=None, + bfd_session_state_change_notify=None, + ecn_ect_threshold_enable=None, + vxlan_default_router_mac=None, + vxlan_default_port=None, + uninit_data_plane_on_removal=None, + tam_object_id=None, + tam_event_notify=None, + pre_shutdown=None, + nat_zone_counter_object_id=None, + nat_enable=None, + firmware_download_broadcast=None, + firmware_load_method=None, + firmware_load_type=None, + firmware_download_execute=None, + firmware_broadcast_stop=None, + firmware_verify_and_init_switch=None, + type=None, + macsec_object_list=None, + qos_mpls_exp_to_tc_map=None, + qos_mpls_exp_to_color_map=None, + qos_tc_and_color_to_mpls_exp_map=None, + failover_config_mode=None, + tunnel_objects_list=None, + pre_ingress_acl=None, + slave_mdio_addr_list=None, + qos_dscp_to_forwarding_class_map=None, + qos_mpls_exp_to_forwarding_class_map=None, + ipsec_object_id=None, + ipsec_sa_tag_tpid=None, + ipsec_sa_status_change_notify=None, + nat_event_notify=None, + ecmp_member_count=None, + custom_attribute=None): + """ + sai_create_switch() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of switch CREATE attributes. + + Returns: + sai_thrift_object_id_t: switch_id + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if init_switch is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=init_switch) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INIT_SWITCH, + value=attribute_value) + attr_list.append(attribute) + + if hardware_access_bus is not None: + attribute_value = sai_thrift_attribute_value_t(s32=hardware_access_bus) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_HARDWARE_ACCESS_BUS, + value=attribute_value) + attr_list.append(attribute) + + if platfrom_context is not None: + attribute_value = sai_thrift_attribute_value_t(u64=platfrom_context) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PLATFROM_CONTEXT, + value=attribute_value) + attr_list.append(attribute) + + if register_read is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=register_read) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_REGISTER_READ, + value=attribute_value) + attr_list.append(attribute) + + if register_write is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=register_write) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_REGISTER_WRITE, + value=attribute_value) + attr_list.append(attribute) + + if switch_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=switch_id) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_ID, + value=attribute_value) + attr_list.append(attribute) + + if max_system_cores is not None: + attribute_value = sai_thrift_attribute_value_t(u32=max_system_cores) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_SYSTEM_CORES, + value=attribute_value) + attr_list.append(attribute) + + if system_port_config_list is not None: + attribute_value = sai_thrift_attribute_value_t(sysportconfiglist=system_port_config_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST, + value=attribute_value) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if egress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_acl) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_EGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if restart_warm is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=restart_warm) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_RESTART_WARM, + value=attribute_value) + attr_list.append(attribute) + + if warm_recover is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=warm_recover) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_WARM_RECOVER, + value=attribute_value) + attr_list.append(attribute) + + if switching_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=switching_mode) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCHING_MODE, + value=attribute_value) + attr_list.append(attribute) + + if bcast_cpu_flood_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=bcast_cpu_flood_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if mcast_cpu_flood_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=mcast_cpu_flood_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SRC_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES, + value=attribute_value) + attr_list.append(attribute) + + if fdb_aging_time is not None: + attribute_value = sai_thrift_attribute_value_t(u32=fdb_aging_time) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_AGING_TIME, + value=attribute_value) + attr_list.append(attribute) + + if fdb_unicast_miss_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fdb_unicast_miss_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if fdb_broadcast_miss_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fdb_broadcast_miss_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if fdb_multicast_miss_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=fdb_multicast_miss_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_default_hash_algorithm is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ecmp_default_hash_algorithm) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_default_hash_seed is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecmp_default_hash_seed) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_default_hash_offset is not None: + attribute_value = sai_thrift_attribute_value_t(u8=ecmp_default_hash_offset) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_default_symmetric_hash is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ecmp_default_symmetric_hash) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_SYMMETRIC_HASH, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_hash_ipv4 is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ecmp_hash_ipv4) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV4, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_hash_ipv4_in_ipv4 is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ecmp_hash_ipv4_in_ipv4) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV4_IN_IPV4, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_hash_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ecmp_hash_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if lag_default_hash_algorithm is not None: + attribute_value = sai_thrift_attribute_value_t(s32=lag_default_hash_algorithm) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM, + value=attribute_value) + attr_list.append(attribute) + + if lag_default_hash_seed is not None: + attribute_value = sai_thrift_attribute_value_t(u32=lag_default_hash_seed) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED, + value=attribute_value) + attr_list.append(attribute) + + if lag_default_hash_offset is not None: + attribute_value = sai_thrift_attribute_value_t(u8=lag_default_hash_offset) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET, + value=attribute_value) + attr_list.append(attribute) + + if lag_default_symmetric_hash is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=lag_default_symmetric_hash) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_SYMMETRIC_HASH, + value=attribute_value) + attr_list.append(attribute) + + if lag_hash_ipv4 is not None: + attribute_value = sai_thrift_attribute_value_t(oid=lag_hash_ipv4) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV4, + value=attribute_value) + attr_list.append(attribute) + + if lag_hash_ipv4_in_ipv4 is not None: + attribute_value = sai_thrift_attribute_value_t(oid=lag_hash_ipv4_in_ipv4) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV4_IN_IPV4, + value=attribute_value) + attr_list.append(attribute) + + if lag_hash_ipv6 is not None: + attribute_value = sai_thrift_attribute_value_t(oid=lag_hash_ipv6) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV6, + value=attribute_value) + attr_list.append(attribute) + + if counter_refresh_interval is not None: + attribute_value = sai_thrift_attribute_value_t(u32=counter_refresh_interval) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if qos_default_tc is not None: + attribute_value = sai_thrift_attribute_value_t(u8=qos_default_tc) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DEFAULT_TC, + value=attribute_value) + attr_list.append(attribute) + + if qos_dot1p_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DOT1P_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_dot1p_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DOT1P_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_dscp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_dscp_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_to_queue_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_to_queue_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_TO_QUEUE_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_dot1p_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dot1p_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_dscp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dscp_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if switch_shell_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_shell_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if switch_profile_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=switch_profile_id) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_PROFILE_ID, + value=attribute_value) + attr_list.append(attribute) + + if switch_hardware_info is not None: + attribute_value = sai_thrift_attribute_value_t(s8list=switch_hardware_info) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO, + value=attribute_value) + attr_list.append(attribute) + + if firmware_path_name is not None: + attribute_value = sai_thrift_attribute_value_t(s8list=firmware_path_name) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_PATH_NAME, + value=attribute_value) + attr_list.append(attribute) + + if switch_state_change_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=switch_state_change_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if switch_shutdown_request_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=switch_shutdown_request_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if fdb_event_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=fdb_event_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if port_state_change_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=port_state_change_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if packet_event_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=packet_event_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if fast_api_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=fast_api_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FAST_API_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if mirror_tc is not None: + attribute_value = sai_thrift_attribute_value_t(u8=mirror_tc) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MIRROR_TC, + value=attribute_value) + attr_list.append(attribute) + + if queue_pfc_deadlock_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=queue_pfc_deadlock_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if pfc_dlr_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=pfc_dlr_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_DLR_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if pfc_tc_dld_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dld_interval) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if pfc_tc_dlr_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dlr_interval) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if tpid_outer_vlan is not None: + attribute_value = sai_thrift_attribute_value_t(u16=tpid_outer_vlan) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TPID_OUTER_VLAN, + value=attribute_value) + attr_list.append(attribute) + + if tpid_inner_vlan is not None: + attribute_value = sai_thrift_attribute_value_t(u16=tpid_inner_vlan) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TPID_INNER_VLAN, + value=attribute_value) + attr_list.append(attribute) + + if crc_check_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=crc_check_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CRC_CHECK_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if crc_recalculation_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=crc_recalculation_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CRC_RECALCULATION_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if bfd_session_state_change_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=bfd_session_state_change_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if ecn_ect_threshold_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ecn_ect_threshold_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECN_ECT_THRESHOLD_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_default_router_mac is not None: + attribute_value = sai_thrift_attribute_value_t(mac=vxlan_default_router_mac) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_default_port is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vxlan_default_port) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT, + value=attribute_value) + attr_list.append(attribute) + + if uninit_data_plane_on_removal is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=uninit_data_plane_on_removal) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL, + value=attribute_value) + attr_list.append(attribute) + + if tam_object_id is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object_id) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TAM_OBJECT_ID, + value=attribute_value) + attr_list.append(attribute) + + if tam_event_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=tam_event_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TAM_EVENT_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if pre_shutdown is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=pre_shutdown) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PRE_SHUTDOWN, + value=attribute_value) + attr_list.append(attribute) + + if nat_zone_counter_object_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=nat_zone_counter_object_id) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_ZONE_COUNTER_OBJECT_ID, + value=attribute_value) + attr_list.append(attribute) + + if nat_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=nat_enable) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if firmware_download_broadcast is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=firmware_download_broadcast) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_BROADCAST, + value=attribute_value) + attr_list.append(attribute) + + if firmware_load_method is not None: + attribute_value = sai_thrift_attribute_value_t(s32=firmware_load_method) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_LOAD_METHOD, + value=attribute_value) + attr_list.append(attribute) + + if firmware_load_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=firmware_load_type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_LOAD_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if firmware_download_execute is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=firmware_download_execute) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_EXECUTE, + value=attribute_value) + attr_list.append(attribute) + + if firmware_broadcast_stop is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=firmware_broadcast_stop) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_BROADCAST_STOP, + value=attribute_value) + attr_list.append(attribute) + + if firmware_verify_and_init_switch is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=firmware_verify_and_init_switch) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_VERIFY_AND_INIT_SWITCH, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if macsec_object_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=macsec_object_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_color_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_color_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_mpls_exp_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if failover_config_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=failover_config_mode) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FAILOVER_CONFIG_MODE, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tunnel_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if pre_ingress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=pre_ingress_acl) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PRE_INGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if slave_mdio_addr_list is not None: + attribute_value = sai_thrift_attribute_value_t(u8list=slave_mdio_addr_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SLAVE_MDIO_ADDR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_dscp_to_forwarding_class_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_forwarding_class_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_forwarding_class_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_forwarding_class_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_object_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ipsec_object_id) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_OBJECT_ID, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_sa_tag_tpid is not None: + attribute_value = sai_thrift_attribute_value_t(u16=ipsec_sa_tag_tpid) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_SA_TAG_TPID, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_sa_status_change_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=ipsec_sa_status_change_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_SA_STATUS_CHANGE_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if nat_event_notify is not None: + attribute_value = sai_thrift_attribute_value_t(ptr=nat_event_notify) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY, + value=attribute_value) + attr_list.append(attribute) + + if ecmp_member_count is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecmp_member_count) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_MEMBER_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_switch(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_switch(client): + """ + sai_remove_switch() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_switch() + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_switch_attribute(client, + ingress_acl=None, + egress_acl=None, + restart_warm=None, + warm_recover=None, + switching_mode=None, + bcast_cpu_flood_enable=None, + mcast_cpu_flood_enable=None, + src_mac_address=None, + max_learned_addresses=None, + fdb_aging_time=None, + fdb_unicast_miss_packet_action=None, + fdb_broadcast_miss_packet_action=None, + fdb_multicast_miss_packet_action=None, + ecmp_default_hash_algorithm=None, + ecmp_default_hash_seed=None, + ecmp_default_hash_offset=None, + ecmp_default_symmetric_hash=None, + ecmp_hash_ipv4=None, + ecmp_hash_ipv4_in_ipv4=None, + ecmp_hash_ipv6=None, + lag_default_hash_algorithm=None, + lag_default_hash_seed=None, + lag_default_hash_offset=None, + lag_default_symmetric_hash=None, + lag_hash_ipv4=None, + lag_hash_ipv4_in_ipv4=None, + lag_hash_ipv6=None, + counter_refresh_interval=None, + qos_default_tc=None, + qos_dot1p_to_tc_map=None, + qos_dot1p_to_color_map=None, + qos_dscp_to_tc_map=None, + qos_dscp_to_color_map=None, + qos_tc_to_queue_map=None, + qos_tc_and_color_to_dot1p_map=None, + qos_tc_and_color_to_dscp_map=None, + switch_shell_enable=None, + switch_state_change_notify=None, + switch_shutdown_request_notify=None, + fdb_event_notify=None, + port_state_change_notify=None, + packet_event_notify=None, + fast_api_enable=None, + mirror_tc=None, + queue_pfc_deadlock_notify=None, + pfc_dlr_packet_action=None, + pfc_tc_dld_interval=None, + pfc_tc_dlr_interval=None, + tpid_outer_vlan=None, + tpid_inner_vlan=None, + crc_check_enable=None, + crc_recalculation_enable=None, + bfd_session_state_change_notify=None, + ecn_ect_threshold_enable=None, + vxlan_default_router_mac=None, + vxlan_default_port=None, + uninit_data_plane_on_removal=None, + tam_object_id=None, + tam_event_notify=None, + pre_shutdown=None, + nat_zone_counter_object_id=None, + nat_enable=None, + register_read=None, + register_write=None, + firmware_download_execute=None, + firmware_broadcast_stop=None, + firmware_verify_and_init_switch=None, + macsec_object_list=None, + qos_mpls_exp_to_tc_map=None, + qos_mpls_exp_to_color_map=None, + qos_tc_and_color_to_mpls_exp_map=None, + failover_config_mode=None, + tunnel_objects_list=None, + pre_ingress_acl=None, + qos_dscp_to_forwarding_class_map=None, + qos_mpls_exp_to_forwarding_class_map=None, + ipsec_object_id=None, + ipsec_sa_tag_tpid=None, + ipsec_sa_status_change_notify=None, + nat_event_notify=None, + ecmp_member_count=None, + custom_attribute=None): + """ + sai_set_switch_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of switch SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if ingress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INGRESS_ACL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if egress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_acl) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_EGRESS_ACL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if restart_warm is not None: + attr_value = sai_thrift_attribute_value_t(booldata=restart_warm) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_RESTART_WARM, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if warm_recover is not None: + attr_value = sai_thrift_attribute_value_t(booldata=warm_recover) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_WARM_RECOVER, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if switching_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=switching_mode) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCHING_MODE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if bcast_cpu_flood_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=bcast_cpu_flood_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if mcast_cpu_flood_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=mcast_cpu_flood_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if src_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SRC_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if max_learned_addresses is not None: + attr_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if fdb_aging_time is not None: + attr_value = sai_thrift_attribute_value_t(u32=fdb_aging_time) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_AGING_TIME, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if fdb_unicast_miss_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=fdb_unicast_miss_packet_action) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if fdb_broadcast_miss_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=fdb_broadcast_miss_packet_action) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if fdb_multicast_miss_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=fdb_multicast_miss_packet_action) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_default_hash_algorithm is not None: + attr_value = sai_thrift_attribute_value_t(s32=ecmp_default_hash_algorithm) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_default_hash_seed is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecmp_default_hash_seed) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_default_hash_offset is not None: + attr_value = sai_thrift_attribute_value_t(u8=ecmp_default_hash_offset) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_default_symmetric_hash is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ecmp_default_symmetric_hash) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_SYMMETRIC_HASH, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_hash_ipv4 is not None: + attr_value = sai_thrift_attribute_value_t(oid=ecmp_hash_ipv4) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV4, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_hash_ipv4_in_ipv4 is not None: + attr_value = sai_thrift_attribute_value_t(oid=ecmp_hash_ipv4_in_ipv4) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV4_IN_IPV4, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_hash_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(oid=ecmp_hash_ipv6) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV6, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_default_hash_algorithm is not None: + attr_value = sai_thrift_attribute_value_t(s32=lag_default_hash_algorithm) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_default_hash_seed is not None: + attr_value = sai_thrift_attribute_value_t(u32=lag_default_hash_seed) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_default_hash_offset is not None: + attr_value = sai_thrift_attribute_value_t(u8=lag_default_hash_offset) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_default_symmetric_hash is not None: + attr_value = sai_thrift_attribute_value_t(booldata=lag_default_symmetric_hash) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_SYMMETRIC_HASH, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_hash_ipv4 is not None: + attr_value = sai_thrift_attribute_value_t(oid=lag_hash_ipv4) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV4, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_hash_ipv4_in_ipv4 is not None: + attr_value = sai_thrift_attribute_value_t(oid=lag_hash_ipv4_in_ipv4) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV4_IN_IPV4, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if lag_hash_ipv6 is not None: + attr_value = sai_thrift_attribute_value_t(oid=lag_hash_ipv6) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV6, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if counter_refresh_interval is not None: + attr_value = sai_thrift_attribute_value_t(u32=counter_refresh_interval) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_default_tc is not None: + attr_value = sai_thrift_attribute_value_t(u8=qos_default_tc) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DEFAULT_TC, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_dot1p_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DOT1P_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_dot1p_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dot1p_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DOT1P_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_dscp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_dscp_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_tc_to_queue_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_to_queue_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_TO_QUEUE_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_tc_and_color_to_dot1p_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dot1p_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_tc_and_color_to_dscp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_dscp_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if switch_shell_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_shell_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if switch_state_change_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=switch_state_change_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if switch_shutdown_request_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=switch_shutdown_request_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if fdb_event_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=fdb_event_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if port_state_change_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=port_state_change_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if packet_event_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=packet_event_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if fast_api_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=fast_api_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FAST_API_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if mirror_tc is not None: + attr_value = sai_thrift_attribute_value_t(u8=mirror_tc) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MIRROR_TC, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if queue_pfc_deadlock_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=queue_pfc_deadlock_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if pfc_dlr_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=pfc_dlr_packet_action) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_DLR_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if pfc_tc_dld_interval is not None: + attr_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dld_interval) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if pfc_tc_dlr_interval is not None: + attr_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dlr_interval) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if tpid_outer_vlan is not None: + attr_value = sai_thrift_attribute_value_t(u16=tpid_outer_vlan) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TPID_OUTER_VLAN, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if tpid_inner_vlan is not None: + attr_value = sai_thrift_attribute_value_t(u16=tpid_inner_vlan) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TPID_INNER_VLAN, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if crc_check_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=crc_check_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CRC_CHECK_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if crc_recalculation_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=crc_recalculation_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CRC_RECALCULATION_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if bfd_session_state_change_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=bfd_session_state_change_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecn_ect_threshold_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ecn_ect_threshold_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECN_ECT_THRESHOLD_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if vxlan_default_router_mac is not None: + attr_value = sai_thrift_attribute_value_t(mac=vxlan_default_router_mac) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if vxlan_default_port is not None: + attr_value = sai_thrift_attribute_value_t(u16=vxlan_default_port) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if uninit_data_plane_on_removal is not None: + attr_value = sai_thrift_attribute_value_t(booldata=uninit_data_plane_on_removal) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if tam_object_id is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam_object_id) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TAM_OBJECT_ID, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if tam_event_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=tam_event_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TAM_EVENT_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if pre_shutdown is not None: + attr_value = sai_thrift_attribute_value_t(booldata=pre_shutdown) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PRE_SHUTDOWN, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if nat_zone_counter_object_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=nat_zone_counter_object_id) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_ZONE_COUNTER_OBJECT_ID, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if nat_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=nat_enable) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_ENABLE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if register_read is not None: + attr_value = sai_thrift_attribute_value_t(ptr=register_read) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_REGISTER_READ, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if register_write is not None: + attr_value = sai_thrift_attribute_value_t(ptr=register_write) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_REGISTER_WRITE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if firmware_download_execute is not None: + attr_value = sai_thrift_attribute_value_t(booldata=firmware_download_execute) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_EXECUTE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if firmware_broadcast_stop is not None: + attr_value = sai_thrift_attribute_value_t(booldata=firmware_broadcast_stop) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_BROADCAST_STOP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if firmware_verify_and_init_switch is not None: + attr_value = sai_thrift_attribute_value_t(booldata=firmware_verify_and_init_switch) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_VERIFY_AND_INIT_SWITCH, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if macsec_object_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=macsec_object_list) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_mpls_exp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_mpls_exp_to_color_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_color_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_and_color_to_mpls_exp_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if failover_config_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=failover_config_mode) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FAILOVER_CONFIG_MODE, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if tunnel_objects_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tunnel_objects_list) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if pre_ingress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=pre_ingress_acl) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PRE_INGRESS_ACL, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_dscp_to_forwarding_class_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_dscp_to_forwarding_class_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if qos_mpls_exp_to_forwarding_class_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_mpls_exp_to_forwarding_class_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ipsec_object_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=ipsec_object_id) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_OBJECT_ID, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ipsec_sa_tag_tpid is not None: + attr_value = sai_thrift_attribute_value_t(u16=ipsec_sa_tag_tpid) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_SA_TAG_TPID, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ipsec_sa_status_change_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=ipsec_sa_status_change_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_SA_STATUS_CHANGE_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if nat_event_notify is not None: + attr_value = sai_thrift_attribute_value_t(ptr=nat_event_notify) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if ecmp_member_count is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecmp_member_count) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_MEMBER_COUNT, + value=attr_value) + client.sai_thrift_set_switch_attribute(attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_switch_attribute(attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_switch_attribute(client, + number_of_active_ports=None, + max_number_of_supported_ports=None, + port_list=None, + port_max_mtu=None, + cpu_port=None, + max_virtual_routers=None, + fdb_table_size=None, + l3_neighbor_table_size=None, + l3_route_table_size=None, + lag_members=None, + number_of_lags=None, + ecmp_members=None, + number_of_ecmp_groups=None, + number_of_unicast_queues=None, + number_of_multicast_queues=None, + number_of_queues=None, + number_of_cpu_queues=None, + on_link_route_supported=None, + oper_status=None, + max_number_of_temp_sensors=None, + temp_list=None, + max_temp=None, + average_temp=None, + acl_table_minimum_priority=None, + acl_table_maximum_priority=None, + acl_entry_minimum_priority=None, + acl_entry_maximum_priority=None, + acl_table_group_minimum_priority=None, + acl_table_group_maximum_priority=None, + fdb_dst_user_meta_data_range=None, + route_dst_user_meta_data_range=None, + neighbor_dst_user_meta_data_range=None, + port_user_meta_data_range=None, + vlan_user_meta_data_range=None, + acl_user_meta_data_range=None, + acl_user_trap_id_range=None, + default_vlan_id=None, + default_stp_inst_id=None, + max_stp_instance=None, + default_virtual_router_id=None, + default_override_virtual_router_id=None, + default_1q_bridge_id=None, + ingress_acl=None, + egress_acl=None, + qos_max_number_of_traffic_classes=None, + qos_max_number_of_scheduler_group_hierarchy_levels=None, + qos_max_number_of_scheduler_groups_per_hierarchy_level=None, + qos_max_number_of_childs_per_scheduler_group=None, + total_buffer_size=None, + ingress_buffer_pool_num=None, + egress_buffer_pool_num=None, + available_ipv4_route_entry=None, + available_ipv6_route_entry=None, + available_ipv4_nexthop_entry=None, + available_ipv6_nexthop_entry=None, + available_ipv4_neighbor_entry=None, + available_ipv6_neighbor_entry=None, + available_next_hop_group_entry=None, + available_next_hop_group_member_entry=None, + available_fdb_entry=None, + available_l2mc_entry=None, + available_ipmc_entry=None, + available_snat_entry=None, + available_dnat_entry=None, + available_double_nat_entry=None, + available_acl_table=None, + available_acl_table_group=None, + available_my_sid_entry=None, + default_trap_group=None, + ecmp_hash=None, + lag_hash=None, + restart_warm=None, + warm_recover=None, + restart_type=None, + min_planned_restart_interval=None, + nv_storage_size=None, + max_acl_action_count=None, + max_acl_range_count=None, + acl_capability=None, + mcast_snooping_capability=None, + switching_mode=None, + bcast_cpu_flood_enable=None, + mcast_cpu_flood_enable=None, + src_mac_address=None, + max_learned_addresses=None, + fdb_aging_time=None, + fdb_unicast_miss_packet_action=None, + fdb_broadcast_miss_packet_action=None, + fdb_multicast_miss_packet_action=None, + ecmp_default_hash_algorithm=None, + ecmp_default_hash_seed=None, + ecmp_default_hash_offset=None, + ecmp_default_symmetric_hash=None, + ecmp_hash_ipv4=None, + ecmp_hash_ipv4_in_ipv4=None, + ecmp_hash_ipv6=None, + lag_default_hash_algorithm=None, + lag_default_hash_seed=None, + lag_default_hash_offset=None, + lag_default_symmetric_hash=None, + lag_hash_ipv4=None, + lag_hash_ipv4_in_ipv4=None, + lag_hash_ipv6=None, + counter_refresh_interval=None, + qos_default_tc=None, + qos_dot1p_to_tc_map=None, + qos_dot1p_to_color_map=None, + qos_dscp_to_tc_map=None, + qos_dscp_to_color_map=None, + qos_tc_to_queue_map=None, + qos_tc_and_color_to_dot1p_map=None, + qos_tc_and_color_to_dscp_map=None, + switch_shell_enable=None, + switch_profile_id=None, + switch_hardware_info=None, + firmware_path_name=None, + init_switch=None, + switch_state_change_notify=None, + switch_shutdown_request_notify=None, + fdb_event_notify=None, + port_state_change_notify=None, + packet_event_notify=None, + fast_api_enable=None, + mirror_tc=None, + acl_stage_ingress=None, + acl_stage_egress=None, + srv6_max_sid_depth=None, + srv6_tlv_type=None, + qos_num_lossless_queues=None, + queue_pfc_deadlock_notify=None, + pfc_dlr_packet_action=None, + pfc_tc_dld_interval_range=None, + pfc_tc_dld_interval=None, + pfc_tc_dlr_interval_range=None, + pfc_tc_dlr_interval=None, + supported_protected_object_type=None, + tpid_outer_vlan=None, + tpid_inner_vlan=None, + crc_check_enable=None, + crc_recalculation_enable=None, + bfd_session_state_change_notify=None, + number_of_bfd_session=None, + max_bfd_session=None, + supported_ipv4_bfd_session_offload_type=None, + supported_ipv6_bfd_session_offload_type=None, + min_bfd_rx=None, + min_bfd_tx=None, + ecn_ect_threshold_enable=None, + vxlan_default_router_mac=None, + vxlan_default_port=None, + max_mirror_session=None, + max_sampled_mirror_session=None, + supported_extended_stats_mode=None, + uninit_data_plane_on_removal=None, + tam_object_id=None, + tam_event_notify=None, + supported_object_type_list=None, + pre_shutdown=None, + nat_zone_counter_object_id=None, + nat_enable=None, + hardware_access_bus=None, + platfrom_context=None, + register_read=None, + register_write=None, + firmware_download_broadcast=None, + firmware_load_method=None, + firmware_load_type=None, + firmware_download_execute=None, + firmware_broadcast_stop=None, + firmware_verify_and_init_switch=None, + firmware_status=None, + firmware_major_version=None, + firmware_minor_version=None, + port_connector_list=None, + propogate_port_state_from_line_to_system_port_support=None, + type=None, + macsec_object_list=None, + qos_mpls_exp_to_tc_map=None, + qos_mpls_exp_to_color_map=None, + qos_tc_and_color_to_mpls_exp_map=None, + switch_id=None, + max_system_cores=None, + system_port_config_list=None, + number_of_system_ports=None, + system_port_list=None, + number_of_fabric_ports=None, + fabric_port_list=None, + packet_dma_memory_pool_size=None, + failover_config_mode=None, + supported_failover_mode=None, + tunnel_objects_list=None, + packet_available_dma_memory_pool_size=None, + pre_ingress_acl=None, + available_snapt_entry=None, + available_dnapt_entry=None, + available_double_napt_entry=None, + slave_mdio_addr_list=None, + my_mac_table_minimum_priority=None, + my_mac_table_maximum_priority=None, + my_mac_list=None, + installed_my_mac_entries=None, + available_my_mac_entries=None, + max_number_of_forwarding_classes=None, + qos_dscp_to_forwarding_class_map=None, + qos_mpls_exp_to_forwarding_class_map=None, + ipsec_object_id=None, + ipsec_sa_tag_tpid=None, + ipsec_sa_status_change_notify=None, + nat_event_notify=None, + max_ecmp_member_count=None, + ecmp_member_count=None, + custom_attribute=None): + """ + sai_get_switch_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of switch GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if number_of_active_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_ACTIVE_PORTS) + attr_list.append(attribute) + + if max_number_of_supported_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_NUMBER_OF_SUPPORTED_PORTS) + attr_list.append(attribute) + + if port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=port_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if port_max_mtu is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_MAX_MTU) + attr_list.append(attribute) + + if cpu_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CPU_PORT) + attr_list.append(attribute) + + if max_virtual_routers is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_VIRTUAL_ROUTERS) + attr_list.append(attribute) + + if fdb_table_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_TABLE_SIZE) + attr_list.append(attribute) + + if l3_neighbor_table_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_L3_NEIGHBOR_TABLE_SIZE) + attr_list.append(attribute) + + if l3_route_table_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_L3_ROUTE_TABLE_SIZE) + attr_list.append(attribute) + + if lag_members is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_MEMBERS) + attr_list.append(attribute) + + if number_of_lags is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_LAGS) + attr_list.append(attribute) + + if ecmp_members is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_MEMBERS) + attr_list.append(attribute) + + if number_of_ecmp_groups is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_ECMP_GROUPS) + attr_list.append(attribute) + + if number_of_unicast_queues is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_UNICAST_QUEUES) + attr_list.append(attribute) + + if number_of_multicast_queues is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_MULTICAST_QUEUES) + attr_list.append(attribute) + + if number_of_queues is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_QUEUES) + attr_list.append(attribute) + + if number_of_cpu_queues is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_CPU_QUEUES) + attr_list.append(attribute) + + if on_link_route_supported is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ON_LINK_ROUTE_SUPPORTED) + attr_list.append(attribute) + + if oper_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_OPER_STATUS) + attr_list.append(attribute) + + if max_number_of_temp_sensors is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS) + attr_list.append(attribute) + + if temp_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=temp_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TEMP_LIST, + value=attribute_value) + attr_list.append(attribute) + + if max_temp is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_TEMP) + attr_list.append(attribute) + + if average_temp is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVERAGE_TEMP) + attr_list.append(attribute) + + if acl_table_minimum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_TABLE_MINIMUM_PRIORITY) + attr_list.append(attribute) + + if acl_table_maximum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_TABLE_MAXIMUM_PRIORITY) + attr_list.append(attribute) + + if acl_entry_minimum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY) + attr_list.append(attribute) + + if acl_entry_maximum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY) + attr_list.append(attribute) + + if acl_table_group_minimum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_TABLE_GROUP_MINIMUM_PRIORITY) + attr_list.append(attribute) + + if acl_table_group_maximum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_TABLE_GROUP_MAXIMUM_PRIORITY) + attr_list.append(attribute) + + if fdb_dst_user_meta_data_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_DST_USER_META_DATA_RANGE) + attr_list.append(attribute) + + if route_dst_user_meta_data_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ROUTE_DST_USER_META_DATA_RANGE) + attr_list.append(attribute) + + if neighbor_dst_user_meta_data_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NEIGHBOR_DST_USER_META_DATA_RANGE) + attr_list.append(attribute) + + if port_user_meta_data_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_USER_META_DATA_RANGE) + attr_list.append(attribute) + + if vlan_user_meta_data_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VLAN_USER_META_DATA_RANGE) + attr_list.append(attribute) + + if acl_user_meta_data_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_USER_META_DATA_RANGE) + attr_list.append(attribute) + + if acl_user_trap_id_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_USER_TRAP_ID_RANGE) + attr_list.append(attribute) + + if default_vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_DEFAULT_VLAN_ID) + attr_list.append(attribute) + + if default_stp_inst_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_DEFAULT_STP_INST_ID) + attr_list.append(attribute) + + if max_stp_instance is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_STP_INSTANCE) + attr_list.append(attribute) + + if default_virtual_router_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID) + attr_list.append(attribute) + + if default_override_virtual_router_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID) + attr_list.append(attribute) + + if default_1q_bridge_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_DEFAULT_1Q_BRIDGE_ID) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INGRESS_ACL) + attr_list.append(attribute) + + if egress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_EGRESS_ACL) + attr_list.append(attribute) + + if qos_max_number_of_traffic_classes is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES) + attr_list.append(attribute) + + if qos_max_number_of_scheduler_group_hierarchy_levels is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_SCHEDULER_GROUP_HIERARCHY_LEVELS) + attr_list.append(attribute) + + if qos_max_number_of_scheduler_groups_per_hierarchy_level is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=qos_max_number_of_scheduler_groups_per_hierarchy_level) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_SCHEDULER_GROUPS_PER_HIERARCHY_LEVEL, + value=attribute_value) + attr_list.append(attribute) + + if qos_max_number_of_childs_per_scheduler_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_CHILDS_PER_SCHEDULER_GROUP) + attr_list.append(attribute) + + if total_buffer_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TOTAL_BUFFER_SIZE) + attr_list.append(attribute) + + if ingress_buffer_pool_num is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INGRESS_BUFFER_POOL_NUM) + attr_list.append(attribute) + + if egress_buffer_pool_num is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_EGRESS_BUFFER_POOL_NUM) + attr_list.append(attribute) + + if available_ipv4_route_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY) + attr_list.append(attribute) + + if available_ipv6_route_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY) + attr_list.append(attribute) + + if available_ipv4_nexthop_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY) + attr_list.append(attribute) + + if available_ipv6_nexthop_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY) + attr_list.append(attribute) + + if available_ipv4_neighbor_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY) + attr_list.append(attribute) + + if available_ipv6_neighbor_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY) + attr_list.append(attribute) + + if available_next_hop_group_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY) + attr_list.append(attribute) + + if available_next_hop_group_member_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY) + attr_list.append(attribute) + + if available_fdb_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY) + attr_list.append(attribute) + + if available_l2mc_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_L2MC_ENTRY) + attr_list.append(attribute) + + if available_ipmc_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY) + attr_list.append(attribute) + + if available_snat_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY) + attr_list.append(attribute) + + if available_dnat_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY) + attr_list.append(attribute) + + if available_double_nat_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAT_ENTRY) + attr_list.append(attribute) + + if available_acl_table is not None: + attribute_value = sai_thrift_attribute_value_t(aclresource=available_acl_table) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE, + value=attribute_value) + attr_list.append(attribute) + + if available_acl_table_group is not None: + attribute_value = sai_thrift_attribute_value_t(aclresource=available_acl_table_group) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if available_my_sid_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_MY_SID_ENTRY) + attr_list.append(attribute) + + if default_trap_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP) + attr_list.append(attribute) + + if ecmp_hash is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH) + attr_list.append(attribute) + + if lag_hash is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH) + attr_list.append(attribute) + + if restart_warm is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_RESTART_WARM) + attr_list.append(attribute) + + if warm_recover is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_WARM_RECOVER) + attr_list.append(attribute) + + if restart_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_RESTART_TYPE) + attr_list.append(attribute) + + if min_planned_restart_interval is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MIN_PLANNED_RESTART_INTERVAL) + attr_list.append(attribute) + + if nv_storage_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NV_STORAGE_SIZE) + attr_list.append(attribute) + + if max_acl_action_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_ACL_ACTION_COUNT) + attr_list.append(attribute) + + if max_acl_range_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_ACL_RANGE_COUNT) + attr_list.append(attribute) + + if acl_capability is not None: + attribute_value = sai_thrift_attribute_value_t(aclcapability=acl_capability) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_CAPABILITY, + value=attribute_value) + attr_list.append(attribute) + + if mcast_snooping_capability is not None: + attribute_value = sai_thrift_attribute_value_t(s32=mcast_snooping_capability) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MCAST_SNOOPING_CAPABILITY, + value=attribute_value) + attr_list.append(attribute) + + if switching_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCHING_MODE) + attr_list.append(attribute) + + if bcast_cpu_flood_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE) + attr_list.append(attribute) + + if mcast_cpu_flood_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SRC_MAC_ADDRESS) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES) + attr_list.append(attribute) + + if fdb_aging_time is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_AGING_TIME) + attr_list.append(attribute) + + if fdb_unicast_miss_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION) + attr_list.append(attribute) + + if fdb_broadcast_miss_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_PACKET_ACTION) + attr_list.append(attribute) + + if fdb_multicast_miss_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION) + attr_list.append(attribute) + + if ecmp_default_hash_algorithm is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM) + attr_list.append(attribute) + + if ecmp_default_hash_seed is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED) + attr_list.append(attribute) + + if ecmp_default_hash_offset is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET) + attr_list.append(attribute) + + if ecmp_default_symmetric_hash is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_DEFAULT_SYMMETRIC_HASH) + attr_list.append(attribute) + + if ecmp_hash_ipv4 is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV4) + attr_list.append(attribute) + + if ecmp_hash_ipv4_in_ipv4 is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV4_IN_IPV4) + attr_list.append(attribute) + + if ecmp_hash_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_HASH_IPV6) + attr_list.append(attribute) + + if lag_default_hash_algorithm is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM) + attr_list.append(attribute) + + if lag_default_hash_seed is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED) + attr_list.append(attribute) + + if lag_default_hash_offset is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET) + attr_list.append(attribute) + + if lag_default_symmetric_hash is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_DEFAULT_SYMMETRIC_HASH) + attr_list.append(attribute) + + if lag_hash_ipv4 is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV4) + attr_list.append(attribute) + + if lag_hash_ipv4_in_ipv4 is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV4_IN_IPV4) + attr_list.append(attribute) + + if lag_hash_ipv6 is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_LAG_HASH_IPV6) + attr_list.append(attribute) + + if counter_refresh_interval is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL) + attr_list.append(attribute) + + if qos_default_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DEFAULT_TC) + attr_list.append(attribute) + + if qos_dot1p_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DOT1P_TO_TC_MAP) + attr_list.append(attribute) + + if qos_dot1p_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DOT1P_TO_COLOR_MAP) + attr_list.append(attribute) + + if qos_dscp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP) + attr_list.append(attribute) + + if qos_dscp_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_COLOR_MAP) + attr_list.append(attribute) + + if qos_tc_to_queue_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_TO_QUEUE_MAP) + attr_list.append(attribute) + + if qos_tc_and_color_to_dot1p_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP) + attr_list.append(attribute) + + if qos_tc_and_color_to_dscp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP) + attr_list.append(attribute) + + if switch_shell_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE) + attr_list.append(attribute) + + if switch_profile_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_PROFILE_ID) + attr_list.append(attribute) + + if switch_hardware_info is not None: + attribute_value = sai_thrift_attribute_value_t(s8list=switch_hardware_info) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO, + value=attribute_value) + attr_list.append(attribute) + + if firmware_path_name is not None: + attribute_value = sai_thrift_attribute_value_t(s8list=firmware_path_name) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_PATH_NAME, + value=attribute_value) + attr_list.append(attribute) + + if init_switch is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INIT_SWITCH) + attr_list.append(attribute) + + if switch_state_change_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY) + attr_list.append(attribute) + + if switch_shutdown_request_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY) + attr_list.append(attribute) + + if fdb_event_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY) + attr_list.append(attribute) + + if port_state_change_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY) + attr_list.append(attribute) + + if packet_event_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY) + attr_list.append(attribute) + + if fast_api_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FAST_API_ENABLE) + attr_list.append(attribute) + + if mirror_tc is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MIRROR_TC) + attr_list.append(attribute) + + if acl_stage_ingress is not None: + attribute_value = sai_thrift_attribute_value_t(aclcapability=acl_stage_ingress) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_STAGE_INGRESS, + value=attribute_value) + attr_list.append(attribute) + + if acl_stage_egress is not None: + attribute_value = sai_thrift_attribute_value_t(aclcapability=acl_stage_egress) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ACL_STAGE_EGRESS, + value=attribute_value) + attr_list.append(attribute) + + if srv6_max_sid_depth is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SRV6_MAX_SID_DEPTH) + attr_list.append(attribute) + + if srv6_tlv_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=srv6_tlv_type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SRV6_TLV_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if qos_num_lossless_queues is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_NUM_LOSSLESS_QUEUES) + attr_list.append(attribute) + + if queue_pfc_deadlock_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY) + attr_list.append(attribute) + + if pfc_dlr_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_DLR_PACKET_ACTION) + attr_list.append(attribute) + + if pfc_tc_dld_interval_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL_RANGE) + attr_list.append(attribute) + + if pfc_tc_dld_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dld_interval) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if pfc_tc_dlr_interval_range is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL_RANGE) + attr_list.append(attribute) + + if pfc_tc_dlr_interval is not None: + attribute_value = sai_thrift_attribute_value_t(maplist=pfc_tc_dlr_interval) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if supported_protected_object_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_protected_object_type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SUPPORTED_PROTECTED_OBJECT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if tpid_outer_vlan is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TPID_OUTER_VLAN) + attr_list.append(attribute) + + if tpid_inner_vlan is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TPID_INNER_VLAN) + attr_list.append(attribute) + + if crc_check_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CRC_CHECK_ENABLE) + attr_list.append(attribute) + + if crc_recalculation_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_CRC_RECALCULATION_ENABLE) + attr_list.append(attribute) + + if bfd_session_state_change_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY) + attr_list.append(attribute) + + if number_of_bfd_session is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_BFD_SESSION) + attr_list.append(attribute) + + if max_bfd_session is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_BFD_SESSION) + attr_list.append(attribute) + + if supported_ipv4_bfd_session_offload_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_ipv4_bfd_session_offload_type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SUPPORTED_IPV4_BFD_SESSION_OFFLOAD_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if supported_ipv6_bfd_session_offload_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_ipv6_bfd_session_offload_type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SUPPORTED_IPV6_BFD_SESSION_OFFLOAD_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if min_bfd_rx is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MIN_BFD_RX) + attr_list.append(attribute) + + if min_bfd_tx is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MIN_BFD_TX) + attr_list.append(attribute) + + if ecn_ect_threshold_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECN_ECT_THRESHOLD_ENABLE) + attr_list.append(attribute) + + if vxlan_default_router_mac is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC) + attr_list.append(attribute) + + if vxlan_default_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT) + attr_list.append(attribute) + + if max_mirror_session is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_MIRROR_SESSION) + attr_list.append(attribute) + + if max_sampled_mirror_session is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_SAMPLED_MIRROR_SESSION) + attr_list.append(attribute) + + if supported_extended_stats_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_extended_stats_mode) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SUPPORTED_EXTENDED_STATS_MODE, + value=attribute_value) + attr_list.append(attribute) + + if uninit_data_plane_on_removal is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL) + attr_list.append(attribute) + + if tam_object_id is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object_id) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TAM_OBJECT_ID, + value=attribute_value) + attr_list.append(attribute) + + if tam_event_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TAM_EVENT_NOTIFY) + attr_list.append(attribute) + + if supported_object_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=supported_object_type_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SUPPORTED_OBJECT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if pre_shutdown is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PRE_SHUTDOWN) + attr_list.append(attribute) + + if nat_zone_counter_object_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_ZONE_COUNTER_OBJECT_ID) + attr_list.append(attribute) + + if nat_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_ENABLE) + attr_list.append(attribute) + + if hardware_access_bus is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_HARDWARE_ACCESS_BUS) + attr_list.append(attribute) + + if platfrom_context is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PLATFROM_CONTEXT) + attr_list.append(attribute) + + if register_read is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_REGISTER_READ) + attr_list.append(attribute) + + if register_write is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_REGISTER_WRITE) + attr_list.append(attribute) + + if firmware_download_broadcast is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_BROADCAST) + attr_list.append(attribute) + + if firmware_load_method is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_LOAD_METHOD) + attr_list.append(attribute) + + if firmware_load_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_LOAD_TYPE) + attr_list.append(attribute) + + if firmware_download_execute is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_EXECUTE) + attr_list.append(attribute) + + if firmware_broadcast_stop is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_BROADCAST_STOP) + attr_list.append(attribute) + + if firmware_verify_and_init_switch is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_VERIFY_AND_INIT_SWITCH) + attr_list.append(attribute) + + if firmware_status is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_STATUS) + attr_list.append(attribute) + + if firmware_major_version is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION) + attr_list.append(attribute) + + if firmware_minor_version is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FIRMWARE_MINOR_VERSION) + attr_list.append(attribute) + + if port_connector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=port_connector_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PORT_CONNECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if propogate_port_state_from_line_to_system_port_support is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PROPOGATE_PORT_STATE_FROM_LINE_TO_SYSTEM_PORT_SUPPORT) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TYPE) + attr_list.append(attribute) + + if macsec_object_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=macsec_object_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if qos_mpls_exp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_TC_MAP) + attr_list.append(attribute) + + if qos_mpls_exp_to_color_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP) + attr_list.append(attribute) + + if qos_tc_and_color_to_mpls_exp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP) + attr_list.append(attribute) + + if switch_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SWITCH_ID) + attr_list.append(attribute) + + if max_system_cores is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_SYSTEM_CORES) + attr_list.append(attribute) + + if system_port_config_list is not None: + attribute_value = sai_thrift_attribute_value_t(sysportconfiglist=system_port_config_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST, + value=attribute_value) + attr_list.append(attribute) + + if number_of_system_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_SYSTEM_PORTS) + attr_list.append(attribute) + + if system_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=system_port_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SYSTEM_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if number_of_fabric_ports is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NUMBER_OF_FABRIC_PORTS) + attr_list.append(attribute) + + if fabric_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=fabric_port_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FABRIC_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if packet_dma_memory_pool_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PACKET_DMA_MEMORY_POOL_SIZE) + attr_list.append(attribute) + + if failover_config_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_FAILOVER_CONFIG_MODE) + attr_list.append(attribute) + + if supported_failover_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SUPPORTED_FAILOVER_MODE) + attr_list.append(attribute) + + if tunnel_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tunnel_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if packet_available_dma_memory_pool_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PACKET_AVAILABLE_DMA_MEMORY_POOL_SIZE) + attr_list.append(attribute) + + if pre_ingress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_PRE_INGRESS_ACL) + attr_list.append(attribute) + + if available_snapt_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_SNAPT_ENTRY) + attr_list.append(attribute) + + if available_dnapt_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_DNAPT_ENTRY) + attr_list.append(attribute) + + if available_double_napt_entry is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAPT_ENTRY) + attr_list.append(attribute) + + if slave_mdio_addr_list is not None: + attribute_value = sai_thrift_attribute_value_t(u8list=slave_mdio_addr_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_SLAVE_MDIO_ADDR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if my_mac_table_minimum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MY_MAC_TABLE_MINIMUM_PRIORITY) + attr_list.append(attribute) + + if my_mac_table_maximum_priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MY_MAC_TABLE_MAXIMUM_PRIORITY) + attr_list.append(attribute) + + if my_mac_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=my_mac_list) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MY_MAC_LIST, + value=attribute_value) + attr_list.append(attribute) + + if installed_my_mac_entries is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_INSTALLED_MY_MAC_ENTRIES) + attr_list.append(attribute) + + if available_my_mac_entries is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_AVAILABLE_MY_MAC_ENTRIES) + attr_list.append(attribute) + + if max_number_of_forwarding_classes is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_NUMBER_OF_FORWARDING_CLASSES) + attr_list.append(attribute) + + if qos_dscp_to_forwarding_class_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP) + attr_list.append(attribute) + + if qos_mpls_exp_to_forwarding_class_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP) + attr_list.append(attribute) + + if ipsec_object_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_OBJECT_ID) + attr_list.append(attribute) + + if ipsec_sa_tag_tpid is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_SA_TAG_TPID) + attr_list.append(attribute) + + if ipsec_sa_status_change_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_IPSEC_SA_STATUS_CHANGE_NOTIFY) + attr_list.append(attribute) + + if nat_event_notify is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY) + attr_list.append(attribute) + + if max_ecmp_member_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_MAX_ECMP_MEMBER_COUNT) + attr_list.append(attribute) + + if ecmp_member_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_ATTR_ECMP_MEMBER_COUNT) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_switch_attribute(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_ACTIVE_PORTS: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_ACTIVE_PORTS"] = attr.value.u32 + attrs["number_of_active_ports"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MAX_NUMBER_OF_SUPPORTED_PORTS: + attrs["SAI_SWITCH_ATTR_MAX_NUMBER_OF_SUPPORTED_PORTS"] = attr.value.u32 + attrs["max_number_of_supported_ports"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_PORT_LIST: + attrs["SAI_SWITCH_ATTR_PORT_LIST"] = attr.value.objlist + attrs["port_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_PORT_MAX_MTU: + attrs["SAI_SWITCH_ATTR_PORT_MAX_MTU"] = attr.value.u32 + attrs["port_max_mtu"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_CPU_PORT: + attrs["SAI_SWITCH_ATTR_CPU_PORT"] = attr.value.oid + attrs["cpu_port"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_MAX_VIRTUAL_ROUTERS: + attrs["SAI_SWITCH_ATTR_MAX_VIRTUAL_ROUTERS"] = attr.value.u32 + attrs["max_virtual_routers"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FDB_TABLE_SIZE: + attrs["SAI_SWITCH_ATTR_FDB_TABLE_SIZE"] = attr.value.u32 + attrs["fdb_table_size"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_L3_NEIGHBOR_TABLE_SIZE: + attrs["SAI_SWITCH_ATTR_L3_NEIGHBOR_TABLE_SIZE"] = attr.value.u32 + attrs["l3_neighbor_table_size"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_L3_ROUTE_TABLE_SIZE: + attrs["SAI_SWITCH_ATTR_L3_ROUTE_TABLE_SIZE"] = attr.value.u32 + attrs["l3_route_table_size"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_LAG_MEMBERS: + attrs["SAI_SWITCH_ATTR_LAG_MEMBERS"] = attr.value.u32 + attrs["lag_members"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_LAGS: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_LAGS"] = attr.value.u32 + attrs["number_of_lags"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ECMP_MEMBERS: + attrs["SAI_SWITCH_ATTR_ECMP_MEMBERS"] = attr.value.u32 + attrs["ecmp_members"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_ECMP_GROUPS: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_ECMP_GROUPS"] = attr.value.u32 + attrs["number_of_ecmp_groups"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_UNICAST_QUEUES: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_UNICAST_QUEUES"] = attr.value.u32 + attrs["number_of_unicast_queues"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_MULTICAST_QUEUES: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_MULTICAST_QUEUES"] = attr.value.u32 + attrs["number_of_multicast_queues"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_QUEUES: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_QUEUES"] = attr.value.u32 + attrs["number_of_queues"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_CPU_QUEUES: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_CPU_QUEUES"] = attr.value.u32 + attrs["number_of_cpu_queues"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ON_LINK_ROUTE_SUPPORTED: + attrs["SAI_SWITCH_ATTR_ON_LINK_ROUTE_SUPPORTED"] = attr.value.booldata + attrs["on_link_route_supported"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_OPER_STATUS: + attrs["SAI_SWITCH_ATTR_OPER_STATUS"] = attr.value.s32 + attrs["oper_status"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS: + attrs["SAI_SWITCH_ATTR_MAX_NUMBER_OF_TEMP_SENSORS"] = attr.value.u8 + attrs["max_number_of_temp_sensors"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_TEMP_LIST: + attrs["SAI_SWITCH_ATTR_TEMP_LIST"] = attr.value.s32list + attrs["temp_list"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_MAX_TEMP: + attrs["SAI_SWITCH_ATTR_MAX_TEMP"] = attr.value.s32 + attrs["max_temp"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_AVERAGE_TEMP: + attrs["SAI_SWITCH_ATTR_AVERAGE_TEMP"] = attr.value.s32 + attrs["average_temp"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_ACL_TABLE_MINIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_ACL_TABLE_MINIMUM_PRIORITY"] = attr.value.u32 + attrs["acl_table_minimum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ACL_TABLE_MAXIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_ACL_TABLE_MAXIMUM_PRIORITY"] = attr.value.u32 + attrs["acl_table_maximum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY"] = attr.value.u32 + attrs["acl_entry_minimum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY"] = attr.value.u32 + attrs["acl_entry_maximum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ACL_TABLE_GROUP_MINIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_ACL_TABLE_GROUP_MINIMUM_PRIORITY"] = attr.value.u32 + attrs["acl_table_group_minimum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ACL_TABLE_GROUP_MAXIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_ACL_TABLE_GROUP_MAXIMUM_PRIORITY"] = attr.value.u32 + attrs["acl_table_group_maximum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FDB_DST_USER_META_DATA_RANGE: + attrs["SAI_SWITCH_ATTR_FDB_DST_USER_META_DATA_RANGE"] = attr.value.u32range + attrs["fdb_dst_user_meta_data_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_ROUTE_DST_USER_META_DATA_RANGE: + attrs["SAI_SWITCH_ATTR_ROUTE_DST_USER_META_DATA_RANGE"] = attr.value.u32range + attrs["route_dst_user_meta_data_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_NEIGHBOR_DST_USER_META_DATA_RANGE: + attrs["SAI_SWITCH_ATTR_NEIGHBOR_DST_USER_META_DATA_RANGE"] = attr.value.u32range + attrs["neighbor_dst_user_meta_data_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_PORT_USER_META_DATA_RANGE: + attrs["SAI_SWITCH_ATTR_PORT_USER_META_DATA_RANGE"] = attr.value.u32range + attrs["port_user_meta_data_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_VLAN_USER_META_DATA_RANGE: + attrs["SAI_SWITCH_ATTR_VLAN_USER_META_DATA_RANGE"] = attr.value.u32range + attrs["vlan_user_meta_data_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_ACL_USER_META_DATA_RANGE: + attrs["SAI_SWITCH_ATTR_ACL_USER_META_DATA_RANGE"] = attr.value.u32range + attrs["acl_user_meta_data_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_ACL_USER_TRAP_ID_RANGE: + attrs["SAI_SWITCH_ATTR_ACL_USER_TRAP_ID_RANGE"] = attr.value.u32range + attrs["acl_user_trap_id_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_DEFAULT_VLAN_ID: + attrs["SAI_SWITCH_ATTR_DEFAULT_VLAN_ID"] = attr.value.oid + attrs["default_vlan_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_DEFAULT_STP_INST_ID: + attrs["SAI_SWITCH_ATTR_DEFAULT_STP_INST_ID"] = attr.value.oid + attrs["default_stp_inst_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_MAX_STP_INSTANCE: + attrs["SAI_SWITCH_ATTR_MAX_STP_INSTANCE"] = attr.value.u32 + attrs["max_stp_instance"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID: + attrs["SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID"] = attr.value.oid + attrs["default_virtual_router_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID: + attrs["SAI_SWITCH_ATTR_DEFAULT_OVERRIDE_VIRTUAL_ROUTER_ID"] = attr.value.oid + attrs["default_override_virtual_router_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_DEFAULT_1Q_BRIDGE_ID: + attrs["SAI_SWITCH_ATTR_DEFAULT_1Q_BRIDGE_ID"] = attr.value.oid + attrs["default_1q_bridge_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_INGRESS_ACL: + attrs["SAI_SWITCH_ATTR_INGRESS_ACL"] = attr.value.oid + attrs["ingress_acl"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_EGRESS_ACL: + attrs["SAI_SWITCH_ATTR_EGRESS_ACL"] = attr.value.oid + attrs["egress_acl"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES: + attrs["SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES"] = attr.value.u8 + attrs["qos_max_number_of_traffic_classes"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_SCHEDULER_GROUP_HIERARCHY_LEVELS: + attrs["SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_SCHEDULER_GROUP_HIERARCHY_LEVELS"] = attr.value.u32 + attrs["qos_max_number_of_scheduler_group_hierarchy_levels"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_SCHEDULER_GROUPS_PER_HIERARCHY_LEVEL: + attrs["SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_SCHEDULER_GROUPS_PER_HIERARCHY_LEVEL"] = attr.value.u32list + attrs["qos_max_number_of_scheduler_groups_per_hierarchy_level"] = attr.value.u32list + + if attr.id == SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_CHILDS_PER_SCHEDULER_GROUP: + attrs["SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_CHILDS_PER_SCHEDULER_GROUP"] = attr.value.u32 + attrs["qos_max_number_of_childs_per_scheduler_group"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_TOTAL_BUFFER_SIZE: + attrs["SAI_SWITCH_ATTR_TOTAL_BUFFER_SIZE"] = attr.value.u64 + attrs["total_buffer_size"] = attr.value.u64 + + if attr.id == SAI_SWITCH_ATTR_INGRESS_BUFFER_POOL_NUM: + attrs["SAI_SWITCH_ATTR_INGRESS_BUFFER_POOL_NUM"] = attr.value.u32 + attrs["ingress_buffer_pool_num"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_EGRESS_BUFFER_POOL_NUM: + attrs["SAI_SWITCH_ATTR_EGRESS_BUFFER_POOL_NUM"] = attr.value.u32 + attrs["egress_buffer_pool_num"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY"] = attr.value.u32 + attrs["available_ipv4_route_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY"] = attr.value.u32 + attrs["available_ipv6_route_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY"] = attr.value.u32 + attrs["available_ipv4_nexthop_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY"] = attr.value.u32 + attrs["available_ipv6_nexthop_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY"] = attr.value.u32 + attrs["available_ipv4_neighbor_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY"] = attr.value.u32 + attrs["available_ipv6_neighbor_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY"] = attr.value.u32 + attrs["available_next_hop_group_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY"] = attr.value.u32 + attrs["available_next_hop_group_member_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY"] = attr.value.u32 + attrs["available_fdb_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_L2MC_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_L2MC_ENTRY"] = attr.value.u32 + attrs["available_l2mc_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY"] = attr.value.u32 + attrs["available_ipmc_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY"] = attr.value.u32 + attrs["available_snat_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY"] = attr.value.u32 + attrs["available_dnat_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAT_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAT_ENTRY"] = attr.value.u32 + attrs["available_double_nat_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE: + attrs["SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE"] = attr.value.aclresource + attrs["available_acl_table"] = attr.value.aclresource + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP: + attrs["SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP"] = attr.value.aclresource + attrs["available_acl_table_group"] = attr.value.aclresource + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_MY_SID_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_MY_SID_ENTRY"] = attr.value.u32 + attrs["available_my_sid_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP: + attrs["SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP"] = attr.value.oid + attrs["default_trap_group"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_ECMP_HASH: + attrs["SAI_SWITCH_ATTR_ECMP_HASH"] = attr.value.oid + attrs["ecmp_hash"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_LAG_HASH: + attrs["SAI_SWITCH_ATTR_LAG_HASH"] = attr.value.oid + attrs["lag_hash"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_RESTART_WARM: + attrs["SAI_SWITCH_ATTR_RESTART_WARM"] = attr.value.booldata + attrs["restart_warm"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_WARM_RECOVER: + attrs["SAI_SWITCH_ATTR_WARM_RECOVER"] = attr.value.booldata + attrs["warm_recover"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_RESTART_TYPE: + attrs["SAI_SWITCH_ATTR_RESTART_TYPE"] = attr.value.s32 + attrs["restart_type"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_MIN_PLANNED_RESTART_INTERVAL: + attrs["SAI_SWITCH_ATTR_MIN_PLANNED_RESTART_INTERVAL"] = attr.value.u32 + attrs["min_planned_restart_interval"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_NV_STORAGE_SIZE: + attrs["SAI_SWITCH_ATTR_NV_STORAGE_SIZE"] = attr.value.u64 + attrs["nv_storage_size"] = attr.value.u64 + + if attr.id == SAI_SWITCH_ATTR_MAX_ACL_ACTION_COUNT: + attrs["SAI_SWITCH_ATTR_MAX_ACL_ACTION_COUNT"] = attr.value.u32 + attrs["max_acl_action_count"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MAX_ACL_RANGE_COUNT: + attrs["SAI_SWITCH_ATTR_MAX_ACL_RANGE_COUNT"] = attr.value.u32 + attrs["max_acl_range_count"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ACL_CAPABILITY: + attrs["SAI_SWITCH_ATTR_ACL_CAPABILITY"] = attr.value.aclcapability + attrs["acl_capability"] = attr.value.aclcapability + + if attr.id == SAI_SWITCH_ATTR_MCAST_SNOOPING_CAPABILITY: + attrs["SAI_SWITCH_ATTR_MCAST_SNOOPING_CAPABILITY"] = attr.value.s32 + attrs["mcast_snooping_capability"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_SWITCHING_MODE: + attrs["SAI_SWITCH_ATTR_SWITCHING_MODE"] = attr.value.s32 + attrs["switching_mode"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE: + attrs["SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE"] = attr.value.booldata + attrs["bcast_cpu_flood_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE: + attrs["SAI_SWITCH_ATTR_MCAST_CPU_FLOOD_ENABLE"] = attr.value.booldata + attrs["mcast_cpu_flood_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_SRC_MAC_ADDRESS: + attrs["SAI_SWITCH_ATTR_SRC_MAC_ADDRESS"] = attr.value.mac + attrs["src_mac_address"] = attr.value.mac + + if attr.id == SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES: + attrs["SAI_SWITCH_ATTR_MAX_LEARNED_ADDRESSES"] = attr.value.u32 + attrs["max_learned_addresses"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FDB_AGING_TIME: + attrs["SAI_SWITCH_ATTR_FDB_AGING_TIME"] = attr.value.u32 + attrs["fdb_aging_time"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION: + attrs["SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION"] = attr.value.s32 + attrs["fdb_unicast_miss_packet_action"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_PACKET_ACTION: + attrs["SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_PACKET_ACTION"] = attr.value.s32 + attrs["fdb_broadcast_miss_packet_action"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION: + attrs["SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION"] = attr.value.s32 + attrs["fdb_multicast_miss_packet_action"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM: + attrs["SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM"] = attr.value.s32 + attrs["ecmp_default_hash_algorithm"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED: + attrs["SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED"] = attr.value.u32 + attrs["ecmp_default_hash_seed"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET: + attrs["SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET"] = attr.value.u8 + attrs["ecmp_default_hash_offset"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_ECMP_DEFAULT_SYMMETRIC_HASH: + attrs["SAI_SWITCH_ATTR_ECMP_DEFAULT_SYMMETRIC_HASH"] = attr.value.booldata + attrs["ecmp_default_symmetric_hash"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_ECMP_HASH_IPV4: + attrs["SAI_SWITCH_ATTR_ECMP_HASH_IPV4"] = attr.value.oid + attrs["ecmp_hash_ipv4"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_ECMP_HASH_IPV4_IN_IPV4: + attrs["SAI_SWITCH_ATTR_ECMP_HASH_IPV4_IN_IPV4"] = attr.value.oid + attrs["ecmp_hash_ipv4_in_ipv4"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_ECMP_HASH_IPV6: + attrs["SAI_SWITCH_ATTR_ECMP_HASH_IPV6"] = attr.value.oid + attrs["ecmp_hash_ipv6"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM: + attrs["SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM"] = attr.value.s32 + attrs["lag_default_hash_algorithm"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED: + attrs["SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED"] = attr.value.u32 + attrs["lag_default_hash_seed"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET: + attrs["SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET"] = attr.value.u8 + attrs["lag_default_hash_offset"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_LAG_DEFAULT_SYMMETRIC_HASH: + attrs["SAI_SWITCH_ATTR_LAG_DEFAULT_SYMMETRIC_HASH"] = attr.value.booldata + attrs["lag_default_symmetric_hash"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_LAG_HASH_IPV4: + attrs["SAI_SWITCH_ATTR_LAG_HASH_IPV4"] = attr.value.oid + attrs["lag_hash_ipv4"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_LAG_HASH_IPV4_IN_IPV4: + attrs["SAI_SWITCH_ATTR_LAG_HASH_IPV4_IN_IPV4"] = attr.value.oid + attrs["lag_hash_ipv4_in_ipv4"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_LAG_HASH_IPV6: + attrs["SAI_SWITCH_ATTR_LAG_HASH_IPV6"] = attr.value.oid + attrs["lag_hash_ipv6"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL: + attrs["SAI_SWITCH_ATTR_COUNTER_REFRESH_INTERVAL"] = attr.value.u32 + attrs["counter_refresh_interval"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_QOS_DEFAULT_TC: + attrs["SAI_SWITCH_ATTR_QOS_DEFAULT_TC"] = attr.value.u8 + attrs["qos_default_tc"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_QOS_DOT1P_TO_TC_MAP: + attrs["SAI_SWITCH_ATTR_QOS_DOT1P_TO_TC_MAP"] = attr.value.oid + attrs["qos_dot1p_to_tc_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_DOT1P_TO_COLOR_MAP: + attrs["SAI_SWITCH_ATTR_QOS_DOT1P_TO_COLOR_MAP"] = attr.value.oid + attrs["qos_dot1p_to_color_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP: + attrs["SAI_SWITCH_ATTR_QOS_DSCP_TO_TC_MAP"] = attr.value.oid + attrs["qos_dscp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_DSCP_TO_COLOR_MAP: + attrs["SAI_SWITCH_ATTR_QOS_DSCP_TO_COLOR_MAP"] = attr.value.oid + attrs["qos_dscp_to_color_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_TC_TO_QUEUE_MAP: + attrs["SAI_SWITCH_ATTR_QOS_TC_TO_QUEUE_MAP"] = attr.value.oid + attrs["qos_tc_to_queue_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP: + attrs["SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DOT1P_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_dot1p_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP: + attrs["SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_DSCP_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_dscp_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE: + attrs["SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE"] = attr.value.booldata + attrs["switch_shell_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_SWITCH_PROFILE_ID: + attrs["SAI_SWITCH_ATTR_SWITCH_PROFILE_ID"] = attr.value.u32 + attrs["switch_profile_id"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO: + attrs["SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO"] = attr.value.s8list + attrs["switch_hardware_info"] = attr.value.s8list + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_PATH_NAME: + attrs["SAI_SWITCH_ATTR_FIRMWARE_PATH_NAME"] = attr.value.s8list + attrs["firmware_path_name"] = attr.value.s8list + + if attr.id == SAI_SWITCH_ATTR_INIT_SWITCH: + attrs["SAI_SWITCH_ATTR_INIT_SWITCH"] = attr.value.booldata + attrs["init_switch"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY: + attrs["SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY"] = attr.value.ptr + attrs["switch_state_change_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY: + attrs["SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY"] = attr.value.ptr + attrs["switch_shutdown_request_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY: + attrs["SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY"] = attr.value.ptr + attrs["fdb_event_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY: + attrs["SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY"] = attr.value.ptr + attrs["port_state_change_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY: + attrs["SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY"] = attr.value.ptr + attrs["packet_event_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_FAST_API_ENABLE: + attrs["SAI_SWITCH_ATTR_FAST_API_ENABLE"] = attr.value.booldata + attrs["fast_api_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_MIRROR_TC: + attrs["SAI_SWITCH_ATTR_MIRROR_TC"] = attr.value.u8 + attrs["mirror_tc"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_ACL_STAGE_INGRESS: + attrs["SAI_SWITCH_ATTR_ACL_STAGE_INGRESS"] = attr.value.aclcapability + attrs["acl_stage_ingress"] = attr.value.aclcapability + + if attr.id == SAI_SWITCH_ATTR_ACL_STAGE_EGRESS: + attrs["SAI_SWITCH_ATTR_ACL_STAGE_EGRESS"] = attr.value.aclcapability + attrs["acl_stage_egress"] = attr.value.aclcapability + + if attr.id == SAI_SWITCH_ATTR_SRV6_MAX_SID_DEPTH: + attrs["SAI_SWITCH_ATTR_SRV6_MAX_SID_DEPTH"] = attr.value.u32 + attrs["srv6_max_sid_depth"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SRV6_TLV_TYPE: + attrs["SAI_SWITCH_ATTR_SRV6_TLV_TYPE"] = attr.value.s32list + attrs["srv6_tlv_type"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_QOS_NUM_LOSSLESS_QUEUES: + attrs["SAI_SWITCH_ATTR_QOS_NUM_LOSSLESS_QUEUES"] = attr.value.u32 + attrs["qos_num_lossless_queues"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY: + attrs["SAI_SWITCH_ATTR_QUEUE_PFC_DEADLOCK_NOTIFY"] = attr.value.ptr + attrs["queue_pfc_deadlock_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_PFC_DLR_PACKET_ACTION: + attrs["SAI_SWITCH_ATTR_PFC_DLR_PACKET_ACTION"] = attr.value.s32 + attrs["pfc_dlr_packet_action"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL_RANGE: + attrs["SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL_RANGE"] = attr.value.u32range + attrs["pfc_tc_dld_interval_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL: + attrs["SAI_SWITCH_ATTR_PFC_TC_DLD_INTERVAL"] = attr.value.maplist + attrs["pfc_tc_dld_interval"] = attr.value.maplist + + if attr.id == SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL_RANGE: + attrs["SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL_RANGE"] = attr.value.u32range + attrs["pfc_tc_dlr_interval_range"] = attr.value.u32range + + if attr.id == SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL: + attrs["SAI_SWITCH_ATTR_PFC_TC_DLR_INTERVAL"] = attr.value.maplist + attrs["pfc_tc_dlr_interval"] = attr.value.maplist + + if attr.id == SAI_SWITCH_ATTR_SUPPORTED_PROTECTED_OBJECT_TYPE: + attrs["SAI_SWITCH_ATTR_SUPPORTED_PROTECTED_OBJECT_TYPE"] = attr.value.s32list + attrs["supported_protected_object_type"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_TPID_OUTER_VLAN: + attrs["SAI_SWITCH_ATTR_TPID_OUTER_VLAN"] = attr.value.u16 + attrs["tpid_outer_vlan"] = attr.value.u16 + + if attr.id == SAI_SWITCH_ATTR_TPID_INNER_VLAN: + attrs["SAI_SWITCH_ATTR_TPID_INNER_VLAN"] = attr.value.u16 + attrs["tpid_inner_vlan"] = attr.value.u16 + + if attr.id == SAI_SWITCH_ATTR_CRC_CHECK_ENABLE: + attrs["SAI_SWITCH_ATTR_CRC_CHECK_ENABLE"] = attr.value.booldata + attrs["crc_check_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_CRC_RECALCULATION_ENABLE: + attrs["SAI_SWITCH_ATTR_CRC_RECALCULATION_ENABLE"] = attr.value.booldata + attrs["crc_recalculation_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY: + attrs["SAI_SWITCH_ATTR_BFD_SESSION_STATE_CHANGE_NOTIFY"] = attr.value.ptr + attrs["bfd_session_state_change_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_BFD_SESSION: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_BFD_SESSION"] = attr.value.u32 + attrs["number_of_bfd_session"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MAX_BFD_SESSION: + attrs["SAI_SWITCH_ATTR_MAX_BFD_SESSION"] = attr.value.u32 + attrs["max_bfd_session"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SUPPORTED_IPV4_BFD_SESSION_OFFLOAD_TYPE: + attrs["SAI_SWITCH_ATTR_SUPPORTED_IPV4_BFD_SESSION_OFFLOAD_TYPE"] = attr.value.s32list + attrs["supported_ipv4_bfd_session_offload_type"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_SUPPORTED_IPV6_BFD_SESSION_OFFLOAD_TYPE: + attrs["SAI_SWITCH_ATTR_SUPPORTED_IPV6_BFD_SESSION_OFFLOAD_TYPE"] = attr.value.s32list + attrs["supported_ipv6_bfd_session_offload_type"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_MIN_BFD_RX: + attrs["SAI_SWITCH_ATTR_MIN_BFD_RX"] = attr.value.u32 + attrs["min_bfd_rx"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MIN_BFD_TX: + attrs["SAI_SWITCH_ATTR_MIN_BFD_TX"] = attr.value.u32 + attrs["min_bfd_tx"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ECN_ECT_THRESHOLD_ENABLE: + attrs["SAI_SWITCH_ATTR_ECN_ECT_THRESHOLD_ENABLE"] = attr.value.booldata + attrs["ecn_ect_threshold_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC: + attrs["SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC"] = attr.value.mac + attrs["vxlan_default_router_mac"] = attr.value.mac + + if attr.id == SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT: + attrs["SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT"] = attr.value.u16 + attrs["vxlan_default_port"] = attr.value.u16 + + if attr.id == SAI_SWITCH_ATTR_MAX_MIRROR_SESSION: + attrs["SAI_SWITCH_ATTR_MAX_MIRROR_SESSION"] = attr.value.u32 + attrs["max_mirror_session"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MAX_SAMPLED_MIRROR_SESSION: + attrs["SAI_SWITCH_ATTR_MAX_SAMPLED_MIRROR_SESSION"] = attr.value.u32 + attrs["max_sampled_mirror_session"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SUPPORTED_EXTENDED_STATS_MODE: + attrs["SAI_SWITCH_ATTR_SUPPORTED_EXTENDED_STATS_MODE"] = attr.value.s32list + attrs["supported_extended_stats_mode"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL: + attrs["SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL"] = attr.value.booldata + attrs["uninit_data_plane_on_removal"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_TAM_OBJECT_ID: + attrs["SAI_SWITCH_ATTR_TAM_OBJECT_ID"] = attr.value.objlist + attrs["tam_object_id"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_TAM_EVENT_NOTIFY: + attrs["SAI_SWITCH_ATTR_TAM_EVENT_NOTIFY"] = attr.value.ptr + attrs["tam_event_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_SUPPORTED_OBJECT_TYPE_LIST: + attrs["SAI_SWITCH_ATTR_SUPPORTED_OBJECT_TYPE_LIST"] = attr.value.s32list + attrs["supported_object_type_list"] = attr.value.s32list + + if attr.id == SAI_SWITCH_ATTR_PRE_SHUTDOWN: + attrs["SAI_SWITCH_ATTR_PRE_SHUTDOWN"] = attr.value.booldata + attrs["pre_shutdown"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_NAT_ZONE_COUNTER_OBJECT_ID: + attrs["SAI_SWITCH_ATTR_NAT_ZONE_COUNTER_OBJECT_ID"] = attr.value.oid + attrs["nat_zone_counter_object_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_NAT_ENABLE: + attrs["SAI_SWITCH_ATTR_NAT_ENABLE"] = attr.value.booldata + attrs["nat_enable"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_HARDWARE_ACCESS_BUS: + attrs["SAI_SWITCH_ATTR_HARDWARE_ACCESS_BUS"] = attr.value.s32 + attrs["hardware_access_bus"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_PLATFROM_CONTEXT: + attrs["SAI_SWITCH_ATTR_PLATFROM_CONTEXT"] = attr.value.u64 + attrs["platfrom_context"] = attr.value.u64 + + if attr.id == SAI_SWITCH_ATTR_REGISTER_READ: + attrs["SAI_SWITCH_ATTR_REGISTER_READ"] = attr.value.ptr + attrs["register_read"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_REGISTER_WRITE: + attrs["SAI_SWITCH_ATTR_REGISTER_WRITE"] = attr.value.ptr + attrs["register_write"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_BROADCAST: + attrs["SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_BROADCAST"] = attr.value.booldata + attrs["firmware_download_broadcast"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_LOAD_METHOD: + attrs["SAI_SWITCH_ATTR_FIRMWARE_LOAD_METHOD"] = attr.value.s32 + attrs["firmware_load_method"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_LOAD_TYPE: + attrs["SAI_SWITCH_ATTR_FIRMWARE_LOAD_TYPE"] = attr.value.s32 + attrs["firmware_load_type"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_EXECUTE: + attrs["SAI_SWITCH_ATTR_FIRMWARE_DOWNLOAD_EXECUTE"] = attr.value.booldata + attrs["firmware_download_execute"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_BROADCAST_STOP: + attrs["SAI_SWITCH_ATTR_FIRMWARE_BROADCAST_STOP"] = attr.value.booldata + attrs["firmware_broadcast_stop"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_VERIFY_AND_INIT_SWITCH: + attrs["SAI_SWITCH_ATTR_FIRMWARE_VERIFY_AND_INIT_SWITCH"] = attr.value.booldata + attrs["firmware_verify_and_init_switch"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_STATUS: + attrs["SAI_SWITCH_ATTR_FIRMWARE_STATUS"] = attr.value.booldata + attrs["firmware_status"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION: + attrs["SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION"] = attr.value.u32 + attrs["firmware_major_version"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FIRMWARE_MINOR_VERSION: + attrs["SAI_SWITCH_ATTR_FIRMWARE_MINOR_VERSION"] = attr.value.u32 + attrs["firmware_minor_version"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_PORT_CONNECTOR_LIST: + attrs["SAI_SWITCH_ATTR_PORT_CONNECTOR_LIST"] = attr.value.objlist + attrs["port_connector_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_PROPOGATE_PORT_STATE_FROM_LINE_TO_SYSTEM_PORT_SUPPORT: + attrs["SAI_SWITCH_ATTR_PROPOGATE_PORT_STATE_FROM_LINE_TO_SYSTEM_PORT_SUPPORT"] = attr.value.booldata + attrs["propogate_port_state_from_line_to_system_port_support"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_TYPE: + attrs["SAI_SWITCH_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST: + attrs["SAI_SWITCH_ATTR_MACSEC_OBJECT_LIST"] = attr.value.objlist + attrs["macsec_object_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_TC_MAP: + attrs["SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_TC_MAP"] = attr.value.oid + attrs["qos_mpls_exp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP: + attrs["SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_COLOR_MAP"] = attr.value.oid + attrs["qos_mpls_exp_to_color_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP: + attrs["SAI_SWITCH_ATTR_QOS_TC_AND_COLOR_TO_MPLS_EXP_MAP"] = attr.value.oid + attrs["qos_tc_and_color_to_mpls_exp_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_SWITCH_ID: + attrs["SAI_SWITCH_ATTR_SWITCH_ID"] = attr.value.u32 + attrs["switch_id"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MAX_SYSTEM_CORES: + attrs["SAI_SWITCH_ATTR_MAX_SYSTEM_CORES"] = attr.value.u32 + attrs["max_system_cores"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST: + attrs["SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST"] = attr.value.sysportconfiglist + attrs["system_port_config_list"] = attr.value.sysportconfiglist + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_SYSTEM_PORTS: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_SYSTEM_PORTS"] = attr.value.u32 + attrs["number_of_system_ports"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SYSTEM_PORT_LIST: + attrs["SAI_SWITCH_ATTR_SYSTEM_PORT_LIST"] = attr.value.objlist + attrs["system_port_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_NUMBER_OF_FABRIC_PORTS: + attrs["SAI_SWITCH_ATTR_NUMBER_OF_FABRIC_PORTS"] = attr.value.u32 + attrs["number_of_fabric_ports"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FABRIC_PORT_LIST: + attrs["SAI_SWITCH_ATTR_FABRIC_PORT_LIST"] = attr.value.objlist + attrs["fabric_port_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_PACKET_DMA_MEMORY_POOL_SIZE: + attrs["SAI_SWITCH_ATTR_PACKET_DMA_MEMORY_POOL_SIZE"] = attr.value.u32 + attrs["packet_dma_memory_pool_size"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_FAILOVER_CONFIG_MODE: + attrs["SAI_SWITCH_ATTR_FAILOVER_CONFIG_MODE"] = attr.value.s32 + attrs["failover_config_mode"] = attr.value.s32 + + if attr.id == SAI_SWITCH_ATTR_SUPPORTED_FAILOVER_MODE: + attrs["SAI_SWITCH_ATTR_SUPPORTED_FAILOVER_MODE"] = attr.value.booldata + attrs["supported_failover_mode"] = attr.value.booldata + + if attr.id == SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST: + attrs["SAI_SWITCH_ATTR_TUNNEL_OBJECTS_LIST"] = attr.value.objlist + attrs["tunnel_objects_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_PACKET_AVAILABLE_DMA_MEMORY_POOL_SIZE: + attrs["SAI_SWITCH_ATTR_PACKET_AVAILABLE_DMA_MEMORY_POOL_SIZE"] = attr.value.u32 + attrs["packet_available_dma_memory_pool_size"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_PRE_INGRESS_ACL: + attrs["SAI_SWITCH_ATTR_PRE_INGRESS_ACL"] = attr.value.oid + attrs["pre_ingress_acl"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_SNAPT_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_SNAPT_ENTRY"] = attr.value.u32 + attrs["available_snapt_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_DNAPT_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_DNAPT_ENTRY"] = attr.value.u32 + attrs["available_dnapt_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAPT_ENTRY: + attrs["SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAPT_ENTRY"] = attr.value.u32 + attrs["available_double_napt_entry"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_SLAVE_MDIO_ADDR_LIST: + attrs["SAI_SWITCH_ATTR_SLAVE_MDIO_ADDR_LIST"] = attr.value.u8list + attrs["slave_mdio_addr_list"] = attr.value.u8list + + if attr.id == SAI_SWITCH_ATTR_MY_MAC_TABLE_MINIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_MY_MAC_TABLE_MINIMUM_PRIORITY"] = attr.value.u32 + attrs["my_mac_table_minimum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MY_MAC_TABLE_MAXIMUM_PRIORITY: + attrs["SAI_SWITCH_ATTR_MY_MAC_TABLE_MAXIMUM_PRIORITY"] = attr.value.u32 + attrs["my_mac_table_maximum_priority"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MY_MAC_LIST: + attrs["SAI_SWITCH_ATTR_MY_MAC_LIST"] = attr.value.objlist + attrs["my_mac_list"] = attr.value.objlist + + if attr.id == SAI_SWITCH_ATTR_INSTALLED_MY_MAC_ENTRIES: + attrs["SAI_SWITCH_ATTR_INSTALLED_MY_MAC_ENTRIES"] = attr.value.u32 + attrs["installed_my_mac_entries"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_AVAILABLE_MY_MAC_ENTRIES: + attrs["SAI_SWITCH_ATTR_AVAILABLE_MY_MAC_ENTRIES"] = attr.value.u32 + attrs["available_my_mac_entries"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_MAX_NUMBER_OF_FORWARDING_CLASSES: + attrs["SAI_SWITCH_ATTR_MAX_NUMBER_OF_FORWARDING_CLASSES"] = attr.value.u8 + attrs["max_number_of_forwarding_classes"] = attr.value.u8 + + if attr.id == SAI_SWITCH_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP: + attrs["SAI_SWITCH_ATTR_QOS_DSCP_TO_FORWARDING_CLASS_MAP"] = attr.value.oid + attrs["qos_dscp_to_forwarding_class_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP: + attrs["SAI_SWITCH_ATTR_QOS_MPLS_EXP_TO_FORWARDING_CLASS_MAP"] = attr.value.oid + attrs["qos_mpls_exp_to_forwarding_class_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_IPSEC_OBJECT_ID: + attrs["SAI_SWITCH_ATTR_IPSEC_OBJECT_ID"] = attr.value.oid + attrs["ipsec_object_id"] = attr.value.oid + + if attr.id == SAI_SWITCH_ATTR_IPSEC_SA_TAG_TPID: + attrs["SAI_SWITCH_ATTR_IPSEC_SA_TAG_TPID"] = attr.value.u16 + attrs["ipsec_sa_tag_tpid"] = attr.value.u16 + + if attr.id == SAI_SWITCH_ATTR_IPSEC_SA_STATUS_CHANGE_NOTIFY: + attrs["SAI_SWITCH_ATTR_IPSEC_SA_STATUS_CHANGE_NOTIFY"] = attr.value.ptr + attrs["ipsec_sa_status_change_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY: + attrs["SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY"] = attr.value.ptr + attrs["nat_event_notify"] = attr.value.ptr + + if attr.id == SAI_SWITCH_ATTR_MAX_ECMP_MEMBER_COUNT: + attrs["SAI_SWITCH_ATTR_MAX_ECMP_MEMBER_COUNT"] = attr.value.u32 + attrs["max_ecmp_member_count"] = attr.value.u32 + + if attr.id == SAI_SWITCH_ATTR_ECMP_MEMBER_COUNT: + attrs["SAI_SWITCH_ATTR_ECMP_MEMBER_COUNT"] = attr.value.u32 + attrs["ecmp_member_count"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_switch_stats(client): + """ + sai_get_switch_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_FABRIC_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_ECC_DROP) + counter_ids.append(SAI_SWITCH_STAT_REACHABILITY_DROP) + counter_ids.append(SAI_SWITCH_STAT_HIGHEST_QUEUE_CONGESTION_LEVEL) + counter_ids.append(SAI_SWITCH_STAT_GLOBAL_DROP) + + counters = [0] * 23 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_switch_stats(counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE"] = counters[0] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[1] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[2] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[3] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[4] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[5] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[6] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[7] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[8] + stats["SAI_SWITCH_STAT_OUT_DROP_REASON_RANGE_BASE"] = counters[9] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[10] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[11] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[12] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[13] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[14] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[15] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[16] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[17] + stats["SAI_SWITCH_STAT_FABRIC_DROP_REASON_RANGE_BASE"] = counters[18] + stats["SAI_SWITCH_STAT_ECC_DROP"] = counters[19] + stats["SAI_SWITCH_STAT_REACHABILITY_DROP"] = counters[20] + stats["SAI_SWITCH_STAT_HIGHEST_QUEUE_CONGESTION_LEVEL"] = counters[21] + stats["SAI_SWITCH_STAT_GLOBAL_DROP"] = counters[22] + + return stats + + +def sai_thrift_get_switch_stats_ext(client, + mode): + """ + sai_get_switch_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_FABRIC_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_ECC_DROP) + counter_ids.append(SAI_SWITCH_STAT_REACHABILITY_DROP) + counter_ids.append(SAI_SWITCH_STAT_HIGHEST_QUEUE_CONGESTION_LEVEL) + counter_ids.append(SAI_SWITCH_STAT_GLOBAL_DROP) + + counters = [0] * 23 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_switch_stats_ext(counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE"] = counters[0] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[1] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[2] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[3] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[4] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[5] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[6] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[7] + stats["SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[8] + stats["SAI_SWITCH_STAT_OUT_DROP_REASON_RANGE_BASE"] = counters[9] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS"] = counters[10] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"] = counters[11] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS"] = counters[12] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS"] = counters[13] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS"] = counters[14] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS"] = counters[15] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS"] = counters[16] + stats["SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS"] = counters[17] + stats["SAI_SWITCH_STAT_FABRIC_DROP_REASON_RANGE_BASE"] = counters[18] + stats["SAI_SWITCH_STAT_ECC_DROP"] = counters[19] + stats["SAI_SWITCH_STAT_REACHABILITY_DROP"] = counters[20] + stats["SAI_SWITCH_STAT_HIGHEST_QUEUE_CONGESTION_LEVEL"] = counters[21] + stats["SAI_SWITCH_STAT_GLOBAL_DROP"] = counters[22] + + return stats + + +def sai_thrift_clear_switch_stats(client): + """ + sai_clear_switch_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_2_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_3_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_4_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_5_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_6_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_OUT_CONFIGURED_DROP_REASONS_7_DROPPED_PKTS) + counter_ids.append(SAI_SWITCH_STAT_FABRIC_DROP_REASON_RANGE_BASE) + counter_ids.append(SAI_SWITCH_STAT_ECC_DROP) + counter_ids.append(SAI_SWITCH_STAT_REACHABILITY_DROP) + counter_ids.append(SAI_SWITCH_STAT_HIGHEST_QUEUE_CONGESTION_LEVEL) + counter_ids.append(SAI_SWITCH_STAT_GLOBAL_DROP) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_switch_stats(counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_switch_tunnel(client, + tunnel_type=None, + loopback_packet_action=None, + tunnel_encap_ecn_mode=None, + encap_mappers=None, + tunnel_decap_ecn_mode=None, + decap_mappers=None, + tunnel_vxlan_udp_sport_mode=None, + vxlan_udp_sport=None, + vxlan_udp_sport_mask=None, + encap_qos_tc_and_color_to_dscp_map=None, + encap_qos_tc_to_queue_map=None, + decap_qos_dscp_to_tc_map=None, + decap_qos_tc_to_priority_group_map=None, + custom_attribute=None): + """ + sai_create_switch_tunnel() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of switch_tunnel CREATE attributes. + + Returns: + sai_thrift_object_id_t: switch_tunnel_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tunnel_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tunnel_type) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if loopback_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=loopback_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_encap_ecn_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tunnel_encap_ecn_mode) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_ENCAP_ECN_MODE, + value=attribute_value) + attr_list.append(attribute) + + if encap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=encap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_decap_ecn_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tunnel_decap_ecn_mode) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_DECAP_ECN_MODE, + value=attribute_value) + attr_list.append(attribute) + + if decap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=decap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_vxlan_udp_sport_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tunnel_vxlan_udp_sport_mode) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_udp_sport is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vxlan_udp_sport) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_udp_sport_mask is not None: + attribute_value = sai_thrift_attribute_value_t(u8=vxlan_udp_sport_mask) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK, + value=attribute_value) + attr_list.append(attribute) + + if encap_qos_tc_and_color_to_dscp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_and_color_to_dscp_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if encap_qos_tc_to_queue_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_to_queue_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP, + value=attribute_value) + attr_list.append(attribute) + + if decap_qos_dscp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=decap_qos_dscp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if decap_qos_tc_to_priority_group_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=decap_qos_tc_to_priority_group_map) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_switch_tunnel(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_switch_tunnel(client, + switch_tunnel_oid): + """ + sai_remove_switch_tunnel() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + switch_tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_switch_tunnel(switch_tunnel_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_switch_tunnel_attribute(client, + switch_tunnel_oid, + loopback_packet_action=None, + tunnel_vxlan_udp_sport_mode=None, + vxlan_udp_sport=None, + vxlan_udp_sport_mask=None, + encap_qos_tc_and_color_to_dscp_map=None, + encap_qos_tc_to_queue_map=None, + decap_qos_dscp_to_tc_map=None, + decap_qos_tc_to_priority_group_map=None, + custom_attribute=None): + """ + sai_set_switch_tunnel_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + switch_tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of switch_tunnel SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if loopback_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=loopback_packet_action) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if tunnel_vxlan_udp_sport_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=tunnel_vxlan_udp_sport_mode) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if vxlan_udp_sport is not None: + attr_value = sai_thrift_attribute_value_t(u16=vxlan_udp_sport) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if vxlan_udp_sport_mask is not None: + attr_value = sai_thrift_attribute_value_t(u8=vxlan_udp_sport_mask) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if encap_qos_tc_and_color_to_dscp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_and_color_to_dscp_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if encap_qos_tc_to_queue_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_to_queue_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if decap_qos_dscp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=decap_qos_dscp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if decap_qos_tc_to_priority_group_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=decap_qos_tc_to_priority_group_map) + attr = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP, + value=attr_value) + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_switch_tunnel_attribute(switch_tunnel_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_switch_tunnel_attribute(client, + switch_tunnel_oid, + tunnel_type=None, + loopback_packet_action=None, + tunnel_encap_ecn_mode=None, + encap_mappers=None, + tunnel_decap_ecn_mode=None, + decap_mappers=None, + tunnel_vxlan_udp_sport_mode=None, + vxlan_udp_sport=None, + vxlan_udp_sport_mask=None, + encap_qos_tc_and_color_to_dscp_map=None, + encap_qos_tc_to_queue_map=None, + decap_qos_dscp_to_tc_map=None, + decap_qos_tc_to_priority_group_map=None, + custom_attribute=None): + """ + sai_get_switch_tunnel_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + switch_tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of switch_tunnel GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tunnel_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE) + attr_list.append(attribute) + + if loopback_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION) + attr_list.append(attribute) + + if tunnel_encap_ecn_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_ENCAP_ECN_MODE) + attr_list.append(attribute) + + if encap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=encap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_decap_ecn_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_DECAP_ECN_MODE) + attr_list.append(attribute) + + if decap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=decap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_vxlan_udp_sport_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE) + attr_list.append(attribute) + + if vxlan_udp_sport is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT) + attr_list.append(attribute) + + if vxlan_udp_sport_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK) + attr_list.append(attribute) + + if encap_qos_tc_and_color_to_dscp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP) + attr_list.append(attribute) + + if encap_qos_tc_to_queue_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP) + attr_list.append(attribute) + + if decap_qos_dscp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP) + attr_list.append(attribute) + + if decap_qos_tc_to_priority_group_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_switch_tunnel_attribute(switch_tunnel_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE: + attrs["SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE"] = attr.value.s32 + attrs["tunnel_type"] = attr.value.s32 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION: + attrs["SAI_SWITCH_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION"] = attr.value.s32 + attrs["loopback_packet_action"] = attr.value.s32 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_TUNNEL_ENCAP_ECN_MODE: + attrs["SAI_SWITCH_TUNNEL_ATTR_TUNNEL_ENCAP_ECN_MODE"] = attr.value.s32 + attrs["tunnel_encap_ecn_mode"] = attr.value.s32 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_ENCAP_MAPPERS: + attrs["SAI_SWITCH_TUNNEL_ATTR_ENCAP_MAPPERS"] = attr.value.objlist + attrs["encap_mappers"] = attr.value.objlist + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_TUNNEL_DECAP_ECN_MODE: + attrs["SAI_SWITCH_TUNNEL_ATTR_TUNNEL_DECAP_ECN_MODE"] = attr.value.s32 + attrs["tunnel_decap_ecn_mode"] = attr.value.s32 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_DECAP_MAPPERS: + attrs["SAI_SWITCH_TUNNEL_ATTR_DECAP_MAPPERS"] = attr.value.objlist + attrs["decap_mappers"] = attr.value.objlist + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE: + attrs["SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE"] = attr.value.s32 + attrs["tunnel_vxlan_udp_sport_mode"] = attr.value.s32 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT: + attrs["SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT"] = attr.value.u16 + attrs["vxlan_udp_sport"] = attr.value.u16 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK: + attrs["SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK"] = attr.value.u8 + attrs["vxlan_udp_sport_mask"] = attr.value.u8 + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP: + attrs["SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP"] = attr.value.oid + attrs["encap_qos_tc_and_color_to_dscp_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP: + attrs["SAI_SWITCH_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP"] = attr.value.oid + attrs["encap_qos_tc_to_queue_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP: + attrs["SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP"] = attr.value.oid + attrs["decap_qos_dscp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP: + attrs["SAI_SWITCH_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP"] = attr.value.oid + attrs["decap_qos_tc_to_priority_group_map"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# system_port API + +def sai_thrift_create_system_port(client, + config_info=None, + admin_state=None, + qos_tc_to_queue_map=None, + custom_attribute=None): + """ + sai_create_system_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of system_port CREATE attributes. + + Returns: + sai_thrift_object_id_t: system_port_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if config_info is not None: + attribute_value = sai_thrift_attribute_value_t(sysportconfig=config_info) + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_CONFIG_INFO, + value=attribute_value) + attr_list.append(attribute) + + if admin_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_state) + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_ADMIN_STATE, + value=attribute_value) + attr_list.append(attribute) + + if qos_tc_to_queue_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=qos_tc_to_queue_map) + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_QOS_TC_TO_QUEUE_MAP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_system_port(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_system_port(client, + system_port_oid): + """ + sai_remove_system_port() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + system_port_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_system_port(system_port_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_system_port_attribute(client, + system_port_oid, + admin_state=None, + qos_tc_to_queue_map=None, + custom_attribute=None): + """ + sai_set_system_port_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + system_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of system_port SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if admin_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_state) + attr = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_ADMIN_STATE, + value=attr_value) + client.sai_thrift_set_system_port_attribute(system_port_oid, attr) + + if qos_tc_to_queue_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=qos_tc_to_queue_map) + attr = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_QOS_TC_TO_QUEUE_MAP, + value=attr_value) + client.sai_thrift_set_system_port_attribute(system_port_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_system_port_attribute(system_port_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_system_port_attribute(client, + system_port_oid, + type=None, + qos_number_of_voqs=None, + qos_voq_list=None, + port=None, + admin_state=None, + config_info=None, + qos_tc_to_queue_map=None, + custom_attribute=None): + """ + sai_get_system_port_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + system_port_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of system_port GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_TYPE) + attr_list.append(attribute) + + if qos_number_of_voqs is not None: + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS) + attr_list.append(attribute) + + if qos_voq_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=qos_voq_list) + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST, + value=attribute_value) + attr_list.append(attribute) + + if port is not None: + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_PORT) + attr_list.append(attribute) + + if admin_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_ADMIN_STATE) + attr_list.append(attribute) + + if config_info is not None: + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_CONFIG_INFO) + attr_list.append(attribute) + + if qos_tc_to_queue_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_SYSTEM_PORT_ATTR_QOS_TC_TO_QUEUE_MAP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_system_port_attribute(system_port_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_SYSTEM_PORT_ATTR_TYPE: + attrs["SAI_SYSTEM_PORT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS: + attrs["SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS"] = attr.value.u32 + attrs["qos_number_of_voqs"] = attr.value.u32 + + if attr.id == SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST: + attrs["SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST"] = attr.value.objlist + attrs["qos_voq_list"] = attr.value.objlist + + if attr.id == SAI_SYSTEM_PORT_ATTR_PORT: + attrs["SAI_SYSTEM_PORT_ATTR_PORT"] = attr.value.oid + attrs["port"] = attr.value.oid + + if attr.id == SAI_SYSTEM_PORT_ATTR_ADMIN_STATE: + attrs["SAI_SYSTEM_PORT_ATTR_ADMIN_STATE"] = attr.value.booldata + attrs["admin_state"] = attr.value.booldata + + if attr.id == SAI_SYSTEM_PORT_ATTR_CONFIG_INFO: + attrs["SAI_SYSTEM_PORT_ATTR_CONFIG_INFO"] = attr.value.sysportconfig + attrs["config_info"] = attr.value.sysportconfig + + if attr.id == SAI_SYSTEM_PORT_ATTR_QOS_TC_TO_QUEUE_MAP: + attrs["SAI_SYSTEM_PORT_ATTR_QOS_TC_TO_QUEUE_MAP"] = attr.value.oid + attrs["qos_tc_to_queue_map"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# tam API + +def sai_thrift_create_tam(client, + telemetry_objects_list=None, + event_objects_list=None, + int_objects_list=None, + tam_bind_point_type_list=None, + custom_attribute=None): + """ + sai_create_tam() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if telemetry_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=telemetry_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_TELEMETRY_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if event_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=event_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_EVENT_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if int_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=int_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_INT_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if tam_bind_point_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tam_bind_point_type_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_TAM_BIND_POINT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam(client, + tam_oid): + """ + sai_remove_tam() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam(tam_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_tam_attribute(client, + tam_oid, + telemetry_objects_list=None, + event_objects_list=None, + int_objects_list=None, + custom_attribute=None): + """ + sai_set_tam_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if telemetry_objects_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=telemetry_objects_list) + attr = sai_thrift_attribute_t(id=SAI_TAM_ATTR_TELEMETRY_OBJECTS_LIST, + value=attr_value) + client.sai_thrift_set_tam_attribute(tam_oid, attr) + + if event_objects_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=event_objects_list) + attr = sai_thrift_attribute_t(id=SAI_TAM_ATTR_EVENT_OBJECTS_LIST, + value=attr_value) + client.sai_thrift_set_tam_attribute(tam_oid, attr) + + if int_objects_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=int_objects_list) + attr = sai_thrift_attribute_t(id=SAI_TAM_ATTR_INT_OBJECTS_LIST, + value=attr_value) + client.sai_thrift_set_tam_attribute(tam_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_attribute(tam_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_attribute(client, + tam_oid, + telemetry_objects_list=None, + event_objects_list=None, + int_objects_list=None, + tam_bind_point_type_list=None, + custom_attribute=None): + """ + sai_get_tam_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if telemetry_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=telemetry_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_TELEMETRY_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if event_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=event_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_EVENT_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if int_objects_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=int_objects_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_INT_OBJECTS_LIST, + value=attribute_value) + attr_list.append(attribute) + + if tam_bind_point_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(s32list=tam_bind_point_type_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_ATTR_TAM_BIND_POINT_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_attribute(tam_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_ATTR_TELEMETRY_OBJECTS_LIST: + attrs["SAI_TAM_ATTR_TELEMETRY_OBJECTS_LIST"] = attr.value.objlist + attrs["telemetry_objects_list"] = attr.value.objlist + + if attr.id == SAI_TAM_ATTR_EVENT_OBJECTS_LIST: + attrs["SAI_TAM_ATTR_EVENT_OBJECTS_LIST"] = attr.value.objlist + attrs["event_objects_list"] = attr.value.objlist + + if attr.id == SAI_TAM_ATTR_INT_OBJECTS_LIST: + attrs["SAI_TAM_ATTR_INT_OBJECTS_LIST"] = attr.value.objlist + attrs["int_objects_list"] = attr.value.objlist + + if attr.id == SAI_TAM_ATTR_TAM_BIND_POINT_TYPE_LIST: + attrs["SAI_TAM_ATTR_TAM_BIND_POINT_TYPE_LIST"] = attr.value.s32list + attrs["tam_bind_point_type_list"] = attr.value.s32list + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_tam_math_func(client, + tam_tel_math_func_type=None, + custom_attribute=None): + """ + sai_create_tam_math_func() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_math_func CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_math_func_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tam_tel_math_func_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tam_tel_math_func_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_MATH_FUNC_ATTR_TAM_TEL_MATH_FUNC_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_math_func(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_math_func(client, + tam_math_func_oid): + """ + sai_remove_tam_math_func() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_math_func_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_math_func(tam_math_func_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_math_func_attribute(client, + tam_math_func_oid, + tam_tel_math_func_type=None, + custom_attribute=None): + """ + sai_get_tam_math_func_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_math_func_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_math_func GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tam_tel_math_func_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_MATH_FUNC_ATTR_TAM_TEL_MATH_FUNC_TYPE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_math_func_attribute(tam_math_func_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_MATH_FUNC_ATTR_TAM_TEL_MATH_FUNC_TYPE: + attrs["SAI_TAM_MATH_FUNC_ATTR_TAM_TEL_MATH_FUNC_TYPE"] = attr.value.s32 + attrs["tam_tel_math_func_type"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_math_func_attribute(client, + tam_math_func_oid, + tam_tel_math_func_type=None, + custom_attribute=None): + """ + sai_set_tam_math_func_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_math_func_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_math_func SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if tam_tel_math_func_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=tam_tel_math_func_type) + attr = sai_thrift_attribute_t(id=SAI_TAM_MATH_FUNC_ATTR_TAM_TEL_MATH_FUNC_TYPE, + value=attr_value) + client.sai_thrift_set_tam_math_func_attribute(tam_math_func_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_math_func_attribute(tam_math_func_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_event_threshold(client, + high_watermark=None, + low_watermark=None, + latency=None, + rate=None, + abs_value=None, + unit=None, + custom_attribute=None): + """ + sai_create_tam_event_threshold() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_event_threshold CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_event_threshold_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if high_watermark is not None: + attribute_value = sai_thrift_attribute_value_t(u32=high_watermark) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_HIGH_WATERMARK, + value=attribute_value) + attr_list.append(attribute) + + if low_watermark is not None: + attribute_value = sai_thrift_attribute_value_t(u32=low_watermark) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_LOW_WATERMARK, + value=attribute_value) + attr_list.append(attribute) + + if latency is not None: + attribute_value = sai_thrift_attribute_value_t(u32=latency) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_LATENCY, + value=attribute_value) + attr_list.append(attribute) + + if rate is not None: + attribute_value = sai_thrift_attribute_value_t(u32=rate) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_RATE, + value=attribute_value) + attr_list.append(attribute) + + if abs_value is not None: + attribute_value = sai_thrift_attribute_value_t(u32=abs_value) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_ABS_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if unit is not None: + attribute_value = sai_thrift_attribute_value_t(s32=unit) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_UNIT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_event_threshold(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_event_threshold(client, + tam_event_threshold_oid): + """ + sai_remove_tam_event_threshold() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_event_threshold_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_event_threshold(tam_event_threshold_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_event_threshold_attribute(client, + tam_event_threshold_oid, + high_watermark=None, + low_watermark=None, + latency=None, + rate=None, + abs_value=None, + unit=None, + custom_attribute=None): + """ + sai_get_tam_event_threshold_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_event_threshold_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_event_threshold GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if high_watermark is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_HIGH_WATERMARK) + attr_list.append(attribute) + + if low_watermark is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_LOW_WATERMARK) + attr_list.append(attribute) + + if latency is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_LATENCY) + attr_list.append(attribute) + + if rate is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_RATE) + attr_list.append(attribute) + + if abs_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_ABS_VALUE) + attr_list.append(attribute) + + if unit is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_UNIT) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_event_threshold_attribute(tam_event_threshold_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_EVENT_THRESHOLD_ATTR_HIGH_WATERMARK: + attrs["SAI_TAM_EVENT_THRESHOLD_ATTR_HIGH_WATERMARK"] = attr.value.u32 + attrs["high_watermark"] = attr.value.u32 + + if attr.id == SAI_TAM_EVENT_THRESHOLD_ATTR_LOW_WATERMARK: + attrs["SAI_TAM_EVENT_THRESHOLD_ATTR_LOW_WATERMARK"] = attr.value.u32 + attrs["low_watermark"] = attr.value.u32 + + if attr.id == SAI_TAM_EVENT_THRESHOLD_ATTR_LATENCY: + attrs["SAI_TAM_EVENT_THRESHOLD_ATTR_LATENCY"] = attr.value.u32 + attrs["latency"] = attr.value.u32 + + if attr.id == SAI_TAM_EVENT_THRESHOLD_ATTR_RATE: + attrs["SAI_TAM_EVENT_THRESHOLD_ATTR_RATE"] = attr.value.u32 + attrs["rate"] = attr.value.u32 + + if attr.id == SAI_TAM_EVENT_THRESHOLD_ATTR_ABS_VALUE: + attrs["SAI_TAM_EVENT_THRESHOLD_ATTR_ABS_VALUE"] = attr.value.u32 + attrs["abs_value"] = attr.value.u32 + + if attr.id == SAI_TAM_EVENT_THRESHOLD_ATTR_UNIT: + attrs["SAI_TAM_EVENT_THRESHOLD_ATTR_UNIT"] = attr.value.s32 + attrs["unit"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_event_threshold_attribute(client, + tam_event_threshold_oid, + high_watermark=None, + low_watermark=None, + latency=None, + rate=None, + abs_value=None, + unit=None, + custom_attribute=None): + """ + sai_set_tam_event_threshold_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_event_threshold_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_event_threshold SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if high_watermark is not None: + attr_value = sai_thrift_attribute_value_t(u32=high_watermark) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_HIGH_WATERMARK, + value=attr_value) + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + if low_watermark is not None: + attr_value = sai_thrift_attribute_value_t(u32=low_watermark) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_LOW_WATERMARK, + value=attr_value) + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + if latency is not None: + attr_value = sai_thrift_attribute_value_t(u32=latency) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_LATENCY, + value=attr_value) + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + if rate is not None: + attr_value = sai_thrift_attribute_value_t(u32=rate) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_RATE, + value=attr_value) + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + if abs_value is not None: + attr_value = sai_thrift_attribute_value_t(u32=abs_value) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_ABS_VALUE, + value=attr_value) + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + if unit is not None: + attr_value = sai_thrift_attribute_value_t(s32=unit) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_THRESHOLD_ATTR_UNIT, + value=attr_value) + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_event_threshold_attribute(tam_event_threshold_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_int(client, + type=None, + device_id=None, + int_presence_type=None, + int_presence_pb1=None, + int_presence_pb2=None, + int_presence_dscp_value=None, + inline=None, + int_presence_l3_protocol=None, + report_id=None, + ioam_trace_type=None, + trace_vector=None, + action_vector=None, + p4_int_instruction_bitmap=None, + metadata_fragment_enable=None, + metadata_checksum_enable=None, + report_all_packets=None, + flow_liveness_period=None, + latency_sensitivity=None, + acl_group=None, + max_hop_count=None, + max_length=None, + name_space_id=None, + name_space_id_global=None, + ingress_samplepacket_enable=None, + collector_list=None, + math_func=None, + custom_attribute=None): + """ + sai_create_tam_int() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_int CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_int_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if device_id is not None: + attribute_value = sai_thrift_attribute_value_t(u32=device_id) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_DEVICE_ID, + value=attribute_value) + attr_list.append(attribute) + + if int_presence_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=int_presence_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if int_presence_pb1 is not None: + attribute_value = sai_thrift_attribute_value_t(u32=int_presence_pb1) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_PB1, + value=attribute_value) + attr_list.append(attribute) + + if int_presence_pb2 is not None: + attribute_value = sai_thrift_attribute_value_t(u32=int_presence_pb2) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_PB2, + value=attribute_value) + attr_list.append(attribute) + + if int_presence_dscp_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=int_presence_dscp_value) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_DSCP_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if inline is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=inline) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INLINE, + value=attribute_value) + attr_list.append(attribute) + + if int_presence_l3_protocol is not None: + attribute_value = sai_thrift_attribute_value_t(u8=int_presence_l3_protocol) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_L3_PROTOCOL, + value=attribute_value) + attr_list.append(attribute) + + if report_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=report_id) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_REPORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if ioam_trace_type is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ioam_trace_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_IOAM_TRACE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if trace_vector is not None: + attribute_value = sai_thrift_attribute_value_t(u16=trace_vector) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_TRACE_VECTOR, + value=attribute_value) + attr_list.append(attribute) + + if action_vector is not None: + attribute_value = sai_thrift_attribute_value_t(u16=action_vector) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_ACTION_VECTOR, + value=attribute_value) + attr_list.append(attribute) + + if p4_int_instruction_bitmap is not None: + attribute_value = sai_thrift_attribute_value_t(u16=p4_int_instruction_bitmap) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_P4_INT_INSTRUCTION_BITMAP, + value=attribute_value) + attr_list.append(attribute) + + if metadata_fragment_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=metadata_fragment_enable) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_METADATA_FRAGMENT_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if metadata_checksum_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=metadata_checksum_enable) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_METADATA_CHECKSUM_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if report_all_packets is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=report_all_packets) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_REPORT_ALL_PACKETS, + value=attribute_value) + attr_list.append(attribute) + + if flow_liveness_period is not None: + attribute_value = sai_thrift_attribute_value_t(u16=flow_liveness_period) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_FLOW_LIVENESS_PERIOD, + value=attribute_value) + attr_list.append(attribute) + + if latency_sensitivity is not None: + attribute_value = sai_thrift_attribute_value_t(u8=latency_sensitivity) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_LATENCY_SENSITIVITY, + value=attribute_value) + attr_list.append(attribute) + + if acl_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=acl_group) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_ACL_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if max_hop_count is not None: + attribute_value = sai_thrift_attribute_value_t(u8=max_hop_count) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MAX_HOP_COUNT, + value=attribute_value) + attr_list.append(attribute) + + if max_length is not None: + attribute_value = sai_thrift_attribute_value_t(u8=max_length) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MAX_LENGTH, + value=attribute_value) + attr_list.append(attribute) + + if name_space_id is not None: + attribute_value = sai_thrift_attribute_value_t(u8=name_space_id) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_NAME_SPACE_ID, + value=attribute_value) + attr_list.append(attribute) + + if name_space_id_global is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=name_space_id_global) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_NAME_SPACE_ID_GLOBAL, + value=attribute_value) + attr_list.append(attribute) + + if ingress_samplepacket_enable is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_samplepacket_enable) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INGRESS_SAMPLEPACKET_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if collector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=collector_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_COLLECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if math_func is not None: + attribute_value = sai_thrift_attribute_value_t(oid=math_func) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MATH_FUNC, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_int(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_int(client, + tam_int_oid): + """ + sai_remove_tam_int() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_int_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_int(tam_int_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_int_attribute(client, + tam_int_oid, + type=None, + device_id=None, + ioam_trace_type=None, + int_presence_type=None, + int_presence_pb1=None, + int_presence_pb2=None, + int_presence_dscp_value=None, + inline=None, + int_presence_l3_protocol=None, + trace_vector=None, + action_vector=None, + p4_int_instruction_bitmap=None, + metadata_fragment_enable=None, + metadata_checksum_enable=None, + report_all_packets=None, + flow_liveness_period=None, + latency_sensitivity=None, + acl_group=None, + max_hop_count=None, + max_length=None, + name_space_id=None, + name_space_id_global=None, + ingress_samplepacket_enable=None, + collector_list=None, + math_func=None, + report_id=None, + custom_attribute=None): + """ + sai_get_tam_int_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_int_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_int GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_TYPE) + attr_list.append(attribute) + + if device_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_DEVICE_ID) + attr_list.append(attribute) + + if ioam_trace_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_IOAM_TRACE_TYPE) + attr_list.append(attribute) + + if int_presence_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_TYPE) + attr_list.append(attribute) + + if int_presence_pb1 is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_PB1) + attr_list.append(attribute) + + if int_presence_pb2 is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_PB2) + attr_list.append(attribute) + + if int_presence_dscp_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_DSCP_VALUE) + attr_list.append(attribute) + + if inline is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INLINE) + attr_list.append(attribute) + + if int_presence_l3_protocol is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INT_PRESENCE_L3_PROTOCOL) + attr_list.append(attribute) + + if trace_vector is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_TRACE_VECTOR) + attr_list.append(attribute) + + if action_vector is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_ACTION_VECTOR) + attr_list.append(attribute) + + if p4_int_instruction_bitmap is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_P4_INT_INSTRUCTION_BITMAP) + attr_list.append(attribute) + + if metadata_fragment_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_METADATA_FRAGMENT_ENABLE) + attr_list.append(attribute) + + if metadata_checksum_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_METADATA_CHECKSUM_ENABLE) + attr_list.append(attribute) + + if report_all_packets is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_REPORT_ALL_PACKETS) + attr_list.append(attribute) + + if flow_liveness_period is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_FLOW_LIVENESS_PERIOD) + attr_list.append(attribute) + + if latency_sensitivity is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_LATENCY_SENSITIVITY) + attr_list.append(attribute) + + if acl_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_ACL_GROUP) + attr_list.append(attribute) + + if max_hop_count is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MAX_HOP_COUNT) + attr_list.append(attribute) + + if max_length is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MAX_LENGTH) + attr_list.append(attribute) + + if name_space_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_NAME_SPACE_ID) + attr_list.append(attribute) + + if name_space_id_global is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_NAME_SPACE_ID_GLOBAL) + attr_list.append(attribute) + + if ingress_samplepacket_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INGRESS_SAMPLEPACKET_ENABLE) + attr_list.append(attribute) + + if collector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=collector_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_COLLECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if math_func is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MATH_FUNC) + attr_list.append(attribute) + + if report_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_REPORT_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_int_attribute(tam_int_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_INT_ATTR_TYPE: + attrs["SAI_TAM_INT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_TAM_INT_ATTR_DEVICE_ID: + attrs["SAI_TAM_INT_ATTR_DEVICE_ID"] = attr.value.u32 + attrs["device_id"] = attr.value.u32 + + if attr.id == SAI_TAM_INT_ATTR_IOAM_TRACE_TYPE: + attrs["SAI_TAM_INT_ATTR_IOAM_TRACE_TYPE"] = attr.value.u32 + attrs["ioam_trace_type"] = attr.value.u32 + + if attr.id == SAI_TAM_INT_ATTR_INT_PRESENCE_TYPE: + attrs["SAI_TAM_INT_ATTR_INT_PRESENCE_TYPE"] = attr.value.s32 + attrs["int_presence_type"] = attr.value.s32 + + if attr.id == SAI_TAM_INT_ATTR_INT_PRESENCE_PB1: + attrs["SAI_TAM_INT_ATTR_INT_PRESENCE_PB1"] = attr.value.u32 + attrs["int_presence_pb1"] = attr.value.u32 + + if attr.id == SAI_TAM_INT_ATTR_INT_PRESENCE_PB2: + attrs["SAI_TAM_INT_ATTR_INT_PRESENCE_PB2"] = attr.value.u32 + attrs["int_presence_pb2"] = attr.value.u32 + + if attr.id == SAI_TAM_INT_ATTR_INT_PRESENCE_DSCP_VALUE: + attrs["SAI_TAM_INT_ATTR_INT_PRESENCE_DSCP_VALUE"] = attr.value.u8 + attrs["int_presence_dscp_value"] = attr.value.u8 + + if attr.id == SAI_TAM_INT_ATTR_INLINE: + attrs["SAI_TAM_INT_ATTR_INLINE"] = attr.value.booldata + attrs["inline"] = attr.value.booldata + + if attr.id == SAI_TAM_INT_ATTR_INT_PRESENCE_L3_PROTOCOL: + attrs["SAI_TAM_INT_ATTR_INT_PRESENCE_L3_PROTOCOL"] = attr.value.u8 + attrs["int_presence_l3_protocol"] = attr.value.u8 + + if attr.id == SAI_TAM_INT_ATTR_TRACE_VECTOR: + attrs["SAI_TAM_INT_ATTR_TRACE_VECTOR"] = attr.value.u16 + attrs["trace_vector"] = attr.value.u16 + + if attr.id == SAI_TAM_INT_ATTR_ACTION_VECTOR: + attrs["SAI_TAM_INT_ATTR_ACTION_VECTOR"] = attr.value.u16 + attrs["action_vector"] = attr.value.u16 + + if attr.id == SAI_TAM_INT_ATTR_P4_INT_INSTRUCTION_BITMAP: + attrs["SAI_TAM_INT_ATTR_P4_INT_INSTRUCTION_BITMAP"] = attr.value.u16 + attrs["p4_int_instruction_bitmap"] = attr.value.u16 + + if attr.id == SAI_TAM_INT_ATTR_METADATA_FRAGMENT_ENABLE: + attrs["SAI_TAM_INT_ATTR_METADATA_FRAGMENT_ENABLE"] = attr.value.booldata + attrs["metadata_fragment_enable"] = attr.value.booldata + + if attr.id == SAI_TAM_INT_ATTR_METADATA_CHECKSUM_ENABLE: + attrs["SAI_TAM_INT_ATTR_METADATA_CHECKSUM_ENABLE"] = attr.value.booldata + attrs["metadata_checksum_enable"] = attr.value.booldata + + if attr.id == SAI_TAM_INT_ATTR_REPORT_ALL_PACKETS: + attrs["SAI_TAM_INT_ATTR_REPORT_ALL_PACKETS"] = attr.value.booldata + attrs["report_all_packets"] = attr.value.booldata + + if attr.id == SAI_TAM_INT_ATTR_FLOW_LIVENESS_PERIOD: + attrs["SAI_TAM_INT_ATTR_FLOW_LIVENESS_PERIOD"] = attr.value.u16 + attrs["flow_liveness_period"] = attr.value.u16 + + if attr.id == SAI_TAM_INT_ATTR_LATENCY_SENSITIVITY: + attrs["SAI_TAM_INT_ATTR_LATENCY_SENSITIVITY"] = attr.value.u8 + attrs["latency_sensitivity"] = attr.value.u8 + + if attr.id == SAI_TAM_INT_ATTR_ACL_GROUP: + attrs["SAI_TAM_INT_ATTR_ACL_GROUP"] = attr.value.oid + attrs["acl_group"] = attr.value.oid + + if attr.id == SAI_TAM_INT_ATTR_MAX_HOP_COUNT: + attrs["SAI_TAM_INT_ATTR_MAX_HOP_COUNT"] = attr.value.u8 + attrs["max_hop_count"] = attr.value.u8 + + if attr.id == SAI_TAM_INT_ATTR_MAX_LENGTH: + attrs["SAI_TAM_INT_ATTR_MAX_LENGTH"] = attr.value.u8 + attrs["max_length"] = attr.value.u8 + + if attr.id == SAI_TAM_INT_ATTR_NAME_SPACE_ID: + attrs["SAI_TAM_INT_ATTR_NAME_SPACE_ID"] = attr.value.u8 + attrs["name_space_id"] = attr.value.u8 + + if attr.id == SAI_TAM_INT_ATTR_NAME_SPACE_ID_GLOBAL: + attrs["SAI_TAM_INT_ATTR_NAME_SPACE_ID_GLOBAL"] = attr.value.booldata + attrs["name_space_id_global"] = attr.value.booldata + + if attr.id == SAI_TAM_INT_ATTR_INGRESS_SAMPLEPACKET_ENABLE: + attrs["SAI_TAM_INT_ATTR_INGRESS_SAMPLEPACKET_ENABLE"] = attr.value.oid + attrs["ingress_samplepacket_enable"] = attr.value.oid + + if attr.id == SAI_TAM_INT_ATTR_COLLECTOR_LIST: + attrs["SAI_TAM_INT_ATTR_COLLECTOR_LIST"] = attr.value.objlist + attrs["collector_list"] = attr.value.objlist + + if attr.id == SAI_TAM_INT_ATTR_MATH_FUNC: + attrs["SAI_TAM_INT_ATTR_MATH_FUNC"] = attr.value.oid + attrs["math_func"] = attr.value.oid + + if attr.id == SAI_TAM_INT_ATTR_REPORT_ID: + attrs["SAI_TAM_INT_ATTR_REPORT_ID"] = attr.value.oid + attrs["report_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_int_attribute(client, + tam_int_oid, + ioam_trace_type=None, + trace_vector=None, + action_vector=None, + p4_int_instruction_bitmap=None, + metadata_fragment_enable=None, + metadata_checksum_enable=None, + report_all_packets=None, + flow_liveness_period=None, + latency_sensitivity=None, + acl_group=None, + max_hop_count=None, + max_length=None, + name_space_id=None, + name_space_id_global=None, + ingress_samplepacket_enable=None, + collector_list=None, + math_func=None, + custom_attribute=None): + """ + sai_set_tam_int_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_int_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_int SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if ioam_trace_type is not None: + attr_value = sai_thrift_attribute_value_t(u32=ioam_trace_type) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_IOAM_TRACE_TYPE, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if trace_vector is not None: + attr_value = sai_thrift_attribute_value_t(u16=trace_vector) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_TRACE_VECTOR, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if action_vector is not None: + attr_value = sai_thrift_attribute_value_t(u16=action_vector) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_ACTION_VECTOR, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if p4_int_instruction_bitmap is not None: + attr_value = sai_thrift_attribute_value_t(u16=p4_int_instruction_bitmap) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_P4_INT_INSTRUCTION_BITMAP, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if metadata_fragment_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=metadata_fragment_enable) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_METADATA_FRAGMENT_ENABLE, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if metadata_checksum_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=metadata_checksum_enable) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_METADATA_CHECKSUM_ENABLE, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if report_all_packets is not None: + attr_value = sai_thrift_attribute_value_t(booldata=report_all_packets) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_REPORT_ALL_PACKETS, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if flow_liveness_period is not None: + attr_value = sai_thrift_attribute_value_t(u16=flow_liveness_period) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_FLOW_LIVENESS_PERIOD, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if latency_sensitivity is not None: + attr_value = sai_thrift_attribute_value_t(u8=latency_sensitivity) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_LATENCY_SENSITIVITY, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if acl_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=acl_group) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_ACL_GROUP, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if max_hop_count is not None: + attr_value = sai_thrift_attribute_value_t(u8=max_hop_count) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MAX_HOP_COUNT, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if max_length is not None: + attr_value = sai_thrift_attribute_value_t(u8=max_length) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MAX_LENGTH, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if name_space_id is not None: + attr_value = sai_thrift_attribute_value_t(u8=name_space_id) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_NAME_SPACE_ID, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if name_space_id_global is not None: + attr_value = sai_thrift_attribute_value_t(booldata=name_space_id_global) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_NAME_SPACE_ID_GLOBAL, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if ingress_samplepacket_enable is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_samplepacket_enable) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_INGRESS_SAMPLEPACKET_ENABLE, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if collector_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=collector_list) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_COLLECTOR_LIST, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if math_func is not None: + attr_value = sai_thrift_attribute_value_t(oid=math_func) + attr = sai_thrift_attribute_t(id=SAI_TAM_INT_ATTR_MATH_FUNC, + value=attr_value) + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_int_attribute(tam_int_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_tel_type(client, + tam_telemetry_type=None, + report_id=None, + int_switch_identifier=None, + switch_enable_port_stats=None, + switch_enable_port_stats_ingress=None, + switch_enable_port_stats_egress=None, + switch_enable_virtual_queue_stats=None, + switch_enable_output_queue_stats=None, + switch_enable_mmu_stats=None, + switch_enable_fabric_stats=None, + switch_enable_filter_stats=None, + switch_enable_resource_utilization_stats=None, + fabric_q=None, + ne_enable=None, + dscp_value=None, + math_func=None, + custom_attribute=None): + """ + sai_create_tam_tel_type() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_tel_type CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_tel_type_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tam_telemetry_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tam_telemetry_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_TAM_TELEMETRY_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if report_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=report_id) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_REPORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if int_switch_identifier is not None: + attribute_value = sai_thrift_attribute_value_t(u32=int_switch_identifier) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_INT_SWITCH_IDENTIFIER, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_port_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_port_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_port_stats_ingress is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_port_stats_ingress) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_INGRESS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_port_stats_egress is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_port_stats_egress) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_EGRESS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_virtual_queue_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_virtual_queue_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_VIRTUAL_QUEUE_STATS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_output_queue_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_output_queue_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_OUTPUT_QUEUE_STATS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_mmu_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_mmu_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_MMU_STATS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_fabric_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_fabric_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FABRIC_STATS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_filter_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_filter_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FILTER_STATS, + value=attribute_value) + attr_list.append(attribute) + + if switch_enable_resource_utilization_stats is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=switch_enable_resource_utilization_stats) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_RESOURCE_UTILIZATION_STATS, + value=attribute_value) + attr_list.append(attribute) + + if fabric_q is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=fabric_q) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_FABRIC_Q, + value=attribute_value) + attr_list.append(attribute) + + if ne_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ne_enable) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_NE_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if dscp_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=dscp_value) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_DSCP_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if math_func is not None: + attribute_value = sai_thrift_attribute_value_t(oid=math_func) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_MATH_FUNC, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_tel_type(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_tel_type(client, + tam_tel_type_oid): + """ + sai_remove_tam_tel_type() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_tel_type_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_tel_type(tam_tel_type_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_tel_type_attribute(client, + tam_tel_type_oid, + tam_telemetry_type=None, + int_switch_identifier=None, + switch_enable_port_stats=None, + switch_enable_port_stats_ingress=None, + switch_enable_port_stats_egress=None, + switch_enable_virtual_queue_stats=None, + switch_enable_output_queue_stats=None, + switch_enable_mmu_stats=None, + switch_enable_fabric_stats=None, + switch_enable_filter_stats=None, + switch_enable_resource_utilization_stats=None, + fabric_q=None, + ne_enable=None, + dscp_value=None, + math_func=None, + report_id=None, + custom_attribute=None): + """ + sai_get_tam_tel_type_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_tel_type_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_tel_type GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tam_telemetry_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_TAM_TELEMETRY_TYPE) + attr_list.append(attribute) + + if int_switch_identifier is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_INT_SWITCH_IDENTIFIER) + attr_list.append(attribute) + + if switch_enable_port_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS) + attr_list.append(attribute) + + if switch_enable_port_stats_ingress is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_INGRESS) + attr_list.append(attribute) + + if switch_enable_port_stats_egress is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_EGRESS) + attr_list.append(attribute) + + if switch_enable_virtual_queue_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_VIRTUAL_QUEUE_STATS) + attr_list.append(attribute) + + if switch_enable_output_queue_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_OUTPUT_QUEUE_STATS) + attr_list.append(attribute) + + if switch_enable_mmu_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_MMU_STATS) + attr_list.append(attribute) + + if switch_enable_fabric_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FABRIC_STATS) + attr_list.append(attribute) + + if switch_enable_filter_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FILTER_STATS) + attr_list.append(attribute) + + if switch_enable_resource_utilization_stats is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_RESOURCE_UTILIZATION_STATS) + attr_list.append(attribute) + + if fabric_q is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_FABRIC_Q) + attr_list.append(attribute) + + if ne_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_NE_ENABLE) + attr_list.append(attribute) + + if dscp_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_DSCP_VALUE) + attr_list.append(attribute) + + if math_func is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_MATH_FUNC) + attr_list.append(attribute) + + if report_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_REPORT_ID) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_tel_type_attribute(tam_tel_type_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_TEL_TYPE_ATTR_TAM_TELEMETRY_TYPE: + attrs["SAI_TAM_TEL_TYPE_ATTR_TAM_TELEMETRY_TYPE"] = attr.value.s32 + attrs["tam_telemetry_type"] = attr.value.s32 + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_INT_SWITCH_IDENTIFIER: + attrs["SAI_TAM_TEL_TYPE_ATTR_INT_SWITCH_IDENTIFIER"] = attr.value.u32 + attrs["int_switch_identifier"] = attr.value.u32 + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS"] = attr.value.booldata + attrs["switch_enable_port_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_INGRESS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_INGRESS"] = attr.value.booldata + attrs["switch_enable_port_stats_ingress"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_EGRESS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_EGRESS"] = attr.value.booldata + attrs["switch_enable_port_stats_egress"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_VIRTUAL_QUEUE_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_VIRTUAL_QUEUE_STATS"] = attr.value.booldata + attrs["switch_enable_virtual_queue_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_OUTPUT_QUEUE_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_OUTPUT_QUEUE_STATS"] = attr.value.booldata + attrs["switch_enable_output_queue_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_MMU_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_MMU_STATS"] = attr.value.booldata + attrs["switch_enable_mmu_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FABRIC_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FABRIC_STATS"] = attr.value.booldata + attrs["switch_enable_fabric_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FILTER_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FILTER_STATS"] = attr.value.booldata + attrs["switch_enable_filter_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_RESOURCE_UTILIZATION_STATS: + attrs["SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_RESOURCE_UTILIZATION_STATS"] = attr.value.booldata + attrs["switch_enable_resource_utilization_stats"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_FABRIC_Q: + attrs["SAI_TAM_TEL_TYPE_ATTR_FABRIC_Q"] = attr.value.booldata + attrs["fabric_q"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_NE_ENABLE: + attrs["SAI_TAM_TEL_TYPE_ATTR_NE_ENABLE"] = attr.value.booldata + attrs["ne_enable"] = attr.value.booldata + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_DSCP_VALUE: + attrs["SAI_TAM_TEL_TYPE_ATTR_DSCP_VALUE"] = attr.value.u8 + attrs["dscp_value"] = attr.value.u8 + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_MATH_FUNC: + attrs["SAI_TAM_TEL_TYPE_ATTR_MATH_FUNC"] = attr.value.oid + attrs["math_func"] = attr.value.oid + + if attr.id == SAI_TAM_TEL_TYPE_ATTR_REPORT_ID: + attrs["SAI_TAM_TEL_TYPE_ATTR_REPORT_ID"] = attr.value.oid + attrs["report_id"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_tel_type_attribute(client, + tam_tel_type_oid, + int_switch_identifier=None, + switch_enable_port_stats=None, + switch_enable_port_stats_ingress=None, + switch_enable_port_stats_egress=None, + switch_enable_virtual_queue_stats=None, + switch_enable_output_queue_stats=None, + switch_enable_mmu_stats=None, + switch_enable_fabric_stats=None, + switch_enable_filter_stats=None, + switch_enable_resource_utilization_stats=None, + fabric_q=None, + ne_enable=None, + dscp_value=None, + math_func=None, + custom_attribute=None): + """ + sai_set_tam_tel_type_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_tel_type_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_tel_type SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if int_switch_identifier is not None: + attr_value = sai_thrift_attribute_value_t(u32=int_switch_identifier) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_INT_SWITCH_IDENTIFIER, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_port_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_port_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_port_stats_ingress is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_port_stats_ingress) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_INGRESS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_port_stats_egress is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_port_stats_egress) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_PORT_STATS_EGRESS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_virtual_queue_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_virtual_queue_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_VIRTUAL_QUEUE_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_output_queue_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_output_queue_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_OUTPUT_QUEUE_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_mmu_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_mmu_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_MMU_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_fabric_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_fabric_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FABRIC_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_filter_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_filter_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_FILTER_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if switch_enable_resource_utilization_stats is not None: + attr_value = sai_thrift_attribute_value_t(booldata=switch_enable_resource_utilization_stats) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_SWITCH_ENABLE_RESOURCE_UTILIZATION_STATS, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if fabric_q is not None: + attr_value = sai_thrift_attribute_value_t(booldata=fabric_q) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_FABRIC_Q, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if ne_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ne_enable) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_NE_ENABLE, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if dscp_value is not None: + attr_value = sai_thrift_attribute_value_t(u8=dscp_value) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_DSCP_VALUE, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if math_func is not None: + attr_value = sai_thrift_attribute_value_t(oid=math_func) + attr = sai_thrift_attribute_t(id=SAI_TAM_TEL_TYPE_ATTR_MATH_FUNC, + value=attr_value) + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_tel_type_attribute(tam_tel_type_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_report(client, + type=None, + histogram_number_of_bins=None, + histogram_bin_boundary=None, + quota=None, + report_mode=None, + report_interval=None, + enterprise_number=None, + custom_attribute=None): + """ + sai_create_tam_report() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_report CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_report_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if histogram_number_of_bins is not None: + attribute_value = sai_thrift_attribute_value_t(u32=histogram_number_of_bins) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_HISTOGRAM_NUMBER_OF_BINS, + value=attribute_value) + attr_list.append(attribute) + + if histogram_bin_boundary is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=histogram_bin_boundary) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_HISTOGRAM_BIN_BOUNDARY, + value=attribute_value) + attr_list.append(attribute) + + if quota is not None: + attribute_value = sai_thrift_attribute_value_t(u32=quota) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_QUOTA, + value=attribute_value) + attr_list.append(attribute) + + if report_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=report_mode) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_REPORT_MODE, + value=attribute_value) + attr_list.append(attribute) + + if report_interval is not None: + attribute_value = sai_thrift_attribute_value_t(u32=report_interval) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_REPORT_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if enterprise_number is not None: + attribute_value = sai_thrift_attribute_value_t(u32=enterprise_number) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_ENTERPRISE_NUMBER, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_report(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_report(client, + tam_report_oid): + """ + sai_remove_tam_report() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_report_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_report(tam_report_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_report_attribute(client, + tam_report_oid, + type=None, + histogram_number_of_bins=None, + histogram_bin_boundary=None, + quota=None, + report_mode=None, + report_interval=None, + enterprise_number=None, + custom_attribute=None): + """ + sai_get_tam_report_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_report_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_report GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_TYPE) + attr_list.append(attribute) + + if histogram_number_of_bins is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_HISTOGRAM_NUMBER_OF_BINS) + attr_list.append(attribute) + + if histogram_bin_boundary is not None: + attribute_value = sai_thrift_attribute_value_t(u32list=histogram_bin_boundary) + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_HISTOGRAM_BIN_BOUNDARY, + value=attribute_value) + attr_list.append(attribute) + + if quota is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_QUOTA) + attr_list.append(attribute) + + if report_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_REPORT_MODE) + attr_list.append(attribute) + + if report_interval is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_REPORT_INTERVAL) + attr_list.append(attribute) + + if enterprise_number is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_ENTERPRISE_NUMBER) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_report_attribute(tam_report_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_REPORT_ATTR_TYPE: + attrs["SAI_TAM_REPORT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_TAM_REPORT_ATTR_HISTOGRAM_NUMBER_OF_BINS: + attrs["SAI_TAM_REPORT_ATTR_HISTOGRAM_NUMBER_OF_BINS"] = attr.value.u32 + attrs["histogram_number_of_bins"] = attr.value.u32 + + if attr.id == SAI_TAM_REPORT_ATTR_HISTOGRAM_BIN_BOUNDARY: + attrs["SAI_TAM_REPORT_ATTR_HISTOGRAM_BIN_BOUNDARY"] = attr.value.u32list + attrs["histogram_bin_boundary"] = attr.value.u32list + + if attr.id == SAI_TAM_REPORT_ATTR_QUOTA: + attrs["SAI_TAM_REPORT_ATTR_QUOTA"] = attr.value.u32 + attrs["quota"] = attr.value.u32 + + if attr.id == SAI_TAM_REPORT_ATTR_REPORT_MODE: + attrs["SAI_TAM_REPORT_ATTR_REPORT_MODE"] = attr.value.s32 + attrs["report_mode"] = attr.value.s32 + + if attr.id == SAI_TAM_REPORT_ATTR_REPORT_INTERVAL: + attrs["SAI_TAM_REPORT_ATTR_REPORT_INTERVAL"] = attr.value.u32 + attrs["report_interval"] = attr.value.u32 + + if attr.id == SAI_TAM_REPORT_ATTR_ENTERPRISE_NUMBER: + attrs["SAI_TAM_REPORT_ATTR_ENTERPRISE_NUMBER"] = attr.value.u32 + attrs["enterprise_number"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_report_attribute(client, + tam_report_oid, + type=None, + quota=None, + report_interval=None, + enterprise_number=None, + custom_attribute=None): + """ + sai_set_tam_report_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_report_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_report SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if type is not None: + attr_value = sai_thrift_attribute_value_t(s32=type) + attr = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_TYPE, + value=attr_value) + client.sai_thrift_set_tam_report_attribute(tam_report_oid, attr) + + if quota is not None: + attr_value = sai_thrift_attribute_value_t(u32=quota) + attr = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_QUOTA, + value=attr_value) + client.sai_thrift_set_tam_report_attribute(tam_report_oid, attr) + + if report_interval is not None: + attr_value = sai_thrift_attribute_value_t(u32=report_interval) + attr = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_REPORT_INTERVAL, + value=attr_value) + client.sai_thrift_set_tam_report_attribute(tam_report_oid, attr) + + if enterprise_number is not None: + attr_value = sai_thrift_attribute_value_t(u32=enterprise_number) + attr = sai_thrift_attribute_t(id=SAI_TAM_REPORT_ATTR_ENTERPRISE_NUMBER, + value=attr_value) + client.sai_thrift_set_tam_report_attribute(tam_report_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_report_attribute(tam_report_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_telemetry(client, + collector_list=None, + tam_type_list=None, + tam_reporting_unit=None, + reporting_interval=None, + custom_attribute=None): + """ + sai_create_tam_telemetry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_telemetry CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_telemetry_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if collector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=collector_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_COLLECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if tam_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_type_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_TAM_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if tam_reporting_unit is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tam_reporting_unit) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_TAM_REPORTING_UNIT, + value=attribute_value) + attr_list.append(attribute) + + if reporting_interval is not None: + attribute_value = sai_thrift_attribute_value_t(u32=reporting_interval) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_REPORTING_INTERVAL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_telemetry(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_telemetry(client, + tam_telemetry_oid): + """ + sai_remove_tam_telemetry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_telemetry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_telemetry(tam_telemetry_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_telemetry_attribute(client, + tam_telemetry_oid, + tam_type_list=None, + collector_list=None, + tam_reporting_unit=None, + reporting_interval=None, + custom_attribute=None): + """ + sai_get_tam_telemetry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_telemetry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_telemetry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tam_type_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_type_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_TAM_TYPE_LIST, + value=attribute_value) + attr_list.append(attribute) + + if collector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=collector_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_COLLECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if tam_reporting_unit is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_TAM_REPORTING_UNIT) + attr_list.append(attribute) + + if reporting_interval is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_REPORTING_INTERVAL) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_telemetry_attribute(tam_telemetry_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_TELEMETRY_ATTR_TAM_TYPE_LIST: + attrs["SAI_TAM_TELEMETRY_ATTR_TAM_TYPE_LIST"] = attr.value.objlist + attrs["tam_type_list"] = attr.value.objlist + + if attr.id == SAI_TAM_TELEMETRY_ATTR_COLLECTOR_LIST: + attrs["SAI_TAM_TELEMETRY_ATTR_COLLECTOR_LIST"] = attr.value.objlist + attrs["collector_list"] = attr.value.objlist + + if attr.id == SAI_TAM_TELEMETRY_ATTR_TAM_REPORTING_UNIT: + attrs["SAI_TAM_TELEMETRY_ATTR_TAM_REPORTING_UNIT"] = attr.value.s32 + attrs["tam_reporting_unit"] = attr.value.s32 + + if attr.id == SAI_TAM_TELEMETRY_ATTR_REPORTING_INTERVAL: + attrs["SAI_TAM_TELEMETRY_ATTR_REPORTING_INTERVAL"] = attr.value.u32 + attrs["reporting_interval"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_telemetry_attribute(client, + tam_telemetry_oid, + tam_type_list=None, + tam_reporting_unit=None, + reporting_interval=None, + custom_attribute=None): + """ + sai_set_tam_telemetry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_telemetry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_telemetry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if tam_type_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam_type_list) + attr = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_TAM_TYPE_LIST, + value=attr_value) + client.sai_thrift_set_tam_telemetry_attribute(tam_telemetry_oid, attr) + + if tam_reporting_unit is not None: + attr_value = sai_thrift_attribute_value_t(s32=tam_reporting_unit) + attr = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_TAM_REPORTING_UNIT, + value=attr_value) + client.sai_thrift_set_tam_telemetry_attribute(tam_telemetry_oid, attr) + + if reporting_interval is not None: + attr_value = sai_thrift_attribute_value_t(u32=reporting_interval) + attr = sai_thrift_attribute_t(id=SAI_TAM_TELEMETRY_ATTR_REPORTING_INTERVAL, + value=attr_value) + client.sai_thrift_set_tam_telemetry_attribute(tam_telemetry_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_telemetry_attribute(tam_telemetry_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_transport(client, + transport_type=None, + src_port=None, + dst_port=None, + transport_auth_type=None, + mtu=None, + custom_attribute=None): + """ + sai_create_tam_transport() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_transport CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_transport_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if transport_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=transport_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_TRANSPORT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if src_port is not None: + attribute_value = sai_thrift_attribute_value_t(u32=src_port) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_SRC_PORT, + value=attribute_value) + attr_list.append(attribute) + + if dst_port is not None: + attribute_value = sai_thrift_attribute_value_t(u32=dst_port) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_DST_PORT, + value=attribute_value) + attr_list.append(attribute) + + if transport_auth_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=transport_auth_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_TRANSPORT_AUTH_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if mtu is not None: + attribute_value = sai_thrift_attribute_value_t(u32=mtu) + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_MTU, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_transport(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_transport(client, + tam_transport_oid): + """ + sai_remove_tam_transport() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_transport_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_transport(tam_transport_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_transport_attribute(client, + tam_transport_oid, + transport_type=None, + src_port=None, + dst_port=None, + transport_auth_type=None, + mtu=None, + custom_attribute=None): + """ + sai_get_tam_transport_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_transport_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_transport GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if transport_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_TRANSPORT_TYPE) + attr_list.append(attribute) + + if src_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_SRC_PORT) + attr_list.append(attribute) + + if dst_port is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_DST_PORT) + attr_list.append(attribute) + + if transport_auth_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_TRANSPORT_AUTH_TYPE) + attr_list.append(attribute) + + if mtu is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_MTU) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_transport_attribute(tam_transport_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_TRANSPORT_ATTR_TRANSPORT_TYPE: + attrs["SAI_TAM_TRANSPORT_ATTR_TRANSPORT_TYPE"] = attr.value.s32 + attrs["transport_type"] = attr.value.s32 + + if attr.id == SAI_TAM_TRANSPORT_ATTR_SRC_PORT: + attrs["SAI_TAM_TRANSPORT_ATTR_SRC_PORT"] = attr.value.u32 + attrs["src_port"] = attr.value.u32 + + if attr.id == SAI_TAM_TRANSPORT_ATTR_DST_PORT: + attrs["SAI_TAM_TRANSPORT_ATTR_DST_PORT"] = attr.value.u32 + attrs["dst_port"] = attr.value.u32 + + if attr.id == SAI_TAM_TRANSPORT_ATTR_TRANSPORT_AUTH_TYPE: + attrs["SAI_TAM_TRANSPORT_ATTR_TRANSPORT_AUTH_TYPE"] = attr.value.s32 + attrs["transport_auth_type"] = attr.value.s32 + + if attr.id == SAI_TAM_TRANSPORT_ATTR_MTU: + attrs["SAI_TAM_TRANSPORT_ATTR_MTU"] = attr.value.u32 + attrs["mtu"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_transport_attribute(client, + tam_transport_oid, + src_port=None, + dst_port=None, + transport_auth_type=None, + mtu=None, + custom_attribute=None): + """ + sai_set_tam_transport_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_transport_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_transport SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if src_port is not None: + attr_value = sai_thrift_attribute_value_t(u32=src_port) + attr = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_SRC_PORT, + value=attr_value) + client.sai_thrift_set_tam_transport_attribute(tam_transport_oid, attr) + + if dst_port is not None: + attr_value = sai_thrift_attribute_value_t(u32=dst_port) + attr = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_DST_PORT, + value=attr_value) + client.sai_thrift_set_tam_transport_attribute(tam_transport_oid, attr) + + if transport_auth_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=transport_auth_type) + attr = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_TRANSPORT_AUTH_TYPE, + value=attr_value) + client.sai_thrift_set_tam_transport_attribute(tam_transport_oid, attr) + + if mtu is not None: + attr_value = sai_thrift_attribute_value_t(u32=mtu) + attr = sai_thrift_attribute_t(id=SAI_TAM_TRANSPORT_ATTR_MTU, + value=attr_value) + client.sai_thrift_set_tam_transport_attribute(tam_transport_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_transport_attribute(tam_transport_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_collector(client, + src_ip=None, + dst_ip=None, + transport=None, + dscp_value=None, + localhost=None, + virtual_router_id=None, + truncate_size=None, + custom_attribute=None): + """ + sai_create_tam_collector() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_collector CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_collector_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=src_ip) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if transport is not None: + attribute_value = sai_thrift_attribute_value_t(oid=transport) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_TRANSPORT, + value=attribute_value) + attr_list.append(attribute) + + if dscp_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=dscp_value) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_DSCP_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if localhost is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=localhost) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_LOCALHOST, + value=attribute_value) + attr_list.append(attribute) + + if virtual_router_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=virtual_router_id) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_VIRTUAL_ROUTER_ID, + value=attribute_value) + attr_list.append(attribute) + + if truncate_size is not None: + attribute_value = sai_thrift_attribute_value_t(u16=truncate_size) + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_TRUNCATE_SIZE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_collector(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_collector(client, + tam_collector_oid): + """ + sai_remove_tam_collector() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_collector_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_collector(tam_collector_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_collector_attribute(client, + tam_collector_oid, + src_ip=None, + dst_ip=None, + localhost=None, + virtual_router_id=None, + truncate_size=None, + transport=None, + dscp_value=None, + custom_attribute=None): + """ + sai_get_tam_collector_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_collector_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_collector GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_SRC_IP) + attr_list.append(attribute) + + if dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_DST_IP) + attr_list.append(attribute) + + if localhost is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_LOCALHOST) + attr_list.append(attribute) + + if virtual_router_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_VIRTUAL_ROUTER_ID) + attr_list.append(attribute) + + if truncate_size is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_TRUNCATE_SIZE) + attr_list.append(attribute) + + if transport is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_TRANSPORT) + attr_list.append(attribute) + + if dscp_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_DSCP_VALUE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_collector_attribute(tam_collector_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_COLLECTOR_ATTR_SRC_IP: + attrs["SAI_TAM_COLLECTOR_ATTR_SRC_IP"] = attr.value.ipaddr + attrs["src_ip"] = attr.value.ipaddr + + if attr.id == SAI_TAM_COLLECTOR_ATTR_DST_IP: + attrs["SAI_TAM_COLLECTOR_ATTR_DST_IP"] = attr.value.ipaddr + attrs["dst_ip"] = attr.value.ipaddr + + if attr.id == SAI_TAM_COLLECTOR_ATTR_LOCALHOST: + attrs["SAI_TAM_COLLECTOR_ATTR_LOCALHOST"] = attr.value.booldata + attrs["localhost"] = attr.value.booldata + + if attr.id == SAI_TAM_COLLECTOR_ATTR_VIRTUAL_ROUTER_ID: + attrs["SAI_TAM_COLLECTOR_ATTR_VIRTUAL_ROUTER_ID"] = attr.value.oid + attrs["virtual_router_id"] = attr.value.oid + + if attr.id == SAI_TAM_COLLECTOR_ATTR_TRUNCATE_SIZE: + attrs["SAI_TAM_COLLECTOR_ATTR_TRUNCATE_SIZE"] = attr.value.u16 + attrs["truncate_size"] = attr.value.u16 + + if attr.id == SAI_TAM_COLLECTOR_ATTR_TRANSPORT: + attrs["SAI_TAM_COLLECTOR_ATTR_TRANSPORT"] = attr.value.oid + attrs["transport"] = attr.value.oid + + if attr.id == SAI_TAM_COLLECTOR_ATTR_DSCP_VALUE: + attrs["SAI_TAM_COLLECTOR_ATTR_DSCP_VALUE"] = attr.value.u8 + attrs["dscp_value"] = attr.value.u8 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_collector_attribute(client, + tam_collector_oid, + src_ip=None, + dst_ip=None, + localhost=None, + virtual_router_id=None, + truncate_size=None, + transport=None, + dscp_value=None, + custom_attribute=None): + """ + sai_set_tam_collector_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_collector_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_collector SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if src_ip is not None: + attr_value = sai_thrift_attribute_value_t(ipaddr=src_ip) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_SRC_IP, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if dst_ip is not None: + attr_value = sai_thrift_attribute_value_t(ipaddr=dst_ip) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_DST_IP, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if localhost is not None: + attr_value = sai_thrift_attribute_value_t(booldata=localhost) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_LOCALHOST, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if virtual_router_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=virtual_router_id) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_VIRTUAL_ROUTER_ID, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if truncate_size is not None: + attr_value = sai_thrift_attribute_value_t(u16=truncate_size) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_TRUNCATE_SIZE, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if transport is not None: + attr_value = sai_thrift_attribute_value_t(oid=transport) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_TRANSPORT, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if dscp_value is not None: + attr_value = sai_thrift_attribute_value_t(u8=dscp_value) + attr = sai_thrift_attribute_t(id=SAI_TAM_COLLECTOR_ATTR_DSCP_VALUE, + value=attr_value) + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_collector_attribute(tam_collector_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_event_action(client, + report_type=None, + qos_action_type=None, + custom_attribute=None): + """ + sai_create_tam_event_action() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_event_action CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_event_action_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if report_type is not None: + attribute_value = sai_thrift_attribute_value_t(oid=report_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ACTION_ATTR_REPORT_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if qos_action_type is not None: + attribute_value = sai_thrift_attribute_value_t(u32=qos_action_type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ACTION_ATTR_QOS_ACTION_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_event_action(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_event_action(client, + tam_event_action_oid): + """ + sai_remove_tam_event_action() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_event_action_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_event_action(tam_event_action_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_event_action_attribute(client, + tam_event_action_oid, + report_type=None, + qos_action_type=None, + custom_attribute=None): + """ + sai_get_tam_event_action_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_event_action_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_event_action GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if report_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ACTION_ATTR_REPORT_TYPE) + attr_list.append(attribute) + + if qos_action_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ACTION_ATTR_QOS_ACTION_TYPE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_event_action_attribute(tam_event_action_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_EVENT_ACTION_ATTR_REPORT_TYPE: + attrs["SAI_TAM_EVENT_ACTION_ATTR_REPORT_TYPE"] = attr.value.oid + attrs["report_type"] = attr.value.oid + + if attr.id == SAI_TAM_EVENT_ACTION_ATTR_QOS_ACTION_TYPE: + attrs["SAI_TAM_EVENT_ACTION_ATTR_QOS_ACTION_TYPE"] = attr.value.u32 + attrs["qos_action_type"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_event_action_attribute(client, + tam_event_action_oid, + report_type=None, + qos_action_type=None, + custom_attribute=None): + """ + sai_set_tam_event_action_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_event_action_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_event_action SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if report_type is not None: + attr_value = sai_thrift_attribute_value_t(oid=report_type) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ACTION_ATTR_REPORT_TYPE, + value=attr_value) + client.sai_thrift_set_tam_event_action_attribute(tam_event_action_oid, attr) + + if qos_action_type is not None: + attr_value = sai_thrift_attribute_value_t(u32=qos_action_type) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ACTION_ATTR_QOS_ACTION_TYPE, + value=attr_value) + client.sai_thrift_set_tam_event_action_attribute(tam_event_action_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_event_action_attribute(tam_event_action_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tam_event(client, + type=None, + action_list=None, + collector_list=None, + threshold=None, + dscp_value=None, + custom_attribute=None): + """ + sai_create_tam_event() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tam_event CREATE attributes. + + Returns: + sai_thrift_object_id_t: tam_event_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if action_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=action_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_ACTION_LIST, + value=attribute_value) + attr_list.append(attribute) + + if collector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=collector_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_COLLECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if threshold is not None: + attribute_value = sai_thrift_attribute_value_t(oid=threshold) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if dscp_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=dscp_value) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_DSCP_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tam_event(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tam_event(client, + tam_event_oid): + """ + sai_remove_tam_event() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tam_event_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tam_event(tam_event_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tam_event_attribute(client, + tam_event_oid, + type=None, + action_list=None, + collector_list=None, + threshold=None, + dscp_value=None, + custom_attribute=None): + """ + sai_get_tam_event_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tam_event_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_event GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_TYPE) + attr_list.append(attribute) + + if action_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=action_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_ACTION_LIST, + value=attribute_value) + attr_list.append(attribute) + + if collector_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=collector_list) + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_COLLECTOR_LIST, + value=attribute_value) + attr_list.append(attribute) + + if threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_THRESHOLD) + attr_list.append(attribute) + + if dscp_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_DSCP_VALUE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tam_event_attribute(tam_event_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TAM_EVENT_ATTR_TYPE: + attrs["SAI_TAM_EVENT_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_TAM_EVENT_ATTR_ACTION_LIST: + attrs["SAI_TAM_EVENT_ATTR_ACTION_LIST"] = attr.value.objlist + attrs["action_list"] = attr.value.objlist + + if attr.id == SAI_TAM_EVENT_ATTR_COLLECTOR_LIST: + attrs["SAI_TAM_EVENT_ATTR_COLLECTOR_LIST"] = attr.value.objlist + attrs["collector_list"] = attr.value.objlist + + if attr.id == SAI_TAM_EVENT_ATTR_THRESHOLD: + attrs["SAI_TAM_EVENT_ATTR_THRESHOLD"] = attr.value.oid + attrs["threshold"] = attr.value.oid + + if attr.id == SAI_TAM_EVENT_ATTR_DSCP_VALUE: + attrs["SAI_TAM_EVENT_ATTR_DSCP_VALUE"] = attr.value.u8 + attrs["dscp_value"] = attr.value.u8 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_set_tam_event_attribute(client, + tam_event_oid, + threshold=None, + dscp_value=None, + custom_attribute=None): + """ + sai_set_tam_event_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tam_event_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tam_event SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if threshold is not None: + attr_value = sai_thrift_attribute_value_t(oid=threshold) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_THRESHOLD, + value=attr_value) + client.sai_thrift_set_tam_event_attribute(tam_event_oid, attr) + + if dscp_value is not None: + attr_value = sai_thrift_attribute_value_t(u8=dscp_value) + attr = sai_thrift_attribute_t(id=SAI_TAM_EVENT_ATTR_DSCP_VALUE, + value=attr_value) + client.sai_thrift_set_tam_event_attribute(tam_event_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tam_event_attribute(tam_event_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# tunnel API + +def sai_thrift_create_tunnel_map(client, + type=None, + custom_attribute=None): + """ + sai_create_tunnel_map() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tunnel_map CREATE attributes. + + Returns: + sai_thrift_object_id_t: tunnel_map_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tunnel_map(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tunnel_map(client, + tunnel_map_oid): + """ + sai_remove_tunnel_map() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_map_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tunnel_map(tunnel_map_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_tunnel_map_attribute(client, + tunnel_map_oid, + custom_attribute=None): + """ + sai_set_tunnel_map_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tunnel_map_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del tunnel_map_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_tunnel_map_attribute(client, + tunnel_map_oid, + type=None, + entry_list=None, + custom_attribute=None): + """ + sai_get_tunnel_map_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tunnel_map_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tunnel_map GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ATTR_TYPE) + attr_list.append(attribute) + + if entry_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=entry_list) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ATTR_ENTRY_LIST, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tunnel_map_attribute(tunnel_map_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TUNNEL_MAP_ATTR_TYPE: + attrs["SAI_TUNNEL_MAP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_MAP_ATTR_ENTRY_LIST: + attrs["SAI_TUNNEL_MAP_ATTR_ENTRY_LIST"] = attr.value.objlist + attrs["entry_list"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_tunnel(client, + type=None, + underlay_interface=None, + overlay_interface=None, + peer_mode=None, + encap_src_ip=None, + encap_dst_ip=None, + encap_ttl_mode=None, + encap_ttl_val=None, + encap_dscp_mode=None, + encap_dscp_val=None, + encap_gre_key_valid=None, + encap_gre_key=None, + encap_ecn_mode=None, + encap_mappers=None, + decap_ecn_mode=None, + decap_mappers=None, + decap_ttl_mode=None, + decap_dscp_mode=None, + loopback_packet_action=None, + vxlan_udp_sport_mode=None, + vxlan_udp_sport=None, + vxlan_udp_sport_mask=None, + sa_index=None, + ipsec_sa_port_list=None, + encap_qos_tc_and_color_to_dscp_map=None, + encap_qos_tc_to_queue_map=None, + decap_qos_dscp_to_tc_map=None, + decap_qos_tc_to_priority_group_map=None, + custom_attribute=None): + """ + sai_create_tunnel() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tunnel CREATE attributes. + + Returns: + sai_thrift_object_id_t: tunnel_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if underlay_interface is not None: + attribute_value = sai_thrift_attribute_value_t(oid=underlay_interface) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE, + value=attribute_value) + attr_list.append(attribute) + + if overlay_interface is not None: + attribute_value = sai_thrift_attribute_value_t(oid=overlay_interface) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_OVERLAY_INTERFACE, + value=attribute_value) + attr_list.append(attribute) + + if peer_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=peer_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_PEER_MODE, + value=attribute_value) + attr_list.append(attribute) + + if encap_src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=encap_src_ip) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if encap_dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=encap_dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if encap_ttl_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=encap_ttl_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_TTL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if encap_ttl_val is not None: + attribute_value = sai_thrift_attribute_value_t(u8=encap_ttl_val) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_TTL_VAL, + value=attribute_value) + attr_list.append(attribute) + + if encap_dscp_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=encap_dscp_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE, + value=attribute_value) + attr_list.append(attribute) + + if encap_dscp_val is not None: + attribute_value = sai_thrift_attribute_value_t(u8=encap_dscp_val) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DSCP_VAL, + value=attribute_value) + attr_list.append(attribute) + + if encap_gre_key_valid is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=encap_gre_key_valid) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_GRE_KEY_VALID, + value=attribute_value) + attr_list.append(attribute) + + if encap_gre_key is not None: + attribute_value = sai_thrift_attribute_value_t(u32=encap_gre_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_GRE_KEY, + value=attribute_value) + attr_list.append(attribute) + + if encap_ecn_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=encap_ecn_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_ECN_MODE, + value=attribute_value) + attr_list.append(attribute) + + if encap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=encap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if decap_ecn_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=decap_ecn_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_ECN_MODE, + value=attribute_value) + attr_list.append(attribute) + + if decap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=decap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if decap_ttl_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=decap_ttl_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_TTL_MODE, + value=attribute_value) + attr_list.append(attribute) + + if decap_dscp_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=decap_dscp_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_DSCP_MODE, + value=attribute_value) + attr_list.append(attribute) + + if loopback_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=loopback_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_udp_sport_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=vxlan_udp_sport_mode) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_udp_sport is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vxlan_udp_sport) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT, + value=attribute_value) + attr_list.append(attribute) + + if vxlan_udp_sport_mask is not None: + attribute_value = sai_thrift_attribute_value_t(u8=vxlan_udp_sport_mask) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK, + value=attribute_value) + attr_list.append(attribute) + + if sa_index is not None: + attribute_value = sai_thrift_attribute_value_t(u32=sa_index) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_SA_INDEX, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_sa_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ipsec_sa_port_list) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_IPSEC_SA_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if encap_qos_tc_and_color_to_dscp_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_and_color_to_dscp_map) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if encap_qos_tc_to_queue_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_to_queue_map) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP, + value=attribute_value) + attr_list.append(attribute) + + if decap_qos_dscp_to_tc_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=decap_qos_dscp_to_tc_map) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP, + value=attribute_value) + attr_list.append(attribute) + + if decap_qos_tc_to_priority_group_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=decap_qos_tc_to_priority_group_map) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tunnel(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tunnel(client, + tunnel_oid): + """ + sai_remove_tunnel() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tunnel(tunnel_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_tunnel_attribute(client, + tunnel_oid, + encap_ttl_mode=None, + encap_ttl_val=None, + encap_dscp_mode=None, + encap_dscp_val=None, + encap_gre_key=None, + decap_ttl_mode=None, + decap_dscp_mode=None, + loopback_packet_action=None, + vxlan_udp_sport_mode=None, + vxlan_udp_sport=None, + vxlan_udp_sport_mask=None, + sa_index=None, + ipsec_sa_port_list=None, + encap_qos_tc_and_color_to_dscp_map=None, + encap_qos_tc_to_queue_map=None, + decap_qos_dscp_to_tc_map=None, + decap_qos_tc_to_priority_group_map=None, + custom_attribute=None): + """ + sai_set_tunnel_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tunnel SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if encap_ttl_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=encap_ttl_mode) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_TTL_MODE, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if encap_ttl_val is not None: + attr_value = sai_thrift_attribute_value_t(u8=encap_ttl_val) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_TTL_VAL, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if encap_dscp_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=encap_dscp_mode) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if encap_dscp_val is not None: + attr_value = sai_thrift_attribute_value_t(u8=encap_dscp_val) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DSCP_VAL, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if encap_gre_key is not None: + attr_value = sai_thrift_attribute_value_t(u32=encap_gre_key) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_GRE_KEY, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if decap_ttl_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=decap_ttl_mode) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_TTL_MODE, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if decap_dscp_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=decap_dscp_mode) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_DSCP_MODE, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if loopback_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=loopback_packet_action) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if vxlan_udp_sport_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=vxlan_udp_sport_mode) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if vxlan_udp_sport is not None: + attr_value = sai_thrift_attribute_value_t(u16=vxlan_udp_sport) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if vxlan_udp_sport_mask is not None: + attr_value = sai_thrift_attribute_value_t(u8=vxlan_udp_sport_mask) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if sa_index is not None: + attr_value = sai_thrift_attribute_value_t(u32=sa_index) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_SA_INDEX, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if ipsec_sa_port_list is not None: + attr_value = sai_thrift_attribute_value_t(objlist=ipsec_sa_port_list) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_IPSEC_SA_PORT_LIST, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if encap_qos_tc_and_color_to_dscp_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_and_color_to_dscp_map) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if encap_qos_tc_to_queue_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=encap_qos_tc_to_queue_map) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if decap_qos_dscp_to_tc_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=decap_qos_dscp_to_tc_map) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if decap_qos_tc_to_priority_group_map is not None: + attr_value = sai_thrift_attribute_value_t(oid=decap_qos_tc_to_priority_group_map) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP, + value=attr_value) + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tunnel_attribute(tunnel_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tunnel_attribute(client, + tunnel_oid, + type=None, + underlay_interface=None, + overlay_interface=None, + peer_mode=None, + encap_src_ip=None, + encap_dst_ip=None, + encap_ttl_mode=None, + encap_ttl_val=None, + encap_dscp_mode=None, + encap_dscp_val=None, + encap_gre_key_valid=None, + encap_gre_key=None, + encap_ecn_mode=None, + encap_mappers=None, + decap_ecn_mode=None, + decap_mappers=None, + decap_ttl_mode=None, + decap_dscp_mode=None, + term_table_entry_list=None, + loopback_packet_action=None, + vxlan_udp_sport_mode=None, + vxlan_udp_sport=None, + vxlan_udp_sport_mask=None, + sa_index=None, + ipsec_sa_port_list=None, + encap_qos_tc_and_color_to_dscp_map=None, + encap_qos_tc_to_queue_map=None, + decap_qos_dscp_to_tc_map=None, + decap_qos_tc_to_priority_group_map=None, + custom_attribute=None): + """ + sai_get_tunnel_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tunnel GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_TYPE) + attr_list.append(attribute) + + if underlay_interface is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE) + attr_list.append(attribute) + + if overlay_interface is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_OVERLAY_INTERFACE) + attr_list.append(attribute) + + if peer_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_PEER_MODE) + attr_list.append(attribute) + + if encap_src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_SRC_IP) + attr_list.append(attribute) + + if encap_dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DST_IP) + attr_list.append(attribute) + + if encap_ttl_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_TTL_MODE) + attr_list.append(attribute) + + if encap_ttl_val is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_TTL_VAL) + attr_list.append(attribute) + + if encap_dscp_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE) + attr_list.append(attribute) + + if encap_dscp_val is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_DSCP_VAL) + attr_list.append(attribute) + + if encap_gre_key_valid is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_GRE_KEY_VALID) + attr_list.append(attribute) + + if encap_gre_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_GRE_KEY) + attr_list.append(attribute) + + if encap_ecn_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_ECN_MODE) + attr_list.append(attribute) + + if encap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=encap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if decap_ecn_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_ECN_MODE) + attr_list.append(attribute) + + if decap_mappers is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=decap_mappers) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_MAPPERS, + value=attribute_value) + attr_list.append(attribute) + + if decap_ttl_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_TTL_MODE) + attr_list.append(attribute) + + if decap_dscp_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_DSCP_MODE) + attr_list.append(attribute) + + if term_table_entry_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=term_table_entry_list) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_TERM_TABLE_ENTRY_LIST, + value=attribute_value) + attr_list.append(attribute) + + if loopback_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION) + attr_list.append(attribute) + + if vxlan_udp_sport_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE) + attr_list.append(attribute) + + if vxlan_udp_sport is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT) + attr_list.append(attribute) + + if vxlan_udp_sport_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK) + attr_list.append(attribute) + + if sa_index is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_SA_INDEX) + attr_list.append(attribute) + + if ipsec_sa_port_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=ipsec_sa_port_list) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_IPSEC_SA_PORT_LIST, + value=attribute_value) + attr_list.append(attribute) + + if encap_qos_tc_and_color_to_dscp_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP) + attr_list.append(attribute) + + if encap_qos_tc_to_queue_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP) + attr_list.append(attribute) + + if decap_qos_dscp_to_tc_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP) + attr_list.append(attribute) + + if decap_qos_tc_to_priority_group_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tunnel_attribute(tunnel_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TUNNEL_ATTR_TYPE: + attrs["SAI_TUNNEL_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE: + attrs["SAI_TUNNEL_ATTR_UNDERLAY_INTERFACE"] = attr.value.oid + attrs["underlay_interface"] = attr.value.oid + + if attr.id == SAI_TUNNEL_ATTR_OVERLAY_INTERFACE: + attrs["SAI_TUNNEL_ATTR_OVERLAY_INTERFACE"] = attr.value.oid + attrs["overlay_interface"] = attr.value.oid + + if attr.id == SAI_TUNNEL_ATTR_PEER_MODE: + attrs["SAI_TUNNEL_ATTR_PEER_MODE"] = attr.value.s32 + attrs["peer_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_SRC_IP: + attrs["SAI_TUNNEL_ATTR_ENCAP_SRC_IP"] = attr.value.ipaddr + attrs["encap_src_ip"] = attr.value.ipaddr + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_DST_IP: + attrs["SAI_TUNNEL_ATTR_ENCAP_DST_IP"] = attr.value.ipaddr + attrs["encap_dst_ip"] = attr.value.ipaddr + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_TTL_MODE: + attrs["SAI_TUNNEL_ATTR_ENCAP_TTL_MODE"] = attr.value.s32 + attrs["encap_ttl_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_TTL_VAL: + attrs["SAI_TUNNEL_ATTR_ENCAP_TTL_VAL"] = attr.value.u8 + attrs["encap_ttl_val"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE: + attrs["SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE"] = attr.value.s32 + attrs["encap_dscp_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_DSCP_VAL: + attrs["SAI_TUNNEL_ATTR_ENCAP_DSCP_VAL"] = attr.value.u8 + attrs["encap_dscp_val"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_GRE_KEY_VALID: + attrs["SAI_TUNNEL_ATTR_ENCAP_GRE_KEY_VALID"] = attr.value.booldata + attrs["encap_gre_key_valid"] = attr.value.booldata + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_GRE_KEY: + attrs["SAI_TUNNEL_ATTR_ENCAP_GRE_KEY"] = attr.value.u32 + attrs["encap_gre_key"] = attr.value.u32 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_ECN_MODE: + attrs["SAI_TUNNEL_ATTR_ENCAP_ECN_MODE"] = attr.value.s32 + attrs["encap_ecn_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_MAPPERS: + attrs["SAI_TUNNEL_ATTR_ENCAP_MAPPERS"] = attr.value.objlist + attrs["encap_mappers"] = attr.value.objlist + + if attr.id == SAI_TUNNEL_ATTR_DECAP_ECN_MODE: + attrs["SAI_TUNNEL_ATTR_DECAP_ECN_MODE"] = attr.value.s32 + attrs["decap_ecn_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_DECAP_MAPPERS: + attrs["SAI_TUNNEL_ATTR_DECAP_MAPPERS"] = attr.value.objlist + attrs["decap_mappers"] = attr.value.objlist + + if attr.id == SAI_TUNNEL_ATTR_DECAP_TTL_MODE: + attrs["SAI_TUNNEL_ATTR_DECAP_TTL_MODE"] = attr.value.s32 + attrs["decap_ttl_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_DECAP_DSCP_MODE: + attrs["SAI_TUNNEL_ATTR_DECAP_DSCP_MODE"] = attr.value.s32 + attrs["decap_dscp_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_TERM_TABLE_ENTRY_LIST: + attrs["SAI_TUNNEL_ATTR_TERM_TABLE_ENTRY_LIST"] = attr.value.objlist + attrs["term_table_entry_list"] = attr.value.objlist + + if attr.id == SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION: + attrs["SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION"] = attr.value.s32 + attrs["loopback_packet_action"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE: + attrs["SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MODE"] = attr.value.s32 + attrs["vxlan_udp_sport_mode"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT: + attrs["SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT"] = attr.value.u16 + attrs["vxlan_udp_sport"] = attr.value.u16 + + if attr.id == SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK: + attrs["SAI_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK"] = attr.value.u8 + attrs["vxlan_udp_sport_mask"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_ATTR_SA_INDEX: + attrs["SAI_TUNNEL_ATTR_SA_INDEX"] = attr.value.u32 + attrs["sa_index"] = attr.value.u32 + + if attr.id == SAI_TUNNEL_ATTR_IPSEC_SA_PORT_LIST: + attrs["SAI_TUNNEL_ATTR_IPSEC_SA_PORT_LIST"] = attr.value.objlist + attrs["ipsec_sa_port_list"] = attr.value.objlist + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP: + attrs["SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP"] = attr.value.oid + attrs["encap_qos_tc_and_color_to_dscp_map"] = attr.value.oid + + if attr.id == SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP: + attrs["SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP"] = attr.value.oid + attrs["encap_qos_tc_to_queue_map"] = attr.value.oid + + if attr.id == SAI_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP: + attrs["SAI_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP"] = attr.value.oid + attrs["decap_qos_dscp_to_tc_map"] = attr.value.oid + + if attr.id == SAI_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP: + attrs["SAI_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP"] = attr.value.oid + attrs["decap_qos_tc_to_priority_group_map"] = attr.value.oid + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_tunnel_stats(client, + tunnel_oid): + """ + sai_get_tunnel_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_TUNNEL_STAT_IN_OCTETS) + counter_ids.append(SAI_TUNNEL_STAT_IN_PACKETS) + counter_ids.append(SAI_TUNNEL_STAT_OUT_OCTETS) + counter_ids.append(SAI_TUNNEL_STAT_OUT_PACKETS) + + counters = [0] * 4 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_tunnel_stats(tunnel_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_TUNNEL_STAT_IN_OCTETS"] = counters[0] + stats["SAI_TUNNEL_STAT_IN_PACKETS"] = counters[1] + stats["SAI_TUNNEL_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_TUNNEL_STAT_OUT_PACKETS"] = counters[3] + + return stats + + +def sai_thrift_get_tunnel_stats_ext(client, + tunnel_oid, + mode): + """ + sai_get_tunnel_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_TUNNEL_STAT_IN_OCTETS) + counter_ids.append(SAI_TUNNEL_STAT_IN_PACKETS) + counter_ids.append(SAI_TUNNEL_STAT_OUT_OCTETS) + counter_ids.append(SAI_TUNNEL_STAT_OUT_PACKETS) + + counters = [0] * 4 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_tunnel_stats_ext(tunnel_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_TUNNEL_STAT_IN_OCTETS"] = counters[0] + stats["SAI_TUNNEL_STAT_IN_PACKETS"] = counters[1] + stats["SAI_TUNNEL_STAT_OUT_OCTETS"] = counters[2] + stats["SAI_TUNNEL_STAT_OUT_PACKETS"] = counters[3] + + return stats + + +def sai_thrift_clear_tunnel_stats(client, + tunnel_oid): + """ + sai_clear_tunnel_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_TUNNEL_STAT_IN_OCTETS) + counter_ids.append(SAI_TUNNEL_STAT_IN_PACKETS) + counter_ids.append(SAI_TUNNEL_STAT_OUT_OCTETS) + counter_ids.append(SAI_TUNNEL_STAT_OUT_PACKETS) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_tunnel_stats(tunnel_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_create_tunnel_term_table_entry(client, + vr_id=None, + type=None, + dst_ip=None, + src_ip=None, + tunnel_type=None, + action_tunnel_id=None, + dst_ip_mask=None, + src_ip_mask=None, + ipsec_verified=None, + custom_attribute=None): + """ + sai_create_tunnel_term_table_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tunnel_term_table_entry CREATE attributes. + + Returns: + sai_thrift_object_id_t: tunnel_term_table_entry_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vr_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=vr_id) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=dst_ip) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP, + value=attribute_value) + attr_list.append(attribute) + + if src_ip is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=src_ip) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tunnel_type) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if action_tunnel_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=action_tunnel_id) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID, + value=attribute_value) + attr_list.append(attribute) + + if dst_ip_mask is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=dst_ip_mask) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP_MASK, + value=attribute_value) + attr_list.append(attribute) + + if src_ip_mask is not None: + attribute_value = sai_thrift_attribute_value_t(ipaddr=src_ip_mask) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP_MASK, + value=attribute_value) + attr_list.append(attribute) + + if ipsec_verified is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=ipsec_verified) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IPSEC_VERIFIED, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tunnel_term_table_entry(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tunnel_term_table_entry(client, + tunnel_term_table_entry_oid): + """ + sai_remove_tunnel_term_table_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_term_table_entry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tunnel_term_table_entry(tunnel_term_table_entry_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_tunnel_term_table_entry_attribute(client, + tunnel_term_table_entry_oid, + ipsec_verified=None, + custom_attribute=None): + """ + sai_set_tunnel_term_table_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tunnel_term_table_entry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tunnel_term_table_entry SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if ipsec_verified is not None: + attr_value = sai_thrift_attribute_value_t(booldata=ipsec_verified) + attr = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IPSEC_VERIFIED, + value=attr_value) + client.sai_thrift_set_tunnel_term_table_entry_attribute(tunnel_term_table_entry_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_tunnel_term_table_entry_attribute(tunnel_term_table_entry_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_tunnel_term_table_entry_attribute(client, + tunnel_term_table_entry_oid, + vr_id=None, + type=None, + dst_ip=None, + dst_ip_mask=None, + src_ip=None, + src_ip_mask=None, + tunnel_type=None, + action_tunnel_id=None, + ip_addr_family=None, + ipsec_verified=None, + custom_attribute=None): + """ + sai_get_tunnel_term_table_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tunnel_term_table_entry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tunnel_term_table_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vr_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE) + attr_list.append(attribute) + + if dst_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP) + attr_list.append(attribute) + + if dst_ip_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP_MASK) + attr_list.append(attribute) + + if src_ip is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP) + attr_list.append(attribute) + + if src_ip_mask is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP_MASK) + attr_list.append(attribute) + + if tunnel_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE) + attr_list.append(attribute) + + if action_tunnel_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID) + attr_list.append(attribute) + + if ip_addr_family is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IP_ADDR_FAMILY) + attr_list.append(attribute) + + if ipsec_verified is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IPSEC_VERIFIED) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tunnel_term_table_entry_attribute(tunnel_term_table_entry_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID"] = attr.value.oid + attrs["vr_id"] = attr.value.oid + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP"] = attr.value.ipaddr + attrs["dst_ip"] = attr.value.ipaddr + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP_MASK: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_DST_IP_MASK"] = attr.value.ipaddr + attrs["dst_ip_mask"] = attr.value.ipaddr + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP"] = attr.value.ipaddr + attrs["src_ip"] = attr.value.ipaddr + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP_MASK: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_SRC_IP_MASK"] = attr.value.ipaddr + attrs["src_ip_mask"] = attr.value.ipaddr + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_TUNNEL_TYPE"] = attr.value.s32 + attrs["tunnel_type"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_ACTION_TUNNEL_ID"] = attr.value.oid + attrs["action_tunnel_id"] = attr.value.oid + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IP_ADDR_FAMILY: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IP_ADDR_FAMILY"] = attr.value.s32 + attrs["ip_addr_family"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IPSEC_VERIFIED: + attrs["SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_IPSEC_VERIFIED"] = attr.value.booldata + attrs["ipsec_verified"] = attr.value.booldata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_tunnel_map_entry(client, + tunnel_map_type=None, + tunnel_map=None, + oecn_key=None, + oecn_value=None, + uecn_key=None, + uecn_value=None, + vlan_id_key=None, + vlan_id_value=None, + vni_id_key=None, + vni_id_value=None, + bridge_id_key=None, + bridge_id_value=None, + virtual_router_id_key=None, + virtual_router_id_value=None, + vsid_id_key=None, + vsid_id_value=None, + custom_attribute=None): + """ + sai_create_tunnel_map_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of tunnel_map_entry CREATE attributes. + + Returns: + sai_thrift_object_id_t: tunnel_map_entry_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tunnel_map_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=tunnel_map_type) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if tunnel_map is not None: + attribute_value = sai_thrift_attribute_value_t(oid=tunnel_map) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP, + value=attribute_value) + attr_list.append(attribute) + + if oecn_key is not None: + attribute_value = sai_thrift_attribute_value_t(u8=oecn_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_KEY, + value=attribute_value) + attr_list.append(attribute) + + if oecn_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=oecn_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if uecn_key is not None: + attribute_value = sai_thrift_attribute_value_t(u8=uecn_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_KEY, + value=attribute_value) + attr_list.append(attribute) + + if uecn_value is not None: + attribute_value = sai_thrift_attribute_value_t(u8=uecn_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id_key is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_KEY, + value=attribute_value) + attr_list.append(attribute) + + if vlan_id_value is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if vni_id_key is not None: + attribute_value = sai_thrift_attribute_value_t(u32=vni_id_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY, + value=attribute_value) + attr_list.append(attribute) + + if vni_id_value is not None: + attribute_value = sai_thrift_attribute_value_t(u32=vni_id_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if bridge_id_key is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_id_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_KEY, + value=attribute_value) + attr_list.append(attribute) + + if bridge_id_value is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_id_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if virtual_router_id_key is not None: + attribute_value = sai_thrift_attribute_value_t(oid=virtual_router_id_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_KEY, + value=attribute_value) + attr_list.append(attribute) + + if virtual_router_id_value is not None: + attribute_value = sai_thrift_attribute_value_t(oid=virtual_router_id_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if vsid_id_key is not None: + attribute_value = sai_thrift_attribute_value_t(u32=vsid_id_key) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_KEY, + value=attribute_value) + attr_list.append(attribute) + + if vsid_id_value is not None: + attribute_value = sai_thrift_attribute_value_t(u32=vsid_id_value) + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_VALUE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_tunnel_map_entry(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_tunnel_map_entry(client, + tunnel_map_entry_oid): + """ + sai_remove_tunnel_map_entry() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + tunnel_map_entry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_tunnel_map_entry(tunnel_map_entry_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_tunnel_map_entry_attribute(client, + tunnel_map_entry_oid, + custom_attribute=None): + """ + sai_set_tunnel_map_entry_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + tunnel_map_entry_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del tunnel_map_entry_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_tunnel_map_entry_attribute(client, + tunnel_map_entry_oid, + tunnel_map_type=None, + tunnel_map=None, + oecn_key=None, + oecn_value=None, + uecn_key=None, + uecn_value=None, + vlan_id_key=None, + vlan_id_value=None, + vni_id_key=None, + vni_id_value=None, + bridge_id_key=None, + bridge_id_value=None, + virtual_router_id_key=None, + virtual_router_id_value=None, + vsid_id_key=None, + vsid_id_value=None, + custom_attribute=None): + """ + sai_get_tunnel_map_entry_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + tunnel_map_entry_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of tunnel_map_entry GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if tunnel_map_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE) + attr_list.append(attribute) + + if tunnel_map is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP) + attr_list.append(attribute) + + if oecn_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_KEY) + attr_list.append(attribute) + + if oecn_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_VALUE) + attr_list.append(attribute) + + if uecn_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_KEY) + attr_list.append(attribute) + + if uecn_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_VALUE) + attr_list.append(attribute) + + if vlan_id_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_KEY) + attr_list.append(attribute) + + if vlan_id_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE) + attr_list.append(attribute) + + if vni_id_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY) + attr_list.append(attribute) + + if vni_id_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE) + attr_list.append(attribute) + + if bridge_id_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_KEY) + attr_list.append(attribute) + + if bridge_id_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_VALUE) + attr_list.append(attribute) + + if virtual_router_id_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_KEY) + attr_list.append(attribute) + + if virtual_router_id_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_VALUE) + attr_list.append(attribute) + + if vsid_id_key is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_KEY) + attr_list.append(attribute) + + if vsid_id_value is not None: + attribute = sai_thrift_attribute_t(id=SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_VALUE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_tunnel_map_entry_attribute(tunnel_map_entry_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP_TYPE"] = attr.value.s32 + attrs["tunnel_map_type"] = attr.value.s32 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_TUNNEL_MAP"] = attr.value.oid + attrs["tunnel_map"] = attr.value.oid + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_KEY"] = attr.value.u8 + attrs["oecn_key"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_OECN_VALUE"] = attr.value.u8 + attrs["oecn_value"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_KEY"] = attr.value.u8 + attrs["uecn_key"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_UECN_VALUE"] = attr.value.u8 + attrs["uecn_value"] = attr.value.u8 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_KEY"] = attr.value.u16 + attrs["vlan_id_key"] = attr.value.u16 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VLAN_ID_VALUE"] = attr.value.u16 + attrs["vlan_id_value"] = attr.value.u16 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_KEY"] = attr.value.u32 + attrs["vni_id_key"] = attr.value.u32 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VNI_ID_VALUE"] = attr.value.u32 + attrs["vni_id_value"] = attr.value.u32 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_KEY"] = attr.value.oid + attrs["bridge_id_key"] = attr.value.oid + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_BRIDGE_ID_VALUE"] = attr.value.oid + attrs["bridge_id_value"] = attr.value.oid + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_KEY"] = attr.value.oid + attrs["virtual_router_id_key"] = attr.value.oid + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VIRTUAL_ROUTER_ID_VALUE"] = attr.value.oid + attrs["virtual_router_id_value"] = attr.value.oid + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_KEY: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_KEY"] = attr.value.u32 + attrs["vsid_id_key"] = attr.value.u32 + + if attr.id == SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_VALUE: + attrs["SAI_TUNNEL_MAP_ENTRY_ATTR_VSID_ID_VALUE"] = attr.value.u32 + attrs["vsid_id_value"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# udf API + +def sai_thrift_create_udf(client, + match_id=None, + group_id=None, + offset=None, + base=None, + hash_mask=None, + custom_attribute=None): + """ + sai_create_udf() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of udf CREATE attributes. + + Returns: + sai_thrift_object_id_t: udf_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if match_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=match_id) + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_MATCH_ID, + value=attribute_value) + attr_list.append(attribute) + + if group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=group_id) + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if offset is not None: + attribute_value = sai_thrift_attribute_value_t(u16=offset) + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_OFFSET, + value=attribute_value) + attr_list.append(attribute) + + if base is not None: + attribute_value = sai_thrift_attribute_value_t(s32=base) + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_BASE, + value=attribute_value) + attr_list.append(attribute) + + if hash_mask is not None: + attribute_value = sai_thrift_attribute_value_t(u8list=hash_mask) + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_HASH_MASK, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_udf(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_udf(client, + udf_oid): + """ + sai_remove_udf() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + udf_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_udf(udf_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_udf_attribute(client, + udf_oid, + base=None, + hash_mask=None, + custom_attribute=None): + """ + sai_set_udf_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + udf_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of udf SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if base is not None: + attr_value = sai_thrift_attribute_value_t(s32=base) + attr = sai_thrift_attribute_t(id=SAI_UDF_ATTR_BASE, + value=attr_value) + client.sai_thrift_set_udf_attribute(udf_oid, attr) + + if hash_mask is not None: + attr_value = sai_thrift_attribute_value_t(u8list=hash_mask) + attr = sai_thrift_attribute_t(id=SAI_UDF_ATTR_HASH_MASK, + value=attr_value) + client.sai_thrift_set_udf_attribute(udf_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_udf_attribute(udf_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_udf_attribute(client, + udf_oid, + match_id=None, + group_id=None, + base=None, + offset=None, + hash_mask=None, + custom_attribute=None): + """ + sai_get_udf_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + udf_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of udf GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if match_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_MATCH_ID) + attr_list.append(attribute) + + if group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_GROUP_ID) + attr_list.append(attribute) + + if base is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_BASE) + attr_list.append(attribute) + + if offset is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_OFFSET) + attr_list.append(attribute) + + if hash_mask is not None: + attribute_value = sai_thrift_attribute_value_t(u8list=hash_mask) + attribute = sai_thrift_attribute_t(id=SAI_UDF_ATTR_HASH_MASK, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_udf_attribute(udf_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_UDF_ATTR_MATCH_ID: + attrs["SAI_UDF_ATTR_MATCH_ID"] = attr.value.oid + attrs["match_id"] = attr.value.oid + + if attr.id == SAI_UDF_ATTR_GROUP_ID: + attrs["SAI_UDF_ATTR_GROUP_ID"] = attr.value.oid + attrs["group_id"] = attr.value.oid + + if attr.id == SAI_UDF_ATTR_BASE: + attrs["SAI_UDF_ATTR_BASE"] = attr.value.s32 + attrs["base"] = attr.value.s32 + + if attr.id == SAI_UDF_ATTR_OFFSET: + attrs["SAI_UDF_ATTR_OFFSET"] = attr.value.u16 + attrs["offset"] = attr.value.u16 + + if attr.id == SAI_UDF_ATTR_HASH_MASK: + attrs["SAI_UDF_ATTR_HASH_MASK"] = attr.value.u8list + attrs["hash_mask"] = attr.value.u8list + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_udf_match(client, + l2_type=None, + l3_type=None, + gre_type=None, + priority=None, + custom_attribute=None): + """ + sai_create_udf_match() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of udf_match CREATE attributes. + + Returns: + sai_thrift_object_id_t: udf_match_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if l2_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=l2_type) + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_L2_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if l3_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=l3_type) + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_L3_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if gre_type is not None: + attribute_value = sai_thrift_attribute_value_t(aclfield=gre_type) + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_GRE_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if priority is not None: + attribute_value = sai_thrift_attribute_value_t(u8=priority) + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_PRIORITY, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_udf_match(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_udf_match(client, + udf_match_oid): + """ + sai_remove_udf_match() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + udf_match_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_udf_match(udf_match_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_udf_match_attribute(client, + udf_match_oid, + custom_attribute=None): + """ + sai_set_udf_match_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + udf_match_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del udf_match_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_udf_match_attribute(client, + udf_match_oid, + l2_type=None, + l3_type=None, + gre_type=None, + priority=None, + custom_attribute=None): + """ + sai_get_udf_match_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + udf_match_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of udf_match GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if l2_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_L2_TYPE) + attr_list.append(attribute) + + if l3_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_L3_TYPE) + attr_list.append(attribute) + + if gre_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_GRE_TYPE) + attr_list.append(attribute) + + if priority is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_MATCH_ATTR_PRIORITY) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_udf_match_attribute(udf_match_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_UDF_MATCH_ATTR_L2_TYPE: + attrs["SAI_UDF_MATCH_ATTR_L2_TYPE"] = attr.value.aclfield + attrs["l2_type"] = attr.value.aclfield + + if attr.id == SAI_UDF_MATCH_ATTR_L3_TYPE: + attrs["SAI_UDF_MATCH_ATTR_L3_TYPE"] = attr.value.aclfield + attrs["l3_type"] = attr.value.aclfield + + if attr.id == SAI_UDF_MATCH_ATTR_GRE_TYPE: + attrs["SAI_UDF_MATCH_ATTR_GRE_TYPE"] = attr.value.aclfield + attrs["gre_type"] = attr.value.aclfield + + if attr.id == SAI_UDF_MATCH_ATTR_PRIORITY: + attrs["SAI_UDF_MATCH_ATTR_PRIORITY"] = attr.value.u8 + attrs["priority"] = attr.value.u8 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_udf_group(client, + length=None, + type=None, + custom_attribute=None): + """ + sai_create_udf_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of udf_group CREATE attributes. + + Returns: + sai_thrift_object_id_t: udf_group_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if length is not None: + attribute_value = sai_thrift_attribute_value_t(u16=length) + attribute = sai_thrift_attribute_t(id=SAI_UDF_GROUP_ATTR_LENGTH, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=type) + attribute = sai_thrift_attribute_t(id=SAI_UDF_GROUP_ATTR_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_udf_group(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_udf_group(client, + udf_group_oid): + """ + sai_remove_udf_group() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + udf_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_udf_group(udf_group_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_udf_group_attribute(client, + udf_group_oid, + custom_attribute=None): + """ + sai_set_udf_group_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + udf_group_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + # No function call - delete all arguments + del client + del udf_group_oid + + global status + status = SAI_STATUS_NOT_SUPPORTED + + if CATCH_EXCEPTIONS: + return status + else: + raise sai_thrift_exception(status) + + +def sai_thrift_get_udf_group_attribute(client, + udf_group_oid, + udf_list=None, + type=None, + length=None, + custom_attribute=None): + """ + sai_get_udf_group_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + udf_group_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of udf_group GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if udf_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=udf_list) + attribute = sai_thrift_attribute_t(id=SAI_UDF_GROUP_ATTR_UDF_LIST, + value=attribute_value) + attr_list.append(attribute) + + if type is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_GROUP_ATTR_TYPE) + attr_list.append(attribute) + + if length is not None: + attribute = sai_thrift_attribute_t(id=SAI_UDF_GROUP_ATTR_LENGTH) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_udf_group_attribute(udf_group_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_UDF_GROUP_ATTR_UDF_LIST: + attrs["SAI_UDF_GROUP_ATTR_UDF_LIST"] = attr.value.objlist + attrs["udf_list"] = attr.value.objlist + + if attr.id == SAI_UDF_GROUP_ATTR_TYPE: + attrs["SAI_UDF_GROUP_ATTR_TYPE"] = attr.value.s32 + attrs["type"] = attr.value.s32 + + if attr.id == SAI_UDF_GROUP_ATTR_LENGTH: + attrs["SAI_UDF_GROUP_ATTR_LENGTH"] = attr.value.u16 + attrs["length"] = attr.value.u16 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# virtual_router API + +def sai_thrift_create_virtual_router(client, + admin_v4_state=None, + admin_v6_state=None, + src_mac_address=None, + violation_ttl1_packet_action=None, + violation_ip_options_packet_action=None, + unknown_l3_multicast_packet_action=None, + label=None, + custom_attribute=None): + """ + sai_create_virtual_router() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of virtual_router CREATE attributes. + + Returns: + sai_thrift_object_id_t: virtual_router_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if admin_v4_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_v4_state) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE, + value=attribute_value) + attr_list.append(attribute) + + if admin_v6_state is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=admin_v6_state) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE, + value=attribute_value) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS, + value=attribute_value) + attr_list.append(attribute) + + if violation_ttl1_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=violation_ttl1_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if violation_ip_options_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=violation_ip_options_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if unknown_l3_multicast_packet_action is not None: + attribute_value = sai_thrift_attribute_value_t(s32=unknown_l3_multicast_packet_action) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION, + value=attribute_value) + attr_list.append(attribute) + + if label is not None: + attribute_value = sai_thrift_attribute_value_t(chardata=label) + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_LABEL, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_virtual_router(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_virtual_router(client, + virtual_router_oid): + """ + sai_remove_virtual_router() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + virtual_router_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_virtual_router(virtual_router_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_virtual_router_attribute(client, + virtual_router_oid, + admin_v4_state=None, + admin_v6_state=None, + src_mac_address=None, + violation_ttl1_packet_action=None, + violation_ip_options_packet_action=None, + unknown_l3_multicast_packet_action=None, + label=None, + custom_attribute=None): + """ + sai_set_virtual_router_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + virtual_router_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of virtual_router SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if admin_v4_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_v4_state) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if admin_v6_state is not None: + attr_value = sai_thrift_attribute_value_t(booldata=admin_v6_state) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if src_mac_address is not None: + attr_value = sai_thrift_attribute_value_t(mac=src_mac_address) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if violation_ttl1_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=violation_ttl1_packet_action) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if violation_ip_options_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=violation_ip_options_packet_action) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if unknown_l3_multicast_packet_action is not None: + attr_value = sai_thrift_attribute_value_t(s32=unknown_l3_multicast_packet_action) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if label is not None: + attr_value = sai_thrift_attribute_value_t(chardata=label) + attr = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_LABEL, + value=attr_value) + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_virtual_router_attribute(virtual_router_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_virtual_router_attribute(client, + virtual_router_oid, + admin_v4_state=None, + admin_v6_state=None, + src_mac_address=None, + violation_ttl1_packet_action=None, + violation_ip_options_packet_action=None, + unknown_l3_multicast_packet_action=None, + label=None, + custom_attribute=None): + """ + sai_get_virtual_router_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + virtual_router_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of virtual_router GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if admin_v4_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE) + attr_list.append(attribute) + + if admin_v6_state is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE) + attr_list.append(attribute) + + if src_mac_address is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS) + attr_list.append(attribute) + + if violation_ttl1_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION) + attr_list.append(attribute) + + if violation_ip_options_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION) + attr_list.append(attribute) + + if unknown_l3_multicast_packet_action is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION) + attr_list.append(attribute) + + if label is not None: + attribute = sai_thrift_attribute_t(id=SAI_VIRTUAL_ROUTER_ATTR_LABEL) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_virtual_router_attribute(virtual_router_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE: + attrs["SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE"] = attr.value.booldata + attrs["admin_v4_state"] = attr.value.booldata + + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE: + attrs["SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE"] = attr.value.booldata + attrs["admin_v6_state"] = attr.value.booldata + + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS: + attrs["SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS"] = attr.value.mac + attrs["src_mac_address"] = attr.value.mac + + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION: + attrs["SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION"] = attr.value.s32 + attrs["violation_ttl1_packet_action"] = attr.value.s32 + + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION: + attrs["SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION"] = attr.value.s32 + attrs["violation_ip_options_packet_action"] = attr.value.s32 + + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION: + attrs["SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION"] = attr.value.s32 + attrs["unknown_l3_multicast_packet_action"] = attr.value.s32 + + if attr.id == SAI_VIRTUAL_ROUTER_ATTR_LABEL: + attrs["SAI_VIRTUAL_ROUTER_ATTR_LABEL"] = attr.value.chardata + attrs["label"] = attr.value.chardata + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +# vlan API + +def sai_thrift_create_vlan(client, + vlan_id=None, + max_learned_addresses=None, + stp_instance=None, + learn_disable=None, + ipv4_mcast_lookup_key_type=None, + ipv6_mcast_lookup_key_type=None, + unknown_non_ip_mcast_output_group_id=None, + unknown_ipv4_mcast_output_group_id=None, + unknown_ipv6_mcast_output_group_id=None, + unknown_linklocal_mcast_output_group_id=None, + ingress_acl=None, + egress_acl=None, + meta_data=None, + unknown_unicast_flood_control_type=None, + unknown_unicast_flood_group=None, + unknown_multicast_flood_control_type=None, + unknown_multicast_flood_group=None, + broadcast_flood_control_type=None, + broadcast_flood_group=None, + custom_igmp_snooping_enable=None, + tam_object=None, + custom_attribute=None): + """ + sai_create_vlan() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of vlan CREATE attributes. + + Returns: + sai_thrift_object_id_t: vlan_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(u16=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES, + value=attribute_value) + attr_list.append(attribute) + + if stp_instance is not None: + attribute_value = sai_thrift_attribute_value_t(oid=stp_instance) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_STP_INSTANCE, + value=attribute_value) + attr_list.append(attribute) + + if learn_disable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=learn_disable) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_LEARN_DISABLE, + value=attribute_value) + attr_list.append(attribute) + + if ipv4_mcast_lookup_key_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ipv4_mcast_lookup_key_type) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_IPV4_MCAST_LOOKUP_KEY_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if ipv6_mcast_lookup_key_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ipv6_mcast_lookup_key_type) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_IPV6_MCAST_LOOKUP_KEY_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if unknown_non_ip_mcast_output_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_non_ip_mcast_output_group_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_NON_IP_MCAST_OUTPUT_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if unknown_ipv4_mcast_output_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_ipv4_mcast_output_group_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_IPV4_MCAST_OUTPUT_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if unknown_ipv6_mcast_output_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_ipv6_mcast_output_group_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_IPV6_MCAST_OUTPUT_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if unknown_linklocal_mcast_output_group_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_linklocal_mcast_output_group_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_LINKLOCAL_MCAST_OUTPUT_GROUP_ID, + value=attribute_value) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_INGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if egress_acl is not None: + attribute_value = sai_thrift_attribute_value_t(oid=egress_acl) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_EGRESS_ACL, + value=attribute_value) + attr_list.append(attribute) + + if meta_data is not None: + attribute_value = sai_thrift_attribute_value_t(u32=meta_data) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_META_DATA, + value=attribute_value) + attr_list.append(attribute) + + if unknown_unicast_flood_control_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=unknown_unicast_flood_control_type) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if unknown_unicast_flood_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_unicast_flood_group) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if unknown_multicast_flood_control_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=unknown_multicast_flood_control_type) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if unknown_multicast_flood_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=unknown_multicast_flood_group) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if broadcast_flood_control_type is not None: + attribute_value = sai_thrift_attribute_value_t(s32=broadcast_flood_control_type) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE, + value=attribute_value) + attr_list.append(attribute) + + if broadcast_flood_group is not None: + attribute_value = sai_thrift_attribute_value_t(oid=broadcast_flood_group) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_BROADCAST_FLOOD_GROUP, + value=attribute_value) + attr_list.append(attribute) + + if custom_igmp_snooping_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=custom_igmp_snooping_enable) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_CUSTOM_IGMP_SNOOPING_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if tam_object is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_TAM_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_vlan(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_vlan(client, + vlan_oid): + """ + sai_remove_vlan() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + vlan_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_vlan(vlan_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_vlan_attribute(client, + vlan_oid, + max_learned_addresses=None, + stp_instance=None, + learn_disable=None, + ipv4_mcast_lookup_key_type=None, + ipv6_mcast_lookup_key_type=None, + unknown_non_ip_mcast_output_group_id=None, + unknown_ipv4_mcast_output_group_id=None, + unknown_ipv6_mcast_output_group_id=None, + unknown_linklocal_mcast_output_group_id=None, + ingress_acl=None, + egress_acl=None, + meta_data=None, + unknown_unicast_flood_control_type=None, + unknown_unicast_flood_group=None, + unknown_multicast_flood_control_type=None, + unknown_multicast_flood_group=None, + broadcast_flood_control_type=None, + broadcast_flood_group=None, + custom_igmp_snooping_enable=None, + tam_object=None, + custom_attribute=None): + """ + sai_set_vlan_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + vlan_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of vlan SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if max_learned_addresses is not None: + attr_value = sai_thrift_attribute_value_t(u32=max_learned_addresses) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if stp_instance is not None: + attr_value = sai_thrift_attribute_value_t(oid=stp_instance) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_STP_INSTANCE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if learn_disable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=learn_disable) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_LEARN_DISABLE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if ipv4_mcast_lookup_key_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=ipv4_mcast_lookup_key_type) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_IPV4_MCAST_LOOKUP_KEY_TYPE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if ipv6_mcast_lookup_key_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=ipv6_mcast_lookup_key_type) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_IPV6_MCAST_LOOKUP_KEY_TYPE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_non_ip_mcast_output_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_non_ip_mcast_output_group_id) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_NON_IP_MCAST_OUTPUT_GROUP_ID, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_ipv4_mcast_output_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_ipv4_mcast_output_group_id) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_IPV4_MCAST_OUTPUT_GROUP_ID, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_ipv6_mcast_output_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_ipv6_mcast_output_group_id) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_IPV6_MCAST_OUTPUT_GROUP_ID, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_linklocal_mcast_output_group_id is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_linklocal_mcast_output_group_id) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_LINKLOCAL_MCAST_OUTPUT_GROUP_ID, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if ingress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=ingress_acl) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_INGRESS_ACL, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if egress_acl is not None: + attr_value = sai_thrift_attribute_value_t(oid=egress_acl) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_EGRESS_ACL, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if meta_data is not None: + attr_value = sai_thrift_attribute_value_t(u32=meta_data) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_META_DATA, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_unicast_flood_control_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=unknown_unicast_flood_control_type) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_unicast_flood_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_unicast_flood_group) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_multicast_flood_control_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=unknown_multicast_flood_control_type) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if unknown_multicast_flood_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=unknown_multicast_flood_group) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if broadcast_flood_control_type is not None: + attr_value = sai_thrift_attribute_value_t(s32=broadcast_flood_control_type) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if broadcast_flood_group is not None: + attr_value = sai_thrift_attribute_value_t(oid=broadcast_flood_group) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_BROADCAST_FLOOD_GROUP, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if custom_igmp_snooping_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=custom_igmp_snooping_enable) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_CUSTOM_IGMP_SNOOPING_ENABLE, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if tam_object is not None: + attr_value = sai_thrift_attribute_value_t(objlist=tam_object) + attr = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_TAM_OBJECT, + value=attr_value) + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_vlan_attribute(vlan_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_vlan_attribute(client, + vlan_oid, + vlan_id=None, + member_list=None, + max_learned_addresses=None, + stp_instance=None, + learn_disable=None, + ipv4_mcast_lookup_key_type=None, + ipv6_mcast_lookup_key_type=None, + unknown_non_ip_mcast_output_group_id=None, + unknown_ipv4_mcast_output_group_id=None, + unknown_ipv6_mcast_output_group_id=None, + unknown_linklocal_mcast_output_group_id=None, + ingress_acl=None, + egress_acl=None, + meta_data=None, + unknown_unicast_flood_control_type=None, + unknown_unicast_flood_group=None, + unknown_multicast_flood_control_type=None, + unknown_multicast_flood_group=None, + broadcast_flood_control_type=None, + broadcast_flood_group=None, + custom_igmp_snooping_enable=None, + tam_object=None, + custom_attribute=None): + """ + sai_get_vlan_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + vlan_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of vlan GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_VLAN_ID) + attr_list.append(attribute) + + if member_list is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=member_list) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_MEMBER_LIST, + value=attribute_value) + attr_list.append(attribute) + + if max_learned_addresses is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES) + attr_list.append(attribute) + + if stp_instance is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_STP_INSTANCE) + attr_list.append(attribute) + + if learn_disable is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_LEARN_DISABLE) + attr_list.append(attribute) + + if ipv4_mcast_lookup_key_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_IPV4_MCAST_LOOKUP_KEY_TYPE) + attr_list.append(attribute) + + if ipv6_mcast_lookup_key_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_IPV6_MCAST_LOOKUP_KEY_TYPE) + attr_list.append(attribute) + + if unknown_non_ip_mcast_output_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_NON_IP_MCAST_OUTPUT_GROUP_ID) + attr_list.append(attribute) + + if unknown_ipv4_mcast_output_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_IPV4_MCAST_OUTPUT_GROUP_ID) + attr_list.append(attribute) + + if unknown_ipv6_mcast_output_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_IPV6_MCAST_OUTPUT_GROUP_ID) + attr_list.append(attribute) + + if unknown_linklocal_mcast_output_group_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_LINKLOCAL_MCAST_OUTPUT_GROUP_ID) + attr_list.append(attribute) + + if ingress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_INGRESS_ACL) + attr_list.append(attribute) + + if egress_acl is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_EGRESS_ACL) + attr_list.append(attribute) + + if meta_data is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_META_DATA) + attr_list.append(attribute) + + if unknown_unicast_flood_control_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE) + attr_list.append(attribute) + + if unknown_unicast_flood_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP) + attr_list.append(attribute) + + if unknown_multicast_flood_control_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE) + attr_list.append(attribute) + + if unknown_multicast_flood_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP) + attr_list.append(attribute) + + if broadcast_flood_control_type is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE) + attr_list.append(attribute) + + if broadcast_flood_group is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_BROADCAST_FLOOD_GROUP) + attr_list.append(attribute) + + if custom_igmp_snooping_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_CUSTOM_IGMP_SNOOPING_ENABLE) + attr_list.append(attribute) + + if tam_object is not None: + attribute_value = sai_thrift_attribute_value_t(objlist=tam_object) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_ATTR_TAM_OBJECT, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_vlan_attribute(vlan_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_VLAN_ATTR_VLAN_ID: + attrs["SAI_VLAN_ATTR_VLAN_ID"] = attr.value.u16 + attrs["vlan_id"] = attr.value.u16 + + if attr.id == SAI_VLAN_ATTR_MEMBER_LIST: + attrs["SAI_VLAN_ATTR_MEMBER_LIST"] = attr.value.objlist + attrs["member_list"] = attr.value.objlist + + if attr.id == SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES: + attrs["SAI_VLAN_ATTR_MAX_LEARNED_ADDRESSES"] = attr.value.u32 + attrs["max_learned_addresses"] = attr.value.u32 + + if attr.id == SAI_VLAN_ATTR_STP_INSTANCE: + attrs["SAI_VLAN_ATTR_STP_INSTANCE"] = attr.value.oid + attrs["stp_instance"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_LEARN_DISABLE: + attrs["SAI_VLAN_ATTR_LEARN_DISABLE"] = attr.value.booldata + attrs["learn_disable"] = attr.value.booldata + + if attr.id == SAI_VLAN_ATTR_IPV4_MCAST_LOOKUP_KEY_TYPE: + attrs["SAI_VLAN_ATTR_IPV4_MCAST_LOOKUP_KEY_TYPE"] = attr.value.s32 + attrs["ipv4_mcast_lookup_key_type"] = attr.value.s32 + + if attr.id == SAI_VLAN_ATTR_IPV6_MCAST_LOOKUP_KEY_TYPE: + attrs["SAI_VLAN_ATTR_IPV6_MCAST_LOOKUP_KEY_TYPE"] = attr.value.s32 + attrs["ipv6_mcast_lookup_key_type"] = attr.value.s32 + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_NON_IP_MCAST_OUTPUT_GROUP_ID: + attrs["SAI_VLAN_ATTR_UNKNOWN_NON_IP_MCAST_OUTPUT_GROUP_ID"] = attr.value.oid + attrs["unknown_non_ip_mcast_output_group_id"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_IPV4_MCAST_OUTPUT_GROUP_ID: + attrs["SAI_VLAN_ATTR_UNKNOWN_IPV4_MCAST_OUTPUT_GROUP_ID"] = attr.value.oid + attrs["unknown_ipv4_mcast_output_group_id"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_IPV6_MCAST_OUTPUT_GROUP_ID: + attrs["SAI_VLAN_ATTR_UNKNOWN_IPV6_MCAST_OUTPUT_GROUP_ID"] = attr.value.oid + attrs["unknown_ipv6_mcast_output_group_id"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_LINKLOCAL_MCAST_OUTPUT_GROUP_ID: + attrs["SAI_VLAN_ATTR_UNKNOWN_LINKLOCAL_MCAST_OUTPUT_GROUP_ID"] = attr.value.oid + attrs["unknown_linklocal_mcast_output_group_id"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_INGRESS_ACL: + attrs["SAI_VLAN_ATTR_INGRESS_ACL"] = attr.value.oid + attrs["ingress_acl"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_EGRESS_ACL: + attrs["SAI_VLAN_ATTR_EGRESS_ACL"] = attr.value.oid + attrs["egress_acl"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_META_DATA: + attrs["SAI_VLAN_ATTR_META_DATA"] = attr.value.u32 + attrs["meta_data"] = attr.value.u32 + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE: + attrs["SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_CONTROL_TYPE"] = attr.value.s32 + attrs["unknown_unicast_flood_control_type"] = attr.value.s32 + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP: + attrs["SAI_VLAN_ATTR_UNKNOWN_UNICAST_FLOOD_GROUP"] = attr.value.oid + attrs["unknown_unicast_flood_group"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE: + attrs["SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_CONTROL_TYPE"] = attr.value.s32 + attrs["unknown_multicast_flood_control_type"] = attr.value.s32 + + if attr.id == SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP: + attrs["SAI_VLAN_ATTR_UNKNOWN_MULTICAST_FLOOD_GROUP"] = attr.value.oid + attrs["unknown_multicast_flood_group"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE: + attrs["SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE"] = attr.value.s32 + attrs["broadcast_flood_control_type"] = attr.value.s32 + + if attr.id == SAI_VLAN_ATTR_BROADCAST_FLOOD_GROUP: + attrs["SAI_VLAN_ATTR_BROADCAST_FLOOD_GROUP"] = attr.value.oid + attrs["broadcast_flood_group"] = attr.value.oid + + if attr.id == SAI_VLAN_ATTR_CUSTOM_IGMP_SNOOPING_ENABLE: + attrs["SAI_VLAN_ATTR_CUSTOM_IGMP_SNOOPING_ENABLE"] = attr.value.booldata + attrs["custom_igmp_snooping_enable"] = attr.value.booldata + + if attr.id == SAI_VLAN_ATTR_TAM_OBJECT: + attrs["SAI_VLAN_ATTR_TAM_OBJECT"] = attr.value.objlist + attrs["tam_object"] = attr.value.objlist + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_create_vlan_member(client, + vlan_id=None, + bridge_port_id=None, + vlan_tagging_mode=None, + custom_attribute=None): + """ + sai_create_vlan_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of vlan_member CREATE attributes. + + Returns: + sai_thrift_object_id_t: vlan_member_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vlan_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=vlan_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_VLAN_ID, + value=attribute_value) + attr_list.append(attribute) + + if bridge_port_id is not None: + attribute_value = sai_thrift_attribute_value_t(oid=bridge_port_id) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID, + value=attribute_value) + attr_list.append(attribute) + + if vlan_tagging_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=vlan_tagging_mode) + attribute = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_vlan_member(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_vlan_member(client, + vlan_member_oid): + """ + sai_remove_vlan_member() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + vlan_member_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_vlan_member(vlan_member_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_vlan_member_attribute(client, + vlan_member_oid, + vlan_tagging_mode=None, + custom_attribute=None): + """ + sai_set_vlan_member_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + vlan_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of vlan_member SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if vlan_tagging_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=vlan_tagging_mode) + attr = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE, + value=attr_value) + client.sai_thrift_set_vlan_member_attribute(vlan_member_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_vlan_member_attribute(vlan_member_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_vlan_member_attribute(client, + vlan_member_oid, + vlan_id=None, + bridge_port_id=None, + vlan_tagging_mode=None, + custom_attribute=None): + """ + sai_get_vlan_member_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + vlan_member_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of vlan_member GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if vlan_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_VLAN_ID) + attr_list.append(attribute) + + if bridge_port_id is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID) + attr_list.append(attribute) + + if vlan_tagging_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_vlan_member_attribute(vlan_member_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_VLAN_MEMBER_ATTR_VLAN_ID: + attrs["SAI_VLAN_MEMBER_ATTR_VLAN_ID"] = attr.value.oid + attrs["vlan_id"] = attr.value.oid + + if attr.id == SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID: + attrs["SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID"] = attr.value.oid + attrs["bridge_port_id"] = attr.value.oid + + if attr.id == SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE: + attrs["SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE"] = attr.value.s32 + attrs["vlan_tagging_mode"] = attr.value.s32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs + + +def sai_thrift_get_vlan_stats(client, + vlan_oid): + """ + sai_get_vlan_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + vlan_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_VLAN_STAT_IN_OCTETS) + counter_ids.append(SAI_VLAN_STAT_IN_PACKETS) + counter_ids.append(SAI_VLAN_STAT_IN_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_IN_DISCARDS) + counter_ids.append(SAI_VLAN_STAT_IN_ERRORS) + counter_ids.append(SAI_VLAN_STAT_IN_UNKNOWN_PROTOS) + counter_ids.append(SAI_VLAN_STAT_OUT_OCTETS) + counter_ids.append(SAI_VLAN_STAT_OUT_PACKETS) + counter_ids.append(SAI_VLAN_STAT_OUT_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_OUT_DISCARDS) + counter_ids.append(SAI_VLAN_STAT_OUT_ERRORS) + counter_ids.append(SAI_VLAN_STAT_OUT_QLEN) + + counters = [0] * 14 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_vlan_stats(vlan_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_VLAN_STAT_IN_OCTETS"] = counters[0] + stats["SAI_VLAN_STAT_IN_PACKETS"] = counters[1] + stats["SAI_VLAN_STAT_IN_UCAST_PKTS"] = counters[2] + stats["SAI_VLAN_STAT_IN_NON_UCAST_PKTS"] = counters[3] + stats["SAI_VLAN_STAT_IN_DISCARDS"] = counters[4] + stats["SAI_VLAN_STAT_IN_ERRORS"] = counters[5] + stats["SAI_VLAN_STAT_IN_UNKNOWN_PROTOS"] = counters[6] + stats["SAI_VLAN_STAT_OUT_OCTETS"] = counters[7] + stats["SAI_VLAN_STAT_OUT_PACKETS"] = counters[8] + stats["SAI_VLAN_STAT_OUT_UCAST_PKTS"] = counters[9] + stats["SAI_VLAN_STAT_OUT_NON_UCAST_PKTS"] = counters[10] + stats["SAI_VLAN_STAT_OUT_DISCARDS"] = counters[11] + stats["SAI_VLAN_STAT_OUT_ERRORS"] = counters[12] + stats["SAI_VLAN_STAT_OUT_QLEN"] = counters[13] + + return stats + + +def sai_thrift_get_vlan_stats_ext(client, + vlan_oid, + mode): + """ + sai_get_vlan_stats_ext() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + vlan_oid(sai_thrift_object_id_t): object_id IN argument + mode(sai_thrift_stats_mode_t): stats_mode IN argument + + Returns: + Dict[str, sai_thrift_uint64_t]: stats + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_VLAN_STAT_IN_OCTETS) + counter_ids.append(SAI_VLAN_STAT_IN_PACKETS) + counter_ids.append(SAI_VLAN_STAT_IN_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_IN_DISCARDS) + counter_ids.append(SAI_VLAN_STAT_IN_ERRORS) + counter_ids.append(SAI_VLAN_STAT_IN_UNKNOWN_PROTOS) + counter_ids.append(SAI_VLAN_STAT_OUT_OCTETS) + counter_ids.append(SAI_VLAN_STAT_OUT_PACKETS) + counter_ids.append(SAI_VLAN_STAT_OUT_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_OUT_DISCARDS) + counter_ids.append(SAI_VLAN_STAT_OUT_ERRORS) + counter_ids.append(SAI_VLAN_STAT_OUT_QLEN) + + counters = [0] * 14 + global status + status = SAI_STATUS_SUCCESS + + try: + counters = client.sai_thrift_get_vlan_stats_ext(vlan_oid, counter_ids, mode) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + pass + else: + raise e + + stats = dict() + + stats["SAI_VLAN_STAT_IN_OCTETS"] = counters[0] + stats["SAI_VLAN_STAT_IN_PACKETS"] = counters[1] + stats["SAI_VLAN_STAT_IN_UCAST_PKTS"] = counters[2] + stats["SAI_VLAN_STAT_IN_NON_UCAST_PKTS"] = counters[3] + stats["SAI_VLAN_STAT_IN_DISCARDS"] = counters[4] + stats["SAI_VLAN_STAT_IN_ERRORS"] = counters[5] + stats["SAI_VLAN_STAT_IN_UNKNOWN_PROTOS"] = counters[6] + stats["SAI_VLAN_STAT_OUT_OCTETS"] = counters[7] + stats["SAI_VLAN_STAT_OUT_PACKETS"] = counters[8] + stats["SAI_VLAN_STAT_OUT_UCAST_PKTS"] = counters[9] + stats["SAI_VLAN_STAT_OUT_NON_UCAST_PKTS"] = counters[10] + stats["SAI_VLAN_STAT_OUT_DISCARDS"] = counters[11] + stats["SAI_VLAN_STAT_OUT_ERRORS"] = counters[12] + stats["SAI_VLAN_STAT_OUT_QLEN"] = counters[13] + + return stats + + +def sai_thrift_clear_vlan_stats(client, + vlan_oid): + """ + sai_clear_vlan_stats() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + vlan_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + counter_ids = [] + + counter_ids.append(SAI_VLAN_STAT_IN_OCTETS) + counter_ids.append(SAI_VLAN_STAT_IN_PACKETS) + counter_ids.append(SAI_VLAN_STAT_IN_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_IN_NON_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_IN_DISCARDS) + counter_ids.append(SAI_VLAN_STAT_IN_ERRORS) + counter_ids.append(SAI_VLAN_STAT_IN_UNKNOWN_PROTOS) + counter_ids.append(SAI_VLAN_STAT_OUT_OCTETS) + counter_ids.append(SAI_VLAN_STAT_OUT_PACKETS) + counter_ids.append(SAI_VLAN_STAT_OUT_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_OUT_NON_UCAST_PKTS) + counter_ids.append(SAI_VLAN_STAT_OUT_DISCARDS) + counter_ids.append(SAI_VLAN_STAT_OUT_ERRORS) + counter_ids.append(SAI_VLAN_STAT_OUT_QLEN) + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_clear_vlan_stats(vlan_oid, counter_ids) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +# wred API + +def sai_thrift_create_wred(client, + green_enable=None, + green_min_threshold=None, + green_max_threshold=None, + green_drop_probability=None, + yellow_enable=None, + yellow_min_threshold=None, + yellow_max_threshold=None, + yellow_drop_probability=None, + red_enable=None, + red_min_threshold=None, + red_max_threshold=None, + red_drop_probability=None, + weight=None, + ecn_mark_mode=None, + ecn_green_min_threshold=None, + ecn_green_max_threshold=None, + ecn_green_mark_probability=None, + ecn_yellow_min_threshold=None, + ecn_yellow_max_threshold=None, + ecn_yellow_mark_probability=None, + ecn_red_min_threshold=None, + ecn_red_max_threshold=None, + ecn_red_mark_probability=None, + ecn_color_unaware_min_threshold=None, + ecn_color_unaware_max_threshold=None, + ecn_color_unaware_mark_probability=None, + custom_attribute=None): + """ + sai_create_wred() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + + For the other parameters, see documentation of wred CREATE attributes. + + Returns: + sai_thrift_object_id_t: wred_oid + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if green_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=green_enable) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if green_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=green_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if green_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=green_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if green_drop_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=green_drop_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_DROP_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if yellow_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=yellow_enable) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if yellow_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=yellow_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if yellow_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=yellow_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if yellow_drop_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=yellow_drop_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if red_enable is not None: + attribute_value = sai_thrift_attribute_value_t(booldata=red_enable) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_ENABLE, + value=attribute_value) + attr_list.append(attribute) + + if red_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=red_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if red_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=red_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if red_drop_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=red_drop_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_DROP_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if weight is not None: + attribute_value = sai_thrift_attribute_value_t(u8=weight) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_WEIGHT, + value=attribute_value) + attr_list.append(attribute) + + if ecn_mark_mode is not None: + attribute_value = sai_thrift_attribute_value_t(s32=ecn_mark_mode) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_MARK_MODE, + value=attribute_value) + attr_list.append(attribute) + + if ecn_green_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_green_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_green_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_green_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_green_mark_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_green_mark_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MARK_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if ecn_yellow_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_yellow_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_yellow_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_yellow_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_yellow_mark_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_yellow_mark_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MARK_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if ecn_red_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_red_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_red_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_red_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_red_mark_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_red_mark_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MARK_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if ecn_color_unaware_min_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_color_unaware_min_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MIN_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_color_unaware_max_threshold is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_color_unaware_max_threshold) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MAX_THRESHOLD, + value=attribute_value) + attr_list.append(attribute) + + if ecn_color_unaware_mark_probability is not None: + attribute_value = sai_thrift_attribute_value_t(u32=ecn_color_unaware_mark_probability) + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MARK_PROBABILITY, + value=attribute_value) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + global status + status = SAI_STATUS_SUCCESS + + try: + return client.sai_thrift_create_wred(attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return SAI_NULL_OBJECT_ID + else: + raise e + + +def sai_thrift_remove_wred(client, + wred_oid): + """ + sai_remove_wred() - RPC client function implementation. + + Args: + client (Client): SAI RPC client + wred_oid(sai_thrift_object_id_t): object_id IN argument + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + global status + status = SAI_STATUS_SUCCESS + + try: + client.sai_thrift_remove_wred(wred_oid) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_set_wred_attribute(client, + wred_oid, + green_enable=None, + green_min_threshold=None, + green_max_threshold=None, + green_drop_probability=None, + yellow_enable=None, + yellow_min_threshold=None, + yellow_max_threshold=None, + yellow_drop_probability=None, + red_enable=None, + red_min_threshold=None, + red_max_threshold=None, + red_drop_probability=None, + weight=None, + ecn_mark_mode=None, + ecn_green_min_threshold=None, + ecn_green_max_threshold=None, + ecn_green_mark_probability=None, + ecn_yellow_min_threshold=None, + ecn_yellow_max_threshold=None, + ecn_yellow_mark_probability=None, + ecn_red_min_threshold=None, + ecn_red_max_threshold=None, + ecn_red_mark_probability=None, + ecn_color_unaware_min_threshold=None, + ecn_color_unaware_max_threshold=None, + ecn_color_unaware_mark_probability=None, + custom_attribute=None): + """ + sai_set_wred_attribute() - RPC client function implementation. + + Note, that only one attribute can be set at once. + + Args: + client (Client): SAI RPC client + wred_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of wred SET attributes. + + Returns: + status: the error code + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr = None + global status + status = SAI_STATUS_SUCCESS + + try: + if green_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=green_enable) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_ENABLE, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if green_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=green_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if green_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=green_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if green_drop_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=green_drop_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_DROP_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if yellow_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=yellow_enable) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_ENABLE, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if yellow_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=yellow_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if yellow_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=yellow_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if yellow_drop_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=yellow_drop_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if red_enable is not None: + attr_value = sai_thrift_attribute_value_t(booldata=red_enable) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_ENABLE, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if red_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=red_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if red_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=red_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if red_drop_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=red_drop_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_DROP_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if weight is not None: + attr_value = sai_thrift_attribute_value_t(u8=weight) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_WEIGHT, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_mark_mode is not None: + attr_value = sai_thrift_attribute_value_t(s32=ecn_mark_mode) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_MARK_MODE, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_green_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_green_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_green_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_green_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_green_mark_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_green_mark_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MARK_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_yellow_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_yellow_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_yellow_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_yellow_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_yellow_mark_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_yellow_mark_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MARK_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_red_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_red_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_red_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_red_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_red_mark_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_red_mark_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MARK_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_color_unaware_min_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_color_unaware_min_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MIN_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_color_unaware_max_threshold is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_color_unaware_max_threshold) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MAX_THRESHOLD, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if ecn_color_unaware_mark_probability is not None: + attr_value = sai_thrift_attribute_value_t(u32=ecn_color_unaware_mark_probability) + attr = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MARK_PROBABILITY, + value=attr_value) + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + if custom_attribute is not None: + attr = custom_attribute + client.sai_thrift_set_wred_attribute(wred_oid, attr) + + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return status + else: + raise e + + return status + + +def sai_thrift_get_wred_attribute(client, + wred_oid, + green_enable=None, + green_min_threshold=None, + green_max_threshold=None, + green_drop_probability=None, + yellow_enable=None, + yellow_min_threshold=None, + yellow_max_threshold=None, + yellow_drop_probability=None, + red_enable=None, + red_min_threshold=None, + red_max_threshold=None, + red_drop_probability=None, + weight=None, + ecn_mark_mode=None, + ecn_green_min_threshold=None, + ecn_green_max_threshold=None, + ecn_green_mark_probability=None, + ecn_yellow_min_threshold=None, + ecn_yellow_max_threshold=None, + ecn_yellow_mark_probability=None, + ecn_red_min_threshold=None, + ecn_red_max_threshold=None, + ecn_red_mark_probability=None, + ecn_color_unaware_min_threshold=None, + ecn_color_unaware_max_threshold=None, + ecn_color_unaware_mark_probability=None, + custom_attribute=None): + """ + sai_get_wred_attribute() - 'get attribute' RPC client function implementation. + + To get a specified attribute, set the argument to 'True'. + If getting attribute requires specified input (like + number of list elements), then set the correct value (e.g. + empty list of specified number of elements) instead. + + Args: + client (Client): SAI RPC client + wred_oid(sai_thrift_object_id_t): object_id IN argument + + For the other parameters, see documentation of wred GET attributes. + + Returns: + Dict[str, sai_thrift_attribute_t]: attrs + + Raises: + sai_thrift_exception: If an error occured + and sai_adapter.CATCH_EXCEPTIONS is False. + """ + + attr_list = [] + + if green_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_ENABLE) + attr_list.append(attribute) + + if green_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_MIN_THRESHOLD) + attr_list.append(attribute) + + if green_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_MAX_THRESHOLD) + attr_list.append(attribute) + + if green_drop_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_GREEN_DROP_PROBABILITY) + attr_list.append(attribute) + + if yellow_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_ENABLE) + attr_list.append(attribute) + + if yellow_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_MIN_THRESHOLD) + attr_list.append(attribute) + + if yellow_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_MAX_THRESHOLD) + attr_list.append(attribute) + + if yellow_drop_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY) + attr_list.append(attribute) + + if red_enable is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_ENABLE) + attr_list.append(attribute) + + if red_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_MIN_THRESHOLD) + attr_list.append(attribute) + + if red_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_MAX_THRESHOLD) + attr_list.append(attribute) + + if red_drop_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_RED_DROP_PROBABILITY) + attr_list.append(attribute) + + if weight is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_WEIGHT) + attr_list.append(attribute) + + if ecn_mark_mode is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_MARK_MODE) + attr_list.append(attribute) + + if ecn_green_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MIN_THRESHOLD) + attr_list.append(attribute) + + if ecn_green_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MAX_THRESHOLD) + attr_list.append(attribute) + + if ecn_green_mark_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_GREEN_MARK_PROBABILITY) + attr_list.append(attribute) + + if ecn_yellow_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MIN_THRESHOLD) + attr_list.append(attribute) + + if ecn_yellow_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MAX_THRESHOLD) + attr_list.append(attribute) + + if ecn_yellow_mark_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_YELLOW_MARK_PROBABILITY) + attr_list.append(attribute) + + if ecn_red_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MIN_THRESHOLD) + attr_list.append(attribute) + + if ecn_red_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MAX_THRESHOLD) + attr_list.append(attribute) + + if ecn_red_mark_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_RED_MARK_PROBABILITY) + attr_list.append(attribute) + + if ecn_color_unaware_min_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MIN_THRESHOLD) + attr_list.append(attribute) + + if ecn_color_unaware_max_threshold is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MAX_THRESHOLD) + attr_list.append(attribute) + + if ecn_color_unaware_mark_probability is not None: + attribute = sai_thrift_attribute_t(id=SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MARK_PROBABILITY) + attr_list.append(attribute) + + if custom_attribute is not None: + attr_list.append(custom_attribute) + + attr_list = sai_thrift_attribute_list_t(attr_list=attr_list) + global status + status = SAI_STATUS_SUCCESS + + try: + attr_list = client.sai_thrift_get_wred_attribute(wred_oid, attr_list) + except sai_thrift_exception as e: + status = e.status + if CATCH_EXCEPTIONS: + return None + else: + raise e + + attrs = dict() + + for attr in attr_list.attr_list: + if attr.id == SAI_WRED_ATTR_GREEN_ENABLE: + attrs["SAI_WRED_ATTR_GREEN_ENABLE"] = attr.value.booldata + attrs["green_enable"] = attr.value.booldata + + if attr.id == SAI_WRED_ATTR_GREEN_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_GREEN_MIN_THRESHOLD"] = attr.value.u32 + attrs["green_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_GREEN_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_GREEN_MAX_THRESHOLD"] = attr.value.u32 + attrs["green_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_GREEN_DROP_PROBABILITY: + attrs["SAI_WRED_ATTR_GREEN_DROP_PROBABILITY"] = attr.value.u32 + attrs["green_drop_probability"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_YELLOW_ENABLE: + attrs["SAI_WRED_ATTR_YELLOW_ENABLE"] = attr.value.booldata + attrs["yellow_enable"] = attr.value.booldata + + if attr.id == SAI_WRED_ATTR_YELLOW_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_YELLOW_MIN_THRESHOLD"] = attr.value.u32 + attrs["yellow_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_YELLOW_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_YELLOW_MAX_THRESHOLD"] = attr.value.u32 + attrs["yellow_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY: + attrs["SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY"] = attr.value.u32 + attrs["yellow_drop_probability"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_RED_ENABLE: + attrs["SAI_WRED_ATTR_RED_ENABLE"] = attr.value.booldata + attrs["red_enable"] = attr.value.booldata + + if attr.id == SAI_WRED_ATTR_RED_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_RED_MIN_THRESHOLD"] = attr.value.u32 + attrs["red_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_RED_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_RED_MAX_THRESHOLD"] = attr.value.u32 + attrs["red_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_RED_DROP_PROBABILITY: + attrs["SAI_WRED_ATTR_RED_DROP_PROBABILITY"] = attr.value.u32 + attrs["red_drop_probability"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_WEIGHT: + attrs["SAI_WRED_ATTR_WEIGHT"] = attr.value.u8 + attrs["weight"] = attr.value.u8 + + if attr.id == SAI_WRED_ATTR_ECN_MARK_MODE: + attrs["SAI_WRED_ATTR_ECN_MARK_MODE"] = attr.value.s32 + attrs["ecn_mark_mode"] = attr.value.s32 + + if attr.id == SAI_WRED_ATTR_ECN_GREEN_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_GREEN_MIN_THRESHOLD"] = attr.value.u32 + attrs["ecn_green_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_GREEN_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_GREEN_MAX_THRESHOLD"] = attr.value.u32 + attrs["ecn_green_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_GREEN_MARK_PROBABILITY: + attrs["SAI_WRED_ATTR_ECN_GREEN_MARK_PROBABILITY"] = attr.value.u32 + attrs["ecn_green_mark_probability"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_YELLOW_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_YELLOW_MIN_THRESHOLD"] = attr.value.u32 + attrs["ecn_yellow_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_YELLOW_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_YELLOW_MAX_THRESHOLD"] = attr.value.u32 + attrs["ecn_yellow_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_YELLOW_MARK_PROBABILITY: + attrs["SAI_WRED_ATTR_ECN_YELLOW_MARK_PROBABILITY"] = attr.value.u32 + attrs["ecn_yellow_mark_probability"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_RED_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_RED_MIN_THRESHOLD"] = attr.value.u32 + attrs["ecn_red_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_RED_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_RED_MAX_THRESHOLD"] = attr.value.u32 + attrs["ecn_red_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_RED_MARK_PROBABILITY: + attrs["SAI_WRED_ATTR_ECN_RED_MARK_PROBABILITY"] = attr.value.u32 + attrs["ecn_red_mark_probability"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MIN_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MIN_THRESHOLD"] = attr.value.u32 + attrs["ecn_color_unaware_min_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MAX_THRESHOLD: + attrs["SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MAX_THRESHOLD"] = attr.value.u32 + attrs["ecn_color_unaware_max_threshold"] = attr.value.u32 + + if attr.id == SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MARK_PROBABILITY: + attrs["SAI_WRED_ATTR_ECN_COLOR_UNAWARE_MARK_PROBABILITY"] = attr.value.u32 + attrs["ecn_color_unaware_mark_probability"] = attr.value.u32 + + if custom_attribute is not None: + if attr.id == custom_attribute.id: + attrs["custom_attribute"] = attr + + return attrs diff --git a/ptf/sai_base_test.py b/ptf/sai_base_test.py index 6feeee96d..cebc089cb 100644 --- a/ptf/sai_base_test.py +++ b/ptf/sai_base_test.py @@ -36,7 +36,7 @@ from sai_thrift import sai_rpc from sai_utils import * -import sai_thrift.sai_adapter as adapter +import sai_adapter as adapter ROUTER_MAC = '00:77:66:55:44:00' THRIFT_PORT = 9092 diff --git a/ptf/sai_utils.py b/ptf/sai_utils.py index 1cc3b611d..d535423bf 100644 --- a/ptf/sai_utils.py +++ b/ptf/sai_utils.py @@ -25,7 +25,7 @@ from ptf.packet import * from ptf.testutils import * -from sai_thrift.sai_adapter import * +from sai_adapter import * def sai_thrift_query_attribute_enum_values_capability(client, diff --git a/ptf/saineighbor.py b/ptf/saineighbor.py index 52fc9e43c..1b34ac855 100644 --- a/ptf/saineighbor.py +++ b/ptf/saineighbor.py @@ -23,7 +23,7 @@ @group("draft") -class NeighborAttrIpv6Test(SaiHelperSimplified): +class NeighborAttrIpv6TestHelper(PlatformSaiHelper): """ Neighbor entry attributes IPv6 tests class Configuration @@ -35,7 +35,7 @@ class NeighborAttrIpv6Test(SaiHelperSimplified): """ def setUp(self): - super(NeighborAttrIpv6Test, self).setUp() + super(NeighborAttrIpv6TestHelper, self).setUp() self.create_routing_interfaces(ports=[0, 1]) @@ -56,34 +56,34 @@ def setUp(self): ipv6_dst=self.ll_ipv6_addr, ipv6_hlim=64) - def runTest(self): - self.noHostRouteIpv6NeighborTest() - self.noHostRouteIpv6LinkLocalNeighborTest() - self.addHostRouteIpv6NeighborTest() - def tearDown(self): self.destroy_routing_interfaces() - super(NeighborAttrIpv6Test, self).tearDown() + super(NeighborAttrIpv6TestHelper, self).tearDown() + + +class noHostRouteIpv6NeighborTest(NeighborAttrIpv6TestHelper): + ''' + Verifies if IPv6 host route is not created according to + SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value + ''' + def setUp(self): + super(noHostRouteIpv6NeighborTest, self).setUp() - def noHostRouteIpv6NeighborTest(self): - ''' - Verifies if IPv6 host route is not created according to - SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value - ''' + def runTest(self): print("\nnoHostRouteIpv6NeighborTest()") - try: - nbr_entry_v6 = sai_thrift_neighbor_entry_t( - rif_id=self.test_rif, - ip_address=sai_ipaddress(self.ipv6_addr)) - status = sai_thrift_create_neighbor_entry( - self.client, - nbr_entry_v6, - dst_mac_address=self.mac_addr, - no_host_route=True) - self.assertEqual(status, SAI_STATUS_SUCCESS) + nbr_entry_v6 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ipv6_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v6, + dst_mac_address=self.mac_addr, + no_host_route=True) + self.assertEqual(status, SAI_STATUS_SUCCESS) + try: print("Sending IPv6 packet when host route not exists") send_packet(self, self.dev_port1, self.pkt_v6) verify_no_other_packets(self) @@ -92,25 +92,33 @@ def noHostRouteIpv6NeighborTest(self): finally: sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v6) - def noHostRouteIpv6LinkLocalNeighborTest(self): - ''' - Verifies if host route is not created for link local IPv6 address - irrespective of SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute - value - ''' + def tearDown(self): + super(noHostRouteIpv6NeighborTest, self).tearDown() + + +class noHostRouteIpv6LinkLocalNeighborTest(NeighborAttrIpv6TestHelper): + ''' + Verifies if host route is not created for link local IPv6 address + irrespective of SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute + value + ''' + def setUp(self): + super(noHostRouteIpv6LinkLocalNeighborTest, self).setUp() + + def runTest(self): print("\nnoHostRouteIpv6LinkLocalNeighborTest()") - try: - ll_nbr_entry_1 = sai_thrift_neighbor_entry_t( - rif_id=self.test_rif, - ip_address=sai_ipaddress(self.ll_ipv6_addr)) - status = sai_thrift_create_neighbor_entry( - self.client, - ll_nbr_entry_1, - dst_mac_address=self.mac_addr, - no_host_route=True) - self.assertEqual(status, SAI_STATUS_SUCCESS) + ll_nbr_entry_1 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ll_ipv6_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + ll_nbr_entry_1, + dst_mac_address=self.mac_addr, + no_host_route=True) + self.assertEqual(status, SAI_STATUS_SUCCESS) + try: print("Sending IPv6 packet - no_host_route was set to True") send_packet(self, self.dev_port1, self.ll_pkt_v6) verify_no_other_packets(self) @@ -138,24 +146,32 @@ def noHostRouteIpv6LinkLocalNeighborTest(self): finally: sai_thrift_remove_neighbor_entry(self.client, ll_nbr_entry_2) - def addHostRouteIpv6NeighborTest(self): - ''' - Verifies if IPv6 host route is created according to - SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value - ''' + def tearDown(self): + super(noHostRouteIpv6LinkLocalNeighborTest, self).tearDown() + + +class addHostRouteIpv6NeighborTest(NeighborAttrIpv6TestHelper): + ''' + Verifies if IPv6 host route is created according to + SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value + ''' + def setUp(self): + super(addHostRouteIpv6NeighborTest, self).setUp() + + def runTest(self): print("\naddHostRouteIpv6NeighborTest()") - try: - nbr_entry_v6 = sai_thrift_neighbor_entry_t( - rif_id=self.test_rif, - ip_address=sai_ipaddress(self.ipv6_addr)) - status = sai_thrift_create_neighbor_entry( - self.client, - nbr_entry_v6, - dst_mac_address=self.mac_addr, - no_host_route=False) - self.assertEqual(status, SAI_STATUS_SUCCESS) + nbr_entry_v6 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ipv6_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v6, + dst_mac_address=self.mac_addr, + no_host_route=False) + self.assertEqual(status, SAI_STATUS_SUCCESS) + try: print("Sending IPv6 packet when host route exists") send_packet(self, self.dev_port1, self.pkt_v6) verify_packet(self, self.exp_pkt_v6, self.dev_port0) @@ -164,9 +180,12 @@ def addHostRouteIpv6NeighborTest(self): finally: sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v6) + def tearDown(self): + super(addHostRouteIpv6NeighborTest, self).tearDown() + @group("draft") -class NeighborAttrIpv4Test(SaiHelperSimplified): +class NeighborAttrIpv4TestHelper(PlatformSaiHelper): """ Neighbor entry attributes IPv4 tests class Configuration @@ -177,13 +196,14 @@ class NeighborAttrIpv4Test(SaiHelperSimplified): +----------+-----------+ """ def setUp(self): - super(NeighborAttrIpv4Test, self).setUp() + super(NeighborAttrIpv4TestHelper, self).setUp() self.create_routing_interfaces(ports=[0, 1]) self.test_rif = self.port0_rif self.ipv4_addr = "10.10.10.1" self.mac_addr = "00:10:10:10:10:10" + self.mac_update_addr = "00:22:22:33:44:66" self.pkt_v4 = simple_udp_packet(eth_dst=ROUTER_MAC, ip_dst=self.ipv4_addr, @@ -192,34 +212,39 @@ def setUp(self): eth_src=ROUTER_MAC, ip_dst=self.ipv4_addr, ip_ttl=63) - - def runTest(self): - self.noHostRouteIpv4NeighborTest() - self.addHostRouteIpv4NeighborTest() + self.exp_updt_mac_pkt = simple_udp_packet(eth_dst=self.mac_update_addr, + eth_src=ROUTER_MAC, + ip_dst=self.ipv4_addr, + ip_ttl=63) def tearDown(self): self.destroy_routing_interfaces() - super(NeighborAttrIpv4Test, self).tearDown() + super(NeighborAttrIpv4TestHelper, self).tearDown() + +class noHostRouteIpv4NeighborTest(NeighborAttrIpv4TestHelper): + ''' + Verifies if IPv4 host route is not created according to + SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value + ''' - def noHostRouteIpv4NeighborTest(self): - ''' - Verifies if IPv4 host route is not created according to - SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value - ''' + def setUp(self): + super(noHostRouteIpv4NeighborTest, self).setUp() + + def runTest(self): print("\nnoHostRouteIpv4NeighborTest()") - try: - nbr_entry_v4 = sai_thrift_neighbor_entry_t( - rif_id=self.test_rif, - ip_address=sai_ipaddress(self.ipv4_addr)) - status = sai_thrift_create_neighbor_entry( - self.client, - nbr_entry_v4, - dst_mac_address=self.mac_addr, - no_host_route=True) - self.assertEqual(status, SAI_STATUS_SUCCESS) + nbr_entry_v4 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ipv4_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v4, + dst_mac_address=self.mac_addr, + no_host_route=True) + self.assertEqual(status, SAI_STATUS_SUCCESS) + try: print("Sending IPv4 packet when host route not exists") send_packet(self, self.dev_port1, self.pkt_v4) verify_no_other_packets(self) @@ -228,28 +253,194 @@ def noHostRouteIpv4NeighborTest(self): finally: sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v4) - def addHostRouteIpv4NeighborTest(self): - ''' - Verifies if IPv4 host route is created according to - SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value - ''' + def tearDown(self): + super(noHostRouteIpv4NeighborTest, self).tearDown() + + +class addHostRouteIpv4NeighborTest(NeighborAttrIpv4TestHelper): + ''' + Verifies if IPv4 host route is created according to + SAI_NEIGHBOR_ENTRY_ATTR_NO_HOST_ROUTE attribute value + ''' + + def setUp(self): + super(addHostRouteIpv4NeighborTest, self).setUp() + + def runTest(self): print("\naddHostRouteIpv4NeighborTest()") + nbr_entry_v4 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ipv4_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v4, + dst_mac_address=self.mac_addr, + no_host_route=False) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + try: + print("Sending IPv4 packet when host route exists") + send_packet(self, self.dev_port1, self.pkt_v4) + verify_packet(self, self.exp_pkt_v4, self.dev_port0) + print("Packet forwarded") + + finally: + sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v4) + + def tearDown(self): + super(addHostRouteIpv4NeighborTest, self).tearDown() + + +class updateNeighborEntryAttributeDstMacAddr(NeighborAttrIpv4TestHelper): + ''' + Verifies if SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS is updated + ''' + + def setUp(self): + super(updateNeighborEntryAttributeDstMacAddr, self).setUp() + + def runTest(self): + print("\nupdateNeighborEntryAttributeDstMacAddr()") + + nbr_entry_v4 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ipv4_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v4, + dst_mac_address=self.mac_addr) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + try: + print("Sending IPv4 packet before updating the destination mac") + send_packet(self, self.dev_port1, self.pkt_v4) + verify_packet(self, self.exp_pkt_v4, self.dev_port0) + print("Packet forwarded") + print("Update neighbor to 00:22:22:33:44:66") + status = sai_thrift_set_neighbor_entry_attribute( + self.client, + nbr_entry_v4, + dst_mac_address="00:22:22:33:44:66") + + self.assertEqual(status, SAI_STATUS_SUCCESS) + + attr = sai_thrift_get_neighbor_entry_attribute( + self.client, nbr_entry_v4, dst_mac_address=True) + self.assertEqual(attr['dst_mac_address'], '00:22:22:33:44:66') + + print("Sending IPv4 packet after updating the destination mac") + send_packet(self, self.dev_port1, self.pkt_v4) + verify_packet(self, self.exp_updt_mac_pkt, self.dev_port0) + print("Packet forwarded") + + finally: + sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v4) + + def tearDown(self): + super(updateNeighborEntryAttributeDstMacAddr, self).tearDown() + + +class addNeighborEntryAttrIPv4addrFamily(NeighborAttrIpv4TestHelper): + ''' + check NeighborEntryAttrIPaddrFamily is SAI_IP_ADDR_FAMILY_IPV4 + ''' + + def setUp(self): + super(addNeighborEntryAttrIPv4addrFamily, self).setUp() + + def runTest(self): + print("\naddNeighborEntryAttrIPv4addrFamily()") + try: + before_ipv4_neighbor_entry = sai_thrift_get_switch_attribute( + self.client, available_ipv4_neighbor_entry=True) nbr_entry_v4 = sai_thrift_neighbor_entry_t( rif_id=self.test_rif, ip_address=sai_ipaddress(self.ipv4_addr)) status = sai_thrift_create_neighbor_entry( self.client, nbr_entry_v4, - dst_mac_address=self.mac_addr, - no_host_route=False) + dst_mac_address=self.mac_addr) self.assertEqual(status, SAI_STATUS_SUCCESS) - print("Sending IPv4 packet when host route exists") - send_packet(self, self.dev_port1, self.pkt_v4) - verify_packet(self, self.exp_pkt_v4, self.dev_port0) - print("Packet forwarded") + nbr_entry_v4_1 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress("10.10.10.2")) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v4_1, + dst_mac_address="00:22:22:33:44:66") + self.assertEqual(status, SAI_STATUS_SUCCESS) + + nbr_entry_v4_2 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress("10.10.10.3")) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v4_2, + dst_mac_address="00:22:22:33:44:88") + self.assertEqual(status, SAI_STATUS_SUCCESS) + + after_ipv4_neighbor_entry = sai_thrift_get_switch_attribute( + self.client, available_ipv4_neighbor_entry=True) + available_ipv4_entries = before_ipv4_neighbor_entry[ + 'available_ipv4_neighbor_entry'] - after_ipv4_neighbor_entry[ + 'available_ipv4_neighbor_entry'] + print("available_ipv4_entries: ", available_ipv4_entries) + self.assertEqual(available_ipv4_entries, 3) finally: sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v4) + sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v4_1) + sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v4_2) + def tearDown(self): + super(addNeighborEntryAttrIPv4addrFamily, self).tearDown() + + +class addNeighborEntryAttrIPv6addrFamily(NeighborAttrIpv6TestHelper): + ''' + check NeighborEntryAttrIPaddrFamily is SAI_IP_ADDR_FAMILY_IPV6 + ''' + + def setUp(self): + super(addNeighborEntryAttrIPv6addrFamily, self).setUp() + + def runTest(self): + print("\naddNeighborEntryAttrIPv6addrFamily()") + + try: + before_ipv6_neighbor_entry = sai_thrift_get_switch_attribute( + self.client, available_ipv6_neighbor_entry=True) + nbr_entry_v6 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress(self.ipv6_addr)) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v6, + dst_mac_address=self.mac_addr) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + nbr_entry_v6_1 = sai_thrift_neighbor_entry_t( + rif_id=self.test_rif, + ip_address=sai_ipaddress("2001:0db8::1:11")) + status = sai_thrift_create_neighbor_entry( + self.client, + nbr_entry_v6_1, + dst_mac_address="00:22:22:33:44:66") + self.assertEqual(status, SAI_STATUS_SUCCESS) + after_ipv6_neighbor_entry = sai_thrift_get_switch_attribute( + self.client, available_ipv6_neighbor_entry=True) + + available_ipv6_entries = before_ipv6_neighbor_entry[ + 'available_ipv6_neighbor_entry'] - after_ipv6_neighbor_entry[ + 'available_ipv6_neighbor_entry'] + print("available_ipv6_entries: ", available_ipv6_entries) + self.assertEqual(available_ipv6_entries, 2) + + finally: + sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v6) + sai_thrift_remove_neighbor_entry(self.client, nbr_entry_v6_1) + + def tearDown(self): + super(addNeighborEntryAttrIPv6addrFamily, self).tearDown() From 28e158b63cf5e1442eeedd2e23aa6e80a48e9c77 Mon Sep 17 00:00:00 2001 From: mounika-adhuri Date: Sun, 20 Nov 2022 21:13:04 -0800 Subject: [PATCH 2/6] Adding changes to SWI-6173_route_refactor branch --- ptf/sairoute.py | 1115 ++++++++++++++++++++++++----------------------- 1 file changed, 578 insertions(+), 537 deletions(-) diff --git a/ptf/sairoute.py b/ptf/sairoute.py index 5809a53ac..053f6c19c 100644 --- a/ptf/sairoute.py +++ b/ptf/sairoute.py @@ -23,19 +23,356 @@ from sai_base_test import * +class multipleRoutesTest(PlatformSaiHelper): + ''' + Verify forwarding with multiple route to the same nhop. + ''' + def setUp(self): + super(multipleRoutesTest, self).setUp() + + def runTest(self): + print("multipleRoutesTest") + dmac = '00:11:22:33:44:55' + + nhop1 = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.2'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + neighbor_entry = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, ip_address=sai_ipaddress('10.10.10.2')) + sai_thrift_create_neighbor_entry(self.client, neighbor_entry, + dst_mac_address=dmac) + + route_entry1 = sai_thrift_route_entry_t( + vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry(self.client, route_entry1, + next_hop_id=nhop1) + + route_entry2 = sai_thrift_route_entry_t( + vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.2/32')) + sai_thrift_create_route_entry(self.client, route_entry2, + next_hop_id=nhop1) + + pkt1 = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + pkt2 = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst='10.10.10.2', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet( + eth_dst='00:11:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet( + eth_dst='00:11:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.2', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + try: + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt1) + verify_packet(self, exp_pkt1, self.dev_port10) + + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt2) + verify_packet(self, exp_pkt2, self.dev_port10) + + finally: + sai_thrift_remove_route_entry(self.client, route_entry1) + sai_thrift_remove_route_entry(self.client, route_entry2) + sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) + sai_thrift_remove_next_hop(self.client, nhop1) + + def tearDown(self): + super(multipleRoutesTest, self).tearDown() + + +class dropRouteTest(PlatformSaiHelper): + ''' + Verify drop route. + ''' + def setUp(self): + super(dropRouteTest, self).setUp() + + def runTest(self): + print("dropRouteTest") + dmac = '00:11:22:33:44:55' + + nhop = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.2'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + neighbor_entry = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, ip_address=sai_ipaddress('10.10.10.2')) + sai_thrift_create_neighbor_entry(self.client, neighbor_entry, + dst_mac_address=dmac) + + route_entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry( + self.client, route_entry, next_hop_id=nhop, + packet_action=SAI_PACKET_ACTION_TRAP) + + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + try: + pre_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + + finally: + sai_thrift_remove_route_entry(self.client, route_entry) + sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) + sai_thrift_remove_next_hop(self.client, nhop) + + def tearDown(self): + super(dropRouteTest, self).tearDown() + + +class routeUpdateTest(PlatformSaiHelper): + ''' + Verify correct forwarding after route update. + ''' + def setUp(self): + super(routeUpdateTest, self).setUp() + + def runTest(self): + print("routeUpdateTest") + dmac = '00:11:22:33:44:55' + dmac2 = '00:11:22:33:44:66' + + nhop1 = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.2'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + neighbor_entry = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, ip_address=sai_ipaddress('10.10.10.2')) + sai_thrift_create_neighbor_entry(self.client, neighbor_entry, + dst_mac_address=dmac) + + route_entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry(self.client, route_entry, + next_hop_id=nhop1) + + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + exp_pkt = simple_tcp_packet( + eth_dst='00:11:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet( + eth_dst='00:11:22:33:44:66', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + try: + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + verify_packet(self, exp_pkt, self.dev_port10) + + print("Updating route nexthop to different nexthop") + nhop2 = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.3'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + neighbor_entry2 = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, ip_address=sai_ipaddress('10.10.10.3')) + sai_thrift_create_neighbor_entry(self.client, neighbor_entry2, + dst_mac_address=dmac2) + sai_thrift_set_route_entry_attribute(self.client, route_entry, + next_hop_id=nhop2) + + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + verify_packet(self, exp_pkt2, self.dev_port10) + + print("Updating route nexthop to drop nexthop") + sai_thrift_set_route_entry_attribute( + self.client, route_entry, packet_action=SAI_PACKET_ACTION_DROP) + + print("Sending packet on port %d, drop" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + verify_no_other_packets(self, timeout=3) + + print("Updating route nexthop to regular nexthop") + sai_thrift_set_route_entry_attribute( + self.client, route_entry, + packet_action=SAI_PACKET_ACTION_FORWARD) + + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + verify_packet(self, exp_pkt2, self.dev_port10) + + print("Updating route nexthop to CPU nexthop") + sai_thrift_set_route_entry_attribute( + self.client, route_entry, packet_action=SAI_PACKET_ACTION_TRAP) + + pre_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + + print("Updating route nexthop to regular nexthop") + sai_thrift_set_route_entry_attribute( + self.client, route_entry, + packet_action=SAI_PACKET_ACTION_FORWARD) + + print("Sending packet on port %d, forward" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) + verify_packet(self, exp_pkt2, self.dev_port10) + + finally: + sai_thrift_remove_route_entry(self.client, route_entry) + sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) + sai_thrift_remove_neighbor_entry(self.client, neighbor_entry2) + sai_thrift_remove_next_hop(self.client, nhop1) + sai_thrift_remove_next_hop(self.client, nhop2) + + def tearDown(self): + super(routeUpdateTest, self).tearDown() + + +class routeIngressRifTest(PlatformSaiHelper): + ''' + Verify forwarding to ingress rif. + ''' + def setUp(self): + super(routeIngressRifTest, self).setUp() + + def runTest(self): + print("routeIngressRifTest") + dmac = '00:11:22:33:44:55' + + nhop1 = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.2'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + neighbor_entry = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, ip_address=sai_ipaddress('10.10.10.2')) + sai_thrift_create_neighbor_entry(self.client, neighbor_entry, + dst_mac_address=dmac) + + route_entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry(self.client, route_entry, + next_hop_id=nhop1) + + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + exp_pkt = simple_tcp_packet( + eth_dst='00:11:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + try: + print("Sending packet on port %d, forward" % self.dev_port10) + send_packet(self, self.dev_port10, pkt) + verify_packet(self, exp_pkt, self.dev_port10) + + finally: + sai_thrift_remove_route_entry(self.client, route_entry) + sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) + sai_thrift_remove_next_hop(self.client, nhop1) + + def tearDown(self): + super(routeIngressRifTest, self).tearDown() + + +class emptyECMPGroupTest(PlatformSaiHelper): + ''' + Verify drop on empty ECMP group. + ''' + def setUp(self): + super(emptyECMPGroupTest, self).setUp() -@group("draft") -class L3RouteSviTest(SaiHelper): - """ - Route SVI test class - """ def runTest(self): - self.sviNeighborTest() + print("emptyECMPGroupTest") + + nhop_group = sai_thrift_create_next_hop_group( + self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) + + route_entry = sai_thrift_route_entry_t( + vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry(self.client, route_entry, + next_hop_id=nhop_group) - def sviNeighborTest(self): - ''' - Function verifying correct SVI neighbor forwarding. - ''' + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst='10.10.10.1', + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + try: + print("Sending packet on port %d, drop" % self.dev_port10) + send_packet(self, self.dev_port10, pkt) + verify_no_other_packets(self, timeout=3) + + finally: + sai_thrift_remove_route_entry(self.client, route_entry) + sai_thrift_remove_next_hop_group(self.client, nhop_group) + + def tearDown(self): + super(emptyECMPGroupTest, self).tearDown() + + +class sviNeighborTest(PlatformSaiHelper): + ''' + Function verifying correct SVI neighbor forwarding. + ''' + def setUp(self): + super(sviNeighborTest, self).setUp() + + def runTest(self): print("sviNeighborTest") port24_bp = sai_thrift_create_bridge_port( @@ -131,13 +468,6 @@ def sviNeighborTest(self): ip_ttl=63) try: - print("Sending packet port %d to ports %d, %d, %d" % - (self.dev_port10, self.dev_port24, self.dev_port25, - self.dev_port26) + "(192.168.0.1 -> 10.10.10.1) Routed") - send_packet(self, self.dev_port10, pkt) - verify_packets(self, exp_pkt, [self.dev_port24, self.dev_port25, - self.dev_port26]) - mac_action = SAI_PACKET_ACTION_FORWARD fdb_entry1 = sai_thrift_fdb_entry_t( switch_id=self.switch_id, mac_address=dmac1, bv_id=vlan100) @@ -194,85 +524,18 @@ def sviNeighborTest(self): sai_thrift_remove_bridge_port(self.client, port25_bp) sai_thrift_remove_bridge_port(self.client, port24_bp) -@group("draft") -class L3RouteTest(SaiHelperSimplified): - """ - Route test class - Configuration - +----------+-----------+ - | port0 | port0_rif | - +----------+-----------+ - | port1 | port1_rif | - +----------+-----------+ - """ - def setUp(self): - super(L3RouteTest, self).setUp() - - self.create_routing_interfaces(ports=[0, 1]) - - def runTest(self): - self.routeIngressRifTest() - self.cpuForwardTest() - self.dropRouteTest() - self.emptyECMPGroupTest() - self.multipleRoutesTest() - self.routeNbrColisionTest() - self.routeUpdateTest() - def tearDown(self): - self.destroy_routing_interfaces() - - super(L3RouteTest, self).tearDown() - - def routeIngressRifTest(self): - ''' - Verify forwarding to ingress rif. - ''' - print("routeIngressRifTest") - dmac = '00:11:22:33:44:55' + super(sviNeighborTest, self).tearDown() - nhop1 = sai_thrift_create_next_hop( - self.client, ip=sai_ipaddress('10.10.10.2'), - router_interface_id=self.port0_rif, - type=SAI_NEXT_HOP_TYPE_IP) - neighbor_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress('10.10.10.2')) - sai_thrift_create_neighbor_entry(self.client, neighbor_entry, - dst_mac_address=dmac) - - route_entry = sai_thrift_route_entry_t( - vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) - sai_thrift_create_route_entry(self.client, route_entry, - next_hop_id=nhop1) - pkt = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - exp_pkt = simple_tcp_packet( - eth_dst='00:11:22:33:44:55', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - try: - print("Sending packet on port %d, forward" % self.dev_port0) - send_packet(self, self.dev_port0, pkt) - verify_packet(self, exp_pkt, self.dev_port0) - - finally: - sai_thrift_remove_route_entry(self.client, route_entry) - sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) - sai_thrift_remove_next_hop(self.client, nhop1) +class cpuForwardTest(PlatformSaiHelper): + ''' + Function verifying forwading to CPU. + ''' + def setUp(self): + super(cpuForwardTest, self).setUp() - def cpuForwardTest(self): - ''' - Function verifying forwarding to CPU. - ''' + def runTest(self): print("cpuForwardTest") cpu_port = sai_thrift_get_switch_attribute(self.client, @@ -307,133 +570,33 @@ def cpuForwardTest(self): pre_stats = sai_thrift_get_queue_stats( self.client, self.cpu_queue4) print("Sending packet on port %d, forward to CPU" % - self.dev_port0) - send_packet(self, self.dev_port0, pkt) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"], - pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) - - finally: - sai_thrift_remove_route_entry(self.client, route_entry) - sai_thrift_remove_hostif_trap(self.client, trap) - sai_thrift_remove_hostif_trap_group(self.client, trap_group) - - def dropRouteTest(self): - ''' - Verify drop route. - ''' - print("dropRouteTest") - dmac = '00:11:22:33:44:55' - - nhop = sai_thrift_create_next_hop( - self.client, ip=sai_ipaddress('10.10.10.2'), - router_interface_id=self.port0_rif, - type=SAI_NEXT_HOP_TYPE_IP) - neighbor_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress('10.10.10.2')) - sai_thrift_create_neighbor_entry(self.client, neighbor_entry, - dst_mac_address=dmac) - - route_entry = sai_thrift_route_entry_t( - vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) - sai_thrift_create_route_entry( - self.client, route_entry, next_hop_id=nhop, - packet_action=SAI_PACKET_ACTION_DROP) - - pkt = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - try: - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_no_other_packets(self, timeout=3) - - finally: - sai_thrift_remove_route_entry(self.client, route_entry) - sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) - sai_thrift_remove_next_hop(self.client, nhop) - - def multipleRoutesTest(self): - ''' - Verify forwarding with multiple route to the same nhop. - ''' - print("multipleRoutesTest") - dmac = '00:11:22:33:44:55' - - nhop1 = sai_thrift_create_next_hop( - self.client, ip=sai_ipaddress('10.10.10.2'), - router_interface_id=self.port0_rif, - type=SAI_NEXT_HOP_TYPE_IP) - neighbor_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress('10.10.10.2')) - sai_thrift_create_neighbor_entry(self.client, neighbor_entry, - dst_mac_address=dmac) - - route_entry1 = sai_thrift_route_entry_t( - vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) - sai_thrift_create_route_entry(self.client, route_entry1, - next_hop_id=nhop1) - - route_entry2 = sai_thrift_route_entry_t( - vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.2/32')) - sai_thrift_create_route_entry(self.client, route_entry2, - next_hop_id=nhop1) - - pkt1 = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - pkt2 = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst='10.10.10.2', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet( - eth_dst='00:11:22:33:44:55', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet( - eth_dst='00:11:22:33:44:55', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.2', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - try: - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt1) - verify_packet(self, exp_pkt1, self.dev_port0) - - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt2) - verify_packet(self, exp_pkt2, self.dev_port0) + self.dev_port10) + send_packet(self, self.dev_port10, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue4) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) finally: - sai_thrift_remove_route_entry(self.client, route_entry1) - sai_thrift_remove_route_entry(self.client, route_entry2) - sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) - sai_thrift_remove_next_hop(self.client, nhop1) + sai_thrift_remove_route_entry(self.client, route_entry) + sai_thrift_remove_hostif_trap(self.client, trap) + sai_thrift_remove_hostif_trap_group(self.client, trap_group) + + def tearDown(self): + super(cpuForwardTest, self).tearDown() + - def routeNbrColisionTest(self): - ''' - Verfies if packet is gleaned to CPU when nexthop id is RIF - for cases with and without a neighbor - ''' +class routeNbrColisionTest(PlatformSaiHelper): + ''' + Verfies if packet is gleaned to CPU when nexthop id is RIF + for cases with and without a neighbor + ''' + def setUp(self): + super(routeNbrColisionTest, self).setUp() + + def runTest(self): print("routeNbrColisionTest") ip_addr = '10.10.10.1' @@ -457,67 +620,66 @@ def routeNbrColisionTest(self): ip_ttl=63) print("Creates nhop with %s ip address and %d router interface id" - % (ip_addr, self.port0_rif)) + % (ip_addr, self.port10_rif)) nhop = sai_thrift_create_next_hop( self.client, ip=sai_ipaddress(ip_addr), - router_interface_id=self.port0_rif, + router_interface_id=self.port10_rif, type=SAI_NEXT_HOP_TYPE_IP) print("Creates neighbor with %s ip address, %d router interface id and" - " %s destination mac" % (ip_addr, self.port0_rif, dmac)) + " %s destination mac" % (ip_addr, self.port10_rif, dmac)) nbr_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress(ip_addr)) + rif_id=self.port10_rif, ip_address=sai_ipaddress(ip_addr)) sai_thrift_create_neighbor_entry( self.client, nbr_entry, dst_mac_address=dmac) try: print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port1, self.dev_port0, pkt_ip_src, pkt_ip_dst)) - send_packet(self, self.dev_port1, pkt) - verify_packets(self, exp_pkt1, [self.dev_port0]) + % (self.dev_port11, self.dev_port10, pkt_ip_src, pkt_ip_dst)) + send_packet(self, self.dev_port11, pkt) + verify_packets(self, exp_pkt1, [self.dev_port10]) print("Creates route with %s ip prefix and %d router interface id" - % (ip_addr_subnet, self.port0_rif)) + % (ip_addr_subnet, self.port10_rif)) route_entry = sai_thrift_route_entry_t( vr_id=self.default_vrf, destination=sai_ipprefix( ip_addr_subnet)) sai_thrift_create_route_entry(self.client, route_entry, - next_hop_id=self.port0_rif) + next_hop_id=self.port10_rif) print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port1, self.dev_port0, pkt_ip_src, pkt_ip_dst)) - send_packet(self, self.dev_port1, pkt) - verify_packets(self, exp_pkt1, [self.dev_port0]) + % (self.dev_port11, self.dev_port10, pkt_ip_src, pkt_ip_dst)) + send_packet(self, self.dev_port11, pkt) + verify_packets(self, exp_pkt1, [self.dev_port10]) print("Removes route") sai_thrift_remove_route_entry(self.client, route_entry) print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port1, self.dev_port0, pkt_ip_src, pkt_ip_dst)) - send_packet(self, self.dev_port1, pkt) - verify_packets(self, exp_pkt1, [self.dev_port0]) + % (self.dev_port11, self.dev_port10, pkt_ip_src, pkt_ip_dst)) + send_packet(self, self.dev_port11, pkt) + verify_packets(self, exp_pkt1, [self.dev_port10]) print("Creates route with %s ip prefix and %d router interface id" - % (ip_addr_subnet, self.port0_rif)) + % (ip_addr_subnet, self.port10_rif)) route_entry = sai_thrift_route_entry_t( vr_id=self.default_vrf, destination=sai_ipprefix( ip_addr_subnet)) sai_thrift_create_route_entry(self.client, route_entry, - next_hop_id=self.port0_rif) + next_hop_id=self.port10_rif) print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port1, self.dev_port0, pkt_ip_src, pkt_ip_dst)) - send_packet(self, self.dev_port1, pkt) - verify_packets(self, exp_pkt1, [self.dev_port0]) + % (self.dev_port11, self.dev_port10, pkt_ip_src, pkt_ip_dst)) + send_packet(self, self.dev_port11, pkt) + verify_packets(self, exp_pkt1, [self.dev_port10]) print("Removes neighbor") sai_thrift_remove_neighbor_entry(self.client, nbr_entry) pre_stats = sai_thrift_get_queue_stats( self.client, self.cpu_queue0) - print("Sending packet on port %d, glean to cpu" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_no_other_packets(self, timeout=1) + print("Sending packet on port %d, glean to cpu" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) time.sleep(4) post_stats = sai_thrift_get_queue_stats( self.client, self.cpu_queue0) @@ -526,39 +688,38 @@ def routeNbrColisionTest(self): pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) print("Creates neighbor with %s ip address, %d router interface id" - " and %s destination mac" % (ip_addr, self.port0_rif, dmac)) + " and %s destination mac" % (ip_addr, self.port10_rif, dmac)) nbr_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress(ip_addr)) + rif_id=self.port10_rif, ip_address=sai_ipaddress(ip_addr)) sai_thrift_create_neighbor_entry( self.client, nbr_entry, dst_mac_address=dmac) print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port1, self.dev_port0, pkt_ip_src, pkt_ip_dst)) - send_packet(self, self.dev_port1, pkt) - verify_packets(self, exp_pkt1, [self.dev_port0]) + % (self.dev_port11, self.dev_port10, pkt_ip_src, pkt_ip_dst)) + send_packet(self, self.dev_port11, pkt) + verify_packets(self, exp_pkt1, [self.dev_port10]) print("Removes route") sai_thrift_remove_route_entry(self.client, route_entry) print("Removes neighbor") sai_thrift_remove_neighbor_entry(self.client, nbr_entry) - print("Sending packet on port %d, dropped" % (self.dev_port1)) - send_packet(self, self.dev_port1, pkt) + print("Sending packet on port %d, dropped" % (self.dev_port11)) + send_packet(self, self.dev_port11, pkt) verify_no_other_packets(self) print("Creates route with %s ip prefix and %d router interface id" - % (ip_addr_subnet, self.port0_rif)) + % (ip_addr_subnet, self.port10_rif)) route_entry = sai_thrift_route_entry_t( vr_id=self.default_vrf, destination=sai_ipprefix( ip_addr_subnet)) sai_thrift_create_route_entry(self.client, route_entry, - next_hop_id=self.port0_rif) + next_hop_id=self.port10_rif) pre_stats = sai_thrift_get_queue_stats( self.client, self.cpu_queue0) - print("Sending packet on port %d, glean to cpu" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_no_other_packets(self, timeout=1) + print("Sending packet on port %d, glean to cpu" % self.dev_port11) + send_packet(self, self.dev_port11, pkt) time.sleep(4) post_stats = sai_thrift_get_queue_stats( self.client, self.cpu_queue0) @@ -567,172 +728,32 @@ def routeNbrColisionTest(self): pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) print("Creates neighbor with %s ip address, %d router interface id" - " and %s destination mac" % (ip_addr, self.port0_rif, dmac)) + " and %s destination mac" % (ip_addr, self.port10_rif, dmac)) nbr_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress(ip_addr)) + rif_id=self.port10_rif, ip_address=sai_ipaddress(ip_addr)) sai_thrift_create_neighbor_entry( self.client, nbr_entry, dst_mac_address=dmac) print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port1, self.dev_port0, pkt_ip_src, pkt_ip_dst)) - send_packet(self, self.dev_port1, pkt) - verify_packets(self, exp_pkt1, [self.dev_port0]) + % (self.dev_port11, self.dev_port10, pkt_ip_src, pkt_ip_dst)) + send_packet(self, self.dev_port11, pkt) + verify_packets(self, exp_pkt1, [self.dev_port10]) finally: sai_thrift_remove_route_entry(self.client, route_entry) sai_thrift_remove_neighbor_entry(self.client, nbr_entry) sai_thrift_remove_next_hop(self.client, nhop) - def routeUpdateTest(self): - ''' - Verify correct forwarding after route update. - ''' - print("routeUpdateTest") - dmac = '00:11:22:33:44:55' - dmac2 = '00:11:22:33:44:66' - - nhop1 = sai_thrift_create_next_hop( - self.client, ip=sai_ipaddress('10.10.10.2'), - router_interface_id=self.port0_rif, - type=SAI_NEXT_HOP_TYPE_IP) - neighbor_entry = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress('10.10.10.2')) - sai_thrift_create_neighbor_entry(self.client, neighbor_entry, - dst_mac_address=dmac) - - route_entry = sai_thrift_route_entry_t( - vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) - sai_thrift_create_route_entry(self.client, route_entry, - next_hop_id=nhop1) - - pkt = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - exp_pkt = simple_tcp_packet( - eth_dst='00:11:22:33:44:55', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet( - eth_dst='00:11:22:33:44:66', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - try: - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_packet(self, exp_pkt, self.dev_port0) - - print("Updating route nexthop to different nexthop") - nhop2 = sai_thrift_create_next_hop( - self.client, ip=sai_ipaddress('10.10.10.3'), - router_interface_id=self.port0_rif, - type=SAI_NEXT_HOP_TYPE_IP) - neighbor_entry2 = sai_thrift_neighbor_entry_t( - rif_id=self.port0_rif, ip_address=sai_ipaddress('10.10.10.3')) - sai_thrift_create_neighbor_entry(self.client, neighbor_entry2, - dst_mac_address=dmac2) - sai_thrift_set_route_entry_attribute(self.client, route_entry, - next_hop_id=nhop2) - - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_packet(self, exp_pkt2, self.dev_port0) - - print("Updating route nexthop to drop nexthop") - sai_thrift_set_route_entry_attribute( - self.client, route_entry, packet_action=SAI_PACKET_ACTION_DROP) - - print("Sending packet on port %d, drop" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_no_other_packets(self, timeout=3) - - print("Updating route nexthop to regular nexthop") - sai_thrift_set_route_entry_attribute( - self.client, route_entry, - packet_action=SAI_PACKET_ACTION_FORWARD) - - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_packet(self, exp_pkt2, self.dev_port0) - - print("Updating route nexthop to CPU nexthop") - sai_thrift_set_route_entry_attribute( - self.client, route_entry, packet_action=SAI_PACKET_ACTION_TRAP) - - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"], - pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) - - print("Updating route nexthop to regular nexthop") - sai_thrift_set_route_entry_attribute( - self.client, route_entry, - packet_action=SAI_PACKET_ACTION_FORWARD) - - print("Sending packet on port %d, forward" % self.dev_port1) - send_packet(self, self.dev_port1, pkt) - verify_packet(self, exp_pkt2, self.dev_port0) - - finally: - sai_thrift_remove_route_entry(self.client, route_entry) - sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) - sai_thrift_remove_neighbor_entry(self.client, neighbor_entry2) - sai_thrift_remove_next_hop(self.client, nhop1) - sai_thrift_remove_next_hop(self.client, nhop2) - - def emptyECMPGroupTest(self): - ''' - Verify drop on empty ECMP group. - ''' - print("emptyECMPGroupTest") - - nhop_group = sai_thrift_create_next_hop_group( - self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) - - route_entry = sai_thrift_route_entry_t( - vr_id=self.default_vrf, destination=sai_ipprefix('10.10.10.1/32')) - sai_thrift_create_route_entry(self.client, route_entry, - next_hop_id=nhop_group) - - pkt = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst='10.10.10.1', - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - try: - print("Sending packet on port %d, drop" % self.dev_port0) - send_packet(self, self.dev_port0, pkt) - verify_no_other_packets(self, timeout=3) - - finally: - sai_thrift_remove_route_entry(self.client, route_entry) - sai_thrift_remove_next_hop_group(self.client, nhop_group) + def tearDown(self): + super(routeNbrColisionTest, self).tearDown() -@group("draft") -class L3DirBcastRouteTest(SaiHelper): - """ +class L3DirBcastRouteTestHelper(PlatformSaiHelper): + ''' Verifies direct broadcast routing - """ + ''' def setUp(self): - super(L3DirBcastRouteTest, self).setUp() + super(L3DirBcastRouteTestHelper, self).setUp() vlan100_id = 100 @@ -783,10 +804,6 @@ def setUp(self): virtual_router_id=self.default_vrf, vlan_id=self.vlan100) - def runTest(self): - self.gleanEndForwardTest() - self.forwardTest() - def tearDown(self): print("Removes router interface %d" % self.vlan100_rif) sai_thrift_remove_router_interface(self.client, self.vlan100_rif) @@ -813,160 +830,172 @@ def tearDown(self): print("Removes bridge port %d" % self.port25_bp) sai_thrift_remove_bridge_port(self.client, self.port25_bp) - super(L3DirBcastRouteTest, self).tearDown() + super(L3DirBcastRouteTestHelper, self).tearDown() def trafficTrapTest1(self): """ Verifies the test packets are gleaned to CPU when neighbors don't exist """ - pkt_ip_src = '192.168.0.1' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:21', - ip_dst=self.ip_addr1, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - print("Sending packet on port %d, glean to cpu" % self.dev_port10) - send_packet(self, self.dev_port10, pkt) - verify_no_other_packets(self, timeout=1) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"], - pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + try: + pkt_ip_src = '192.168.0.1' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:21', + ip_dst=self.ip_addr1, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=64) + pre_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + print("Sending packet on port %d, glean to cpu" % self.dev_port10) + send_packet(self, self.dev_port10, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst=self.ip_addr2, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - print("Sending packet on port %d, glean to cpu" % self.dev_port24) - send_packet(self, self.dev_port24, pkt) - verify_no_other_packets(self, timeout=1) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"], - pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst=self.ip_addr2, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=64) + pre_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + print("Sending packet on port %d, glean to cpu" % self.dev_port24) + send_packet(self, self.dev_port24, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + + finally: + pass def trafficTrapTest2(self): """ Verifies the test packets are gleaned to CPU when neighbors don't exist """ - pkt_ip_src = '192.168.0.1' - pkt_ip_dst = '10.10.10.2' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:21', - ip_dst=pkt_ip_dst, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - print("Sending packet on port %d, glean to cpu" % self.dev_port10) - send_packet(self, self.dev_port10, pkt) - verify_no_other_packets(self, timeout=1) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"], - pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) - - pkt_ip_dst = '20.20.20.2' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst=pkt_ip_dst, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - print("Sending packet on port %d, glean to cpu" % self.dev_port24) - send_packet(self, self.dev_port24, pkt) - verify_no_other_packets(self, timeout=1) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue0) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"], - pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + try: + pkt_ip_src = '192.168.0.1' + pkt_ip_dst = '10.10.10.2' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:21', + ip_dst=pkt_ip_dst, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=64) + pre_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + print("Sending packet on port %d, glean to cpu" % self.dev_port10) + send_packet(self, self.dev_port10, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + + pkt_ip_dst = '20.20.20.2' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst=pkt_ip_dst, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=64) + pre_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + print("Sending packet on port %d, glean to cpu" % self.dev_port24) + send_packet(self, self.dev_port24, pkt) + time.sleep(4) + post_stats = sai_thrift_get_queue_stats( + self.client, self.cpu_queue0) + self.assertEqual( + post_stats["SAI_QUEUE_STAT_PACKETS"], + pre_stats["SAI_QUEUE_STAT_PACKETS"] + 1) + + finally: + pass def trafficTest(self): """ Verfies if test packets are properly forwarded """ - pkt_ip_src = '192.168.0.1' - # send the test packet(s) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:21', - ip_dst=self.ip_addr1, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - exp_pkt = simple_tcp_packet(eth_dst=self.dmac1, - eth_src=ROUTER_MAC, + try: + pkt_ip_src = '192.168.0.1' + # send the test packet(s) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:21', ip_dst=self.ip_addr1, ip_src=pkt_ip_src, ip_id=105, - ip_ttl=63) - print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port10, self.dev_port24, pkt_ip_src, - self.ip_addr1)) - send_packet(self, self.dev_port10, pkt) - verify_packets(self, exp_pkt, [self.dev_port24]) + ip_ttl=64) + exp_pkt = simple_tcp_packet(eth_dst=self.dmac1, + eth_src=ROUTER_MAC, + ip_dst=self.ip_addr1, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=63) + print("Sending packet on port %d to port %d, forward from %s to %s" + % (self.dev_port10, self.dev_port24, pkt_ip_src, + self.ip_addr1)) + send_packet(self, self.dev_port10, pkt) + verify_packets(self, exp_pkt, [self.dev_port24]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst=self.dir_bcast_ip_addr1, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - exp_pkt = simple_tcp_packet(eth_dst=self.dir_bcast_dmac1, - eth_src=ROUTER_MAC, + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', ip_dst=self.dir_bcast_ip_addr1, ip_src=pkt_ip_src, ip_id=105, - ip_ttl=63) - print("Sending packet on port %d to port %d and %d, forward from " - "%s to %s" % (self.dev_port10, self.dev_port24, - self.dev_port25, pkt_ip_src, - self.dir_bcast_ip_addr1)) - send_packet(self, self.dev_port10, pkt) - verify_packets(self, exp_pkt, ports=[self.dev_port24, - self.dev_port25]) + ip_ttl=64) + exp_pkt = simple_tcp_packet(eth_dst=self.dir_bcast_dmac1, + eth_src=ROUTER_MAC, + ip_dst=self.dir_bcast_ip_addr1, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=63) + print("Sending packet on port %d to port %d and %d, forward from " + "%s to %s" % (self.dev_port10, self.dev_port24, + self.dev_port25, pkt_ip_src, + self.dir_bcast_ip_addr1)) + send_packet(self, self.dev_port10, pkt) + verify_packets(self, exp_pkt, ports=[self.dev_port24, + self.dev_port25]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:23', - ip_dst=self.ip_addr2, - ip_src=pkt_ip_src, - ip_id=105, - ip_ttl=64) - exp_pkt = simple_tcp_packet(eth_dst=self.dmac2, - eth_src=ROUTER_MAC, + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:23', ip_dst=self.ip_addr2, ip_src=pkt_ip_src, ip_id=105, - ip_ttl=63) - print("Sending packet on port %d to port %d, forward from %s to %s" - % (self.dev_port25, self.dev_port10, pkt_ip_src, - self.ip_addr2)) - send_packet(self, self.dev_port25, pkt) - verify_packets(self, exp_pkt, [self.dev_port10]) - - def gleanEndForwardTest(self): - """ - Verifies if frame is frowarded to cpu when there is only route without - neighbor then if frame is forwarded properly after creating neighbor - and nhop - """ + ip_ttl=64) + exp_pkt = simple_tcp_packet(eth_dst=self.dmac2, + eth_src=ROUTER_MAC, + ip_dst=self.ip_addr2, + ip_src=pkt_ip_src, + ip_id=105, + ip_ttl=63) + print("Sending packet on port %d to port %d, forward from %s to %s" + % (self.dev_port25, self.dev_port10, pkt_ip_src, + self.ip_addr2)) + send_packet(self, self.dev_port25, pkt) + verify_packets(self, exp_pkt, [self.dev_port10]) + + finally: + pass + +class gleanEndForwardTest(L3DirBcastRouteTestHelper): + """ + Verifies if frame is frowarded to cpu when there is only route without + neighbor then if frame is forwarded properly after creating neighbor + and nhop + """ + def setUp(self): + super(gleanEndForwardTest, self).setUp() + + def runTest(self): nhop1 = 0 nhop2 = 0 @@ -1050,10 +1079,19 @@ def gleanEndForwardTest(self): sai_thrift_remove_neighbor_entry(self.client, nbr_entry2) sai_thrift_remove_neighbor_entry(self.client, nbr_entry0) - def forwardTest(self): - """ - Verifies if frame is forwarded properly when configuration is correct - """ + def tearDown(self): + super(gleanEndForwardTest, self).tearDown() + + +class forwardTest(L3DirBcastRouteTestHelper): + """ + Verifies if frame is forwarded properly when configuration is correct + """ + + def setUp(self): + super(forwardTest, self).setUp() + + def runTest(self): nhop1 = 0 nhop2 = 0 @@ -1134,3 +1172,6 @@ def forwardTest(self): sai_thrift_remove_neighbor_entry(self.client, nbr_entry1) sai_thrift_remove_neighbor_entry(self.client, nbr_entry2) sai_thrift_remove_neighbor_entry(self.client, nbr_entry0) + + def tearDown(self): + super(forwardTest, self).tearDown() From 0ebe69fade63eb56464c1be5283d37ac82bb9524 Mon Sep 17 00:00:00 2001 From: mounika-adhuri Date: Mon, 28 Nov 2022 04:30:37 -0800 Subject: [PATCH 3/6] Adding changes to SWI-6183 SONiC PTF sainexthop.py refactor --- ptf/sainexthop.py | 434 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 368 insertions(+), 66 deletions(-) diff --git a/ptf/sainexthop.py b/ptf/sainexthop.py index d73b9fb28..670350667 100644 --- a/ptf/sainexthop.py +++ b/ptf/sainexthop.py @@ -17,7 +17,7 @@ """ from sai_thrift.sai_headers import * -import ptf.mask as mask +from ptf.mask import * from ptf.packet import * from ptf.testutils import * from ptf.thriftutils import * @@ -26,7 +26,7 @@ @group("draft") -class L3NexthopTest(SaiHelperSimplified): +class L3NexthopTestHelper(PlatformSaiHelper): """ Basic L3 nexthop tests. Configuration @@ -37,23 +37,23 @@ class L3NexthopTest(SaiHelperSimplified): +----------+-----------+ """ def setUp(self): - super(L3NexthopTest, self).setUp() + super(L3NexthopTestHelper, self).setUp() self.create_routing_interfaces(ports=[0, 1]) - def runTest(self): - self.removeNexthopTest() - self.cpuNexthopTest() - def tearDown(self): self.destroy_routing_interfaces() - super(L3NexthopTest, self).tearDown() + super(L3NexthopTestHelper, self).tearDown() - def removeNexthopTest(self): - """ - Test verifies correct nexthop removal. - """ +class removeNexthopTest(L3NexthopTestHelper): + """ + Test verifies correct nexthop removal. + """ + def setUp(self): + super(removeNexthopTest, self).setUp() + + def runTest(self): print("RemoveNexthopTest") nhop = sai_thrift_create_next_hop(self.client, ip=sai_ipaddress('10.10.10.10'), @@ -113,10 +113,18 @@ def removeNexthopTest(self): sai_thrift_remove_neighbor_entry(self.client, neighbor_entry) sai_thrift_remove_next_hop(self.client, nhop) - def cpuNexthopTest(self): - ''' - Test verifies nexthop to CPU. - ''' + def tearDown(self): + super(removeNexthopTest, self).tearDown() + + +class cpuNexthopTest(L3NexthopTestHelper): + ''' + Test verifies nexthop to CPU. + ''' + def setUp(self): + super(cpuNexthopTest, self).setUp() + + def runTest(self): print("cpuNexthopTest") print("Creating hostif trap for IP2ME") @@ -218,15 +226,53 @@ def cpuNexthopTest(self): sai_thrift_remove_hostif_trap(self.client, trap) sai_thrift_remove_hostif_trap_group(self.client, trap_group) + def tearDown(self): + super(cpuNexthopTest, self).tearDown() + + +class customAttrTest(L3NexthopTestHelper): + ''' + Test verifies nexthop custom attribute. + ''' + def setUp(self): + super(customAttrTest, self).setUp() + + def runTest(self): + print("customAttrTest") + try: + print("Creating nexthop with custom attribute") + attr_value = sai_thrift_attribute_value_t(oid=self.port0_rif) + attr = sai_thrift_attribute_t(id=(SAI_NEXT_HOP_ATTR_END + 0), + value=attr_value) + nhop = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.10'), + router_interface_id=self.port0_rif, + type=SAI_NEXT_HOP_TYPE_IP, custom_attribute=attr) + + print("Getting nexthop custom attribute") + + print("Setting nexthop custom attribute") + attr_value = sai_thrift_attribute_value_t(oid=self.port1_rif) + attr = sai_thrift_attribute_t(id=(SAI_NEXT_HOP_ATTR_END + 0), + value=attr_value) + sai_thrift_set_next_hop_attribute(self.client, + nhop, + custom_attribute=attr) + finally: + sai_thrift_remove_next_hop(self.client, nhop) + + def tearDown(self): + super(customAttrTest, self).tearDown() + @group("draft") @group("tunnel") -class NhopTunnelEncapDecapTest(SaiHelper): +class NhopTunnelEncapDecapTestHelper(PlatformSaiHelper): ''' Nexthop tunnel encapsulation and decapsulation tests. ''' def setUp(self): - super(NhopTunnelEncapDecapTest, self).setUp() + super(NhopTunnelEncapDecapTestHelper, self).setUp() # underlay config self.uvrf = sai_thrift_create_virtual_router(self.client) @@ -304,11 +350,6 @@ def setUp(self): sai_thrift_create_route_entry(self.client, self.customer_route2, next_hop_id=self.tunnel_nexthop) - def runTest(self): - self.l3InterfaceTunnelTest() - self.subPortTunnelTest() - self.sviTunnelTest() - def tearDown(self): sai_thrift_remove_route_entry(self.client, self.customer_route2) sai_thrift_remove_route_entry(self.client, self.customer_route1) @@ -329,12 +370,17 @@ def tearDown(self): sai_thrift_remove_virtual_router(self.client, self.ovrf) sai_thrift_remove_virtual_router(self.client, self.uvrf) - super(NhopTunnelEncapDecapTest, self).tearDown() + super(NhopTunnelEncapDecapTestHelper, self).tearDown() - def l3InterfaceTunnelTest(self): - ''' - Test verifies l3 interface tunnel nexthop. - ''' + +class l3InterfaceTunnelTest(NhopTunnelEncapDecapTestHelper): + ''' + Test verifies l3 interface tunnel nexthop. + ''' + def setUp(self): + super(l3InterfaceTunnelTest, self).setUp() + + def runTest(self): print("l3InterfaceTunnelTest") try: orif = sai_thrift_create_router_interface( @@ -411,10 +457,18 @@ def l3InterfaceTunnelTest(self): sai_thrift_remove_next_hop(self.client, onhop4) sai_thrift_remove_router_interface(self.client, orif) - def subPortTunnelTest(self): - ''' - Test verifies subport tunnel nexthop. - ''' + def tearDown(self): + super(l3InterfaceTunnelTest, self).tearDown() + + +class subPortTunnelTest(NhopTunnelEncapDecapTestHelper): + ''' + Test verifies subport tunnel nexthop. + ''' + def setUp(self): + super(subPortTunnelTest, self).setUp() + + def runTest(self): print("subPortTunnelTest") try: osubport = sai_thrift_create_router_interface( @@ -500,10 +554,18 @@ def subPortTunnelTest(self): sai_thrift_remove_next_hop(self.client, onhop) sai_thrift_remove_router_interface(self.client, osubport) - def sviTunnelTest(self): - ''' - Test verifies SVI tunnel nexthop. - ''' + def tearDown(self): + super(subPortTunnelTest, self).tearDown() + + +class sviTunnelTest(NhopTunnelEncapDecapTestHelper): + ''' + Test verifies SVI tunnel nexthop. + ''' + def setUp(self): + super(sviTunnelTest, self).setUp() + + def runTest(self): print("sviTunnelTest") try: port24_bp = sai_thrift_create_bridge_port( @@ -543,6 +605,14 @@ def sviTunnelTest(self): destination=sai_ipprefix(self.customer_ip4+'/32')) sai_thrift_create_route_entry(self.client, customer_route3, next_hop_id=onhop) + test_fdb = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address="00:22:22:22:22:33", + bv_id=vlan100) + sai_thrift_create_fdb_entry(self.client, + test_fdb, + type=SAI_FDB_ENTRY_TYPE_STATIC, + bridge_port_id=port24_bp) print("Verifying IP 4in4 (encap)") pkt = simple_tcp_packet( @@ -597,6 +667,7 @@ def sviTunnelTest(self): verify_packet(self, pkt2, self.dev_port24) finally: + sai_thrift_remove_fdb_entry(self.client, test_fdb) sai_thrift_remove_route_entry(self.client, customer_route3) sai_thrift_remove_neighbor_entry(self.client, oneighbor) sai_thrift_remove_next_hop(self.client, onhop) @@ -611,15 +682,18 @@ def sviTunnelTest(self): sai_thrift_remove_bridge_port(self.client, port24_bp) sai_thrift_remove_bridge_port(self.client, port26_bp) + def tearDown(self): + super(sviTunnelTest, self).tearDown() + @group("draft") @group("tunnel") -class NhopTunnelVNITest(SaiHelper): +class NhopTunnelVNITestHelper(PlatformSaiHelper): ''' Nexthop tunnel VNI tests. ''' def setUp(self): - super(NhopTunnelVNITest, self).setUp() + super(NhopTunnelVNITestHelper, self).setUp() # underlay config self.uvrf = sai_thrift_create_virtual_router(self.client) @@ -634,6 +708,7 @@ def setUp(self): self.inner_dmac = '00:33:33:33:33:33' self.inner_dmac2 = '00:33:33:33:33:44' self.inner_dmac3 = '00:33:33:33:33:55' + self.inner_dmac4 = '00:33:33:33:33:66' self.underlay_neighbor_mac = '00:11:11:11:11:11' self.underlay_neighbor_mac2 = '00:11:11:11:11:22' self.underlay_neighbor_mac3 = '00:11:11:11:11:33' @@ -677,22 +752,19 @@ def setUp(self): vni_id_value=self.vni) encap_mappers_list = [self.encap_tunnel_map] decap_mappers_list = [self.decap_tunnel_map] - encap_mappers_objlist = sai_thrift_object_list_t( + self.encap_mappers_objlist = sai_thrift_object_list_t( count=1, idlist=encap_mappers_list) - decap_mappers_objlist = sai_thrift_object_list_t( + self.decap_mappers_objlist = sai_thrift_object_list_t( count=1, idlist=decap_mappers_list) self.tunnel = sai_thrift_create_tunnel( self.client, type=self.tunnel_type, encap_src_ip=sai_ipaddress(self.my_lb_ip), - decap_mappers=decap_mappers_objlist, - encap_mappers=encap_mappers_objlist, + decap_mappers=self.decap_mappers_objlist, + encap_mappers=self.encap_mappers_objlist, encap_ttl_mode=self.ttl_mode, decap_ttl_mode=self.ttl_mode, underlay_interface=self.urif_lb) - def runTest(self): - self.tunnelVniTest() - def tearDown(self): sai_thrift_remove_tunnel(self.client, self.tunnel) sai_thrift_remove_tunnel_map_entry(self.client, @@ -706,13 +778,19 @@ def tearDown(self): sai_thrift_remove_virtual_router(self.client, self.ovrf) sai_thrift_remove_virtual_router(self.client, self.uvrf) - super(NhopTunnelVNITest, self).tearDown() + super(NhopTunnelVNITestHelper, self).tearDown() - def tunnelVniTest(self): - ''' - Test verifies corrent tunnel VNI behaviour. - ''' + +class tunnelVniTest(NhopTunnelVNITestHelper): + ''' + Test verifies correct tunnel VNI behavior. + ''' + def setUp(self): + super(tunnelVniTest, self).setUp() + + def runTest(self): print("tunnelVniTest") + vni2 = 5000 service_vm_ip = "200.200.200.2" service_vtep_ip = "30.30.30.3" service_vni = 3000 @@ -754,12 +832,20 @@ def tunnelVniTest(self): tunnel_nexthop1 = sai_thrift_create_next_hop( self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP, tunnel_id=self.tunnel, ip=sai_ipaddress(self.tunnel_ip), - tunnel_vni=2000, tunnel_mac=self.inner_dmac) + tunnel_vni=self.vni, tunnel_mac=self.inner_dmac) tunnel_nexthop2 = sai_thrift_create_next_hop( + self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP, + tunnel_id=self.tunnel, ip=sai_ipaddress(self.tunnel_ip), + tunnel_vni=vni2, tunnel_mac=self.inner_dmac) + self.assertNotEqual( + tunnel_nexthop2, 0, + "Failed to create nexthop to same dest ip with different vni") + + tunnel_nexthop3 = sai_thrift_create_next_hop( self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP, tunnel_id=self.tunnel, ip=sai_ipaddress(service_vtep_ip), - tunnel_vni=service_vni, tunnel_mac=self.inner_dmac2) + tunnel_vni=service_vni, tunnel_mac=self.inner_dmac3) customer_route1 = sai_thrift_route_entry_t( vr_id=self.ovrf, destination=sai_ipprefix(self.vm_ip+'/32')) @@ -767,10 +853,15 @@ def tunnelVniTest(self): next_hop_id=tunnel_nexthop1) customer_route2 = sai_thrift_route_entry_t( - vr_id=self.ovrf, destination=sai_ipprefix(service_vm_ip+'/32')) + vr_id=self.ovrf, destination=sai_ipprefix(self.vm_ip2+'/32')) sai_thrift_create_route_entry(self.client, customer_route2, next_hop_id=tunnel_nexthop2) + customer_route3 = sai_thrift_route_entry_t( + vr_id=self.ovrf, destination=sai_ipprefix(service_vm_ip+'/32')) + sai_thrift_create_route_entry(self.client, customer_route3, + next_hop_id=tunnel_nexthop3) + pkt = simple_tcp_packet( eth_dst=ROUTER_MAC, eth_src='00:22:22:22:22:22', @@ -785,7 +876,7 @@ def tunnelVniTest(self): ip_src=self.customer_ip, ip_id=108, ip_ttl=63) - vxlan_pkt = mask.Mask(simple_vxlan_packet( + vxlan_pkt = Mask(simple_vxlan_packet( eth_src=ROUTER_MAC, eth_dst=self.underlay_neighbor_mac, ip_id=0, @@ -797,9 +888,50 @@ def tunnelVniTest(self): vxlan_vni=self.vni, inner_frame=inner_pkt)) vxlan_pkt.set_do_not_care_scapy(UDP, 'sport') + print("Sending packet on port %d to vni %d" % + (self.dev_port24, self.vni)) + send_packet(self, self.dev_port24, pkt) + verify_packet(self, vxlan_pkt, self.dev_port25) + + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst=self.vm_ip2, + ip_src=self.customer_ip, + ip_id=108, + ip_ttl=64) + inner_pkt = simple_tcp_packet( + eth_dst=self.inner_dmac, + eth_src=ROUTER_MAC, + ip_dst=self.vm_ip2, + ip_src=self.customer_ip, + ip_id=108, + ip_ttl=63) + vxlan_pkt = Mask(simple_vxlan_packet( + eth_src=ROUTER_MAC, + eth_dst=self.underlay_neighbor_mac, + ip_id=0, + ip_src=self.my_lb_ip, + ip_dst=self.tunnel_ip, + ip_ttl=64, + ip_flags=0x2, + with_udp_chksum=False, + vxlan_vni=vni2, + inner_frame=inner_pkt)) + vxlan_pkt.set_do_not_care_scapy(UDP, 'sport') + print("Sending packet on port %d to vni %d" % + (self.dev_port24, vni2)) send_packet(self, self.dev_port24, pkt) verify_packet(self, vxlan_pkt, self.dev_port25) + print("Updating nexthop tunnel mac {} -> {}".format( + self.inner_dmac3, + self.inner_dmac4)) + sai_thrift_set_next_hop_attribute( + self.client, tunnel_nexthop3, tunnel_mac=self.inner_dmac4) + print(sai_thrift_get_next_hop_attribute( + self.client, tunnel_nexthop3, tunnel_mac=True)) + pkt = simple_tcp_packet( eth_dst=ROUTER_MAC, eth_src='00:22:22:22:22:22', @@ -808,13 +940,13 @@ def tunnelVniTest(self): ip_id=108, ip_ttl=64) inner_pkt = simple_tcp_packet( - eth_dst=self.inner_dmac2, + eth_dst=self.inner_dmac4, eth_src=ROUTER_MAC, ip_dst=service_vm_ip, ip_src=self.customer_ip, ip_id=108, ip_ttl=63) - vxlan_pkt = mask.Mask(simple_vxlan_packet( + vxlan_pkt = Mask(simple_vxlan_packet( eth_src=ROUTER_MAC, eth_dst=self.underlay_neighbor_mac2, ip_id=0, @@ -826,6 +958,8 @@ def tunnelVniTest(self): vxlan_vni=service_vni, inner_frame=inner_pkt)) vxlan_pkt.set_do_not_care_scapy(UDP, 'sport') + print("Sending packet on port %d to vni %d" % + (self.dev_port24, service_vni)) send_packet(self, self.dev_port24, pkt) verify_packet(self, vxlan_pkt, self.dev_port26) @@ -837,13 +971,13 @@ def tunnelVniTest(self): ip_id=108, ip_ttl=64) inner_pkt = simple_tcp_packet( - eth_dst=self.inner_dmac2, + eth_dst=self.inner_dmac4, eth_src=ROUTER_MAC, ip_dst=service_vm_ip, ip_src=self.customer_ip, ip_id=108, ip_ttl=63) - vxlan_pkt = mask.Mask(simple_vxlan_packet( + vxlan_pkt = Mask(simple_vxlan_packet( eth_src=ROUTER_MAC, eth_dst=self.underlay_neighbor_mac2, ip_id=0, @@ -854,29 +988,197 @@ def tunnelVniTest(self): with_udp_chksum=False, vxlan_vni=service_vni2, inner_frame=inner_pkt)) - print("Updating nexthop tunnel {} -> {}".format(service_vni, - service_vni2)) + print("Updating nexthop tunnel vni {} -> {}".format(service_vni, + service_vni2)) - sai_thrift_set_next_hop_attribute(self.client, tunnel_nexthop2, + sai_thrift_set_next_hop_attribute(self.client, tunnel_nexthop3, tunnel_vni=4000) print(sai_thrift_get_next_hop_attribute(self.client, - tunnel_nexthop2, + tunnel_nexthop3, tunnel_vni=True)) vxlan_pkt.set_do_not_care_scapy(UDP, 'sport') + print("Sending packet on port %d to vni %d" % + (self.dev_port24, service_vni2)) send_packet(self, self.dev_port24, pkt) verify_packet(self, vxlan_pkt, self.dev_port26) finally: - sai_thrift_remove_route_entry(self.client, customer_route2) - sai_thrift_remove_route_entry(self.client, customer_route1) + if 'customer_route3' in locals() and customer_route3: + sai_thrift_remove_route_entry(self.client, customer_route3) + if 'customer_route2' in locals() and customer_route2: + sai_thrift_remove_route_entry(self.client, customer_route2) + if 'customer_route1' in locals() and customer_route1: + sai_thrift_remove_route_entry(self.client, customer_route1) + if 'tunnel_nexthop3' in locals() and tunnel_nexthop3: + sai_thrift_remove_next_hop(self.client, tunnel_nexthop3) + if 'tunnel_nexthop2' in locals() and tunnel_nexthop2: + sai_thrift_remove_next_hop(self.client, tunnel_nexthop2) + if 'tunnel_nexthop1' in locals() and tunnel_nexthop1: + sai_thrift_remove_next_hop(self.client, tunnel_nexthop1) sai_thrift_remove_route_entry(self.client, tunnel_route2) sai_thrift_remove_route_entry(self.client, tunnel_route1) - sai_thrift_remove_next_hop(self.client, tunnel_nexthop2) - sai_thrift_remove_next_hop(self.client, tunnel_nexthop1) sai_thrift_remove_next_hop(self.client, unhop2) sai_thrift_remove_next_hop(self.client, unhop1) sai_thrift_remove_neighbor_entry(self.client, uneighbor2) sai_thrift_remove_neighbor_entry(self.client, uneighbor1) sai_thrift_remove_router_interface(self.client, urif2) sai_thrift_remove_router_interface(self.client, urif1) + + def tearDown(self): + super(tunnelVniTest, self).tearDown() + + +class tunnelVrfTest(NhopTunnelVNITestHelper): + ''' + Test verifies correct tunnel behavior with multiple nexthops + in different VRFs. + ''' + def setUp(self): + super(tunnelVrfTest, self).setUp() + + def runTest(self): + print("tunnelVniTest") + + uvrf2 = sai_thrift_create_virtual_router(self.client) + + # overlay config + ovrf2 = sai_thrift_create_virtual_router(self.client) + + # create underlay loopback rif for tunnel + urif_lb2 = sai_thrift_create_router_interface( + self.client, type=SAI_ROUTER_INTERFACE_TYPE_LOOPBACK, + virtual_router_id=uvrf2) + + orif2 = sai_thrift_create_router_interface( + self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, + virtual_router_id=ovrf2, + port_id=self.port27) + + # Encap configuration follows + tunnel2 = sai_thrift_create_tunnel( + self.client, type=self.tunnel_type, + encap_src_ip=sai_ipaddress(self.my_lb_ip), + decap_mappers=self.decap_mappers_objlist, + encap_mappers=self.encap_mappers_objlist, + encap_ttl_mode=self.ttl_mode, + decap_ttl_mode=self.ttl_mode, + underlay_interface=urif_lb2) + + try: + urif1 = sai_thrift_create_router_interface( + self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, + port_id=self.port25, virtual_router_id=self.uvrf) + uneighbor1 = sai_thrift_neighbor_entry_t( + rif_id=urif1, ip_address=sai_ipaddress(self.tunnel_ip)) + sai_thrift_create_neighbor_entry( + self.client, uneighbor1, + dst_mac_address=self.underlay_neighbor_mac) + unhop1 = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.1'), + router_interface_id=urif1, type=SAI_NEXT_HOP_TYPE_IP) + tunnel_route1 = sai_thrift_route_entry_t( + vr_id=self.uvrf, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry(self.client, tunnel_route1, + next_hop_id=unhop1) + + urif2 = sai_thrift_create_router_interface( + self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, + port_id=self.port26, virtual_router_id=uvrf2) + uneighbor2 = sai_thrift_neighbor_entry_t( + rif_id=urif2, ip_address=sai_ipaddress(self.tunnel_ip)) + sai_thrift_create_neighbor_entry( + self.client, uneighbor2, + dst_mac_address=self.underlay_neighbor_mac) + unhop2 = sai_thrift_create_next_hop( + self.client, ip=sai_ipaddress('10.10.10.1'), + router_interface_id=urif2, type=SAI_NEXT_HOP_TYPE_IP) + tunnel_route2 = sai_thrift_route_entry_t( + vr_id=uvrf2, destination=sai_ipprefix('10.10.10.1/32')) + sai_thrift_create_route_entry(self.client, tunnel_route2, + next_hop_id=unhop2) + + tunnel_nexthop1 = sai_thrift_create_next_hop( + self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP, + tunnel_id=self.tunnel, ip=sai_ipaddress(self.tunnel_ip), + tunnel_vni=self.vni, tunnel_mac=self.inner_dmac) + + tunnel_nexthop2 = sai_thrift_create_next_hop( + self.client, type=SAI_NEXT_HOP_TYPE_TUNNEL_ENCAP, + tunnel_id=tunnel2, ip=sai_ipaddress(self.tunnel_ip), + tunnel_vni=self.vni, tunnel_mac=self.inner_dmac) + self.assertNotEqual( + tunnel_nexthop2, 0, + "Failed to create nexthop to same dest ip in different vrf") + + customer_route1 = sai_thrift_route_entry_t( + vr_id=self.ovrf, destination=sai_ipprefix(self.vm_ip+'/32')) + sai_thrift_create_route_entry(self.client, customer_route1, + next_hop_id=tunnel_nexthop1) + + customer_route2 = sai_thrift_route_entry_t( + vr_id=ovrf2, destination=sai_ipprefix(self.vm_ip+'/32')) + sai_thrift_create_route_entry(self.client, customer_route2, + next_hop_id=tunnel_nexthop2) + + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst=self.vm_ip, + ip_src=self.customer_ip, + ip_id=108, + ip_ttl=64) + inner_pkt = simple_tcp_packet( + eth_dst=self.inner_dmac, + eth_src=ROUTER_MAC, + ip_dst=self.vm_ip, + ip_src=self.customer_ip, + ip_id=108, + ip_ttl=63) + vxlan_pkt = Mask(simple_vxlan_packet( + eth_src=ROUTER_MAC, + eth_dst=self.underlay_neighbor_mac, + ip_id=0, + ip_src=self.my_lb_ip, + ip_dst=self.tunnel_ip, + ip_ttl=64, + ip_flags=0x2, + with_udp_chksum=False, + vxlan_vni=self.vni, + inner_frame=inner_pkt)) + vxlan_pkt.set_do_not_care_scapy(UDP, 'sport') + print("Sending packet on port %d to vni %d" % + (self.dev_port24, self.vni)) + send_packet(self, self.dev_port24, pkt) + verify_packet(self, vxlan_pkt, self.dev_port25) + + print("Sending packet on port %d to vni %d" % + (self.dev_port27, self.vni)) + send_packet(self, self.dev_port27, pkt) + verify_packet(self, vxlan_pkt, self.dev_port26) + + finally: + if 'customer_route2' in locals() and customer_route2: + sai_thrift_remove_route_entry(self.client, customer_route2) + if 'customer_route1' in locals() and customer_route1: + sai_thrift_remove_route_entry(self.client, customer_route1) + if 'tunnel_nexthop2' in locals() and tunnel_nexthop2: + sai_thrift_remove_next_hop(self.client, tunnel_nexthop2) + if 'tunnel_nexthop1' in locals() and tunnel_nexthop1: + sai_thrift_remove_next_hop(self.client, tunnel_nexthop1) + sai_thrift_remove_route_entry(self.client, tunnel_route2) + sai_thrift_remove_route_entry(self.client, tunnel_route1) + sai_thrift_remove_next_hop(self.client, unhop2) + sai_thrift_remove_next_hop(self.client, unhop1) + sai_thrift_remove_neighbor_entry(self.client, uneighbor2) + sai_thrift_remove_neighbor_entry(self.client, uneighbor1) + sai_thrift_remove_router_interface(self.client, urif2) + sai_thrift_remove_router_interface(self.client, urif1) + sai_thrift_remove_tunnel(self.client, tunnel2) + sai_thrift_remove_router_interface(self.client, orif2) + sai_thrift_remove_router_interface(self.client, urif_lb2) + sai_thrift_remove_virtual_router(self.client, ovrf2) + sai_thrift_remove_virtual_router(self.client, uvrf2) + + def tearDown(self): + super(tunnelVrfTest, self).tearDown() From 6f9a9c2fcacd2d2cf15709f8e6de6c3428154bf7 Mon Sep 17 00:00:00 2001 From: mounika-adhuri Date: Wed, 30 Nov 2022 09:16:17 -0800 Subject: [PATCH 4/6] Adding changes to SWI-6184 SONiC PTF sainexthopgroup.py refactor --- ptf/sainexthopgroup.py | 4659 +++++++++++++++++++++------------------- 1 file changed, 2464 insertions(+), 2195 deletions(-) diff --git a/ptf/sainexthopgroup.py b/ptf/sainexthopgroup.py index 06e689533..f19ae14b8 100644 --- a/ptf/sainexthopgroup.py +++ b/ptf/sainexthopgroup.py @@ -21,10 +21,10 @@ from sai_base_test import * -TEST_ECMP_SEED = 37 -TEST_LAG_SEED = 127 +TEST_ECMP_SEED = 0xabcdef +TEST_LAG_SEED = 0xfedcba ROUTER_MAC = '00:77:66:55:44:00' -MAX_ITRS = 120 +MAX_ITRS = 160 def nhg_members_count(client, next_hop_group): @@ -105,8 +105,10 @@ def release_hash(self, ipv4_hash_id, ipv6_hash_id): self.lag_ipv4_hash_id = 0 if ipv6_hash_id != 0: sai_thrift_remove_hash(self.client, ipv6_hash_id) + ipv6_hash_id = 0 if ipv4_hash_id != 0: sai_thrift_remove_hash(self.client, ipv4_hash_id) + ipv4_hash_id = 0 def print_number_of_available_nhg_resources(self): @@ -166,13 +168,13 @@ def save_number_of_available_nhg_resources(self, debug=False): @group("draft") -class L3IPv4EcmpHost(SaiHelper): +class L3IPv4EcmpHostHelper(PlatformSaiHelper): """ Base ECMP tests for IPv4 and ECMP members as regular L3 port RIFs """ def setUp(self): - super(L3IPv4EcmpHost, self).setUp() + super(L3IPv4EcmpHostHelper, self).setUp() dmac1 = '00:11:22:33:44:55' dmac2 = '00:11:22:33:44:56' @@ -225,10 +227,6 @@ def setUp(self): # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) - def runTest(self): - self.l3SaiNhgSetGetTest() - self.l3IPv4EcmpHostTest() - def tearDown(self): try: sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry1) @@ -243,17 +241,22 @@ def tearDown(self): sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) sai_thrift_remove_next_hop(self.client, self.nhop1) sai_thrift_remove_next_hop(self.client, self.nhop2) - resources_valid = self.verifyNumberOfAvaiableResources(debug=True) + self.switch_resources = self.saveNumberOfAvaiableResources(debug=True) + resources_valid = self.verifyNumberOfAvaiableResources(self.switch_resources, debug=True) self.assertEqual(resources_valid, True) release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) finally: - super(L3IPv4EcmpHost, self).tearDown() + super(L3IPv4EcmpHostHelper, self).tearDown() - def l3SaiNhgSetGetTest(self): - """ - Checks SAI switch ECMP attributes and validates - get and set attributes - """ +class l3SaiNhgSetGetTest(L3IPv4EcmpHostHelper): + """ + Checks SAI switch ECMP attributes and validates + get and set attributes + """ + def setUp(self): + super(l3SaiNhgSetGetTest, self).setUp() + + def runTest(self): print("l3SaiNhgSetGetTest") try: # predefined NHG self.nhop_group1 with 2 memners @@ -395,10 +398,18 @@ def l3SaiNhgSetGetTest(self): attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"], self.nhop2) - def l3IPv4EcmpHostTest(self): - """ - IPv4 ECMP tests with all members which are port RIFs - """ + def tearDown(self): + super(l3SaiNhgSetGetTest, self).tearDown() + + +class l3IPv4EcmpHostTest(L3IPv4EcmpHostHelper): + """ + IPv4 ECMP tests with all members which are port RIFs + """ + def setUp(self): + super(l3IPv4EcmpHostTest, self).setUp() + + def runTest(self): print("l3IPv4EcmpHostTest") pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, eth_src='00:22:22:22:22:22', @@ -453,15 +464,17 @@ def l3IPv4EcmpHostTest(self): verify_any_packet_any_port( self, [exp_pkt2, exp_pkt1], [self.dev_port11, self.dev_port12]) + def tearDown(self): + super(l3IPv4EcmpHostTest, self).tearDown() @group("draft") -class L3ipv6EcmpHost(SaiHelper): +class L3ipv6EcmpHostHelper(PlatformSaiHelper): """ Basic ECMP tests for IPv6 and regular L3 port RIFs """ def setUp(self): - super(L3ipv6EcmpHost, self).setUp() + super(L3ipv6EcmpHostHelper, self).setUp() ip_addr1 = '5000:1:1:0:0:0:0:1' ip_addr2 = '5000:1:1:0:0:0:0:2' @@ -516,9 +529,6 @@ def setUp(self): # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) - def runTest(self): - self.saiL3ipv6EcmpHostTest() - def tearDown(self): sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry1) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry2) @@ -531,15 +541,21 @@ def tearDown(self): sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) sai_thrift_remove_next_hop(self.client, self.nhop1) sai_thrift_remove_next_hop(self.client, self.nhop2) - self.assertEqual(True, self.verifyNumberOfAvaiableResources()) + self.switch_resources = self.saveNumberOfAvaiableResources(debug=True) + self.assertEqual(True, self.verifyNumberOfAvaiableResources(self.switch_resources)) release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) - super(L3ipv6EcmpHost, self).tearDown() + super(L3ipv6EcmpHostHelper, self).tearDown() - def saiL3ipv6EcmpHostTest(self): - """ - IPv6 ECMP tests with all members as regular L3 port RIFs - """ + +class saiL3ipv6EcmpHostTest(L3ipv6EcmpHostHelper): + """ + IPv6 ECMP tests with all members as regular L3 port RIFs + """ + def setUp(self): + super(saiL3ipv6EcmpHostTest, self).setUp() + + def runTest(self): print("saiL3ipv6EcmpHostTest") # send the test packet(s) pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, @@ -585,15 +601,18 @@ def saiL3ipv6EcmpHostTest(self): verify_any_packet_any_port( self, [exp_pkt2, exp_pkt1], [self.dev_port11, self.dev_port12]) + def tearDown(self): + super(saiL3ipv6EcmpHostTest, self).tearDown() + @group("draft") -class L3IPv4EcmpLpmTest(SaiHelper): +class L3IPv4EcmpLpmTestHelper(PlatformSaiHelper): """ Base ECMP tests with LPM routes for IPv4 """ def setUp(self): - super(L3IPv4EcmpLpmTest, self).setUp() + super(L3IPv4EcmpLpmTestHelper, self).setUp() dmac1 = '00:11:22:33:44:55' dmac2 = '00:11:22:33:44:56' @@ -707,10 +726,6 @@ def setUp(self): # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) - def runTest(self): - self.l3IPv4EcmpLpmTest() - self.l3Ipv4EcmpLpmAddRemoveNhopTest() - def tearDown(self): sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry11) @@ -735,12 +750,17 @@ def tearDown(self): sai_thrift_remove_router_interface(self.client, self.port15_rif) release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) - super(L3IPv4EcmpLpmTest, self).tearDown() + super(L3IPv4EcmpLpmTestHelper, self).tearDown() - def l3IPv4EcmpLpmTest(self): - """ - Verifies ECMP load balancing with LPM routes configured - """ + +class l3IPv4EcmpLpmTest(L3IPv4EcmpLpmTestHelper): + """ + Verifies ECMP load balancing with LPM routes configured + """ + def setUp(self): + super(l3IPv4EcmpLpmTest, self).setUp() + + def runTest(self): print("l3IPv4EcmpLpmTest") count = [0, 0, 0] dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) @@ -784,10 +804,18 @@ def l3IPv4EcmpLpmTest(self): (count[i] >= ((MAX_ITRS / 3) * 0.8)), "Not all paths are equally balanced, %s" % count) - def l3Ipv4EcmpLpmAddRemoveNhopTest(self): # to be removed from here - """ - IPv4 ECMP rebalance test with removal of a nexthop member - """ + def tearDown(self): + super(l3IPv4EcmpLpmTest, self).tearDown() + + +class l3Ipv4EcmpLpmAddRemoveNhopTest(L3IPv4EcmpLpmTestHelper): # to be removed from here + """ + IPv4 ECMP rebalance test with removal of a nexthop member + """ + def setUp(self): + super(l3Ipv4EcmpLpmAddRemoveNhopTest, self).setUp() + + def runTest(self): print("l3Ipv4EcmpLpmAddRemoveNhopTest") src_mac_start = '00:22:22:22:22:' nhop_ip4 = '44.44.44.44' @@ -906,15 +934,203 @@ def l3Ipv4EcmpLpmAddRemoveNhopTest(self): # to be removed from here finally: sai_thrift_remove_next_hop(self.client, nhop4) + def tearDown(self): + super(l3Ipv4EcmpLpmAddRemoveNhopTest, self).tearDown() + + + def setupECMPHash(self, hash_fields_list): + """ + Setups ECMP hash + + Args: + hash_fields_list (list): list of hash fields + """ + print("Setting the ECMP hash fields..") + # Set ECMP HASH + attr_list = sai_thrift_get_switch_attribute( + self.client, ecmp_hash=True) + hash_id = attr_list['SAI_SWITCH_ATTR_ECMP_HASH'] + print("ECMP hash id =0x%x" % (hash_id)) + + hash_attr_list = [] + s32list = sai_thrift_s32_list_t(count=100, int32list=hash_attr_list) + hash_data = sai_thrift_get_hash_attribute( + self.client, hash_id, native_hash_field_list=s32list) + data_val = hash_data['native_hash_field_list'].int32list + print('hash_data: ', hash_data) + print('hash_val: ', data_val) + hash_attr_list = hash_fields_list + hash_field_list = sai_thrift_s32_list_t( + count=len(hash_attr_list), int32list=hash_attr_list) + status = sai_thrift_set_hash_attribute( + self.client, hash_id, native_hash_field_list=hash_field_list) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + + def l3IPv4EcmpHashSeedPortLag(self): + """ + Changes ECMP seed attribute and checks for rebalancing + """ + print("l3IPv4EcmpHashSeedPortLag") + # setup the SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED + attr = sai_thrift_get_switch_attribute( + self.client, ecmp_default_hash_seed=200) + print(attr) + ecmp_default_hash_seed = attr['ecmp_default_hash_seed'] + status = sai_thrift_set_switch_attribute( + self.client, ecmp_default_hash_seed=200) + self.assertEqual(status, SAI_STATUS_SUCCESS) + attr = sai_thrift_get_switch_attribute( + self.client, ecmp_default_hash_seed=True) + print(attr) + self.assertEqual(attr['ecmp_default_hash_seed'], 200) + try: + count = [0, 0, 0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_mac = '00:22:22:22:22:22' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) + count[rcv_idx] += 1 + dst_ip += 1 + print("PORT lb counts:", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count:", ecmp_count) + # Traffic should equally be ballanced, should apear on all port or + # LAG + for i in range(0, 4): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), + "Ecmp paths are not equally balanced") + # reconfugure the default ECMP hash seed + sai_thrift_set_switch_attribute( + self.client, ecmp_default_hash_seed=400) + self.assertEqual(attr['ecmp_default_hash_seed'], 400) + count = [0, 0, 0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_mac = '00:22:22:22:22:22' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) + count[rcv_idx] += 1 + dst_ip += 1 + print("PORT lb counts:", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count:", ecmp_count) + # Traffic should equally be ballanced, should apear on all port or + # LAG + for i in range(0, 4): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.75)), + "Ecmp paths are not equally balanced") + finally: + sai_thrift_set_switch_attribute( + self.client, + ecmp_default_hash_seed=ecmp_default_hash_seed) + @group("draft") -class L3IPv4EcmpLagTest(SaiHelper): +class L3IPv6EcmpLagTestHelper(PlatformSaiHelper): """ - Base ECMP tests with lag for IPv4 + Base ECMP tests with ECMP members as LAG RIFs """ - def setUp(self): - super(L3IPv4EcmpLagTest, self).setUp() + def setUp(self): + super(L3IPv6EcmpLagTestHelper, self).setUp() dmac1 = '00:11:11:11:11:11' dmac2 = '00:22:22:22:22:22' @@ -922,62 +1138,87 @@ def setUp(self): dmac4 = '00:44:44:44:44:44' dmac5 = '00:55:55:55:55:55' dmac6 = '00:66:66:66:66:66' - nhop_ip1 = '11.11.11.11' - nhop_ip2 = '22.22.22.22' - nhop_ip3 = '33.33.33.33' - nhop_ip4 = '44.44.44.44' - nhop_ip5 = '44.55.55.55' - nhop_ip6 = '44.66.66.66' + + nhop_ip1 = '1000:1:1:0:0:0:0:1' + nhop_ip2 = '2000:1:1:0:0:0:0:1' + nhop_ip3 = '3000:1:1:0:0:0:0:1' + nhop_ip4 = '4000:1:1:0:0:0:0:1' + nhop_ip5 = '5000:1:1:0:0:0:0:1' + nhop_ip6 = '6000:1:1:0:0:0:0:1' + # set switch src mac address sai_thrift_set_switch_attribute( self.client, src_mac_address=ROUTER_MAC) - sai_thrift_set_switch_attribute( + + status = sai_thrift_set_switch_attribute( self.client, ecmp_default_hash_seed=TEST_ECMP_SEED) - sai_thrift_set_switch_attribute( + status = sai_thrift_set_switch_attribute( self.client, lag_default_hash_seed=TEST_LAG_SEED) + self.lag1_rif = sai_thrift_create_router_interface( self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, virtual_router_id=self.default_vrf, port_id=self.lag1, - admin_v4_state=True) + admin_v6_state=True) self.lag2_rif = sai_thrift_create_router_interface( self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, virtual_router_id=self.default_vrf, port_id=self.lag2, - admin_v4_state=True) + admin_v6_state=True) self.port15_rif = sai_thrift_create_router_interface( self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, virtual_router_id=self.default_vrf, port_id=self.port15, - admin_v4_state=True) + admin_v6_state=True) + # test neighbor creation self.neighbor_entry11 = sai_thrift_neighbor_entry_t( self.switch_id, self.port11_rif, sai_ipaddress(nhop_ip1)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry11, dst_mac_address=dmac1) + self.client, + self.neighbor_entry11, + dst_mac_address=dmac1, + no_host_route=True) self.neighbor_entry12 = sai_thrift_neighbor_entry_t( self.switch_id, self.port12_rif, sai_ipaddress(nhop_ip2)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry12, dst_mac_address=dmac2) + self.client, + self.neighbor_entry12, + dst_mac_address=dmac2, + no_host_route=True) self.neighbor_entry13 = sai_thrift_neighbor_entry_t( self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip3)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry13, dst_mac_address=dmac3) + self.client, + self.neighbor_entry13, + dst_mac_address=dmac3, + no_host_route=True) self.neighbor_entry14 = sai_thrift_neighbor_entry_t( self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip4)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry14, dst_mac_address=dmac4) + self.client, + self.neighbor_entry14, + dst_mac_address=dmac4, + no_host_route=True) + self.neighbor_entry15 = sai_thrift_neighbor_entry_t( self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip5)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry15, dst_mac_address=dmac5) + self.client, + self.neighbor_entry15, + dst_mac_address=dmac5, + no_host_route=True) self.neighbor_entry16 = sai_thrift_neighbor_entry_t( self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip6)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry16, dst_mac_address=dmac6) + self.client, + self.neighbor_entry16, + dst_mac_address=dmac6, + no_host_route=True) + self.nhop1 = sai_thrift_create_next_hop( self.client, type=SAI_NEXT_HOP_TYPE_IP, @@ -998,6 +1239,7 @@ def setUp(self): type=SAI_NEXT_HOP_TYPE_IP, router_interface_id=self.lag2_rif, ip=sai_ipaddress(nhop_ip4)) + self.nhop5_lag1 = sai_thrift_create_next_hop( self.client, type=SAI_NEXT_HOP_TYPE_IP, @@ -1008,8 +1250,10 @@ def setUp(self): type=SAI_NEXT_HOP_TYPE_IP, router_interface_id=self.lag2_rif, ip=sai_ipaddress(nhop_ip6)) + self.nhop_group1 = sai_thrift_create_next_hop_group( self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) + self.nh_group1_member1 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group1, @@ -1026,6 +1270,7 @@ def setUp(self): self.client, next_hop_group_id=self.nhop_group1, next_hop_id=self.nhop4_lag2) + self.nhop_group2 = sai_thrift_create_next_hop_group( self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) self.nh_group2_member1 = sai_thrift_create_next_hop_group_member( @@ -1036,38 +1281,36 @@ def setUp(self): self.client, next_hop_group_id=self.nhop_group2, next_hop_id=self.nhop6_lag2) + # create route entries self.route0 = sai_thrift_route_entry_t( switch_id=self.switch_id, - destination=sai_ipprefix('10.10.10.1/16'), + destination=sai_ipprefix('1000:1:1:0:0:0:0:0/65'), vr_id=self.default_vrf) status = sai_thrift_create_route_entry( self.client, self.route0, next_hop_id=self.nhop_group1) self.assertEqual(status, SAI_STATUS_SUCCESS) + self.route1 = sai_thrift_route_entry_t( switch_id=self.switch_id, - destination=sai_ipprefix('20.20.20.1/16'), + destination=sai_ipprefix('5500:1:1:0:0:0:0:1/65'), vr_id=self.default_vrf) status = sai_thrift_create_route_entry( self.client, self.route1, next_hop_id=self.nhop_group2) self.assertEqual(status, SAI_STATUS_SUCCESS) + # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) - def runTest(self): - self.l3IPv4EcmpHostTwoLagsTest() - self.l3IPv4EcmpHostTwoLagsDisabledLagMembersTest() - self.l3IPv4EcmpHostPortLagTest() - self.l3IPv4EcmpHostPortLagSharedMembersTest() - self.l3IPv4EcmpHashPortLagTest() - def tearDown(self): + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry11) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry12) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry13) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry14) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry15) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry16) + sai_thrift_remove_next_hop_group_member(self.client, self.nh_group1_member1) sai_thrift_remove_next_hop_group_member(self.client, @@ -1076,14 +1319,18 @@ def tearDown(self): self.nh_group1_member3) sai_thrift_remove_next_hop_group_member(self.client, self.nh_group1_member4) + sai_thrift_remove_next_hop_group_member(self.client, self.nh_group2_member1) sai_thrift_remove_next_hop_group_member(self.client, self.nh_group2_member2) - self.assertEqual(nhg_members_count(self.client, self.nhop_group1), 0) - self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) + sai_thrift_remove_route_entry(self.client, self.route0) sai_thrift_remove_route_entry(self.client, self.route1) + + self.assertEqual(nhg_members_count(self.client, self.nhop_group1), 0) + self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) + sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) sai_thrift_remove_next_hop_group(self.client, self.nhop_group2) sai_thrift_remove_next_hop(self.client, self.nhop1) @@ -1092,259 +1339,157 @@ def tearDown(self): sai_thrift_remove_next_hop(self.client, self.nhop4_lag2) sai_thrift_remove_next_hop(self.client, self.nhop5_lag1) sai_thrift_remove_next_hop(self.client, self.nhop6_lag2) + sai_thrift_remove_router_interface(self.client, self.lag1_rif) sai_thrift_remove_router_interface(self.client, self.lag2_rif) sai_thrift_remove_router_interface(self.client, self.port15_rif) - release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) - super(L3IPv4EcmpLagTest, self).tearDown() + release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) - def l3IPv4EcmpHostTwoLagsDisabledLagMembersTest(self): - """ - IPv4 ECMP tests with LAG RIF and some LAG member in disable state - """ - print("l3IPv4EcmpHostTwoLagsDisabledLagMembersTest") - print("Disable LAG1 member 4 and 5") - status = sai_thrift_set_lag_member_attribute( - self.client, self.lag1_member4, egress_disable=True) - self.assertEqual(status, SAI_STATUS_SUCCESS) - status = sai_thrift_set_lag_member_attribute( - self.client, self.lag1_member5, egress_disable=True) - self.assertEqual(status, SAI_STATUS_SUCCESS) - try: - count = [0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('20.20.20.1')), 16) - src_mac_start = '00:22:22:22:{0}:{1}' - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2], ports_to_verify) - count[rcv_idx] += 1 - dst_ip += 1 - print("PORT lb counts", count) - ecmp_count = [(count[0] + count[1] + count[2]), - (count[3] + count[4] + count[5])] - # check LAG1 traffic - self.assertEqual(count[0], 0) # LAG1 member 1 port4 disabled - self.assertEqual(count[1], 0) # LAG1 member 2 port5 disabled - self.assertTrue((count[2] >= ((MAX_ITRS / 2) * 0.6)), - "Lag path1 is not equally balanced") - print("ECMP count:", ecmp_count) - for i in range(0, 2): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.75)), - "Ecmp paths are not equally balanced") - # check LAG2 traffic - for i in range(3, 6): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), - "Lag path2 is not equally balanced") - finally: - print("Enable LAG1 member 4 and 5") - status = sai_thrift_set_lag_member_attribute( - self.client, self.lag1_member4, egress_disable=False) - self.assertEqual(status, SAI_STATUS_SUCCESS) - status = sai_thrift_set_lag_member_attribute( - self.client, self.lag1_member5, egress_disable=False) - self.assertEqual(status, SAI_STATUS_SUCCESS) + super(L3IPv6EcmpLagTestHelper, self).tearDown() - def l3IPv4EcmpHostPortLagSharedMembersTest(self): - """ - IPv4 multiples ECMP with shared nexthop members - """ - print("l3IPv4EcmpHostPortLagSharedMembersTest") - src_mac = '00:01:01:01:01:01' - # verify NG1 route - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - verify_any_packet_any_port(self, [exp_pkt1, exp_pkt2, exp_pkt3, - exp_pkt4], ports_to_verify) - # verify NG2 traffic - dst_ip = "20.20.1.21" - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip, - ip_src='192.168.1.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ip_dst=dst_ip, - ip_src='192.168.1.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ip_dst=dst_ip, - ip_src='192.168.1.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - verify_any_packet_any_port(self, [exp_pkt1, exp_pkt2], - ports_to_verify) - def setupECMPIPv4Hash(self, hash_field_list=None): + def setupECMPIPv6Hash(self, hash_field_list=None): """ - Setups ECMP IPv4 hash - + Setups ECMP IPv6 hash Args: hash_field_list (list): list of hash fields """ - print("Setting the ECMP IPv4 hash fields..") + print("Setting the ECMP IPv6 hash fields..") if hash_field_list is None: hash_field_list = [ - SAI_NATIVE_HASH_FIELD_SRC_IP, - SAI_NATIVE_HASH_FIELD_DST_IP, + SAI_NATIVE_HASH_FIELD_SRC_IP, SAI_NATIVE_HASH_FIELD_DST_IP, SAI_NATIVE_HASH_FIELD_IP_PROTOCOL, SAI_NATIVE_HASH_FIELD_L4_DST_PORT, SAI_NATIVE_HASH_FIELD_L4_SRC_PORT ] s32list = sai_thrift_s32_list_t( count=len(hash_field_list), int32list=hash_field_list) - if self.ipv4_hash_id == 0: - self.ipv4_hash_id = sai_thrift_create_hash( + if self.ipv6_hash_id == 0: + self.ipv6_hash_id = sai_thrift_create_hash( self.client, native_hash_field_list=s32list) + self.assertTrue(self.ipv6_hash_id != 0, + "Failed to create IPv6 hash") else: status = sai_thrift_set_hash_attribute( - self.client, self.ipv4_hash_id, native_hash_field_list=s32list) + self.client, self.ipv6_hash_id, native_hash_field_list=s32list) self.assertEqual(status, SAI_STATUS_SUCCESS) - def setupECMPHash(self, hash_fields_list): - """ - Setups ECMP hash - - Args: - hash_fields_list (list): list of hash fields - """ - print("Setting the ECMP hash fields..") - # Set ECMP HASH - attr_list = sai_thrift_get_switch_attribute( - self.client, ecmp_hash=True) - hash_id = attr_list['SAI_SWITCH_ATTR_ECMP_HASH'] - print("ECMP hash id =0x%x" % (hash_id)) - - hash_attr_list = [] - s32list = sai_thrift_s32_list_t(count=100, int32list=hash_attr_list) - hash_data = sai_thrift_get_hash_attribute( - self.client, hash_id, native_hash_field_list=s32list) - data_val = hash_data['native_hash_field_list'].int32list - print('hash_data: ', hash_data) - print('hash_val: ', data_val) - hash_attr_list = hash_fields_list - hash_field_list = sai_thrift_s32_list_t( - count=len(hash_attr_list), int32list=hash_attr_list) - status = sai_thrift_set_hash_attribute( - self.client, hash_id, native_hash_field_list=hash_field_list) - self.assertEqual(status, SAI_STATUS_SUCCESS) +class l3Ipv6EcmpLpmTest(L3IPv6EcmpLagTestHelper): + """ + Base ECMP tests with LPM routes for IPv6 + """ + def setUp(self): + super(l3Ipv6EcmpLpmTest, self).setUp() - def l3IPv4EcmpHostTwoLagsTest(self): - """ - IPv4 ECMP tests with all LAG RIFs members - """ - print("l3IPv4EcmpHostTwoLagsTest") + def runTest(self): + print("l3Ipv6EcmpLpmTest") + dmac7 = '00:77:77:77:77:77' + nhop_ip7 = '7000:1:1:0:0:0:0:1' + try: + # create the IPv6 LPM route entry + neighbor_entry17 = sai_thrift_neighbor_entry_t( + self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip7)) + sai_thrift_create_neighbor_entry( + self.client, neighbor_entry17, dst_mac_address=dmac7) + nhop7 = sai_thrift_create_next_hop( + self.client, + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.lag2_rif, + ip=sai_ipaddress(nhop_ip7)) + nhop_group3 = sai_thrift_create_next_hop_group( + self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) + nh_group3_member1 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=nhop_group3, + next_hop_id=nhop7) + route3 = sai_thrift_route_entry_t( + switch_id=self.switch_id, + destination=sai_ipprefix('5500:1:1:0:0:0:0:1/70'), + vr_id=self.default_vrf) + status = sai_thrift_create_route_entry( + self.client, route3, next_hop_id=nhop_group3) + self.assertEqual(status, SAI_STATUS_SUCCESS) + count = [0, 0, 0] + dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:22:22' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=64) + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:77:77:77:77:77', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1], ports_to_verify) + count[rcv_idx] += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + print("PORT lb counts", count) + ecmp_count = [(count[0] + count[1] + count[2])] + print("ECMP count:", ecmp_count) + for i in range(0, 3): + self.assertTrue((count[i] >= ((MAX_ITRS / 3) * 0.75)), + "Ecmp paths are not equally balanced") + finally: + sai_thrift_remove_neighbor_entry( + self.client, neighbor_entry17) + sai_thrift_remove_next_hop_group_member(self.client, + nh_group3_member1) + sai_thrift_remove_route_entry(self.client, route3) + sai_thrift_remove_next_hop_group(self.client, nhop_group3) + sai_thrift_remove_next_hop(self.client, nhop7) + + def tearDown(self): + super(l3Ipv6EcmpLpmTest, self).tearDown() + +class l3IPv6EcmpHostTwoLagsTest(L3IPv6EcmpLagTestHelper): + """ + IPv6 ECMP tests with all members with RIF as LAG + """ + def setUp(self): + super(l3IPv6EcmpHostTwoLagsTest, self).setUp() + + def runTest(self): + print("l3IPv6EcmpHostTwoLagsTest") count = [0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('20.20.20.1')), 16) - src_mac_start = '00:22:22:22:{0}:{1}' + dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:22:22' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) src_mac = src_mac_start.format( str(i).zfill(4)[:2], str(i).zfill(4)[2:]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='6000:1:1:0:0:0:0:1', + ipv6_hlim=64) + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:55:55:55:55:55', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='6000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet(eth_dst='00:66:66:66:66:66', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='6000:1:1:0:0:0:0:1', + ipv6_hlim=63) send_packet(self, self.dev_port15, pkt) ports_to_verify = [ self.dev_port4, # LAG1 ports @@ -1357,326 +1502,66 @@ def l3IPv4EcmpHostTwoLagsTest(self): rcv_idx = verify_any_packet_any_port( self, [exp_pkt1, exp_pkt2], ports_to_verify) count[rcv_idx] += 1 - dst_ip += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) print("PORT lb counts", count) ecmp_count = [(count[0] + count[1] + count[2]), (count[3] + count[4] + count[5])] print("ECMP count:", ecmp_count) for i in range(0, 2): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.7)), + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.5)), "Ecmp paths are not equally balanced") - for i in range(0, 3): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), - "Lag path1 is not equally balanced") - for i in range(3, 6): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), - "Lag path2 is not equally balanced") + def tearDown(self): + super(l3IPv6EcmpHostTwoLagsTest, self).tearDown() - def l3IPv4EcmpHostPortLagTest(self): - """ - IPv4 ECMP load balance tests to check fair share on all members - """ - print("l3IPv4EcmpHostPortLagTest") - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - src_mac = '00:22:22:22:00:00' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], - ports_to_verify) - count[rcv_idx] += 1 - dst_ip += 1 - print("PORT lb counts", count) - ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP count:", ecmp_count) - for i in range(0, 4): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Ecmp paths are not equally balanced") - for i in range(2, 5): - self.assertTrue((count[i] >= ((MAX_ITRS / 12) * 0.5)), - "Lag path1 is not equally balanced") - for i in range(5, 8): - self.assertTrue((count[i] >= ((MAX_ITRS / 12) * 0.5)), - "Lag path2 is not equally balanced") - def l3IPv4EcmpHashPortLagTest(self): - """ - Creates hash object and sends multiple packets - Validates that there is no load balancing with various fields - in ECMP hash - """ - print("l3IPv4EcmpHashPortLagTest") - # setup the ECMP hash to SRC IP - print("Limit ECMP IPv4 hash to SRC_IP only.") - # for our test it will disable LB. - self.setupECMPIPv4Hash([SAI_NATIVE_HASH_FIELD_SRC_IP]) - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - src_mac = '00:22:22:22:22:22' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], - ports_to_verify) - count[rcv_idx] += 1 - dst_ip += 1 - print("PORT lb counts:", count) - ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP count:", ecmp_count) - # Traffic should not be ballanced, should apear on single port or - # LAG - if ecmp_count[0] != 0: - self.assertTrue(ecmp_count[0] == MAX_ITRS, - "100% expected on this port") - self.assertTrue(ecmp_count[1] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[2] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[3] == 0, - "No traffic expected on this port") - elif ecmp_count[1] != 0: - self.assertTrue(ecmp_count[0] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[1] == MAX_ITRS, - "100% expected on this port") - self.assertTrue(ecmp_count[2] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[3] == 0, - "No traffic expected on this port") - elif ecmp_count[2] != 0: - self.assertTrue(ecmp_count[0] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[1] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[2] == MAX_ITRS, - "100% expected on this port") - self.assertTrue(ecmp_count[3] == 0, - "No traffic expected on this port") - elif ecmp_count[3] != 0: - self.assertTrue(ecmp_count[0] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[1] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[2] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[3] == MAX_ITRS, - "100% expected on this port") - # enable LB back to IPv4 full fields list - print("Enable ECMP IPv4 LB") - self.setupECMPIPv4Hash() - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - src_mac = '00:22:22:22:22:22' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], - ports_to_verify) - count[rcv_idx] += 1 - dst_ip += 1 - print("PORT lb counts:", count) - ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP count:", ecmp_count) - # Traffic should equally be ballanced, should apear on all port or - # LAG - for i in range(0, 4): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Ecmp paths are not equally balanced") +class l3IPv6EcmpHostPortLagTest(L3IPv6EcmpLagTestHelper): + """ + IPv6 ECMP tests with members combination of port and LAG RIFs + """ + def setUp(self): + super(l3IPv6EcmpHostPortLagTest, self).setUp() - def l3IPv4EcmpHashSeedPortLag(self): - """ - Changes ECMP seed attribute and checks for rebalancing - """ - print("l3IPv4EcmpHashSeedPortLag") - # setup the SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED - attr = sai_thrift_get_switch_attribute( - self.client, ecmp_default_hash_seed=200) - print(attr) - ecmp_default_hash_seed = attr['ecmp_default_hash_seed'] - status = sai_thrift_set_switch_attribute( - self.client, ecmp_default_hash_seed=200) - self.assertEqual(status, SAI_STATUS_SUCCESS) - attr = sai_thrift_get_switch_attribute( - self.client, ecmp_default_hash_seed=True) - print(attr) - self.assertEqual(attr['ecmp_default_hash_seed'], 200) + def runTest(self): + print("l3IPv6EcmpHostPortLagTest") try: count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:{0}:{1}' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - src_mac = '00:22:22:22:22:22' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=64) + + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + send_packet(self, self.dev_port15, pkt) ports_to_verify = [ self.dev_port11, @@ -1692,59 +1577,79 @@ def l3IPv4EcmpHashSeedPortLag(self): self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], ports_to_verify) count[rcv_idx] += 1 - dst_ip += 1 - print("PORT lb counts:", count) + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + + print("PORT lb counts", count) ecmp_count = [ count[0], count[1], (count[2] + count[3] + count[4]), (count[5] + count[6] + count[7])] - print("ECMP count:", ecmp_count) - # Traffic should equally be ballanced, should apear on all port or - # LAG + print("ECMP counts", ecmp_count) for i in range(0, 4): self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), "Ecmp paths are not equally balanced") - # reconfugure the default ECMP hash seed - sai_thrift_set_switch_attribute( - self.client, ecmp_default_hash_seed=400) - self.assertEqual(attr['ecmp_default_hash_seed'], 400) + + finally: + pass + + def tearDown(self): + super(l3IPv6EcmpHostPortLagTest, self).tearDown() + + +class l3IPv6EcmpHashPortLagTest(L3IPv6EcmpLagTestHelper): + """ + IPv6 ECMP loads balance tests to check fair share on all members + """ + def setUp(self): + super(l3IPv6EcmpHashPortLagTest, self).setUp() + + def runTest(self): + print("l3IPv6EcmpHashPortLagTest") + + print("Limit ECMP IPv6 hash to SRC_IP only.") + # for our test it will disable LB. + self.setupECMPIPv6Hash([SAI_NATIVE_HASH_FIELD_SRC_IP]) + + try: count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:{0}:{1}' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) src_mac = '00:22:22:22:22:22' - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=64) + + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + send_packet(self, self.dev_port15, pkt) ports_to_verify = [ self.dev_port11, @@ -1760,7 +1665,9 @@ def l3IPv4EcmpHashSeedPortLag(self): self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], ports_to_verify) count[rcv_idx] += 1 - dst_ip += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + print("PORT lb counts:", count) ecmp_count = [ count[0], @@ -1768,600 +1675,168 @@ def l3IPv4EcmpHashSeedPortLag(self): (count[2] + count[3] + count[4]), (count[5] + count[6] + count[7])] print("ECMP count:", ecmp_count) - # Traffic should equally be ballanced, should apear on all port or + # Traffic should not be ballanced, should apear on single port or # LAG - for i in range(0, 4): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.75)), - "Ecmp paths are not equally balanced") - finally: - sai_thrift_set_switch_attribute( - self.client, - ecmp_default_hash_seed=ecmp_default_hash_seed) - + if ecmp_count[0] != 0: + self.assertTrue( + ecmp_count[0] == MAX_ITRS, + "100 % traffic({}) expected on port: {}, but received only" + "{} packets".format(MAX_ITRS, self.dev_port11, + ecmp_count[0])) # port 11 + self.assertTrue( + ecmp_count[1] == 0, + "No traffic expected on port:{}".format( + self.dev_port12)) # port 12 + self.assertTrue(ecmp_count[2] == 0, + "No traffic expected on ports: {}" + .format([self.dev_port4, self.dev_port5, + self.dev_port6])) # LAG 1 + self.assertTrue(ecmp_count[3] == 0, + "No traffic expected on ports:{}" + .format([self.dev_port7, self.dev_port8, + self.dev_port9])) # LAG 2 + elif ecmp_count[1] != 0: + self.assertTrue( + ecmp_count[0] == 0, + "No traffic expected on port:{}" + .format(self.dev_port11)) + self.assertTrue( + ecmp_count[1] == MAX_ITRS, + "100 % traffic({}) expected on port: {}, but received" + "only {} packets".format(MAX_ITRS, self.dev_port12, + ecmp_count[1])) + self.assertTrue(ecmp_count[2] == 0, + "No traffic expected on ports:{}" + .format([self.dev_port4, self.dev_port5, + self.dev_port6])) + self.assertTrue(ecmp_count[3] == 0, + "No traffic expected on ports:{}" + .format([self.dev_port7, self.dev_port8, + self.dev_port9])) + elif ecmp_count[2] != 0: + self.assertTrue( + ecmp_count[0] == 0, + "No traffic expected on port:{}".format(self.dev_port11)) + self.assertTrue( + ecmp_count[1] == 0, + "No traffic expected on port:{}".format(self.dev_port12)) + self.assertTrue( + ecmp_count[2] == MAX_ITRS, + "100 % traffic({}) expected on ports: {}, but received" + "only {} packets".format(MAX_ITRS, + [self.dev_port4, self.dev_port5, + self.dev_port6], + ecmp_count[2])) + self.assertTrue(ecmp_count[3] == 0, + "No traffic expected on ports:{}" + .format([self.dev_port7, self.dev_port8, + self.dev_port9])) + elif ecmp_count[3] != 0: + self.assertTrue( + ecmp_count[0] == 0, + "No traffic expected on port:{}".format(self.dev_port11)) + self.assertTrue( + ecmp_count[1] == 0, + "No traffic expected on port:{}".format(self.dev_port12)) + self.assertTrue(ecmp_count[2] == 0, + "No traffic expected on ports:{}" + .format([self.dev_port4, self.dev_port5, + self.dev_port6])) + self.assertTrue( + ecmp_count[3] == MAX_ITRS, + "100 % traffic({}) expected on ports: {}, but received" + "only {} pakets".format(MAX_ITRS, + [self.dev_port7, self.dev_port8, + self.dev_port9], ecmp_count[3])) -@group("draft") -class L3IPv6EcmpLagTest(SaiHelper): - """ - Base ECMP tests with ECMP members as LAG RIFs - """ - def setUp(self): + # enable LB back to IPv4 full fields list + print("Enable ECMP IPv6 LB") + self.setupECMPIPv6Hash() - super(L3IPv6EcmpLagTest, self).setUp() + count = [0, 0, 0, 0, 0, 0, 0, 0] + dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:{0}:{1}' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + src_mac = '00:22:22:22:22:22' + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=64) - dmac1 = '00:11:11:11:11:11' - dmac2 = '00:22:22:22:22:22' - dmac3 = '00:33:33:33:33:33' - dmac4 = '00:44:44:44:44:44' - dmac5 = '00:55:55:55:55:55' - dmac6 = '00:66:66:66:66:66' - nhop_ip1 = '1000:1:1:0:0:0:0:1' - nhop_ip2 = '2000:1:1:0:0:0:0:1' - nhop_ip3 = '3000:1:1:0:0:0:0:1' - nhop_ip4 = '4000:1:1:0:0:0:0:1' - nhop_ip5 = '5000:1:1:0:0:0:0:1' - nhop_ip6 = '6000:1:1:0:0:0:0:1' - # set switch src mac address - sai_thrift_set_switch_attribute( - self.client, src_mac_address=ROUTER_MAC) - sai_thrift_set_switch_attribute( - self.client, ecmp_default_hash_seed=TEST_ECMP_SEED) - sai_thrift_set_switch_attribute( - self.client, lag_default_hash_seed=TEST_LAG_SEED) - self.lag1_rif = sai_thrift_create_router_interface( - self.client, - type=SAI_ROUTER_INTERFACE_TYPE_PORT, - virtual_router_id=self.default_vrf, - port_id=self.lag1, - admin_v6_state=True) - self.lag2_rif = sai_thrift_create_router_interface( - self.client, - type=SAI_ROUTER_INTERFACE_TYPE_PORT, - virtual_router_id=self.default_vrf, - port_id=self.lag2, - admin_v6_state=True) - self.port15_rif = sai_thrift_create_router_interface( - self.client, - type=SAI_ROUTER_INTERFACE_TYPE_PORT, - virtual_router_id=self.default_vrf, - port_id=self.port15, - admin_v6_state=True) - # test neighbor creation - self.neighbor_entry11 = sai_thrift_neighbor_entry_t( - self.switch_id, self.port11_rif, sai_ipaddress(nhop_ip1)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry11, dst_mac_address=dmac1) - self.neighbor_entry12 = sai_thrift_neighbor_entry_t( - self.switch_id, self.port12_rif, sai_ipaddress(nhop_ip2)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry12, dst_mac_address=dmac2) - self.neighbor_entry13 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip3)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry13, dst_mac_address=dmac3) - self.neighbor_entry14 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip4)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry14, dst_mac_address=dmac4) - self.neighbor_entry15 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip5)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry15, dst_mac_address=dmac5) - self.neighbor_entry16 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip6)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry16, dst_mac_address=dmac6) - self.nhop1 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.port11_rif, - ip=sai_ipaddress(nhop_ip1)) - self.nhop2 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.port12_rif, - ip=sai_ipaddress(nhop_ip2)) - self.nhop3_lag1 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag1_rif, - ip=sai_ipaddress(nhop_ip3)) - self.nhop4_lag2 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag2_rif, - ip=sai_ipaddress(nhop_ip4)) - self.nhop5_lag1 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag1_rif, - ip=sai_ipaddress(nhop_ip5)) - self.nhop6_lag2 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag2_rif, - ip=sai_ipaddress(nhop_ip6)) - self.nhop_group1 = sai_thrift_create_next_hop_group( - self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) - self.nh_group1_member1 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop1) - self.nh_group1_member2 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop2) - self.nh_group1_member3 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop3_lag1) - self.nh_group1_member4 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop4_lag2) - self.nhop_group2 = sai_thrift_create_next_hop_group( - self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) - self.nh_group2_member1 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop5_lag1) - self.nh_group2_member2 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop6_lag2) - # create route entries - self.route0 = sai_thrift_route_entry_t( - switch_id=self.switch_id, - destination=sai_ipprefix('1000:1:1:0:0:0:0:0/65'), - vr_id=self.default_vrf) - status = sai_thrift_create_route_entry( - self.client, self.route0, next_hop_id=self.nhop_group1) - self.assertEqual(status, SAI_STATUS_SUCCESS) - self.route1 = sai_thrift_route_entry_t( - switch_id=self.switch_id, - destination=sai_ipprefix('5500:1:1:0:0:0:0:1/65'), - vr_id=self.default_vrf) - status = sai_thrift_create_route_entry( - self.client, self.route1, next_hop_id=self.nhop_group2) - self.assertEqual(status, SAI_STATUS_SUCCESS) - # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash - self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) - def runTest(self): - self.l3IPv6EcmpHostTwoLagsTest() - self.l3IPv6EcmpHostTwoLagsDisabledLagMembersTest() - self.l3IPv6EcmpHostPortLagTest() - self.l3IPv6EcmpHostPortLagSharedMembersTest() - self.l3IPv6EcmpHashPortLagTest() - self.l3Ipv6EcmpAddRemoveNhopTest() - self.l3Ipv6EcmpLpmTest() + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) + count[rcv_idx] += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + + print("PORT lb counts:", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count:", ecmp_count) + # Traffic should equally be ballanced, should apear on all port or + # LAG + for i in range(0, 4): + print("ecmp_count=", ecmp_count, (MAX_ITRS / 4) * 0.5) + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), + "Ecmp paths are not equally balanced") + + finally: + pass def tearDown(self): - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry11) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry12) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry13) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry14) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry15) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry16) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member1) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member2) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member3) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member4) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member1) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member2) - sai_thrift_remove_route_entry(self.client, self.route0) - sai_thrift_remove_route_entry(self.client, self.route1) - self.assertEqual(nhg_members_count(self.client, self.nhop_group1), 0) - self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) - sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) - sai_thrift_remove_next_hop_group(self.client, self.nhop_group2) - sai_thrift_remove_next_hop(self.client, self.nhop1) - sai_thrift_remove_next_hop(self.client, self.nhop2) - sai_thrift_remove_next_hop(self.client, self.nhop3_lag1) - sai_thrift_remove_next_hop(self.client, self.nhop4_lag2) - sai_thrift_remove_next_hop(self.client, self.nhop5_lag1) - sai_thrift_remove_next_hop(self.client, self.nhop6_lag2) - sai_thrift_remove_router_interface(self.client, self.lag1_rif) - sai_thrift_remove_router_interface(self.client, self.lag2_rif) - sai_thrift_remove_router_interface(self.client, self.port15_rif) - release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) + super(l3IPv6EcmpHashPortLagTest, self).tearDown() - super(L3IPv6EcmpLagTest, self).tearDown() - def setupECMPIPv6Hash(self, hash_field_list=None): - """ - Setups ECMP IPv6 hash - Args: - hash_field_list (list): list of hash fields - """ - print("Setting the ECMP IPv6 hash fields..") - if hash_field_list is None: - hash_field_list = [ - SAI_NATIVE_HASH_FIELD_SRC_IP, SAI_NATIVE_HASH_FIELD_DST_IP, - SAI_NATIVE_HASH_FIELD_IP_PROTOCOL, - SAI_NATIVE_HASH_FIELD_L4_DST_PORT, - SAI_NATIVE_HASH_FIELD_L4_SRC_PORT - ] - s32list = sai_thrift_s32_list_t( - count=len(hash_field_list), int32list=hash_field_list) - if self.ipv6_hash_id == 0: - self.ipv6_hash_id = sai_thrift_create_hash( - self.client, native_hash_field_list=s32list) - self.assertTrue(self.ipv6_hash_id != 0, - "Failed to create IPv6 hash") - else: - status = sai_thrift_set_hash_attribute( - self.client, self.ipv6_hash_id, native_hash_field_list=s32list) - self.assertEqual(status, SAI_STATUS_SUCCESS) +class l3IPv6EcmpHostTwoLagsDisabledLagMembersTest(L3IPv6EcmpLagTestHelper): + """ + IPv6 ECMP tests with LAG RIF and some LAG member in disable state + """ + def setUp(self): + super(l3IPv6EcmpHostTwoLagsDisabledLagMembersTest, self).setUp() - def l3Ipv6EcmpLpmTest(self): - """ - Base ECMP tests with LPM routes for IPv6 - """ - print("l3Ipv6EcmpLpmTest") - dmac7 = '00:77:77:77:77:77' - nhop_ip7 = '7000:1:1:0:0:0:0:1' - try: - # create the IPv6 LPM route entry - neighbor_entry17 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip7)) - sai_thrift_create_neighbor_entry( - self.client, neighbor_entry17, dst_mac_address=dmac7) - nhop7 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag2_rif, - ip=sai_ipaddress(nhop_ip7)) - nhop_group3 = sai_thrift_create_next_hop_group( - self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) - nh_group3_member1 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=nhop_group3, - next_hop_id=nhop7) - route3 = sai_thrift_route_entry_t( - switch_id=self.switch_id, - destination=sai_ipprefix('5500:1:1:0:0:0:0:1/70'), - vr_id=self.default_vrf) - status = sai_thrift_create_route_entry( - self.client, route3, next_hop_id=nhop_group3) - self.assertEqual(status, SAI_STATUS_SUCCESS) - count = [0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:22:22' - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:77:77:77:77:77', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1], ports_to_verify) - count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("PORT lb counts", count) - ecmp_count = [(count[0] + count[1] + count[2])] - print("ECMP count:", ecmp_count) - for i in range(0, 3): - self.assertTrue((count[i] >= ((MAX_ITRS / 3) * 0.75)), - "Ecmp paths are not equally balanced") - finally: - sai_thrift_remove_neighbor_entry( - self.client, neighbor_entry17) - sai_thrift_remove_next_hop_group_member(self.client, - nh_group3_member1) - sai_thrift_remove_route_entry(self.client, route3) - sai_thrift_remove_next_hop_group(self.client, nhop_group3) - sai_thrift_remove_next_hop(self.client, nhop7) - - def l3IPv6EcmpHostTwoLagsTest(self): - """ - IPv6 ECMP tests with all members with RIF as LAG - """ - print("l3IPv6EcmpHostTwoLagsTest") - count = [0, 0, 0, 0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:22:22' - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='6000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='6000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='6000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2], ports_to_verify) - count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("PORT lb counts", count) - ecmp_count = [(count[0] + count[1] + count[2]), - (count[3] + count[4] + count[5])] - print("ECMP count:", ecmp_count) - for i in range(0, 2): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.5)), - "Ecmp paths are not equally balanced") - - def l3IPv6EcmpHostPortLagTest(self): - """ - IPv6 ECMP tests with members combination of port and LAG RIFs - """ - print("l3IPv6EcmpHostPortLagTest") - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:{0}:{1}' - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], - ports_to_verify) - count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("PORT lb counts", count) - ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP counts", ecmp_count) - for i in range(0, 4): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Ecmp paths are not equally balanced") - - def l3IPv6EcmpHashPortLagTest(self): - """ - IPv6 ECMP loads balance tests to check fair share on all members - """ - print("l3IPv6EcmpHashPortLagTest") - print("Limit ECMP IPv6 hash to SRC_IP only.") - # for our test it will disable LB. - self.setupECMPIPv6Hash([SAI_NATIVE_HASH_FIELD_SRC_IP]) - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = '00:22:22:22:22:22' - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], - ports_to_verify) - count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("PORT lb counts:", count) - ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP count:", ecmp_count) - # Traffic should not be ballanced, should apear on single port or - # LAG - if ecmp_count[0] != 0: - self.assertTrue(ecmp_count[0] == MAX_ITRS, - "100% expected on this port") - self.assertTrue(ecmp_count[1] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[2] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[3] == 0, - "No traffic expected on this port") - elif ecmp_count[1] != 0: - self.assertTrue(ecmp_count[0] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[1] == MAX_ITRS, - "100% expected on this port") - self.assertTrue(ecmp_count[2] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[3] == 0, - "No traffic expected on this port") - elif ecmp_count[2] != 0: - self.assertTrue(ecmp_count[0] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[1] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[2] == MAX_ITRS, - "100% expected on this port") - self.assertTrue(ecmp_count[3] == 0, - "No traffic expected on this port") - elif ecmp_count[3] != 0: - self.assertTrue(ecmp_count[0] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[1] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[2] == 0, - "No traffic expected on this port") - self.assertTrue(ecmp_count[3] == MAX_ITRS, - "100% expected on this port") - # enable LB back to IPv4 full fields list - print("Enable ECMP IPv6 LB") - self.setupECMPIPv6Hash() - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = '00:22:22:22:22:22' - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, - self.dev_port5, - self.dev_port6, - self.dev_port7, - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], - ports_to_verify) - count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("PORT lb counts:", count) - ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP count:", ecmp_count) - # Traffic should equally be ballanced, should apear on all port or - # LAG - for i in range(0, 4): - print("ecmp_count=", ecmp_count, (MAX_ITRS / 4) * 0.5) - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Ecmp paths are not equally balanced") - - def l3IPv6EcmpHostTwoLagsDisabledLagMembersTest(self): - """ - IPv6 ECMP tests with LAG RIF and some LAG member in disable state - """ + def runTest(self): print("l3IPv6EcmpHostTwoLagsDisabledLagMembersTest") print("Disable LAG1 member 4 and 5") print("Disable LAG2 member 7") @@ -2445,10 +1920,18 @@ def l3IPv6EcmpHostTwoLagsDisabledLagMembersTest(self): self.client, self.lag2_member7, egress_disable=False) self.assertEqual(status, SAI_STATUS_SUCCESS) - def l3Ipv6EcmpAddRemoveNhopTest(self): - """ - IPv6 ECMP rebalance test with removal of a nexthop member - """ + def tearDown(self): + super(l3IPv6EcmpHostTwoLagsDisabledLagMembersTest, self).tearDown() + + +class l3Ipv6EcmpAddRemoveNhopTest(L3IPv6EcmpLagTestHelper): + """ + IPv6 ECMP rebalance test with removal of a nexthop member + """ + def setUp(self): + super(l3Ipv6EcmpAddRemoveNhopTest, self).setUp() + + def runTest(self): print("l3Ipv6EcmpAddRemoveNhopTest") print("Add new nhg member") dmac7 = '00:77:77:77:77:77' @@ -2607,138 +2090,646 @@ def l3Ipv6EcmpAddRemoveNhopTest(self): self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), "Ecmp paths are not equally balanced") - def l3IPv6EcmpHostPortLagSharedMembersTest(self): - """ - IPv6 Multiple ECMP with shared nexthop members - """ - print("l3IPv6EcmpHostPortLagSharedMembersTest") + def tearDown(self): + super(l3Ipv6EcmpAddRemoveNhopTest, self).tearDown() + + +class l3IPv6EcmpHostPortLagSharedMembersTest(L3IPv6EcmpLagTestHelper): + """ + IPv6 Multiple ECMP with shared nexthop members + """ + def setUp(self): + super(l3IPv6EcmpHostPortLagSharedMembersTest, self).setUp() + + def runTest(self): + print("l3IPv6EcmpHostPortLagSharedMembersTest") + try: + count = [0, 0, 0, 0, 0, 0] + dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:{0}:{1}' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='6000:1:1:0:0:0:0:1', + ipv6_hlim=64) + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:55:55:55:55:55', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='6000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet(eth_dst='00:66:66:66:66:66', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='6000:1:1:0:0:0:0:1', + ipv6_hlim=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port4, + self.dev_port5, + self.dev_port6, + self.dev_port7, + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2], ports_to_verify) + count[rcv_idx] += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + print("PORT lb counts:", count) + ecmp_count = [(count[0] + count[1] + count[2]), + (count[3] + count[4] + count[5])] + print("ECMP count:", ecmp_count) + # check LAG1 traffic + for i in range(0, 3): + self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.75)), + "Lag path1 is not equally balanced") + # check LAG2 traffic + for i in range(3, 6): + self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.5)), + "Lag path2 is not equally balanced") + print(ecmp_count) + for i in range(0, 2): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.5)), + "Ecmp paths are not equally balanced") + finally: + count = [0, 0, 0, 0, 0, 0, 0, 0] + dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:{0}:{1}' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=64) + exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ipv6_dst=dst_ip_addr, + ipv6_src='5000:1:1:0:0:0:0:1', + ipv6_hlim=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port11, + self.dev_port12, + self.dev_port4, + self.dev_port5, + self.dev_port6, + self.dev_port7, + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) + count[rcv_idx] += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + print("Port lb counts:", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count :", ecmp_count) + for i in range(0, 4): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), + "Ecmp paths are not equally balanced") + + def tearDown(self): + super(l3IPv6EcmpHostPortLagSharedMembersTest, self).tearDown() + +@group("draft") +class L3IPv4SVIEcmpTestHelper(PlatformSaiHelper): + """ + Base ECMP tests for IPv4 and ECMP members as SVI RIFs + """ + def setUp(self): + + super(L3IPv4SVIEcmpTestHelper, self).setUp() + + self.vlan100_rif_counter_in = 0 + self.vlan100_rif_counter_out = 0 + self.vlan200_rif_counter_in = 0 + self.vlan200_rif_counter_out = 0 + self.vlan100_bcast_in = 0 + self.vlan100_bcast_out = 0 + self.vlan200_bcast_in = 0 + self.vlan200_bcast_out = 0 + # set switch src mac address + sai_thrift_set_switch_attribute( + self.client, src_mac_address=ROUTER_MAC) + sai_thrift_set_switch_attribute( + self.client, ecmp_default_hash_seed=TEST_ECMP_SEED) + sai_thrift_set_switch_attribute( + self.client, lag_default_hash_seed=TEST_LAG_SEED) + self.port24_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.port24, + type=SAI_BRIDGE_PORT_TYPE_PORT) + self.port25_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.port25, + type=SAI_BRIDGE_PORT_TYPE_PORT) + self.port26_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.port26, + type=SAI_BRIDGE_PORT_TYPE_PORT) + # vlan100 with members port24, port25 and port26 + self.vlan100 = sai_thrift_create_vlan(self.client, vlan_id=100) + self.vlan_member100 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan100, + bridge_port_id=self.port24_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + self.vlan_member101 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan100, + bridge_port_id=self.port25_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + self.vlan_member102 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan100, + bridge_port_id=self.port26_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + sai_thrift_set_port_attribute( + self.client, self.port24, port_vlan_id=100) + sai_thrift_set_port_attribute( + self.client, self.port25, port_vlan_id=100) + sai_thrift_set_port_attribute( + self.client, self.port26, port_vlan_id=100) + # create vlan100_rif + self.vlan100_rif = sai_thrift_create_router_interface( + self.client, + type=SAI_ROUTER_INTERFACE_TYPE_VLAN, + virtual_router_id=self.default_vrf, + vlan_id=self.vlan100) + dmac1 = '00:11:22:33:44:55' + dmac2 = '00:22:22:33:44:55' + dmac3 = '00:33:22:33:44:55' + dmac4 = '00:44:22:33:44:55' + dmac5 = '00:11:33:33:44:55' + dmac6 = '00:22:33:33:44:55' + dmac7 = '00:44:33:33:44:55' + # create nhop1, nhop2 & nhop3 on SVI + self.nhop1 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('10.10.0.1'), + router_interface_id=self.vlan100_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry1 = sai_thrift_neighbor_entry_t( + rif_id=self.vlan100_rif, ip_address=sai_ipaddress('10.10.0.1')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry1, dst_mac_address=dmac1) + self.nhop2 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('10.10.0.2'), + router_interface_id=self.vlan100_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry2 = sai_thrift_neighbor_entry_t( + rif_id=self.vlan100_rif, ip_address=sai_ipaddress('10.10.0.2')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry2, dst_mac_address=dmac2) + self.nhop3 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('10.10.0.3'), + router_interface_id=self.vlan100_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry3 = sai_thrift_neighbor_entry_t( + rif_id=self.vlan100_rif, ip_address=sai_ipaddress('10.10.0.3')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry3, dst_mac_address=dmac3) + self.nhop_group1 = sai_thrift_create_next_hop_group( + self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) + self.nh_group1_member1 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group1, + next_hop_id=self.nhop1) + self.nh_group1_member2 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group1, + next_hop_id=self.nhop2) + self.nh_group1_member3 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group1, + next_hop_id=self.nhop3) + # create route entries + self.route0 = sai_thrift_route_entry_t( + switch_id=self.switch_id, + destination=sai_ipprefix('10.20.30.1/16'), + vr_id=self.default_vrf) + status = sai_thrift_create_route_entry( + self.client, self.route0, next_hop_id=self.nhop_group1) + self.assertEqual(status, SAI_STATUS_SUCCESS) + # create nhop and route to L2 intf + self.nhop4 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('11.11.0.2'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry4 = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, ip_address=sai_ipaddress('11.11.0.2')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry4, dst_mac_address=dmac4) + self.lag10 = sai_thrift_create_lag(self.client) + self.lag10_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.lag10, + type=SAI_BRIDGE_PORT_TYPE_PORT) + self.lag10_member30 = sai_thrift_create_lag_member( + self.client, lag_id=self.lag10, port_id=self.port30) + self.lag10_member31 = sai_thrift_create_lag_member( + self.client, lag_id=self.lag10, port_id=self.port31) + self.lag11 = sai_thrift_create_lag(self.client) + self.lag11_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.lag11, + type=SAI_BRIDGE_PORT_TYPE_PORT) + self.lag11_member28 = sai_thrift_create_lag_member( + self.client, lag_id=self.lag11, port_id=self.port28) + self.lag11_member29 = sai_thrift_create_lag_member( + self.client, lag_id=self.lag11, port_id=self.port29) + # create vlan200_rif + self.vlan200 = sai_thrift_create_vlan(self.client, vlan_id=200) + self.vlan_member200 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan200, + bridge_port_id=self.lag10_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + self.vlan_member201 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan200, + bridge_port_id=self.lag11_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + sai_thrift_set_lag_attribute(self.client, self.lag10, port_vlan_id=200) + sai_thrift_set_lag_attribute(self.client, self.lag11, port_vlan_id=200) + self.vlan200_rif = sai_thrift_create_router_interface( + self.client, + type=SAI_ROUTER_INTERFACE_TYPE_VLAN, + virtual_router_id=self.default_vrf, + vlan_id=self.vlan200) + # Create nhop5 and nhop6 on SVI + self.nhop5 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('20.10.0.1'), + router_interface_id=self.vlan200_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry5 = sai_thrift_neighbor_entry_t( + rif_id=self.vlan200_rif, ip_address=sai_ipaddress('20.10.0.1')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry5, dst_mac_address=dmac5) + self.nhop6 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('20.10.0.2'), + router_interface_id=self.vlan200_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry6 = sai_thrift_neighbor_entry_t( + rif_id=self.vlan200_rif, ip_address=sai_ipaddress('20.10.0.2')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry6, dst_mac_address=dmac6) + self.nhop7 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('21.11.0.2'), + router_interface_id=self.port11_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry7 = sai_thrift_neighbor_entry_t( + rif_id=self.port11_rif, ip_address=sai_ipaddress('21.11.0.2')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry7, dst_mac_address=dmac7) + self.nhop_group2 = sai_thrift_create_next_hop_group( + self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) + self.nh_group2_member1 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group2, + next_hop_id=self.nhop4) + self.nh_group2_member2 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group2, + next_hop_id=self.nhop5) + self.nh_group2_member3 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group2, + next_hop_id=self.nhop6) + self.nh_group2_member4 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group2, + next_hop_id=self.nhop7) + self.route1 = sai_thrift_route_entry_t( + switch_id=self.switch_id, + destination=sai_ipprefix('10.40.40.1/16'), + vr_id=self.default_vrf) + status = sai_thrift_create_route_entry( + self.client, self.route1, next_hop_id=self.nhop_group2) + self.assertEqual(status, SAI_STATUS_SUCCESS) + # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash + self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) + + def tearDown(self): + sai_thrift_remove_route_entry(self.client, self.route1) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry4) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry5) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry6) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry7) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group2_member1) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group2_member2) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group2_member3) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group2_member4) + self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) + sai_thrift_remove_next_hop_group(self.client, self.nhop_group2) + sai_thrift_remove_next_hop(self.client, self.nhop4) + sai_thrift_remove_next_hop(self.client, self.nhop5) + sai_thrift_remove_next_hop(self.client, self.nhop6) + sai_thrift_remove_next_hop(self.client, self.nhop7) + sai_thrift_set_lag_attribute(self.client, self.lag10, port_vlan_id=0) + sai_thrift_set_lag_attribute(self.client, self.lag11, port_vlan_id=0) + sai_thrift_remove_router_interface(self.client, self.vlan200_rif) + sai_thrift_remove_vlan_member(self.client, self.vlan_member200) + sai_thrift_remove_vlan_member(self.client, self.vlan_member201) + sai_thrift_remove_vlan(self.client, self.vlan200) + sai_thrift_remove_lag_member(self.client, self.lag10_member30) + sai_thrift_remove_lag_member(self.client, self.lag10_member31) + sai_thrift_remove_lag_member(self.client, self.lag11_member28) + sai_thrift_remove_lag_member(self.client, self.lag11_member29) + sai_thrift_remove_bridge_port(self.client, self.lag10_bp) + sai_thrift_remove_bridge_port(self.client, self.lag11_bp) + sai_thrift_remove_lag(self.client, self.lag10) + sai_thrift_remove_lag(self.client, self.lag11) + sai_thrift_remove_route_entry(self.client, self.route0) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry1) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry2) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry3) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member1) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member2) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member3) + sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) + sai_thrift_remove_next_hop(self.client, self.nhop1) + sai_thrift_remove_next_hop(self.client, self.nhop2) + sai_thrift_remove_next_hop(self.client, self.nhop3) + sai_thrift_remove_router_interface(self.client, self.vlan100_rif) + sai_thrift_set_port_attribute(self.client, self.port24, port_vlan_id=0) + sai_thrift_set_port_attribute(self.client, self.port25, port_vlan_id=0) + sai_thrift_set_port_attribute(self.client, self.port26, port_vlan_id=0) + sai_thrift_remove_vlan_member(self.client, self.vlan_member100) + sai_thrift_remove_vlan_member(self.client, self.vlan_member101) + sai_thrift_remove_vlan_member(self.client, self.vlan_member102) + sai_thrift_remove_vlan(self.client, self.vlan100) + sai_thrift_remove_bridge_port(self.client, self.port24_bp) + sai_thrift_remove_bridge_port(self.client, self.port25_bp) + sai_thrift_remove_bridge_port(self.client, self.port26_bp) + release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) + + super(L3IPv4SVIEcmpTestHelper, self).tearDown() + +class l3IPv4EcmpSVIHostTest(L3IPv4SVIEcmpTestHelper): + """ + IPv4 ECMP tests with SVI RIF as member + """ + def setUp(self): + super(l3IPv4EcmpSVIHostTest, self).setUp() + + def runTest(self): + print("l3IPv4EcmpSVIHostTest") + mac_action = SAI_PACKET_ACTION_FORWARD + fdb_entry1 = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address='00:11:22:33:44:55', + bv_id=self.vlan100) + sai_thrift_create_fdb_entry( + self.client, + fdb_entry1, + type=SAI_FDB_ENTRY_TYPE_STATIC, + bridge_port_id=self.port24_bp, + packet_action=mac_action) + fdb_entry2 = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address='00:22:22:33:44:55', + bv_id=self.vlan100) + sai_thrift_create_fdb_entry( + self.client, + fdb_entry2, + type=SAI_FDB_ENTRY_TYPE_STATIC, + bridge_port_id=self.port25_bp, + packet_action=mac_action) + fdb_entry3 = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address='00:33:22:33:44:55', + bv_id=self.vlan100) + sai_thrift_create_fdb_entry( + self.client, + fdb_entry3, + type=SAI_FDB_ENTRY_TYPE_STATIC, + bridge_port_id=self.port26_bp, + packet_action=mac_action) try: - count = [0, 0, 0, 0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:{0}:{1}' + count = [0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('10.20.30.1')), 16) for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='6000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='6000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='6000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet( + eth_dst='00:11:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet( + eth_dst='00:22:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet( + eth_dst='00:33:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + send_packet(self, self.dev_port10, pkt) + self.vlan100_rif_counter_out += 1 ports_to_verify = [ - self.dev_port4, - self.dev_port5, - self.dev_port6, - self.dev_port7, - self.dev_port8, - self.dev_port9 + self.dev_port24, self.dev_port25, self.dev_port26 ] rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2], ports_to_verify) + self, [exp_pkt1, exp_pkt2, exp_pkt3], ports_to_verify) count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("PORT lb counts:", count) - ecmp_count = [(count[0] + count[1] + count[2]), - (count[3] + count[4] + count[5])] - print("ECMP count:", ecmp_count) - # check LAG1 traffic + dst_ip += 1 + print("Port LB counts:", count) for i in range(0, 3): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.75)), - "Lag path1 is not equally balanced") - # check LAG2 traffic - for i in range(3, 6): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.5)), - "Lag path2 is not equally balanced") - print(ecmp_count) - for i in range(0, 2): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.5)), - "Ecmp paths are not equally balanced") + self.assertTrue( + (count[i] >= ((MAX_ITRS / 3) * 0.5)), + "Not all paths are equally balanced, %s" % count) finally: - count = [0, 0, 0, 0, 0, 0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '1000:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:{0}:{1}' + sai_thrift_remove_fdb_entry(self.client, fdb_entry1) + sai_thrift_remove_fdb_entry(self.client, fdb_entry2) + sai_thrift_remove_fdb_entry(self.client, fdb_entry3) + + def tearDown(self): + super(l3IPv4EcmpSVIHostTest, self).tearDown() + + +class l3IPv4EcmpSVILagHostTest(L3IPv4SVIEcmpTestHelper): + """ + IPv4 ECMP tests with Port, LAG and SVI RIFs as nexthop members + """ + def setUp(self): + super(l3IPv4EcmpSVILagHostTest, self).setUp() + + def runTest(self): + print("l3IPv4EcmpSVILagHostTest") + mac_action = SAI_PACKET_ACTION_FORWARD + fdb_entry1 = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address='00:11:33:33:44:55', + bv_id=self.vlan200) + sai_thrift_create_fdb_entry( + self.client, + fdb_entry1, + type=SAI_FDB_ENTRY_TYPE_STATIC, + bridge_port_id=self.lag10_bp, + packet_action=mac_action) + fdb_entry2 = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address='00:22:33:33:44:55', + bv_id=self.vlan200) + sai_thrift_create_fdb_entry( + self.client, + fdb_entry2, + type=SAI_FDB_ENTRY_TYPE_STATIC, + bridge_port_id=self.lag11_bp, + packet_action=mac_action) + try: + count = [0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('10.40.40.1')), 16) for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt3 = simple_tcpv6_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt4 = simple_tcpv6_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='5000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port15, pkt) + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + pkt = simple_tcp_packet( + eth_dst=ROUTER_MAC, + eth_src='00:22:22:22:22:22', + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet( + eth_dst='00:44:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet( + eth_dst='00:11:33:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet( + eth_dst='00:22:33:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet( + eth_dst='00:44:33:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.0.1', + ip_id=105, + ip_ttl=63) + send_packet(self, self.dev_port10, pkt) ports_to_verify = [ + self.dev_port10, self.dev_port11, - self.dev_port12, - self.dev_port4, - self.dev_port5, - self.dev_port6, - self.dev_port7, - self.dev_port8, - self.dev_port9 - ] + self.dev_port28, + self.dev_port29, + self.dev_port30, + self.dev_port31] rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + self, + [exp_pkt1, + exp_pkt2, + exp_pkt3, + exp_pkt4], ports_to_verify) count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("Port lb counts:", count) + dst_ip += 1 ecmp_count = [ - count[0], - count[1], - (count[2] + count[3] + count[4]), - (count[5] + count[6] + count[7])] - print("ECMP count :", ecmp_count) + count[0], count[1], (count[2] + count[3]), + (count[4] + count[5]) + ] + print("PORT lb counts", count) for i in range(0, 4): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Ecmp paths are not equally balanced") + print("ECMP count LB[%d], %d, %d%%" % ( + i, ecmp_count[i], ecmp_count[i] * 100 / MAX_ITRS)) + for i in range(0, 4): + self.assertTrue( + (ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), + "Not all paths are equally balanced, %s" % count) + finally: + sai_thrift_remove_fdb_entry(self.client, fdb_entry1) + sai_thrift_remove_fdb_entry(self.client, fdb_entry2) + + def tearDown(self): + super(l3IPv4EcmpSVILagHostTest, self).tearDown() @group("draft") -class L3IPv4SVIEcmpTest(SaiHelper): +class L3IPv6SVIEcmpTestHelper(PlatformSaiHelper): """ - Base ECMP tests for IPv4 and ECMP members as SVI RIFs + Base ECMP tests for IPv6 and ECMP members as SVI RIFs """ def setUp(self): - super(L3IPv4SVIEcmpTest, self).setUp() + super(L3IPv6SVIEcmpTestHelper, self).setUp() self.vlan100_rif_counter_in = 0 self.vlan100_rif_counter_out = 0 @@ -2770,6 +2761,16 @@ def setUp(self): bridge_id=self.default_1q_bridge, port_id=self.port26, type=SAI_BRIDGE_PORT_TYPE_PORT) + self.port10_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.port10, + type=SAI_BRIDGE_PORT_TYPE_PORT) + self.port11_bp = sai_thrift_create_bridge_port( + self.client, + bridge_id=self.default_1q_bridge, + port_id=self.port11, + type=SAI_BRIDGE_PORT_TYPE_PORT) # vlan100 with members port24, port25 and port26 self.vlan100 = sai_thrift_create_vlan(self.client, vlan_id=100) self.vlan_member100 = sai_thrift_create_vlan_member( @@ -2798,40 +2799,44 @@ def setUp(self): self.client, type=SAI_ROUTER_INTERFACE_TYPE_VLAN, virtual_router_id=self.default_vrf, - vlan_id=self.vlan100) + vlan_id=self.vlan100, + admin_v6_state=True) dmac1 = '00:11:22:33:44:55' dmac2 = '00:22:22:33:44:55' dmac3 = '00:33:22:33:44:55' - dmac4 = '00:44:22:33:44:55' - dmac5 = '00:11:33:33:44:55' - dmac6 = '00:22:33:33:44:55' - dmac7 = '00:44:33:33:44:55' + dmac4 = '00:11:00:00:00:04' + dmac5 = '00:11:00:00:00:05' + dmac6 = '00:11:00:00:00:06' + dmac7 = '00:11:00:00:00:07' # create nhop1, nhop2 & nhop3 on SVI self.nhop1 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('10.10.0.1'), + ip=sai_ipaddress('1000:1:1:0:0:0:0:1'), router_interface_id=self.vlan100_rif, type=SAI_NEXT_HOP_TYPE_IP) self.neighbor_entry1 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan100_rif, ip_address=sai_ipaddress('10.10.0.1')) + rif_id=self.vlan100_rif, + ip_address=sai_ipaddress('1000:1:1:0:0:0:0:1')) sai_thrift_create_neighbor_entry( self.client, self.neighbor_entry1, dst_mac_address=dmac1) self.nhop2 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('10.10.0.2'), + ip=sai_ipaddress('1000:1:1:0:0:0:0:2'), router_interface_id=self.vlan100_rif, type=SAI_NEXT_HOP_TYPE_IP) self.neighbor_entry2 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan100_rif, ip_address=sai_ipaddress('10.10.0.2')) + rif_id=self.vlan100_rif, + ip_address=sai_ipaddress('1000:1:1:0:0:0:0:2')) sai_thrift_create_neighbor_entry( self.client, self.neighbor_entry2, dst_mac_address=dmac2) self.nhop3 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('10.10.0.3'), + ip=sai_ipaddress('1000:1:1:0:0:0:0:3'), router_interface_id=self.vlan100_rif, type=SAI_NEXT_HOP_TYPE_IP) self.neighbor_entry3 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan100_rif, ip_address=sai_ipaddress('10.10.0.3')) + rif_id=self.vlan100_rif, + ip_address=sai_ipaddress('1000:1:1:0:0:0:0:3')) sai_thrift_create_neighbor_entry( self.client, self.neighbor_entry3, dst_mac_address=dmac3) self.nhop_group1 = sai_thrift_create_next_hop_group( @@ -2851,21 +2856,12 @@ def setUp(self): # create route entries self.route0 = sai_thrift_route_entry_t( switch_id=self.switch_id, - destination=sai_ipprefix('10.20.30.1/16'), + destination=sai_ipprefix('4000:1:1:0:0:0:0:1/16'), vr_id=self.default_vrf) status = sai_thrift_create_route_entry( self.client, self.route0, next_hop_id=self.nhop_group1) self.assertEqual(status, SAI_STATUS_SUCCESS) # create nhop and route to L2 intf - self.nhop4 = sai_thrift_create_next_hop( - self.client, - ip=sai_ipaddress('11.11.0.2'), - router_interface_id=self.port10_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry4 = sai_thrift_neighbor_entry_t( - rif_id=self.port10_rif, ip_address=sai_ipaddress('11.11.0.2')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry4, dst_mac_address=dmac4) self.lag10 = sai_thrift_create_lag(self.client) self.lag10_bp = sai_thrift_create_bridge_port( self.client, @@ -2898,39 +2894,67 @@ def setUp(self): vlan_id=self.vlan200, bridge_port_id=self.lag11_bp, vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + self.vlan_member202 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan200, + bridge_port_id=self.port10_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) + self.vlan_member203 = sai_thrift_create_vlan_member( + self.client, + vlan_id=self.vlan200, + bridge_port_id=self.port11_bp, + vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) sai_thrift_set_lag_attribute(self.client, self.lag10, port_vlan_id=200) sai_thrift_set_lag_attribute(self.client, self.lag11, port_vlan_id=200) + sai_thrift_set_port_attribute( + self.client, self.port10, port_vlan_id=200) + sai_thrift_set_port_attribute( + self.client, self.port11, port_vlan_id=200) self.vlan200_rif = sai_thrift_create_router_interface( self.client, type=SAI_ROUTER_INTERFACE_TYPE_VLAN, virtual_router_id=self.default_vrf, - vlan_id=self.vlan200) + vlan_id=self.vlan200, + admin_v6_state=True) + self.nhop4 = sai_thrift_create_next_hop( + self.client, + ip=sai_ipaddress('2010:1:1:0:0:0:0:1'), + router_interface_id=self.port10_rif, + type=SAI_NEXT_HOP_TYPE_IP) + self.neighbor_entry4 = sai_thrift_neighbor_entry_t( + rif_id=self.port10_rif, + ip_address=sai_ipaddress('2010:1:1:0:0:0:0:1')) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry4, dst_mac_address=dmac4) # Create nhop5 and nhop6 on SVI self.nhop5 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('20.10.0.1'), + ip=sai_ipaddress('2010:1:1:0:0:0:0:2'), router_interface_id=self.vlan200_rif, type=SAI_NEXT_HOP_TYPE_IP) self.neighbor_entry5 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan200_rif, ip_address=sai_ipaddress('20.10.0.1')) + rif_id=self.vlan200_rif, + ip_address=sai_ipaddress('2010:1:1:0:0:0:0:2')) sai_thrift_create_neighbor_entry( self.client, self.neighbor_entry5, dst_mac_address=dmac5) self.nhop6 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('20.10.0.2'), + ip=sai_ipaddress('2010:1:1:0:0:0:0:3'), router_interface_id=self.vlan200_rif, type=SAI_NEXT_HOP_TYPE_IP) self.neighbor_entry6 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan200_rif, ip_address=sai_ipaddress('20.10.0.2')) + rif_id=self.vlan200_rif, + ip_address=sai_ipaddress('2010:1:1:0:0:0:0:3')) sai_thrift_create_neighbor_entry( self.client, self.neighbor_entry6, dst_mac_address=dmac6) self.nhop7 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('21.11.0.2'), + ip=sai_ipaddress('2010:1:1:0:0:0:0:4'), router_interface_id=self.port11_rif, type=SAI_NEXT_HOP_TYPE_IP) self.neighbor_entry7 = sai_thrift_neighbor_entry_t( - rif_id=self.port11_rif, ip_address=sai_ipaddress('21.11.0.2')) + rif_id=self.port11_rif, + ip_address=sai_ipaddress('2010:1:1:0:0:0:0:4')) sai_thrift_create_neighbor_entry( self.client, self.neighbor_entry7, dst_mac_address=dmac7) self.nhop_group2 = sai_thrift_create_next_hop_group( @@ -2953,7 +2977,7 @@ def setUp(self): next_hop_id=self.nhop7) self.route1 = sai_thrift_route_entry_t( switch_id=self.switch_id, - destination=sai_ipprefix('10.40.40.1/16'), + destination=sai_ipprefix('5500:1:1:0:0:0:0:1/65'), vr_id=self.default_vrf) status = sai_thrift_create_route_entry( self.client, self.route1, next_hop_id=self.nhop_group2) @@ -2961,11 +2985,8 @@ def setUp(self): # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) - def runTest(self): - self.l3IPv4EcmpSVIHostTest() - self.l3IPv4EcmpSVILagHostTest() - def tearDown(self): + sai_thrift_remove_route_entry(self.client, self.route1) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry4) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry5) @@ -2987,9 +3008,13 @@ def tearDown(self): sai_thrift_remove_next_hop(self.client, self.nhop7) sai_thrift_set_lag_attribute(self.client, self.lag10, port_vlan_id=0) sai_thrift_set_lag_attribute(self.client, self.lag11, port_vlan_id=0) + sai_thrift_set_port_attribute(self.client, self.port10, port_vlan_id=0) + sai_thrift_set_port_attribute(self.client, self.port11, port_vlan_id=0) sai_thrift_remove_router_interface(self.client, self.vlan200_rif) sai_thrift_remove_vlan_member(self.client, self.vlan_member200) sai_thrift_remove_vlan_member(self.client, self.vlan_member201) + sai_thrift_remove_vlan_member(self.client, self.vlan_member202) + sai_thrift_remove_vlan_member(self.client, self.vlan_member203) sai_thrift_remove_vlan(self.client, self.vlan200) sai_thrift_remove_lag_member(self.client, self.lag10_member30) sai_thrift_remove_lag_member(self.client, self.lag10_member31) @@ -2999,6 +3024,8 @@ def tearDown(self): sai_thrift_remove_bridge_port(self.client, self.lag11_bp) sai_thrift_remove_lag(self.client, self.lag10) sai_thrift_remove_lag(self.client, self.lag11) + sai_thrift_remove_bridge_port(self.client, self.port10_bp) + sai_thrift_remove_bridge_port(self.client, self.port11_bp) sai_thrift_remove_route_entry(self.client, self.route0) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry1) sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry2) @@ -3026,13 +3053,17 @@ def tearDown(self): sai_thrift_remove_bridge_port(self.client, self.port26_bp) release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) - super(L3IPv4SVIEcmpTest, self).tearDown() + super(L3IPv6SVIEcmpTestHelper, self).tearDown() - def l3IPv4EcmpSVIHostTest(self): - """ - IPv4 ECMP tests with SVI RIF as member - """ - print("l3IPv4EcmpSVIHostTest") +class l3IPv6EcmpSVIHostTest(L3IPv6SVIEcmpTestHelper): + """ + IPv6 ECMP tests with SVI RIF members + """ + def setUp(self): + super(l3IPv6EcmpSVIHostTest, self).setUp() + + def runTest(self): + print("l3IPv6EcmpSVIHostTest") mac_action = SAI_PACKET_ACTION_FORWARD fdb_entry1 = sai_thrift_fdb_entry_t( switch_id=self.switch_id, @@ -3066,38 +3097,37 @@ def l3IPv4EcmpSVIHostTest(self): packet_action=mac_action) try: count = [0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.20.30.1')), 16) + dst_ip = socket.inet_pton(socket.AF_INET6, '4000:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:22:22' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - pkt = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet( + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=64) + exp_pkt1 = simple_tcpv6_packet( eth_dst='00:11:22:33:44:55', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet( + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet( eth_dst='00:22:22:33:44:55', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet( + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt3 = simple_tcpv6_packet( eth_dst='00:33:22:33:44:55', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) send_packet(self, self.dev_port10, pkt) self.vlan100_rif_counter_out += 1 ports_to_verify = [ @@ -3106,135 +3136,138 @@ def l3IPv4EcmpSVIHostTest(self): rcv_idx = verify_any_packet_any_port( self, [exp_pkt1, exp_pkt2, exp_pkt3], ports_to_verify) count[rcv_idx] += 1 - dst_ip += 1 + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) print("Port LB counts:", count) for i in range(0, 3): self.assertTrue( - (count[i] >= ((MAX_ITRS / 3) * 0.5)), + (count[i] >= ((MAX_ITRS / 3) * 0.6)), "Not all paths are equally balanced, %s" % count) finally: sai_thrift_remove_fdb_entry(self.client, fdb_entry1) sai_thrift_remove_fdb_entry(self.client, fdb_entry2) sai_thrift_remove_fdb_entry(self.client, fdb_entry3) - def l3IPv4EcmpSVILagHostTest(self): - """ - IPv4 ECMP tests with Port, LAG and SVI RIFs as nexthop members - """ - print("l3IPv4EcmpSVILagHostTest") + + def tearDown(self): + super(l3IPv6EcmpSVIHostTest, self).tearDown() + + +class l3IPv6EcmpSVIPortLagHostTest(L3IPv6SVIEcmpTestHelper): + """ + IPv6 ECMP tests with Port, LAG and SVI RIFs as ECMP members + """ + def setUp(self): + super(l3IPv6EcmpSVIPortLagHostTest, self).setUp() + + def runTest(self): + print("l3IPv6EcmpSVIPortLagHostTest") mac_action = SAI_PACKET_ACTION_FORWARD fdb_entry1 = sai_thrift_fdb_entry_t( switch_id=self.switch_id, - mac_address='00:11:33:33:44:55', + mac_address='00:11:00:00:00:05', bv_id=self.vlan200) sai_thrift_create_fdb_entry( self.client, fdb_entry1, type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.lag10_bp, + bridge_port_id=self.lag11_bp, packet_action=mac_action) fdb_entry2 = sai_thrift_fdb_entry_t( switch_id=self.switch_id, - mac_address='00:22:33:33:44:55', + mac_address='00:11:00:00:00:06', bv_id=self.vlan200) sai_thrift_create_fdb_entry( self.client, fdb_entry2, type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.lag11_bp, + bridge_port_id=self.lag10_bp, packet_action=mac_action) try: - count = [0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('10.40.40.1')), 16) + count = [0] * 6 + dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') + dst_ip_arr = list(dst_ip) + src_mac_start = '00:22:22:22:22:22' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - pkt = simple_tcp_packet( - eth_dst=ROUTER_MAC, - eth_src='00:22:22:22:22:22', - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet( - eth_dst='00:44:22:33:44:55', + dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=64) + exp_pkt1 = simple_tcpv6_packet( + eth_dst='00:11:00:00:00:04', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet( - eth_dst='00:11:33:33:44:55', + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt2 = simple_tcpv6_packet( + eth_dst='00:11:00:00:00:05', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet( - eth_dst='00:22:33:33:44:55', + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt3 = simple_tcpv6_packet( + eth_dst='00:11:00:00:00:06', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet( - eth_dst='00:44:33:33:44:55', + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) + exp_pkt4 = simple_tcpv6_packet( + eth_dst='00:11:00:00:00:07', eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.0.1', - ip_id=105, - ip_ttl=63) + ipv6_dst=dst_ip_addr, + ipv6_src='7000:1:1:0:0:0:0:1', + ipv6_hlim=63) send_packet(self, self.dev_port10, pkt) ports_to_verify = [ self.dev_port10, - self.dev_port11, - self.dev_port28, - self.dev_port29, - self.dev_port30, - self.dev_port31] + self.dev_port28, self.dev_port29, # Lag11 + self.dev_port30, self.dev_port31, # Lag10 + self.dev_port11] rcv_idx = verify_any_packet_any_port( - self, - [exp_pkt1, - exp_pkt2, - exp_pkt3, - exp_pkt4], - ports_to_verify) + self, [exp_pkt1, exp_pkt2, exp_pkt3, + exp_pkt4], ports_to_verify) count[rcv_idx] += 1 - dst_ip += 1 - ecmp_count = [ - count[0], count[1], (count[2] + count[3]), - (count[4] + count[5]) - ] - print("PORT lb counts", count) - for i in range(0, 4): - print("ECMP count LB[%d], %d, %d%%" % ( - i, ecmp_count[i], ecmp_count[i] * 100 / MAX_ITRS)) + dst_ip_arr[15] = dst_ip_arr[15] + 1 + dst_ip = bytearray(dst_ip_arr) + ecmp_count = [count[0], count[1] + count[2], + count[3] + count[4], count[5]] + print("Port ECMP counts:", ecmp_count) for i in range(0, 4): self.assertTrue( (ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Not all paths are equally balanced, %s" % count) + "Not all paths are equally balanced, %s" % ecmp_count) finally: sai_thrift_remove_fdb_entry(self.client, fdb_entry1) sai_thrift_remove_fdb_entry(self.client, fdb_entry2) + def tearDown(self): + super(l3IPv6EcmpSVIPortLagHostTest, self).tearDown() -@group("draft") -class L3IPv6SVIEcmpTest(SaiHelper): + +class L3IPv4EcmpLagTestHelper(PlatformSaiHelper): """ - Base ECMP tests for IPv6 and ECMP members as SVI RIFs + Base ECMP tests common setup and teardown with lag for IPv4 """ def setUp(self): + super(L3IPv4EcmpLagTestHelper, self).setUp() - super(L3IPv6SVIEcmpTest, self).setUp() - - self.vlan100_rif_counter_in = 0 - self.vlan100_rif_counter_out = 0 - self.vlan200_rif_counter_in = 0 - self.vlan200_rif_counter_out = 0 - self.vlan100_bcast_in = 0 - self.vlan100_bcast_out = 0 - self.vlan200_bcast_in = 0 - self.vlan200_bcast_out = 0 + dmac1 = '00:11:11:11:11:11' + dmac2 = '00:22:22:22:22:22' + dmac3 = '00:33:33:33:33:33' + dmac4 = '00:44:44:44:44:44' + dmac5 = '00:55:55:55:55:55' + dmac6 = '00:66:66:66:66:66' + nhop_ip1 = '11.11.11.11' + nhop_ip2 = '22.22.22.22' + nhop_ip3 = '33.33.33.33' + nhop_ip4 = '44.44.44.44' + nhop_ip5 = '44.55.55.55' + nhop_ip6 = '44.66.66.66' # set switch src mac address sai_thrift_set_switch_attribute( self.client, src_mac_address=ROUTER_MAC) @@ -3242,99 +3275,79 @@ def setUp(self): self.client, ecmp_default_hash_seed=TEST_ECMP_SEED) sai_thrift_set_switch_attribute( self.client, lag_default_hash_seed=TEST_LAG_SEED) - self.port24_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.port24, - type=SAI_BRIDGE_PORT_TYPE_PORT) - self.port25_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.port25, - type=SAI_BRIDGE_PORT_TYPE_PORT) - self.port26_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.port26, - type=SAI_BRIDGE_PORT_TYPE_PORT) - self.port10_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.port10, - type=SAI_BRIDGE_PORT_TYPE_PORT) - self.port11_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.port11, - type=SAI_BRIDGE_PORT_TYPE_PORT) - # vlan100 with members port24, port25 and port26 - self.vlan100 = sai_thrift_create_vlan(self.client, vlan_id=100) - self.vlan_member100 = sai_thrift_create_vlan_member( - self.client, - vlan_id=self.vlan100, - bridge_port_id=self.port24_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - self.vlan_member101 = sai_thrift_create_vlan_member( + self.lag1_rif = sai_thrift_create_router_interface( self.client, - vlan_id=self.vlan100, - bridge_port_id=self.port25_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - self.vlan_member102 = sai_thrift_create_vlan_member( + type=SAI_ROUTER_INTERFACE_TYPE_PORT, + virtual_router_id=self.default_vrf, + port_id=self.lag1, + admin_v4_state=True) + self.lag2_rif = sai_thrift_create_router_interface( self.client, - vlan_id=self.vlan100, - bridge_port_id=self.port26_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - sai_thrift_set_port_attribute( - self.client, self.port24, port_vlan_id=100) - sai_thrift_set_port_attribute( - self.client, self.port25, port_vlan_id=100) - sai_thrift_set_port_attribute( - self.client, self.port26, port_vlan_id=100) - # create vlan100_rif - self.vlan100_rif = sai_thrift_create_router_interface( + type=SAI_ROUTER_INTERFACE_TYPE_PORT, + virtual_router_id=self.default_vrf, + port_id=self.lag2, + admin_v4_state=True) + self.port15_rif = sai_thrift_create_router_interface( self.client, - type=SAI_ROUTER_INTERFACE_TYPE_VLAN, + type=SAI_ROUTER_INTERFACE_TYPE_PORT, virtual_router_id=self.default_vrf, - vlan_id=self.vlan100, - admin_v6_state=True) - dmac1 = '00:11:22:33:44:55' - dmac2 = '00:22:22:33:44:55' - dmac3 = '00:33:22:33:44:55' - dmac4 = '00:11:00:00:00:04' - dmac5 = '00:11:00:00:00:05' - dmac6 = '00:11:00:00:00:06' - dmac7 = '00:11:00:00:00:07' - # create nhop1, nhop2 & nhop3 on SVI + port_id=self.port15, + admin_v4_state=True) + # test neighbor creation + self.neighbor_entry11 = sai_thrift_neighbor_entry_t( + self.switch_id, self.port11_rif, sai_ipaddress(nhop_ip1)) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry11, dst_mac_address=dmac1) + self.neighbor_entry12 = sai_thrift_neighbor_entry_t( + self.switch_id, self.port12_rif, sai_ipaddress(nhop_ip2)) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry12, dst_mac_address=dmac2) + self.neighbor_entry13 = sai_thrift_neighbor_entry_t( + self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip3)) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry13, dst_mac_address=dmac3) + self.neighbor_entry14 = sai_thrift_neighbor_entry_t( + self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip4)) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry14, dst_mac_address=dmac4) + self.neighbor_entry15 = sai_thrift_neighbor_entry_t( + self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip5)) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry15, dst_mac_address=dmac5) + self.neighbor_entry16 = sai_thrift_neighbor_entry_t( + self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip6)) + sai_thrift_create_neighbor_entry( + self.client, self.neighbor_entry16, dst_mac_address=dmac6) self.nhop1 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('1000:1:1:0:0:0:0:1'), - router_interface_id=self.vlan100_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry1 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan100_rif, - ip_address=sai_ipaddress('1000:1:1:0:0:0:0:1')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry1, dst_mac_address=dmac1) + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.port11_rif, + ip=sai_ipaddress(nhop_ip1)) self.nhop2 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('1000:1:1:0:0:0:0:2'), - router_interface_id=self.vlan100_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry2 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan100_rif, - ip_address=sai_ipaddress('1000:1:1:0:0:0:0:2')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry2, dst_mac_address=dmac2) - self.nhop3 = sai_thrift_create_next_hop( + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.port12_rif, + ip=sai_ipaddress(nhop_ip2)) + self.nhop3_lag1 = sai_thrift_create_next_hop( + self.client, + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.lag1_rif, + ip=sai_ipaddress(nhop_ip3)) + self.nhop4_lag2 = sai_thrift_create_next_hop( + self.client, + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.lag2_rif, + ip=sai_ipaddress(nhop_ip4)) + self.nhop5_lag1 = sai_thrift_create_next_hop( self.client, - ip=sai_ipaddress('1000:1:1:0:0:0:0:3'), - router_interface_id=self.vlan100_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry3 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan100_rif, - ip_address=sai_ipaddress('1000:1:1:0:0:0:0:3')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry3, dst_mac_address=dmac3) + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.lag1_rif, + ip=sai_ipaddress(nhop_ip5)) + self.nhop6_lag2 = sai_thrift_create_next_hop( + self.client, + type=SAI_NEXT_HOP_TYPE_IP, + router_interface_id=self.lag2_rif, + ip=sai_ipaddress(nhop_ip6)) self.nhop_group1 = sai_thrift_create_next_hop_group( self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) self.nh_group1_member1 = sai_thrift_create_next_hop_group_member( @@ -3348,132 +3361,32 @@ def setUp(self): self.nh_group1_member3 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop3) - # create route entries - self.route0 = sai_thrift_route_entry_t( - switch_id=self.switch_id, - destination=sai_ipprefix('4000:1:1:0:0:0:0:1/16'), - vr_id=self.default_vrf) - status = sai_thrift_create_route_entry( - self.client, self.route0, next_hop_id=self.nhop_group1) - self.assertEqual(status, SAI_STATUS_SUCCESS) - # create nhop and route to L2 intf - self.lag10 = sai_thrift_create_lag(self.client) - self.lag10_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.lag10, - type=SAI_BRIDGE_PORT_TYPE_PORT) - self.lag10_member30 = sai_thrift_create_lag_member( - self.client, lag_id=self.lag10, port_id=self.port30) - self.lag10_member31 = sai_thrift_create_lag_member( - self.client, lag_id=self.lag10, port_id=self.port31) - self.lag11 = sai_thrift_create_lag(self.client) - self.lag11_bp = sai_thrift_create_bridge_port( - self.client, - bridge_id=self.default_1q_bridge, - port_id=self.lag11, - type=SAI_BRIDGE_PORT_TYPE_PORT) - self.lag11_member28 = sai_thrift_create_lag_member( - self.client, lag_id=self.lag11, port_id=self.port28) - self.lag11_member29 = sai_thrift_create_lag_member( - self.client, lag_id=self.lag11, port_id=self.port29) - # create vlan200_rif - self.vlan200 = sai_thrift_create_vlan(self.client, vlan_id=200) - self.vlan_member200 = sai_thrift_create_vlan_member( - self.client, - vlan_id=self.vlan200, - bridge_port_id=self.lag10_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - self.vlan_member201 = sai_thrift_create_vlan_member( - self.client, - vlan_id=self.vlan200, - bridge_port_id=self.lag11_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - self.vlan_member202 = sai_thrift_create_vlan_member( - self.client, - vlan_id=self.vlan200, - bridge_port_id=self.port10_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - self.vlan_member203 = sai_thrift_create_vlan_member( - self.client, - vlan_id=self.vlan200, - bridge_port_id=self.port11_bp, - vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_UNTAGGED) - sai_thrift_set_lag_attribute(self.client, self.lag10, port_vlan_id=200) - sai_thrift_set_lag_attribute(self.client, self.lag11, port_vlan_id=200) - sai_thrift_set_port_attribute( - self.client, self.port10, port_vlan_id=200) - sai_thrift_set_port_attribute( - self.client, self.port11, port_vlan_id=200) - self.vlan200_rif = sai_thrift_create_router_interface( - self.client, - type=SAI_ROUTER_INTERFACE_TYPE_VLAN, - virtual_router_id=self.default_vrf, - vlan_id=self.vlan200, - admin_v6_state=True) - self.nhop4 = sai_thrift_create_next_hop( - self.client, - ip=sai_ipaddress('2010:1:1:0:0:0:0:1'), - router_interface_id=self.port10_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry4 = sai_thrift_neighbor_entry_t( - rif_id=self.port10_rif, - ip_address=sai_ipaddress('2010:1:1:0:0:0:0:1')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry4, dst_mac_address=dmac4) - # Create nhop5 and nhop6 on SVI - self.nhop5 = sai_thrift_create_next_hop( - self.client, - ip=sai_ipaddress('2010:1:1:0:0:0:0:2'), - router_interface_id=self.vlan200_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry5 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan200_rif, - ip_address=sai_ipaddress('2010:1:1:0:0:0:0:2')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry5, dst_mac_address=dmac5) - self.nhop6 = sai_thrift_create_next_hop( - self.client, - ip=sai_ipaddress('2010:1:1:0:0:0:0:3'), - router_interface_id=self.vlan200_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry6 = sai_thrift_neighbor_entry_t( - rif_id=self.vlan200_rif, - ip_address=sai_ipaddress('2010:1:1:0:0:0:0:3')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry6, dst_mac_address=dmac6) - self.nhop7 = sai_thrift_create_next_hop( + next_hop_id=self.nhop3_lag1) + self.nh_group1_member4 = sai_thrift_create_next_hop_group_member( self.client, - ip=sai_ipaddress('2010:1:1:0:0:0:0:4'), - router_interface_id=self.port11_rif, - type=SAI_NEXT_HOP_TYPE_IP) - self.neighbor_entry7 = sai_thrift_neighbor_entry_t( - rif_id=self.port11_rif, - ip_address=sai_ipaddress('2010:1:1:0:0:0:0:4')) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry7, dst_mac_address=dmac7) + next_hop_group_id=self.nhop_group1, + next_hop_id=self.nhop4_lag2) self.nhop_group2 = sai_thrift_create_next_hop_group( self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) self.nh_group2_member1 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop4) + next_hop_id=self.nhop5_lag1) self.nh_group2_member2 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop5) - self.nh_group2_member3 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop6) - self.nh_group2_member4 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop7) + next_hop_id=self.nhop6_lag2) + # create route entries + self.route0 = sai_thrift_route_entry_t( + switch_id=self.switch_id, + destination=sai_ipprefix('10.10.10.1/16'), + vr_id=self.default_vrf) + status = sai_thrift_create_route_entry( + self.client, self.route0, next_hop_id=self.nhop_group1) + self.assertEqual(status, SAI_STATUS_SUCCESS) self.route1 = sai_thrift_route_entry_t( switch_id=self.switch_id, - destination=sai_ipprefix('5500:1:1:0:0:0:0:1/65'), + destination=sai_ipprefix('20.20.20.1/16'), vr_id=self.default_vrf) status = sai_thrift_create_route_entry( self.client, self.route1, next_hop_id=self.nhop_group2) @@ -3481,328 +3394,687 @@ def setUp(self): # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) + def tearDown(self): + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry11) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry12) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry13) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry14) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry15) + sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry16) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member1) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member2) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member3) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group1_member4) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group2_member1) + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group2_member2) + self.assertEqual(nhg_members_count(self.client, self.nhop_group1), 0) + self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) + sai_thrift_remove_route_entry(self.client, self.route0) + sai_thrift_remove_route_entry(self.client, self.route1) + sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) + sai_thrift_remove_next_hop_group(self.client, self.nhop_group2) + sai_thrift_remove_next_hop(self.client, self.nhop1) + sai_thrift_remove_next_hop(self.client, self.nhop2) + sai_thrift_remove_next_hop(self.client, self.nhop3_lag1) + sai_thrift_remove_next_hop(self.client, self.nhop4_lag2) + sai_thrift_remove_next_hop(self.client, self.nhop5_lag1) + sai_thrift_remove_next_hop(self.client, self.nhop6_lag2) + sai_thrift_remove_router_interface(self.client, self.lag1_rif) + sai_thrift_remove_router_interface(self.client, self.lag2_rif) + sai_thrift_remove_router_interface(self.client, self.port15_rif) + release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) + + super(L3IPv4EcmpLagTestHelper, self).tearDown() + + +class L3IPv4EcmpHostTwoLagsTest(L3IPv4EcmpLagTestHelper): + """ + IPv4 ECMP tests with all LAG RIFs members + """ + + def setUp(self): + super(L3IPv4EcmpHostTwoLagsTest, self).setUp() + + def runTest(self): + print("l3IPv4EcmpHostTwoLagsTest") + + count = [0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('20.20.20.1')), 16) + src_mac_start = '00:22:22:22:{0}:{1}' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2], ports_to_verify) + count[rcv_idx] += 1 + dst_ip += 1 + print("PORT lb counts", count) + ecmp_count = [(count[0] + count[1] + count[2]), + (count[3] + count[4] + count[5])] + print("ECMP count:", ecmp_count) + for i in range(0, 2): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.7)), + "Ecmp paths are not equally balanced") + for i in range(0, 3): + self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), + "Lag path1 is not equally balanced") + + for i in range(3, 6): + self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), + "Lag path2 is not equally balanced") + print("\nVerification done") + + def tearDown(self): + super(L3IPv4EcmpHostTwoLagsTest, self).tearDown() + + +class L3IPv4EcmpHostPortLagSharedMembersTest(L3IPv4EcmpLagTestHelper): + """ + IPv4 multiples ECMP with shared nexthop members + """ + + def setUp(self): + super(L3IPv4EcmpHostPortLagSharedMembersTest, self).setUp() + def runTest(self): - self.l3IPv6EcmpSVIPortLagHostTest() - self.l3IPv6EcmpSVIHostTest() + print("l3IPv4EcmpHostPortLagSharedMembersTest") + src_mac = '00:01:01:01:01:01' + # verify NG1 route + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst='10.10.10.1', + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ip_dst='10.10.10.1', + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + verify_any_packet_any_port(self, [exp_pkt1, exp_pkt2, exp_pkt3, + exp_pkt4], ports_to_verify) + # verify NG2 traffic + dst_ip = "20.20.1.21" + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip, + ip_src='192.168.1.1', + ip_id=106, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip, + ip_src='192.168.1.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', + eth_src=ROUTER_MAC, + ip_dst=dst_ip, + ip_src='192.168.1.1', + ip_id=106, + ip_ttl=63) + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + verify_any_packet_any_port(self, [exp_pkt1, exp_pkt2], + ports_to_verify) + print("\nVerification done") def tearDown(self): + super(L3IPv4EcmpHostPortLagSharedMembersTest, self).tearDown() - sai_thrift_remove_route_entry(self.client, self.route1) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry4) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry5) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry6) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry7) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member1) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member2) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member3) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member4) - self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) - sai_thrift_remove_next_hop_group(self.client, self.nhop_group2) - sai_thrift_remove_next_hop(self.client, self.nhop4) - sai_thrift_remove_next_hop(self.client, self.nhop5) - sai_thrift_remove_next_hop(self.client, self.nhop6) - sai_thrift_remove_next_hop(self.client, self.nhop7) - sai_thrift_set_lag_attribute(self.client, self.lag10, port_vlan_id=0) - sai_thrift_set_lag_attribute(self.client, self.lag11, port_vlan_id=0) - sai_thrift_set_port_attribute(self.client, self.port10, port_vlan_id=0) - sai_thrift_set_port_attribute(self.client, self.port11, port_vlan_id=0) - sai_thrift_remove_router_interface(self.client, self.vlan200_rif) - sai_thrift_remove_vlan_member(self.client, self.vlan_member200) - sai_thrift_remove_vlan_member(self.client, self.vlan_member201) - sai_thrift_remove_vlan_member(self.client, self.vlan_member202) - sai_thrift_remove_vlan_member(self.client, self.vlan_member203) - sai_thrift_remove_vlan(self.client, self.vlan200) - sai_thrift_remove_lag_member(self.client, self.lag10_member30) - sai_thrift_remove_lag_member(self.client, self.lag10_member31) - sai_thrift_remove_lag_member(self.client, self.lag11_member28) - sai_thrift_remove_lag_member(self.client, self.lag11_member29) - sai_thrift_remove_bridge_port(self.client, self.lag10_bp) - sai_thrift_remove_bridge_port(self.client, self.lag11_bp) - sai_thrift_remove_lag(self.client, self.lag10) - sai_thrift_remove_lag(self.client, self.lag11) - sai_thrift_remove_bridge_port(self.client, self.port10_bp) - sai_thrift_remove_bridge_port(self.client, self.port11_bp) - sai_thrift_remove_route_entry(self.client, self.route0) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry1) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry2) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry3) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member1) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member2) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member3) - sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) - sai_thrift_remove_next_hop(self.client, self.nhop1) - sai_thrift_remove_next_hop(self.client, self.nhop2) - sai_thrift_remove_next_hop(self.client, self.nhop3) - sai_thrift_remove_router_interface(self.client, self.vlan100_rif) - sai_thrift_set_port_attribute(self.client, self.port24, port_vlan_id=0) - sai_thrift_set_port_attribute(self.client, self.port25, port_vlan_id=0) - sai_thrift_set_port_attribute(self.client, self.port26, port_vlan_id=0) - sai_thrift_remove_vlan_member(self.client, self.vlan_member100) - sai_thrift_remove_vlan_member(self.client, self.vlan_member101) - sai_thrift_remove_vlan_member(self.client, self.vlan_member102) - sai_thrift_remove_vlan(self.client, self.vlan100) - sai_thrift_remove_bridge_port(self.client, self.port24_bp) - sai_thrift_remove_bridge_port(self.client, self.port25_bp) - sai_thrift_remove_bridge_port(self.client, self.port26_bp) - release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) - super(L3IPv6SVIEcmpTest, self).tearDown() +class L3IPv4EcmpHostTwoLagsDisabledLagMembersTest(L3IPv4EcmpLagTestHelper): + """ + IPv4 ECMP tests with LAG RIF and some LAG member in disable state + """ - def l3IPv6EcmpSVIHostTest(self): - """ - IPv6 ECMP tests with SVI RIF members - """ - print("l3IPv6EcmpSVIHostTest") - mac_action = SAI_PACKET_ACTION_FORWARD - fdb_entry1 = sai_thrift_fdb_entry_t( - switch_id=self.switch_id, - mac_address='00:11:22:33:44:55', - bv_id=self.vlan100) - sai_thrift_create_fdb_entry( - self.client, - fdb_entry1, - type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.port24_bp, - packet_action=mac_action) - fdb_entry2 = sai_thrift_fdb_entry_t( - switch_id=self.switch_id, - mac_address='00:22:22:33:44:55', - bv_id=self.vlan100) - sai_thrift_create_fdb_entry( - self.client, - fdb_entry2, - type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.port25_bp, - packet_action=mac_action) - fdb_entry3 = sai_thrift_fdb_entry_t( - switch_id=self.switch_id, - mac_address='00:33:22:33:44:55', - bv_id=self.vlan100) - sai_thrift_create_fdb_entry( - self.client, - fdb_entry3, - type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.port26_bp, - packet_action=mac_action) + def setUp(self): + super(L3IPv4EcmpHostTwoLagsDisabledLagMembersTest, self).setUp() + + def runTest(self): + print("l3IPv4EcmpHostTwoLagsDisabledLagMembersTest") + print("Disable LAG1 member 4 and 5") + + status = sai_thrift_set_lag_member_attribute( + self.client, self.lag1_member4, egress_disable=True) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_set_lag_member_attribute( + self.client, self.lag1_member5, egress_disable=True) + self.assertEqual(status, SAI_STATUS_SUCCESS) + try: + count = [0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('20.20.20.1')), 16) + src_ip = int(binascii.hexlify(socket.inet_aton('192.168.8.1')), 16) + src_mac_start = '00:22:22:22:{0}:{1}' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(src_ip)[2:].zfill(8))) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=64) + + exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=63) + + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2], ports_to_verify) + count[rcv_idx] += 1 + dst_ip += 1 + src_ip += 1 + + print("PORT lb counts", count) + ecmp_count = [(count[0] + count[1] + count[2]), + (count[3] + count[4] + count[5])] + + # check LAG1 traffic + self.assertTrue(count[0] == 0) # LAG1 member 1 port4 disabled + self.assertTrue(count[1] == 0) # LAG1 member 2 port5 disabled + self.assertTrue((count[2] >= ((MAX_ITRS / 2) * 0.6)), + "Lag path1 is not equally balanced") + print("ECMP count:", ecmp_count) + for i in range(0, 2): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.75)), + "Ecmp paths are not equally balanced") + + # check LAG2 traffic + for i in range(3, 6): + self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), + "Lag path2 is not equally balanced") + finally: + print("Enable LAG1 member 4 and 5") + status = sai_thrift_set_lag_member_attribute( + self.client, self.lag1_member4, egress_disable=False) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_set_lag_member_attribute( + self.client, self.lag1_member5, egress_disable=False) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + def tearDown(self): + super(L3IPv4EcmpHostTwoLagsDisabledLagMembersTest, self).tearDown() + + +class L3IPv4EcmpHostPortLagTest(L3IPv4EcmpLagTestHelper): + """ + IPv4 ECMP load balance tests to check fair share on all members + """ + def setUp(self): + super(L3IPv4EcmpHostPortLagTest, self).setUp() + + def runTest(self): + print("l3IPv4EcmpHostPortLagTest") try: - count = [0, 0, 0] - dst_ip = socket.inet_pton(socket.AF_INET6, '4000:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:22:22' + count = [0, 0, 0, 0, 0, 0, 0, 0] + + dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + src_ip = int(binascii.hexlify(socket.inet_aton('192.168.8.1')), 16) + src_mac_start = '00:22:22:22:{0}:{1}' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(src_ip)[2:].zfill(8))) src_mac = src_mac_start.format( str(i).zfill(4)[:2], str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet( - eth_dst='00:11:22:33:44:55', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet( - eth_dst='00:22:22:33:44:55', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt3 = simple_tcpv6_packet( - eth_dst='00:33:22:33:44:55', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port10, pkt) - self.vlan100_rif_counter_out += 1 + src_mac = '00:22:22:22:00:00' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=64) + + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src=src_ip_addr, + ip_id=106, + ip_ttl=63) + + send_packet(self, self.dev_port15, pkt) ports_to_verify = [ - self.dev_port24, self.dev_port25, self.dev_port26 + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 ] rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3], ports_to_verify) + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - print("Port LB counts:", count) - for i in range(0, 3): - self.assertTrue( - (count[i] >= ((MAX_ITRS / 3) * 0.6)), - "Not all paths are equally balanced, %s" % count) + dst_ip += 1 + src_ip += 1 + + print("PORT lb counts", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count:", ecmp_count) + for i in range(0, 4): + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), + "Ecmp paths are not equally balanced") + + for i in range(2, 5): + self.assertTrue((count[i] >= ((MAX_ITRS / 12) * 0.5)), + "Lag path1 is not equally balanced") + + for i in range(5, 8): + self.assertTrue((count[i] >= ((MAX_ITRS / 12) * 0.5)), + "Lag path2 is not equally balanced") finally: - sai_thrift_remove_fdb_entry(self.client, fdb_entry1) - sai_thrift_remove_fdb_entry(self.client, fdb_entry2) - sai_thrift_remove_fdb_entry(self.client, fdb_entry3) + pass + + def tearDown(self): + super(L3IPv4EcmpHostPortLagTest, self).tearDown() + + +class L3IPv4EcmpHashPortLagTest(L3IPv4EcmpLagTestHelper): + """ + Creates hash object and sends multiple packets + Validates that there is no load balancing with various fields + in ECMP hash + """ + def setUp(self): + super(L3IPv4EcmpHashPortLagTest, self).setUp() + + def runTest(self): + print("l3IPv4EcmpHashPortLagTest") + + # setup the ECMP hash to SRC IP + print("Limit ECMP IPv4 hash to SRC_IP only.") + # for our test it will disable LB. + self.setupECMPIPv4Hash([SAI_NATIVE_HASH_FIELD_SRC_IP]) - def l3IPv6EcmpSVIPortLagHostTest(self): - """ - IPv6 ECMP tests with Port, LAG and SVI RIFs as ECMP members - """ - print("l3IPv6EcmpSVIPortLagHostTest") - mac_action = SAI_PACKET_ACTION_FORWARD - fdb_entry1 = sai_thrift_fdb_entry_t( - switch_id=self.switch_id, - mac_address='00:11:00:00:00:05', - bv_id=self.vlan200) - sai_thrift_create_fdb_entry( - self.client, - fdb_entry1, - type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.lag11_bp, - packet_action=mac_action) - fdb_entry2 = sai_thrift_fdb_entry_t( - switch_id=self.switch_id, - mac_address='00:11:00:00:00:06', - bv_id=self.vlan200) - sai_thrift_create_fdb_entry( - self.client, - fdb_entry2, - type=SAI_FDB_ENTRY_TYPE_STATIC, - bridge_port_id=self.lag10_bp, - packet_action=mac_action) try: - count = [0] * 6 - dst_ip = socket.inet_pton(socket.AF_INET6, '5500:1:1:0:0:0:0:1') - dst_ip_arr = list(dst_ip) - src_mac_start = '00:22:22:22:22:22' + count = [0, 0, 0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + src_mac_start = '00:22:22:22:{0}:{1}' for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntop(socket.AF_INET6, dst_ip) + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) src_mac = src_mac_start.format( str(i).zfill(4)[:2], str(i).zfill(4)[2:]) - pkt = simple_tcpv6_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=64) - exp_pkt1 = simple_tcpv6_packet( - eth_dst='00:11:00:00:00:04', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt2 = simple_tcpv6_packet( - eth_dst='00:11:00:00:00:05', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt3 = simple_tcpv6_packet( - eth_dst='00:11:00:00:00:06', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - exp_pkt4 = simple_tcpv6_packet( - eth_dst='00:11:00:00:00:07', - eth_src=ROUTER_MAC, - ipv6_dst=dst_ip_addr, - ipv6_src='7000:1:1:0:0:0:0:1', - ipv6_hlim=63) - send_packet(self, self.dev_port10, pkt) + src_mac = '00:22:22:22:22:22' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + + send_packet(self, self.dev_port15, pkt) + ports_to_verify = [ + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) + count[rcv_idx] += 1 + dst_ip += 1 + + print("PORT lb counts:", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count:", ecmp_count) + # Traffic should not be ballanced, should apear on single port or + # LAG + if ecmp_count[0] != 0: + self.assertTrue(ecmp_count[0] == MAX_ITRS, + "100% expected on this port") + self.assertTrue(ecmp_count[1] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[2] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[3] == 0, + "No traffic expected on this port") + elif ecmp_count[1] != 0: + self.assertTrue(ecmp_count[0] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[1] == MAX_ITRS, + "100% expected on this port") + self.assertTrue(ecmp_count[2] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[3] == 0, + "No traffic expected on this port") + elif ecmp_count[2] != 0: + self.assertTrue(ecmp_count[0] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[1] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[2] == MAX_ITRS, + "100% expected on this port") + self.assertTrue(ecmp_count[3] == 0, + "No traffic expected on this port") + elif ecmp_count[3] != 0: + self.assertTrue(ecmp_count[0] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[1] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[2] == 0, + "No traffic expected on this port") + self.assertTrue(ecmp_count[3] == MAX_ITRS, + "100% expected on this port") + + # enable LB back to IPv4 full fields list + print("Enable ECMP IPv4 LB") + self.setupECMPIPv4Hash() + count = [0, 0, 0, 0, 0, 0, 0, 0] + dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + src_mac_start = '00:22:22:22:{0}:{1}' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_mac = src_mac_start.format( + str(i).zfill(4)[:2], + str(i).zfill(4)[2:]) + src_mac = '00:22:22:22:22:22' + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + + send_packet(self, self.dev_port15, pkt) ports_to_verify = [ - self.dev_port10, - self.dev_port28, self.dev_port29, # Lag11 - self.dev_port30, self.dev_port31, # Lag10 - self.dev_port11] + self.dev_port11, + self.dev_port12, + self.dev_port4, # LAG1 ports + self.dev_port5, + self.dev_port6, + self.dev_port7, # LAG2 ports + self.dev_port8, + self.dev_port9 + ] rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2, exp_pkt3, - exp_pkt4], ports_to_verify) + self, [exp_pkt1, exp_pkt2, exp_pkt3, exp_pkt4], + ports_to_verify) count[rcv_idx] += 1 - dst_ip_arr[15] = dst_ip_arr[15] + 1 - dst_ip = bytearray(dst_ip_arr) - ecmp_count = [count[0], count[1] + count[2], - count[3] + count[4], count[5]] - print("Port ECMP counts:", ecmp_count) + dst_ip += 1 + + print("PORT lb counts:", count) + ecmp_count = [ + count[0], + count[1], + (count[2] + count[3] + count[4]), + (count[5] + count[6] + count[7])] + print("ECMP count:", ecmp_count) + # Traffic should equally be ballanced, should apear on all port or + # LAG for i in range(0, 4): - self.assertTrue( - (ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), - "Not all paths are equally balanced, %s" % ecmp_count) + self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 4) * 0.5)), + "Ecmp paths are not equally balanced") + finally: - sai_thrift_remove_fdb_entry(self.client, fdb_entry1) - sai_thrift_remove_fdb_entry(self.client, fdb_entry2) + pass + def tearDown(self): + super(L3IPv4EcmpHashPortLagTest, self).tearDown() -class L3IPv4EcmpLagTestHelper(PlatformSaiHelper): - """ - Base ECMP tests common setup and teardown with lag for IPv4 - """ - + def setupECMPIPv4Hash(self, hash_field_list=None): + """ + Setups ECMP IPv4 hash + Args: + hash_field_list (list): list of hash fields + """ + print("Setting the ECMP IPv4 hash fields..") + if hash_field_list is None: + hash_field_list = [ + SAI_NATIVE_HASH_FIELD_SRC_IP, + SAI_NATIVE_HASH_FIELD_DST_IP, + SAI_NATIVE_HASH_FIELD_IP_PROTOCOL, + SAI_NATIVE_HASH_FIELD_L4_DST_PORT, + SAI_NATIVE_HASH_FIELD_L4_SRC_PORT + ] + s32list = sai_thrift_s32_list_t( + count=len(hash_field_list), int32list=hash_field_list) + if self.ipv4_hash_id == 0: + self.ipv4_hash_id = sai_thrift_create_hash( + self.client, native_hash_field_list=s32list) + else: + status = sai_thrift_set_hash_attribute( + self.client, self.ipv4_hash_id, native_hash_field_list=s32list) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + +class EcmpFGTestHelper(PlatformSaiHelper): + ''' + ECMP Fine Grain Test cases + ''' def setUp(self): - super(L3IPv4EcmpLagTestHelper, self).setUp() + super(EcmpFGTestHelper, self).setUp() + print('') - dmac1 = '00:11:11:11:11:11' - dmac2 = '00:22:22:22:22:22' - dmac3 = '00:33:33:33:33:33' - dmac4 = '00:44:44:44:44:44' - dmac5 = '00:55:55:55:55:55' - dmac6 = '00:66:66:66:66:66' nhop_ip1 = '11.11.11.11' nhop_ip2 = '22.22.22.22' nhop_ip3 = '33.33.33.33' - nhop_ip4 = '44.44.44.44' - nhop_ip5 = '44.55.55.55' - nhop_ip6 = '44.66.66.66' + dmac1 = '00:11:22:33:44:55' + dmac2 = '00:11:22:33:44:56' + dmac3 = '00:11:22:33:44:57' + # set switch src mac address sai_thrift_set_switch_attribute( - self.client, src_mac_address=ROUTER_MAC) - sai_thrift_set_switch_attribute( - self.client, ecmp_default_hash_seed=TEST_ECMP_SEED) - sai_thrift_set_switch_attribute( - self.client, lag_default_hash_seed=TEST_LAG_SEED) - self.lag1_rif = sai_thrift_create_router_interface( - self.client, - type=SAI_ROUTER_INTERFACE_TYPE_PORT, - virtual_router_id=self.default_vrf, - port_id=self.lag1, - admin_v4_state=True) - self.lag2_rif = sai_thrift_create_router_interface( self.client, - type=SAI_ROUTER_INTERFACE_TYPE_PORT, - virtual_router_id=self.default_vrf, - port_id=self.lag2, - admin_v4_state=True) - self.port15_rif = sai_thrift_create_router_interface( + src_mac_address=ROUTER_MAC) + self.port14_rif = sai_thrift_create_router_interface( self.client, type=SAI_ROUTER_INTERFACE_TYPE_PORT, virtual_router_id=self.default_vrf, - port_id=self.port15, + port_id=self.port14, admin_v4_state=True) - # test neighbor creation + + # neighbor creation self.neighbor_entry11 = sai_thrift_neighbor_entry_t( - self.switch_id, self.port11_rif, sai_ipaddress(nhop_ip1)) + self.switch_id, + self.port11_rif, + sai_ipaddress(nhop_ip1)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry11, dst_mac_address=dmac1) + self.client, + self.neighbor_entry11, + dst_mac_address=dmac1) self.neighbor_entry12 = sai_thrift_neighbor_entry_t( - self.switch_id, self.port12_rif, sai_ipaddress(nhop_ip2)) + self.switch_id, + self.port12_rif, + sai_ipaddress(nhop_ip2)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry12, dst_mac_address=dmac2) + self.client, + self.neighbor_entry12, + dst_mac_address=dmac2) self.neighbor_entry13 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip3)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry13, dst_mac_address=dmac3) - self.neighbor_entry14 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip4)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry14, dst_mac_address=dmac4) - self.neighbor_entry15 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag1_rif, sai_ipaddress(nhop_ip5)) - sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry15, dst_mac_address=dmac5) - self.neighbor_entry16 = sai_thrift_neighbor_entry_t( - self.switch_id, self.lag2_rif, sai_ipaddress(nhop_ip6)) + self.switch_id, + self.port13_rif, + sai_ipaddress(nhop_ip3)) sai_thrift_create_neighbor_entry( - self.client, self.neighbor_entry16, dst_mac_address=dmac6) + self.client, + self.neighbor_entry13, + dst_mac_address=dmac3) + + # NH creation self.nhop1 = sai_thrift_create_next_hop( self.client, type=SAI_NEXT_HOP_TYPE_IP, @@ -3813,270 +4085,267 @@ def setUp(self): type=SAI_NEXT_HOP_TYPE_IP, router_interface_id=self.port12_rif, ip=sai_ipaddress(nhop_ip2)) - self.nhop3_lag1 = sai_thrift_create_next_hop( + self.nhop3 = sai_thrift_create_next_hop( self.client, type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag1_rif, + router_interface_id=self.port13_rif, ip=sai_ipaddress(nhop_ip3)) - self.nhop4_lag2 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag2_rif, - ip=sai_ipaddress(nhop_ip4)) - self.nhop5_lag1 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag1_rif, - ip=sai_ipaddress(nhop_ip5)) - self.nhop6_lag2 = sai_thrift_create_next_hop( - self.client, - type=SAI_NEXT_HOP_TYPE_IP, - router_interface_id=self.lag2_rif, - ip=sai_ipaddress(nhop_ip6)) + + # Create Fine Grained ECMP group self.nhop_group1 = sai_thrift_create_next_hop_group( - self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) - self.nh_group1_member1 = sai_thrift_create_next_hop_group_member( self.client, - next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop1) - self.nh_group1_member2 = sai_thrift_create_next_hop_group_member( + type=SAI_NEXT_HOP_GROUP_TYPE_FINE_GRAIN_ECMP, + configured_size=50) + + # Add members with index to FG Ecmp group + self.nh_group_member1 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop2) - self.nh_group1_member3 = sai_thrift_create_next_hop_group_member( + next_hop_id=self.nhop1, + index=0) + self.nh_group_member2 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop3_lag1) - self.nh_group1_member4 = sai_thrift_create_next_hop_group_member( + next_hop_id=self.nhop2, + index=1) + self.nh_group_member3 = sai_thrift_create_next_hop_group_member( self.client, next_hop_group_id=self.nhop_group1, - next_hop_id=self.nhop4_lag2) - self.nhop_group2 = sai_thrift_create_next_hop_group( - self.client, type=SAI_NEXT_HOP_GROUP_TYPE_ECMP) - self.nh_group2_member1 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop5_lag1) - self.nh_group2_member2 = sai_thrift_create_next_hop_group_member( - self.client, - next_hop_group_id=self.nhop_group2, - next_hop_id=self.nhop6_lag2) + next_hop_id=self.nhop3, + index=2) + self.ecmp_members = [self.nh_group_member1, self.nh_group_member2, + self.nh_group_member3] + # create route entries self.route0 = sai_thrift_route_entry_t( switch_id=self.switch_id, destination=sai_ipprefix('10.10.10.1/16'), - vr_id=self.default_vrf) - status = sai_thrift_create_route_entry( - self.client, self.route0, next_hop_id=self.nhop_group1) - self.assertEqual(status, SAI_STATUS_SUCCESS) - self.route1 = sai_thrift_route_entry_t( - switch_id=self.switch_id, - destination=sai_ipprefix('20.20.20.1/16'), - vr_id=self.default_vrf) - status = sai_thrift_create_route_entry( - self.client, self.route1, next_hop_id=self.nhop_group2) - self.assertEqual(status, SAI_STATUS_SUCCESS) - # define IPv4 IPv6 LagIPv4Hash and LagIPv6Hash - self.ipv4_hash_id, self.ipv6_hash_id = setup_hash(self) - - def tearDown(self): - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry11) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry12) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry13) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry14) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry15) - sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry16) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member1) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member2) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member3) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group1_member4) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member1) - sai_thrift_remove_next_hop_group_member(self.client, - self.nh_group2_member2) - self.assertEqual(nhg_members_count(self.client, self.nhop_group1), 0) - self.assertEqual(nhg_members_count(self.client, self.nhop_group2), 0) + vr_id=self.default_vrf) + self.assertTrue(self.route0 != 0) + status = sai_thrift_create_route_entry( + self.client, + self.route0, + next_hop_id=self.nhop_group1) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + def tearDown(self): + sai_thrift_remove_neighbor_entry( + self.client, + self.neighbor_entry11) + sai_thrift_remove_neighbor_entry( + self.client, + self.neighbor_entry12) + sai_thrift_remove_neighbor_entry( + self.client, + self.neighbor_entry13) + sai_thrift_remove_next_hop_group_member( + self.client, + self.nh_group_member1) + sai_thrift_remove_next_hop_group_member( + self.client, + self.nh_group_member2) + sai_thrift_remove_next_hop_group_member( + self.client, + self.nh_group_member3) sai_thrift_remove_route_entry(self.client, self.route0) - sai_thrift_remove_route_entry(self.client, self.route1) sai_thrift_remove_next_hop_group(self.client, self.nhop_group1) - sai_thrift_remove_next_hop_group(self.client, self.nhop_group2) sai_thrift_remove_next_hop(self.client, self.nhop1) sai_thrift_remove_next_hop(self.client, self.nhop2) - sai_thrift_remove_next_hop(self.client, self.nhop3_lag1) - sai_thrift_remove_next_hop(self.client, self.nhop4_lag2) - sai_thrift_remove_next_hop(self.client, self.nhop5_lag1) - sai_thrift_remove_next_hop(self.client, self.nhop6_lag2) - sai_thrift_remove_router_interface(self.client, self.lag1_rif) - sai_thrift_remove_router_interface(self.client, self.lag2_rif) - sai_thrift_remove_router_interface(self.client, self.port15_rif) - release_hash(self, self.ipv4_hash_id, self.ipv6_hash_id) + sai_thrift_remove_next_hop(self.client, self.nhop3) + sai_thrift_remove_router_interface(self.client, self.port14_rif) + super(EcmpFGTestHelper, self).tearDown() - super(L3IPv4EcmpLagTestHelper, self).tearDown() + def packetTest(self): + ''' + For sending traffic + Returns: + int: pkts count + ''' + print('Sending Traffic') + count = [0, 0, 0] + try: + dst_ip = int(binascii.hexlify(socket.inet_aton('10.10.10.1')), 16) + src_mac_start = '00:22:22:22:22:' + for i in range(0, MAX_ITRS): + dst_ip_addr = socket.inet_ntoa( + binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) + src_mac = src_mac_start + str(i % 99).zfill(2) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src=src_mac, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=64) + exp_pkt1 = simple_tcp_packet(eth_dst='00:11:22:33:44:55', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt2 = simple_tcp_packet(eth_dst='00:11:22:33:44:56', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) + exp_pkt3 = simple_tcp_packet(eth_dst='00:11:22:33:44:57', + eth_src=ROUTER_MAC, + ip_dst=dst_ip_addr, + ip_src='192.168.8.1', + ip_id=106, + ip_ttl=63) -class L3IPv4EcmpHostTwoLagsTest(L3IPv4EcmpLagTestHelper): - """ - IPv4 ECMP tests with all LAG RIFs members - """ + send_packet(self, self.dev_port14, pkt) + rcv_idx = verify_any_packet_any_port( + self, [exp_pkt1, exp_pkt2, exp_pkt3], + [self.dev_port11, self.dev_port12, self.dev_port13]) + count[rcv_idx] += 1 + dst_ip += 1 + return count + finally: + pass +class ecmpFGBasicTest(EcmpFGTestHelper): + ''' + Ecmp FG Basic TCs + ''' def setUp(self): - super(L3IPv4EcmpHostTwoLagsTest, self).setUp() + super(ecmpFGBasicTest, self).setUp() def runTest(self): - print("l3IPv4EcmpHostTwoLagsTest") + print('ecmpFGBasicTest1') + attr = sai_thrift_get_next_hop_group_attribute(self.client, + self.nhop_group1, + configured_size=True) + nhop_grp_conf_size = attr["SAI_NEXT_HOP_GROUP_ATTR_CONFIGURED_SIZE"] + print('FG ECMP group --> Configured Size: %u' % nhop_grp_conf_size) + self.assertTrue((nhop_grp_conf_size == 50), + 'Configured size is %u, expected size should be 50' + % nhop_grp_conf_size) - count = [0, 0, 0, 0, 0, 0] - dst_ip = int(binascii.hexlify(socket.inet_aton('20.20.20.1')), 16) - src_mac_start = '00:22:22:22:{0}:{1}' - for i in range(0, MAX_ITRS): - dst_ip_addr = socket.inet_ntoa( - binascii.unhexlify(hex(dst_ip)[2:].zfill(8))) - src_mac = src_mac_start.format( - str(i).zfill(4)[:2], - str(i).zfill(4)[2:]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ip_dst=dst_ip_addr, - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - rcv_idx = verify_any_packet_any_port( - self, [exp_pkt1, exp_pkt2], ports_to_verify) - count[rcv_idx] += 1 - dst_ip += 1 - print("PORT lb counts", count) - ecmp_count = [(count[0] + count[1] + count[2]), - (count[3] + count[4] + count[5])] - print("ECMP count:", ecmp_count) - for i in range(0, 2): - self.assertTrue((ecmp_count[i] >= ((MAX_ITRS / 2) * 0.7)), - "Ecmp paths are not equally balanced") - for i in range(0, 3): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), - "Lag path1 is not equally balanced") + attr = sai_thrift_get_next_hop_group_attribute(self.client, + self.nhop_group1, + real_size=True) + nhop_grp_real_size = attr["SAI_NEXT_HOP_GROUP_ATTR_REAL_SIZE"] + print('FG ECMP group --> Real Size: %u' % nhop_grp_real_size) + self.assertTrue((nhop_grp_real_size > 0), + 'Real size is %u, expected size should be > 0' + % nhop_grp_real_size) - for i in range(3, 6): - self.assertTrue((count[i] >= ((MAX_ITRS / 6) * 0.6)), - "Lag path2 is not equally balanced") - print("\nVerification done") + try: + count = self.packetTest() + print('Traffic distribution [port11, port12, port13] --> %s' + % count) + for i in range(0, 3): + self.assertTrue((count[i] >= ((MAX_ITRS / 3) * 0.8)), + 'Not all paths are equally balanced, %s' + % count) + finally: + pass def tearDown(self): - super(L3IPv4EcmpHostTwoLagsTest, self).tearDown() + super(ecmpFGBasicTest, self).tearDown() -class L3IPv4EcmpHostPortLagSharedMembersTest(L3IPv4EcmpLagTestHelper): - """ - IPv4 multiples ECMP with shared nexthop members - """ - +class ecmpFGAddDelMemTest(EcmpFGTestHelper): + ''' + Ecmp FG Add & Del member TCs + ''' def setUp(self): - super(L3IPv4EcmpHostPortLagSharedMembersTest, self).setUp() + super(ecmpFGAddDelMemTest, self).setUp() def runTest(self): - print("l3IPv4EcmpHostPortLagSharedMembersTest") - src_mac = '00:01:01:01:01:01' - # verify NG1 route - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:11:11:11:11:11', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:22:22:22:22:22', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt3 = simple_tcp_packet(eth_dst='00:33:33:33:33:33', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - exp_pkt4 = simple_tcp_packet(eth_dst='00:44:44:44:44:44', - eth_src=ROUTER_MAC, - ip_dst='10.10.10.1', - ip_src='192.168.8.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port11, - self.dev_port12, - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - verify_any_packet_any_port(self, [exp_pkt1, exp_pkt2, exp_pkt3, - exp_pkt4], ports_to_verify) - # verify NG2 traffic - dst_ip = "20.20.1.21" - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src=src_mac, - ip_dst=dst_ip, - ip_src='192.168.1.1', - ip_id=106, - ip_ttl=64) - exp_pkt1 = simple_tcp_packet(eth_dst='00:55:55:55:55:55', - eth_src=ROUTER_MAC, - ip_dst=dst_ip, - ip_src='192.168.1.1', - ip_id=106, - ip_ttl=63) - exp_pkt2 = simple_tcp_packet(eth_dst='00:66:66:66:66:66', - eth_src=ROUTER_MAC, - ip_dst=dst_ip, - ip_src='192.168.1.1', - ip_id=106, - ip_ttl=63) - send_packet(self, self.dev_port15, pkt) - ports_to_verify = [ - self.dev_port4, # LAG1 ports - self.dev_port5, - self.dev_port6, - self.dev_port7, # LAG2 ports - self.dev_port8, - self.dev_port9 - ] - verify_any_packet_any_port(self, [exp_pkt1, exp_pkt2], - ports_to_verify) - print("\nVerification done") + print('ecmpFGAddDelMemTest') + try: + count = self.packetTest() + print('Traffic distribution [port11, port12, port13] --> %s' + % count) + + print('Removing nexthop2 at Member Index 1, port12') + sai_thrift_remove_next_hop_group_member(self.client, + self.nh_group_member2) + count = self.packetTest() + print('Traffic dist after change [port11, port12, port13] -> %s' + % count) + self.assertTrue((count[1] == 0), 'Pkts are still fwds to port12,%s' + % count) + + print('Re-Inserting member nexthop2 back at Member Index 1') + self.nh_group_member2 = sai_thrift_create_next_hop_group_member( + self.client, + next_hop_group_id=self.nhop_group1, + next_hop_id=self.nhop2, + index=1) + count = self.packetTest() + print('Traffic distribution now [port11, port12, port13] --> %s' + % count) + + finally: + pass def tearDown(self): - super(L3IPv4EcmpHostPortLagSharedMembersTest, self).tearDown() + super(ecmpFGAddDelMemTest, self).tearDown() + + +class ecmpFGGrpMemAttrTest(EcmpFGTestHelper): + ''' + Ecmp FG Member Attribure TCs + ''' + def setUp(self): + super(ecmpFGGrpMemAttrTest, self).setUp() + + def runTest(self): + print('ecmpFGGrpMemAttrTest') + try: + print('Assigning Nexthop2 to an Ecmp Grp Member') + sai_thrift_set_next_hop_group_member_attribute( + self.client, self.nhop_group1, next_hop_id=self.nhop2) + + attr_list = sai_thrift_get_next_hop_group_member_attribute( + self.client, + self.nh_group_member2, + next_hop_group_id=True, + next_hop_id=True, + index=True) + self.assertEqual( + attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"], + self.nhop_group1) + self.assertEqual( + attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"], + self.nhop2) + self.assertEqual( + attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_INDEX"], + 1) + + count = self.packetTest() + print('Traffic flow - [port11, port12, port13] --> %s' % count) + + print('Assigning Nexthop1 to an Ecmp Grp Member') + sai_thrift_set_next_hop_group_member_attribute( + self.client, self.nhop_group1, next_hop_id=self.nhop1) + attr_list = sai_thrift_get_next_hop_group_member_attribute( + self.client, + self.nh_group_member1, + next_hop_group_id=True, + next_hop_id=True, + index=True) + self.assertEqual( + attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"], + self.nhop_group1) + self.assertEqual( + attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"], + self.nhop1) + self.assertEqual( + attr_list["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_INDEX"], + 0) + + count = self.packetTest() + print('Traffic flow - [port11, port12, port13] --> %s' % count) + + finally: + pass + + def tearDown(self): + super(ecmpFGGrpMemAttrTest, self).tearDown() From 14d0dc2043b870f03da3e372ff74d04832551a52 Mon Sep 17 00:00:00 2001 From: mounika-adhuri Date: Fri, 2 Dec 2022 05:11:03 -0800 Subject: [PATCH 5/6] Adding changes to SWI-6191 SONiC PTF saiqueue.py refactor --- ptf/saiqueue.py | 949 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 737 insertions(+), 212 deletions(-) diff --git a/ptf/saiqueue.py b/ptf/saiqueue.py index c975dd678..8d3e58cee 100644 --- a/ptf/saiqueue.py +++ b/ptf/saiqueue.py @@ -20,24 +20,25 @@ @group("draft") -class QueueConfigData(SaiHelper): +class QueueConfigDataHelper(PlatformSaiHelper): """ Queue Configuration Class """ def setUp(self): - super(QueueConfigData, self).setUp() + super(QueueConfigDataHelper, self).setUp() attr = sai_thrift_get_port_attribute(self.client, self.port25, qos_number_of_queues=True) self.num_queues = attr["qos_number_of_queues"] + self.num_ports = len(self.port_list) self.q_list = sai_thrift_object_list_t(count=self.num_queues) # L3 layer configuration self.vr_id = sai_thrift_create_virtual_router(self.client, admin_v4_state=True, admin_v6_state=True) - self.assertNotEqual(self.vr_id, 0) + self.assertTrue(self.vr_id != 0) # RIFs self.rif_id25 = sai_thrift_create_router_interface( @@ -47,7 +48,7 @@ def setUp(self): port_id=self.port25, admin_v4_state=True, admin_v6_state=True) - self.assertNotEqual(self.rif_id25, 0) + self.assertTrue(self.rif_id25 != 0) self.rif_id26 = sai_thrift_create_router_interface( self.client, virtual_router_id=self.vr_id, @@ -55,7 +56,7 @@ def setUp(self): port_id=self.port26, admin_v4_state=True, admin_v6_state=True) - self.assertNotEqual(self.rif_id26, 0) + self.assertTrue(self.rif_id26 != 0) # Neighbor dst_ip = "172.16.1.1" @@ -86,15 +87,6 @@ def setUp(self): next_hop_id=self.nhop) self.assertEqual(status, SAI_STATUS_SUCCESS) - def runTest(self): - self.queueCreateTest() - self.portQueueQueryTest() - self.bufferQueueTest() - self.schedulerQueueTest() - self.pfcPriorityQueueTest() - self.cpuPortQueueObjectTest() - self.wredQueueTest() - def tearDown(self): sai_thrift_remove_neighbor_entry(self.client, self.neighbor_entry1) sai_thrift_remove_route_entry(self.client, self.route) @@ -102,96 +94,123 @@ def tearDown(self): sai_thrift_remove_router_interface(self.client, self.rif_id26) sai_thrift_remove_router_interface(self.client, self.rif_id25) sai_thrift_remove_virtual_router(self.client, self.vr_id) - super(QueueConfigData, self).tearDown() + super(QueueConfigDataHelper, self).tearDown() + +class queueCreateTest(QueueConfigDataHelper): + """ + The test verifies a queue creation. + """ + def setUp(self): + super(queueCreateTest, self).setUp() - def queueCreateTest(self): - """ - The test verifies a queue creation. - """ + def runTest(self): print("\nQueue Create Test") test_port = self.port1 - queue = sai_thrift_create_queue( - self.client, type=SAI_QUEUE_TYPE_UNICAST, - index=1) - # The port is missing, the creation should fail. - self.assertEqual(queue, 0) + try: + queue = sai_thrift_create_queue( + self.client, type=SAI_QUEUE_TYPE_ALL, + index=1) + # port is missing, creation should fail + self.assertTrue(queue == 0) - queue = sai_thrift_create_queue( - self.client, - port=test_port, index=1) - # The type is missing, the creation should fail. - self.assertEqual(queue, 0) - - queue = sai_thrift_create_queue( - self.client, type=SAI_QUEUE_TYPE_ALL, - port=test_port, index=1) - # The type is wrong, the creation should fail. - self.assertEqual(queue, 0) - - queue = sai_thrift_create_queue( - self.client, type=SAI_QUEUE_TYPE_UNICAST, - port=test_port) - # The index is missing, the creation should fail. - self.assertEqual(queue, 0) - - queue = sai_thrift_create_queue( - self.client, type=SAI_QUEUE_TYPE_UNICAST, - port=test_port, index=60) - # The index is wrong, the creation should fail. - self.assertEqual(queue, 0) - - queue = sai_thrift_create_queue( - self.client, type=SAI_QUEUE_TYPE_UNICAST, - port=test_port, index=1) - # The queue with such index already exists. - self.assertEqual(queue, 0) - - print("\tTest completed successfully") - - def portQueueQueryTest(self): - """ - The test queries SAI_QUEUE_ATTR_PORT and SAI_QUEUE_ATTR_INDEX - attributes for all physical ports configured by default. - NOTE: If you modify this test, remember to apply the changes to - cpuPortQueueObjectTest too. - """ + queue = sai_thrift_create_queue( + self.client, + port=test_port, index=1) + # type is missing, creation should fail + self.assertTrue(queue == 0) + + queue = sai_thrift_create_queue( + self.client, type=SAI_QUEUE_TYPE_ALL, + port=test_port, index=1) + # type is wrong, creation should fail + self.assertTrue(queue == 0) + + queue = sai_thrift_create_queue( + self.client, type=SAI_QUEUE_TYPE_ALL, + port=test_port) + # index is missing, creation should fail + self.assertTrue(queue == 0) + + queue = sai_thrift_create_queue( + self.client, type=SAI_QUEUE_TYPE_ALL, + port=test_port, index=60) + # index is wrong, creation should fail + self.assertTrue(queue == 0) + + queue = sai_thrift_create_queue( + self.client, type=SAI_QUEUE_TYPE_ALL, + port=test_port, index=1) + # queue with such index already exists + self.assertTrue(queue == 0) + + print("\tTest completed successfully") + finally: + pass + def tearDown(self): + super(queueCreateTest, self).tearDown() + + +class portQueueQueryTest(QueueConfigDataHelper): + """ + The test queries SAI_QUEUE_ATTR_PORT and SAI_QUEUE_ATTR_INDEX + attributes for all physical ports configured by default. + NOTE: If you modify this test, remember to apply the changes to + cpuPortQueueObjectTest too. + """ + def setUp(self): + super(portQueueQueryTest, self).setUp() + + def runTest(self): print("Port Queue Query Test") - for port in self.port_list: - attr = sai_thrift_get_port_attribute(self.client, - port, - qos_number_of_queues=True) - num_queues = attr["qos_number_of_queues"] - q_list = sai_thrift_object_list_t(count=num_queues) - attr = sai_thrift_get_port_attribute(self.client, - port, - qos_queue_list=q_list) - for queue in range(num_queues): - queue_id = attr["qos_queue_list"].idlist[queue] - q_attr = sai_thrift_get_queue_attribute( - self.client, - queue_id, - port=True, - index=True, - parent_scheduler_node=True) - self.assertEqual(queue, q_attr["index"]) - self.assertEqual(port, q_attr["port"]) - # If SDK does not support hierarhical QoS, - # the port handle should be returned. - self.assertEqual(port, q_attr["parent_scheduler_node"]) - - print("\tTest completed successfully") - - def bufferQueueTest(self): - """ - The test is dedicated to working buffers with queues. After creating - buffer pool and buffer profile, the last one is assigned to a queue. - Later the buffer profile is being removed and the default buffer - profile should be assigned to the queue. - NOTE: If you modify this test, remember to apply the changes to - cpuPortQueueObjectTest too. - """ + attr = sai_thrift_get_port_attribute(self.client, + self.port1, + qos_number_of_queues=True) + num_queues = attr["qos_number_of_queues"] + num_ports = len(self.port_list) + q_list = sai_thrift_object_list_t(count=num_queues) + try: + for port in range(0, num_ports): + attr = sai_thrift_get_port_attribute(self.client, + self.port_list[port], + qos_queue_list=q_list) + for queue in range(0, num_queues): + queue_id = attr["qos_queue_list"].idlist[queue] + q_attr = sai_thrift_get_queue_attribute( + self.client, + queue_id, + port=True, + index=True, + parent_scheduler_node=True) + self.assertTrue(queue == q_attr["index"]) + self.assertTrue(self.port_list[port] == q_attr["port"]) + # It should return port handle, + # because SDK does not support hierarchical QoS + self.assertTrue(self.port_list[port] == + q_attr["parent_scheduler_node"]) + + print("\tTest completed successfully") + finally: + pass + + def tearDown(self): + super(portQueueQueryTest, self).tearDown() + + +class bufferQueueTest(QueueConfigDataHelper): + """ + The test is dedicated to working buffers with queues. After creating + buffer pool and buffer profile, the last one is assigned to a queue. + Later the buffer profile is being removed and the default buffer + profile should be assigned to the queue. + NOTE: If you modify this test, remember to apply the changes to + cpuPortQueueObjectTest too. + """ + def setUp(self): + super(bufferQueueTest, self).setUp() + + def runTest(self): print("Buffer Queue Test") mode = SAI_BUFFER_POOL_THRESHOLD_MODE_DYNAMIC buff_pool = sai_thrift_create_buffer_pool( @@ -199,7 +218,7 @@ def bufferQueueTest(self): type=SAI_BUFFER_POOL_TYPE_EGRESS, size=1024, threshold_mode=mode) - self.assertNotEqual(buff_pool, 0) + self.assertTrue(buff_pool != 0) buff_prof = sai_thrift_create_buffer_profile(self.client, pool_id=buff_pool, reserved_buffer_size=1024, @@ -207,94 +226,116 @@ def bufferQueueTest(self): shared_dynamic_th=1, xoff_th=100, xon_th=10) - self.assertNotEqual(buff_prof, 0) - - attr = sai_thrift_get_port_attribute(self.client, - self.port26, - qos_queue_list=self.q_list) + self.assertTrue(buff_prof != 0) - queue_id = attr["qos_queue_list"].idlist + try: + attr = sai_thrift_get_port_attribute( + self.client, + self.port26, + qos_queue_list=self.q_list) - attr = sai_thrift_get_queue_attribute(self.client, - queue_id[0], - buffer_profile_id=True) - default_buff_prof = attr["buffer_profile_id"] + queue_id = attr["qos_queue_list"].idlist - status = sai_thrift_set_queue_attribute(self.client, - queue_id[0], - buffer_profile_id=buff_prof) - self.assertEqual(status, SAI_STATUS_SUCCESS) + attr = sai_thrift_get_queue_attribute(self.client, + queue_id[0], + buffer_profile_id=True) + default_buff_prof = attr["buffer_profile_id"] - sai_thrift_clear_queue_stats(self.client, queue_id[0]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src="00:00:00:00:00:22", - ip_dst="172.16.1.1", - ip_src="192.168.0.1", - ip_id=105, - ip_ttl=64) + status = sai_thrift_set_queue_attribute( + self.client, + queue_id[0], + buffer_profile_id=buff_prof) + self.assertEqual(status, SAI_STATUS_SUCCESS) - exp_pkt = simple_tcp_packet(eth_dst="00:11:22:33:44:55", - eth_src=ROUTER_MAC, + sai_thrift_clear_queue_stats(self.client, queue_id[0]) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src="00:00:00:00:00:22", ip_dst="172.16.1.1", ip_src="192.168.0.1", ip_id=105, - ip_ttl=63) + ip_ttl=64) - send_packet(self, self.dev_port25, pkt) - verify_packet(self, exp_pkt, self.dev_port26) - print("\tPacket received on PORT26") - stats = sai_thrift_get_queue_stats(self.client, queue_id[0]) - cnt = stats["SAI_QUEUE_STAT_PACKETS"] - self.assertEqual(cnt, 1) + exp_pkt = simple_tcp_packet(eth_dst="00:11:22:33:44:55", + eth_src=ROUTER_MAC, + ip_dst="172.16.1.1", + ip_src="192.168.0.1", + ip_id=105, + ip_ttl=63) - # Now the buffer profile is being detached. - status = sai_thrift_set_queue_attribute( - self.client, - queue_id[0], - buffer_profile_id=int(SAI_NULL_OBJECT_ID)) - self.assertEqual(status, SAI_STATUS_SUCCESS) - status = sai_thrift_remove_buffer_profile(self.client, buff_prof) - self.assertEqual(status, SAI_STATUS_SUCCESS) - status = sai_thrift_remove_buffer_pool(self.client, buff_pool) - self.assertEqual(status, SAI_STATUS_SUCCESS) + send_packet(self, self.dev_port25, pkt) + verify_packet(self, exp_pkt, self.dev_port26) + print("\tPacket received on PORT26") + stats = sai_thrift_get_queue_stats(self.client, queue_id[0]) + cnt = stats["SAI_QUEUE_STAT_PACKETS"] + self.assertEqual(cnt, 1) - # The queue should be assigned to the default buffer profile. - attr = sai_thrift_get_queue_attribute(self.client, - queue_id[0], - buffer_profile_id=True) - self.assertEqual(attr["buffer_profile_id"], default_buff_prof) + # Now the buffer profile is being detached. + status = sai_thrift_set_queue_attribute( + self.client, + queue_id[0], + buffer_profile_id=int(SAI_NULL_OBJECT_ID)) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_remove_buffer_profile(self.client, buff_prof) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_remove_buffer_pool(self.client, buff_pool) + self.assertEqual(status, SAI_STATUS_SUCCESS) - sai_thrift_clear_queue_stats(self.client, queue_id[0]) - pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, - eth_src="00:00:00:00:00:22", - ip_dst="172.16.1.1", - ip_src="192.168.0.1", - ip_id=105, - ip_ttl=64) + # The queue should be assigned to the default buffer profile. + attr = sai_thrift_get_queue_attribute(self.client, + queue_id[0], + buffer_profile_id=True) + self.assertEqual(attr["buffer_profile_id"], default_buff_prof) - exp_pkt = simple_tcp_packet(eth_dst="00:11:22:33:44:55", - eth_src=ROUTER_MAC, + sai_thrift_clear_queue_stats(self.client, queue_id[0]) + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src="00:00:00:00:00:22", ip_dst="172.16.1.1", ip_src="192.168.0.1", ip_id=105, - ip_ttl=63) + ip_ttl=64) + + exp_pkt = simple_tcp_packet(eth_dst="00:11:22:33:44:55", + eth_src=ROUTER_MAC, + ip_dst="172.16.1.1", + ip_src="192.168.0.1", + ip_id=105, + ip_ttl=63) + + send_packet(self, self.dev_port25, pkt) + verify_packet(self, exp_pkt, self.dev_port26) + print("\tPacket received on PORT26") + stats = sai_thrift_get_queue_stats(self.client, queue_id[0]) + cnt = stats["SAI_QUEUE_STAT_PACKETS"] + self.assertEqual(cnt, 1) + print("\tTest completed successfully") - send_packet(self, self.dev_port25, pkt) - verify_packet(self, exp_pkt, self.dev_port26) - print("\tPacket received on PORT26") - stats = sai_thrift_get_queue_stats(self.client, queue_id[0]) - cnt = stats["SAI_QUEUE_STAT_PACKETS"] - self.assertEqual(cnt, 1) - print("\tTest completed successfully") - - def schedulerQueueTest(self): - """ - The test scenario consists of attaching scheduler profile to a queue - and validate following parameters: queue priority, weight, - min and max rate. - NOTE: If you modify this test, remember to apply the changes to - cpuPortQueueObjectTest too. - """ + finally: + stats = sai_thrift_get_queue_stats_ext( + self.client, queue_id[0], SAI_STATS_MODE_READ_AND_CLEAR) + cnt = stats["SAI_QUEUE_STAT_PACKETS"] + self.assertEqual(cnt, 1) + stats = sai_thrift_get_queue_stats( + self.client, queue_id[0]) + cnt = stats["SAI_QUEUE_STAT_PACKETS"] + self.assertEqual(cnt, 0) + print("\tTest completed successfully") + + def tearDown(self): + super(bufferQueueTest, self).tearDown() + + +class schedulerQueueTest(QueueConfigDataHelper): + """ + The test scenario consists of attaching scheduler profile to a queue + and validate following parameters: queue priority, weight, + min and max rate. + NOTE: If you modify this test, remember to apply the changes to + cpuPortQueueObjectTest too. + """ + def setUp(self): + super(schedulerQueueTest, self).setUp() + + def runTest(self): print("Scheduler Queue Test") weight = 4 min_rate = 100 @@ -306,21 +347,21 @@ def schedulerQueueTest(self): meter_type=SAI_METER_TYPE_PACKETS, scheduling_type=SAI_SCHEDULING_TYPE_DWRR, scheduling_weight=weight) - self.assertNotEqual(sched1, 0) + self.assertTrue(sched1 != 0) sched2 = sai_thrift_create_scheduler( self.client, meter_type=SAI_METER_TYPE_PACKETS, scheduling_type=SAI_SCHEDULING_TYPE_STRICT, min_bandwidth_rate=min_rate, max_bandwidth_rate=max_rate) - self.assertNotEqual(sched2, 0) + self.assertTrue(sched2 != 0) sched3 = sai_thrift_create_scheduler( self.client, meter_type=SAI_METER_TYPE_PACKETS, scheduling_type=SAI_SCHEDULING_TYPE_STRICT, min_bandwidth_burst_rate=min_burst, max_bandwidth_burst_rate=max_burst) - self.assertNotEqual(sched3, 0) + self.assertTrue(sched3 != 0) print("\tScheduler profiles created successfully") try: attr = sai_thrift_get_port_attribute( @@ -471,13 +512,22 @@ def schedulerQueueTest(self): sai_thrift_remove_scheduler(self.client, sched2) sai_thrift_remove_scheduler(self.client, sched1) - def pfcPriorityQueueTest(self): - """ - The test verifies the correct configuration of mapping - between Priority-based Flow Control (PFC) and a queue. - NOTE: If you modify this test, remember to apply the changes to - cpuPortQueueObjectTest too. - """ + def tearDown(self): + super(schedulerQueueTest, self).tearDown() + + +class pfcPriorityQueueTest(QueueConfigDataHelper): + """ + The test verifies the correct configuration of mapping + between Priority-based Flow Control (PFC) and a queue. + NOTE: If you modify this test, remember to apply the changes to + cpuPortQueueObjectTest too. + """ + + def setUp(self): + super(pfcPriorityQueueTest, self).setUp() + + def runTest(self): print("PFC Priority Queue Test") p_attr = sai_thrift_get_port_attribute(self.client, self.port25, @@ -502,7 +552,7 @@ def pfcPriorityQueueTest(self): self.client, type=SAI_QOS_MAP_TYPE_PFC_PRIORITY_TO_QUEUE, map_to_value_list=qos_map_list) - self.assertNotEqual(qos_map, 0) + self.assertTrue(qos_map != 0) # The queue index modification in the previously created QoS map. p_attr = sai_thrift_get_port_attribute(self.client, @@ -541,28 +591,37 @@ def pfcPriorityQueueTest(self): finally: sai_thrift_remove_qos_map(self.client, qos_map) - def cpuPortQueueObjectTest(self): - """ - The test uses CPU port instead of external port for - all test cases above: portQueueQueryTest, bufferQueueTest - and schedulerQueueTest, pfcPriorityQueueTest. - """ + def tearDown(self): + super(pfcPriorityQueueTest, self).tearDown() + + +class cpuPortQueueObjectTest(QueueConfigDataHelper): + """ + The test uses CPU port instead of external port for + all test cases above: portQueueQueryTest, bufferQueueTest + and schedulerQueueTest, pfcPriorityQueueTest. + WRED is not supported on CPU queues. + """ + def setUp(self): + super(cpuPortQueueObjectTest, self).setUp() + + def runTest(self): print("CPU Port Queue Object Test") attr = sai_thrift_get_switch_attribute(self.client, cpu_port=True) cpu_port_id = attr["cpu_port"] print("\tPART1: Port Queue Query Test") - attr = sai_thrift_get_port_attribute(self.client, - cpu_port_id, - qos_number_of_queues=True) - num_queues = attr["qos_number_of_queues"] - q_list = sai_thrift_object_list_t(count=num_queues) try: for port in self.port_list: + attr = sai_thrift_get_port_attribute(self.client, + port, + qos_number_of_queues=True) + num_queues = attr["qos_number_of_queues"] + q_list = sai_thrift_object_list_t(count=num_queues) attr = sai_thrift_get_port_attribute(self.client, port, qos_queue_list=q_list) - for queue in range(num_queues): + for queue in range(0, num_queues): queue_id = attr["qos_queue_list"].idlist[queue] q_attr = sai_thrift_get_queue_attribute( self.client, @@ -570,19 +629,24 @@ def cpuPortQueueObjectTest(self): port=True, index=True, parent_scheduler_node=True) - self.assertEqual(queue, q_attr["index"]) - self.assertEqual(port, q_attr["port"]) - # If SDK does not support hierarhical QoS, - # the port handle should be returned. - self.assertEqual(port, q_attr["parent_scheduler_node"]) + self.assertTrue(queue == q_attr["index"]) + self.assertTrue(port == q_attr["port"]) + # It should return port handle, + # because SDK does not support hierarchical QoS + self.assertTrue(port == q_attr["parent_scheduler_node"]) print("\t\tPART1 completed successfully") print("\tPART2: Buffer Queue Test") # Get the queue for the CPU port - for the buffer queue test. + attr = sai_thrift_get_port_attribute(self.client, + cpu_port_id, + qos_number_of_queues=True) + num_queues = attr["qos_number_of_queues"] + q_list = sai_thrift_object_list_t(count=num_queues) attr = sai_thrift_get_port_attribute( self.client, cpu_port_id, - qos_queue_list=self.q_list) + qos_queue_list=q_list) queue_id = attr["qos_queue_list"].idlist @@ -592,7 +656,7 @@ def cpuPortQueueObjectTest(self): type=SAI_BUFFER_POOL_TYPE_EGRESS, size=1024, threshold_mode=mode) - self.assertNotEqual(buff_pool, 0) + self.assertTrue(buff_pool != 0) buff_prof = sai_thrift_create_buffer_profile( self.client, pool_id=buff_pool, @@ -601,7 +665,7 @@ def cpuPortQueueObjectTest(self): shared_dynamic_th=1, xoff_th=100, xon_th=10) - self.assertNotEqual(buff_prof, 0) + self.assertTrue(buff_prof != 0) attr = sai_thrift_get_queue_attribute(self.client, queue_id[0], @@ -643,7 +707,7 @@ def cpuPortQueueObjectTest(self): attr = sai_thrift_get_port_attribute( self.client, cpu_port_id, - qos_queue_list=self.q_list) + qos_queue_list=q_list) queue_id = attr["qos_queue_list"].idlist sched1 = sai_thrift_create_scheduler( @@ -651,21 +715,21 @@ def cpuPortQueueObjectTest(self): meter_type=SAI_METER_TYPE_PACKETS, scheduling_type=SAI_SCHEDULING_TYPE_DWRR, scheduling_weight=weight) - self.assertNotEqual(sched1, 0) + self.assertTrue(sched1 != 0) sched2 = sai_thrift_create_scheduler( self.client, meter_type=SAI_METER_TYPE_PACKETS, scheduling_type=SAI_SCHEDULING_TYPE_STRICT, min_bandwidth_rate=min_rate, max_bandwidth_rate=max_rate) - self.assertNotEqual(sched2, 0) + self.assertTrue(sched2 != 0) sched3 = sai_thrift_create_scheduler( self.client, meter_type=SAI_METER_TYPE_PACKETS, scheduling_type=SAI_SCHEDULING_TYPE_STRICT, min_bandwidth_burst_rate=min_burst, max_bandwidth_burst_rate=max_burst) - self.assertNotEqual(sched3, 0) + self.assertTrue(sched3 != 0) print("\t\tScheduler profiles created successfully") status = sai_thrift_set_queue_attribute( @@ -794,7 +858,7 @@ def cpuPortQueueObjectTest(self): p_attr = sai_thrift_get_port_attribute( self.client, cpu_port_id, - qos_queue_list=self.q_list) + qos_queue_list=q_list) queue_id = p_attr["qos_queue_list"].idlist q_attr = sai_thrift_get_queue_attribute( @@ -814,7 +878,7 @@ def cpuPortQueueObjectTest(self): self.client, type=SAI_QOS_MAP_TYPE_PFC_PRIORITY_TO_QUEUE, map_to_value_list=qos_map_list) - self.assertNotEqual(qos_map, 0) + self.assertTrue(qos_map != 0) # The queue index modification in the previously created QoS map. q_attr = sai_thrift_get_queue_attribute( @@ -835,7 +899,7 @@ def cpuPortQueueObjectTest(self): map_to_value_list=new_qos_map_list) self.assertEqual(status, SAI_STATUS_SUCCESS) - # Verify if the correct queue is applied to the QoS map. + # The verification if correct queue is applied to QoS map map_lists = sai_thrift_qos_map_list_t(count=1) attr = sai_thrift_get_qos_map_attribute( self.client, @@ -868,17 +932,27 @@ def cpuPortQueueObjectTest(self): sai_thrift_remove_scheduler(self.client, sched2) sai_thrift_remove_scheduler(self.client, sched1) - def wredQueueTest(self): - """ - The test verifies WRED attaching and removing for a particular queue. - """ + def tearDown(self): + super(cpuPortQueueObjectTest, self).tearDown() + + +@group("queue-wred") +#QueueX2ProfileDependentTests +class wredQueueTest(QueueConfigDataHelper): + """ + The test verifies WRED attaching and removing for a particular queue. + """ + def setUp(self): + super(wredQueueTest, self).setUp() + + def runTest(self): print("\nWRED Queue Test") wred_id = sai_thrift_create_wred(self.client, green_enable=True, green_min_threshold=0, green_max_threshold=4000, green_drop_probability=100) - self.assertNotEqual(wred_id, 0) + self.assertTrue(wred_id != 0) attr = sai_thrift_get_port_attribute( self.client, self.port25, @@ -919,3 +993,454 @@ def wredQueueTest(self): self.assertEqual(status, SAI_STATUS_SUCCESS) status = sai_thrift_remove_wred(self.client, wred_id) self.assertEqual(status, SAI_STATUS_SUCCESS) + + def tearDown(self): + super(wredQueueTest, self).tearDown() + + +@group("queue-hw") +#QueueHardwareSpecificTests +class dwrrBandwidthDistributionTest(QueueConfigDataHelper): # noqa pylint: disable=too-many-branches + """ + The configuration of scheduler to a given queue is done. + Then DWRR bandwidth distribution according to DWRR weight + is being validated. The last step is to modify weights + in previously created scheduler profile and the analogous + validation is repeated. + """ + def setUp(self): + super(dwrrBandwidthDistributionTest, self).setUp() + + def runTest(self): + print("DWRR Bandwidth Distribution Test") + # Create configuration + # 1. QoS map configuration for egress port to redirect traffic + # on queues. + # DSCP -> TC egress, PORT 25 (sender) + map_list = [] + dscp_list = [0, 1, 2, 3, 4, 5, 6, 7] + tc_list = [0, 1, 2, 3, 4, 5, 6, 7] + for traffic_class, dscp in zip(tc_list, dscp_list): + dscp_to_tc = sai_thrift_qos_map_t( + key=sai_thrift_qos_map_params_t(dscp=dscp), + value=sai_thrift_qos_map_params_t(tc=traffic_class)) + map_list.append(dscp_to_tc) + qos_map_list = sai_thrift_qos_map_list_t( + count=len(map_list), + maplist=map_list) + indirect_qos_map = sai_thrift_create_qos_map( + self.client, + type=SAI_QOS_MAP_TYPE_DSCP_TO_TC, + map_to_value_list=qos_map_list) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_dscp_to_tc_map=indirect_qos_map) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + # TC -> Queue on egress, PORT 25 (sender) + map_list2 = [] + egress_queue_indices = [] + + # Port 25 queue list (sender) + port25_attr = sai_thrift_get_port_attribute( + self.client, + self.port25, + qos_number_of_queues=True, + qos_queue_list=self.q_list) + num_queues = port25_attr["qos_number_of_queues"] + queue_id_list_port25 = port25_attr["qos_queue_list"].idlist + + # Port 26 queue list (receiver) + port26_attr = sai_thrift_get_port_attribute( + self.client, + self.port26, + qos_queue_list=self.q_list) + queue_id_list_port26 = port26_attr["qos_queue_list"].idlist + + for i in tc_list: + egress_queue_attr = sai_thrift_get_queue_attribute( + self.client, + port25_attr["qos_queue_list"].idlist[i], + index=True) + queue_index = egress_queue_attr["index"] + egress_queue_indices.append(queue_index) + tc_to_queue = sai_thrift_qos_map_t( + key=sai_thrift_qos_map_params_t(tc=i), + value=sai_thrift_qos_map_params_t(queue_index=queue_index)) + map_list2.append(tc_to_queue) + + # Clear statistics for each queue in PORT25 + sai_thrift_clear_queue_stats(self.client, queue_id_list_port25[i]) + # Clear statistics for each queue in PORT26 + sai_thrift_clear_queue_stats(self.client, queue_id_list_port26[i]) + + qos_map_list2 = sai_thrift_qos_map_list_t( + count=len(map_list2), + maplist=map_list2) + target_qos_map = sai_thrift_create_qos_map( + self.client, + type=SAI_QOS_MAP_TYPE_TC_TO_QUEUE, + map_to_value_list=qos_map_list2) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_tc_to_queue_map=target_qos_map) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + # 2. Create scheduler's structre + # Scheduler profiles for queues + schedulers = [] + weight = 8 + for queue in range(0, int(num_queues / 2)): + sched = sai_thrift_create_scheduler( + self.client, + meter_type=SAI_METER_TYPE_PACKETS, + scheduling_type=SAI_SCHEDULING_TYPE_DWRR, + scheduling_weight=weight) + self.assertTrue(sched != 0) + schedulers.append(sched) + weight //= 2 + + # Scheduler profile for port shape + shaper = sai_thrift_create_scheduler( + self.client, + meter_type=SAI_METER_TYPE_PACKETS, + scheduling_type=SAI_SCHEDULING_TYPE_DWRR, + max_bandwidth_rate=750) + self.assertTrue(shaper != 0) + + status = sai_thrift_set_port_attribute( + self.client, + self.port26, + qos_scheduler_profile_id=shaper) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + # 3. Create queue's structure + for queue in range(0, num_queues): + # weights for: queue.0 = 8, queue.1 = 4, queue.2 = 2 + if num_queues < 3: + status = sai_thrift_set_queue_attribute( + self.client, + queue_id_list_port26[queue], + scheduler_profile_id=schedulers[queue % 3]) + # weights for others: queue.x = 1 + else: + status = sai_thrift_set_queue_attribute( + self.client, + queue_id_list_port26[queue], + scheduler_profile_id=schedulers[3]) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + print("\tConfiguration completed") + # Build packets with different type of service + pkts = [] + exp_pkts = [] + for i in range(0, num_queues): + tos = i << 2 + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src="00:00:00:00:00:22", + ip_dst="172.16.1.1", + ip_src="192.168.0.1", + ip_id=105, + ip_tos=tos, + ip_ttl=64) + pkts.append(pkt) + + exp_pkt = simple_tcp_packet(eth_dst="00:11:22:33:44:55", + eth_src=ROUTER_MAC, + ip_dst="172.16.1.1", + ip_src="192.168.0.1", + ip_id=105, + ip_tos=tos, + ip_ttl=63) + exp_pkts.append(exp_pkt) + + try: + print("\tSending 19 packets PORT25 -> PORT26") + rec_pkt = 0 + congestion_rate = 2 + pkt_cnt = congestion_rate * num_queues + for _ in range(0, congestion_rate): + for i in range(0, num_queues): + send_packet(self, self.dev_port25, pkts[i]) + # To increase packet rate, disable verification + # verify_packet(self, exp_pkts[i], self.dev_port26) + rec_pkt += 1 + + send_packet(self, self.dev_port25, pkts[2]) + + print("\tChecking if received packet number equals sent one") + print("Expected: {}, Received: {}".format(pkt_cnt, rec_pkt)) + self.assertTrue(rec_pkt == pkt_cnt) + print("\tPackets received on PORT26") + + print("\tDelay for statistics read") + time.sleep(5) + + print("\tChecking received packets on particular queues") + exp_pkt_num = 8 + for queue in range(0, num_queues): + time.sleep(5) + + q_stats = sai_thrift_get_queue_stats( + self.client, + queue_id_list_port26[queue]) + rec_pkt_num = q_stats["SAI_QUEUE_STAT_PACKETS"] + print("Queue:", queue) + print("Received no. packets:", rec_pkt_num) + print("Expected no. packets:", exp_pkt_num) + # self.assertTrue(rec_pkt_num == exp_pkt_num) + if exp_pkt_num != 1: + exp_pkt_num //= 2 + print("\tThe packet distribution is correct.") + print("\tTest completed successfully") + + finally: + stats = sai_thrift_get_queue_stats_ext( + self.client, + queue_id_list_port26[0], + SAI_STATS_MODE_READ_AND_CLEAR) + cnt = stats["SAI_QUEUE_STAT_PACKETS"] + self.assertEqual(cnt, 2) + stats = sai_thrift_get_queue_stats( + self.client, queue_id_list_port26[0]) + cnt = stats["SAI_QUEUE_STAT_PACKETS"] + self.assertEqual(cnt, 0) + print("\tTest completed successfully") + + status = sai_thrift_set_port_attribute( + self.client, + self.port26, + qos_scheduler_profile_id=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + sai_thrift_remove_scheduler(self.client, shaper) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_tc_to_queue_map=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_dscp_to_tc_map=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + sai_thrift_remove_qos_map(self.client, indirect_qos_map) + sai_thrift_remove_qos_map(self.client, target_qos_map) + for queue in range(0, num_queues): + status = sai_thrift_set_queue_attribute( + self.client, + queue_id_list_port26[queue], + scheduler_profile_id=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + for i in range(0, int(num_queues / 2)): + sai_thrift_remove_scheduler(self.client, schedulers[i]) + + def tearDown(self): + super(dwrrBandwidthDistributionTest, self).tearDown() + + +class strictPriorityQueueTest(QueueConfigDataHelper): + """ + After the creation of strict priority type for scheduler profile, + it has been attached to a queue. Then, overwriting the port number + causes forwarding the traffic to other port. + """ + def setUp(self): + super(strictPriorityQueueTest, self).setUp() + + def runTest(self): + print("Strict Priority Queue Test") + # 1. QoS map configuration for egress port to redirect traffic + # on queues. + # DSCP -> TC egress, PORT 25 (sender) + map_list = [] + dscp_list = [0, 1, 2, 3, 4, 5, 6, 7] + tc_list = [0, 1, 2, 3, 4, 5, 6, 7] + for traffic_class, dscp in zip(tc_list, dscp_list): + dscp_to_tc = sai_thrift_qos_map_t( + key=sai_thrift_qos_map_params_t(dscp=dscp), + value=sai_thrift_qos_map_params_t(tc=traffic_class)) + map_list.append(dscp_to_tc) + qos_map_list = sai_thrift_qos_map_list_t( + count=len(map_list), + maplist=map_list) + indirect_qos_map = sai_thrift_create_qos_map( + self.client, + type=SAI_QOS_MAP_TYPE_DSCP_TO_TC, + map_to_value_list=qos_map_list) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_dscp_to_tc_map=indirect_qos_map) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + # TC -> Queue on egress, PORT 25 (sender) + map_list2 = [] + egress_queue_indices = [] + + # Port 25 queue list (sender) + port25_attr = sai_thrift_get_port_attribute( + self.client, + self.port25, + qos_number_of_queues=True, + qos_queue_list=self.q_list) + queue_id_list_port25 = port25_attr["qos_queue_list"].idlist + + # Port 26 queue list (receiver) + port26_attr = sai_thrift_get_port_attribute( + self.client, + self.port26, + qos_queue_list=self.q_list) + queue_id_list_port26 = port26_attr["qos_queue_list"].idlist + + for i in tc_list: + egress_queue_attr = sai_thrift_get_queue_attribute( + self.client, + port25_attr["qos_queue_list"].idlist[i], + index=True) + queue_index = egress_queue_attr["index"] + egress_queue_indices.append(queue_index) + tc_to_queue = sai_thrift_qos_map_t( + key=sai_thrift_qos_map_params_t(tc=i), + value=sai_thrift_qos_map_params_t(queue_index=queue_index)) + map_list2.append(tc_to_queue) + + # Clear statistics for each queue in PORT25 + sai_thrift_clear_queue_stats(self.client, queue_id_list_port25[i]) + # Clear statistics for each queue in PORT26 + sai_thrift_clear_queue_stats(self.client, queue_id_list_port26[i]) + + qos_map_list2 = sai_thrift_qos_map_list_t( + count=len(map_list2), + maplist=map_list2) + target_qos_map = sai_thrift_create_qos_map( + self.client, + type=SAI_QOS_MAP_TYPE_TC_TO_QUEUE, + map_to_value_list=qos_map_list2) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_tc_to_queue_map=target_qos_map) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + # Port 27 queue list (oversubscribed port) + port27_attr = sai_thrift_get_port_attribute( + self.client, + self.port27, + qos_queue_list=self.q_list) + queue_id_list_port27 = port27_attr["qos_queue_list"].idlist + + # Attach the scheduler profile to queue[1] of port26 + sched = sai_thrift_create_scheduler( + self.client, + meter_type=SAI_METER_TYPE_PACKETS, + scheduling_type=SAI_SCHEDULING_TYPE_STRICT) + self.assertTrue(sched != 0) + status = sai_thrift_set_queue_attribute( + self.client, + queue_id_list_port26[1], + scheduler_profile_id=sched) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + port27_attr = sai_thrift_get_port_attribute( + self.client, + self.port27, + qos_number_of_scheduler_groups=True) + num_sched_grps = port27_attr["qos_number_of_scheduler_groups"] + sched_grp_list = sai_thrift_object_list_t(count=num_sched_grps) + + port27_attr = sai_thrift_get_port_attribute( + self.client, + self.port27, + qos_scheduler_group_list=sched_grp_list) + sch_grps_port27 = port27_attr["qos_scheduler_group_list"].idlist + + # Oversubscribe port - attach scheduler to PORT27 + status = sai_thrift_set_scheduler_group_attribute( + self.client, + sch_grps_port27[0], + scheduler_profile_id=sched) + self.assertEqual(status, SAI_STATUS_SUCCESS) + + print("\tConfiguration completed") + pkt = simple_tcp_packet(eth_dst=ROUTER_MAC, + eth_src="00:00:00:00:00:22", + ip_dst="172.16.1.1", + ip_src="192.168.0.1", + ip_id=105, + ip_tos=4, + ip_ttl=64) + + exp_pkt = simple_tcp_packet(eth_dst="00:11:22:33:44:55", + eth_src=ROUTER_MAC, + ip_dst="172.16.1.1", + ip_src="192.168.0.1", + ip_id=105, + ip_tos=4, + ip_ttl=63) + + try: + print("\tSending 19 packets PORT25 -> PORT26") + pkt_cnt = 19 + for _ in range(0, pkt_cnt): + send_packet(self, self.dev_port25, pkt) + time.sleep(0.1) + verify_packet(self, exp_pkt, self.dev_port26) + verify_no_other_packets(self) + print("\tReceived all packets") + + # Sleep added to enable statistics reading + time.sleep(4) + + # Statistics read + q_stats_port26 = sai_thrift_get_queue_stats( + self.client, + queue_id_list_port26[1]) + received_pkt_num = q_stats_port26["SAI_QUEUE_STAT_PACKETS"] + print("\tqueue[1] of PORT26, no. packets:", received_pkt_num) + # queue[0] + q_stats_port27 = sai_thrift_get_queue_stats( + self.client, + queue_id_list_port27[0]) + forwarded_pkt_num = q_stats_port27["SAI_QUEUE_STAT_PACKETS"] + print("\tqueue[0] of PORT27, no. packets:", forwarded_pkt_num) + # queue[1] + q_stats_port27 = sai_thrift_get_queue_stats( + self.client, + queue_id_list_port27[1]) + forwarded_pkt_num = q_stats_port27["SAI_QUEUE_STAT_PACKETS"] + print("\tqueue[1] of PORT27, no. packets:", forwarded_pkt_num) + + print("\tChecking if received packet number equals sent one") + self.assertTrue(received_pkt_num == pkt_cnt) + + print("\tTest completed successfully") + + finally: + status = sai_thrift_set_scheduler_group_attribute( + self.client, + sch_grps_port27[0], + scheduler_profile_id=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_set_queue_attribute( + self.client, + queue_id_list_port26[1], + scheduler_profile_id=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + sai_thrift_remove_scheduler(self.client, sched) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_tc_to_queue_map=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + status = sai_thrift_set_port_attribute( + self.client, + self.port25, + qos_dscp_to_tc_map=0) + self.assertEqual(status, SAI_STATUS_SUCCESS) + sai_thrift_remove_qos_map(self.client, indirect_qos_map) + sai_thrift_remove_qos_map(self.client, target_qos_map) + + def tearDown(self): + super(strictPriorityQueueTest, self).tearDown() From c4d97af68c413b1f7b229c63fd5dd389d3a5c127 Mon Sep 17 00:00:00 2001 From: mounika-adhuri Date: Mon, 12 Dec 2022 02:09:51 -0800 Subject: [PATCH 6/6] Adding changes to SWI-6201 SONiC PTF saifdb.py refactor --- ptf/saifdb.py | 1047 +++++++++++++++++++++++++++++++------------------ 1 file changed, 663 insertions(+), 384 deletions(-) diff --git a/ptf/saifdb.py b/ptf/saifdb.py index 351053492..43aadd701 100644 --- a/ptf/saifdb.py +++ b/ptf/saifdb.py @@ -21,7 +21,7 @@ @group("draft") -class FdbAttributeTest(SaiHelper): +class FdbAttributeTest(PlatformSaiHelper): ''' Basic FDB attributes getting and setting test ''' @@ -69,13 +69,13 @@ def tearDown(self): @group("draft") -class FdbNoLearnTest(SaiHelper): +class FdbNoLearnTestHelper(PlatformSaiHelper): ''' Verify different cases when MAC addresses should not be learned ''' def setUp(self): - super(FdbNoLearnTest, self).setUp() + super(FdbNoLearnTestHelper, self).setUp() vlan_id = 10 self.src_mac = "00:11:11:11:11:11" @@ -99,23 +99,23 @@ def setUp(self): vlan_vid=vlan_id, pktlen=104) + def tearDown(self): + super(FdbNoLearnTestHelper, self).tearDown() + + +class vlanPortNoLearnTest(FdbNoLearnTestHelper): + ''' + Verify if MAC addresses are not learned on port when VLAN learning + is disabled + Send a packet on port0 with SMAC 00:11:11:11:11:11 and we verify it + was broadcasted on other ports in VLAN. + Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify + it was also broadcasted on other ports in VLAN + ''' + def setUp(self): + super(vlanPortNoLearnTest, self).setUp() + def runTest(self): - self.vlanPortNoLearnTest() - self.vlanLagNoLearnTest() - self.bpPortNoLearnTest() - self.bpLagNoLearnTest() - self.noBpNoLearnTest() - self.removedBpNoLearnTest() - - def vlanPortNoLearnTest(self): - ''' - Verify if MAC addresses are not learned on port when VLAN learning - is disabled - Send a packet on port0 with SMAC 00:11:11:11:11:11 and we verify it - was broadcasted on other ports in VLAN. - Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify - it was also broadcasted on other ports in VLAN - ''' print("\nvlanPortNoLearnTest()") try: @@ -151,15 +151,23 @@ def vlanPortNoLearnTest(self): sai_thrift_set_vlan_attribute( self.client, self.vlan10, learn_disable=False) - def vlanLagNoLearnTest(self): - ''' - Verify if MAC addresses are not learned on LAG when VLAN learning - is disabled - Send a packet on LAG1 with SMAC 00:11:11:11:11:11, and verify it was - broadcasted on other ports in VLAN. - Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify - it was also broadcasted on other ports in VLAN - ''' + def tearDown(self): + super(vlanPortNoLearnTest, self).tearDown() + + +class vlanLagNoLearnTest(FdbNoLearnTestHelper): + ''' + Verify if MAC addresses are not learned on LAG when VLAN learning + is disabled + Send a packet on LAG1 with SMAC 00:11:11:11:11:11, and verify it was + broadcasted on other ports in VLAN. + Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify + it was also broadcasted on other ports in VLAN + ''' + def setUp(self): + super(vlanLagNoLearnTest, self).setUp() + + def runTest(self): print("\nvlanLagNoLearnTest()") try: @@ -193,15 +201,23 @@ def vlanLagNoLearnTest(self): sai_thrift_set_vlan_attribute( self.client, self.vlan10, learn_disable=False) - def bpPortNoLearnTest(self): - ''' - Verify if MAC addresses are not learned on port when bridge port - learning is disabled. - Disable learning on port0, send a packet on port0 with SMAC - 00:11:11:11:11:11 and verify it was broadcasted on other ports in VLAN. - Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify - it was also broadcasted on other ports in VLAN - ''' + def tearDown(self): + super(vlanLagNoLearnTest, self).tearDown() + + +class bpPortNoLearnTest(FdbNoLearnTestHelper): + ''' + Verify if MAC addresses are not learned on port when bridge port + learning is disabled. + Disable learning on port0, send a packet on port0 with SMAC + 00:11:11:11:11:11 and verify it was broadcasted on other ports in VLAN. + Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify + it was also broadcasted on other ports in VLAN + ''' + def setUp(self): + super(bpPortNoLearnTest, self).setUp() + + def runTest(self): print("\nbpPortNoLearnTest()") try: @@ -240,16 +256,24 @@ def bpPortNoLearnTest(self): self.client, self.port0_bp, fdb_learning_mode=SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW) - def bpLagNoLearnTest(self): - ''' - Verify if MAC addresses are not learned on port when LAG bridge - port learning is disabled. - Disable learning on LAG1, send a packet on port0 with - SMAC: 00:11:11:11:11:11, and then we verify it was broadcasted on other - ports in VLAN. - Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify - it was also broadcasted on other ports in VLAN - ''' + def tearDown(self): + super(bpPortNoLearnTest, self).tearDown() + + +class bpLagNoLearnTest(FdbNoLearnTestHelper): + ''' + Verify if MAC addresses are not learned on port when LAG bridge + port learning is disabled. + Disable learning on LAG1, send a packet on port0 with + SMAC: 00:11:11:11:11:11, and then we verify it was broadcasted on other + ports in VLAN. + Next send a packet on port1 with DMAC 00:11:11:11:11:11 and verify + it was also broadcasted on other ports in VLAN + ''' + def setUp(self): + super(bpLagNoLearnTest, self).setUp() + + def runTest(self): print("\nbpLagNoLearnTest()") try: @@ -286,11 +310,19 @@ def bpLagNoLearnTest(self): self.client, self.lag1_bp, fdb_learning_mode=SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW) - def noBpNoLearnTest(self): - ''' - Verify if MAC is not learned on port if bridge port is not created - on that port - ''' + def tearDown(self): + super(bpLagNoLearnTest, self).tearDown() + + +class noBpNoLearnTest(FdbNoLearnTestHelper): + ''' + Verify if MAC is not learned on port if bridge port is not created + on that port + ''' + def setUp(self): + super(noBpNoLearnTest, self).setUp() + + def runTest(self): print("\nnoBpNoLearnTest()") test_port = self.port24 @@ -331,11 +363,19 @@ def noBpNoLearnTest(self): sai_thrift_set_port_attribute( self.client, test_port, port_vlan_id=0) - def removedBpNoLearnTest(self): - ''' - Verify if MAC address is not learned on port after bridge port - is removed on that port - ''' + def tearDown(self): + super(noBpNoLearnTest, self).tearDown() + + +class removedBpNoLearnTest(FdbNoLearnTestHelper): + ''' + Verify if MAC address is not learned on port after bridge port + is removed on that port + ''' + def setUp(self): + super(removedBpNoLearnTest, self).setUp() + + def runTest(self): print("\nremovedBpNoLearnTest()") try: @@ -372,15 +412,18 @@ def removedBpNoLearnTest(self): admin_state=True) self.assertNotEqual(self.port0_bp, 0) + def tearDown(self): + super(removedBpNoLearnTest, self).tearDown() + @group("draft") -class FdbLearnTest(SaiHelper): +class FdbLearnTestHelper(PlatformSaiHelper): ''' Verify different cases of FDB learning ''' def setUp(self): - super(FdbLearnTest, self).setUp() + super(FdbLearnTestHelper, self).setUp() self.vlan_id = 10 @@ -403,28 +446,29 @@ def setUp(self): self.dst_ports = [[self.dev_port0], [self.dev_port1], self.utg_lag_ports, self.tg_lag_ports] - def runTest(self): - self.dynamicMacLearnTest() - self.macLearnErrorTest() - def tearDown(self): # remove LAG2 from VLAN 10 sai_thrift_remove_vlan_member(self.client, self.vlan10_member3) sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) - super(FdbLearnTest, self).tearDown() + super(FdbLearnTestHelper, self).tearDown() - def dynamicMacLearnTest(self): # noqa pylint: disable=too-many-branches - ''' - Verify if MAC addresses are learned on tagged and untagged VLAN - ports and LAGs. The test checks also if MAC addresses are learned on - newly added VLAN and LAG member. - Send packets with given SMACs and verify they are broadcasted - on other ports. - Next send packets with DMACs == previous SMACs and verify they are - forwarded only to the proper ports - ''' + +class dynamicMacLearnTest(FdbLearnTestHelper): # noqa pylint: disable=too-many-branches + ''' + Verify if MAC addresses are learned on tagged and untagged VLAN + ports and LAGs. The test checks also if MAC addresses are learned on + newly added VLAN and LAG member. + Send packets with given SMACs and verify they are broadcasted + on other ports. + Next send packets with DMACs == previous SMACs and verify they are + forwarded only to the proper ports + ''' + def setUp(self): + super(dynamicMacLearnTest, self).setUp() + + def runTest(self): print("\ndynamicMacLearnTest()") try: @@ -659,17 +703,25 @@ def dynamicMacLearnTest(self): # noqa pylint: disable=too-many-branches sai_thrift_remove_vlan_member(self.client, vlan10_member4) sai_thrift_remove_bridge_port(self.client, new_vlan_member_bp) - def macLearnErrorTest(self): - ''' - Verify if MAC addresses are not learned when different undesirable - conditions occured: - 1 - invalid VLAN tag - 2 - src_mac is a broadcast address (packet drop) - 3 - src_mac is a multicast address (packet drop) - 4 - src_mac previously added statically - 5 - removed VLAN member - 6 - removed LAG member - ''' + def tearDown(self): + super(dynamicMacLearnTest, self).tearDown() + + +class macLearnErrorTest(FdbLearnTestHelper): + ''' + Verify if MAC addresses are not learned when different undesirable + conditions occured: + 1 - invalid VLAN tag + 2 - src_mac is a broadcast address (packet drop) + 3 - src_mac is a multicast address (packet drop) + 4 - src_mac previously added statically + 5 - removed VLAN member + 6 - removed LAG member + ''' + def setUp(self): + super(macLearnErrorTest, self).setUp() + + def runTest(self): print("\nmacLearnErrorTest()") access_port = self.dev_port0 # untagged @@ -956,15 +1008,18 @@ def macLearnErrorTest(self): self.client, vlan_id=self.vlan10, bridge_port_id=self.port1_bp, vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_TAGGED) + def tearDown(self): + super(macLearnErrorTest, self).tearDown() + @group("draft") -class FdbStaticMacTest(SaiHelper): +class FdbStaticMacTestHelper(PlatformSaiHelper): ''' Verify static MAC entries ''' def setUp(self): - super(FdbStaticMacTest, self).setUp() + super(FdbStaticMacTestHelper, self).setUp() self.vlan_id = 10 @@ -1008,22 +1063,22 @@ def setUp(self): self.assertEqual(status, SAI_STATUS_SUCCESS) print("FDB entries added") - def runTest(self): - self.staticMacForwardTest() - self.selfForwardingTest() - def tearDown(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) - super(FdbStaticMacTest, self).tearDown() + super(FdbStaticMacTestHelper, self).tearDown() - def staticMacForwardTest(self): - ''' - Static MAC tests - Send a packet from one port with DMAC installed on other port and - verify packet forwarding - ''' +class staticMacForwardTest(FdbStaticMacTestHelper): + ''' + Static MAC tests + Send a packet from one port with DMAC installed on other port and + verify packet forwarding + ''' + def setUp(self): + super(staticMacForwardTest, self).setUp() + + def runTest(self): print("\nstaticMacForwardTest()") try: @@ -1053,11 +1108,18 @@ def staticMacForwardTest(self): except BaseException: print("Test error occured") + def tearDown(self): + super(staticMacForwardTest, self).tearDown() - def selfForwardingTest(self): - ''' - Verify if packet send with ingress port MAC address is dropped - ''' + +class selfForwardingTest(FdbStaticMacTestHelper): + ''' + Verify if packet send with ingress port MAC address is dropped + ''' + def setUp(self): + super(selfForwardingTest, self).setUp() + + def runTest(self): print("\nselfForwardingTest()") test_port_dev = self.dev_port0 @@ -1070,15 +1132,18 @@ def selfForwardingTest(self): verify_no_other_packets(self) print("\tOK") + def tearDown(self): + super(selfForwardingTest, self).tearDown() + @group("draft") -class FdbMacMoveTest(SaiHelper): +class FdbMacMoveTestHelper(PlatformSaiHelper): ''' Verify MAC entries moving ''' def setUp(self): - super(FdbMacMoveTest, self).setUp() + super(FdbMacMoveTestHelper, self).setUp() # change port1 original tagging mode sai_thrift_remove_vlan_member(self.client, self.vlan10_member1) @@ -1143,11 +1208,6 @@ def setUp(self): bridge_port_id=self.port24_bp) self.assertEqual(status, SAI_STATUS_SUCCESS) - def runTest(self): - self.dynamicMacMoveTest() - self.dynamicMacMoveTest(static_entry=True) - self.staticMacMoveTest() - def tearDown(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) @@ -1175,25 +1235,34 @@ def tearDown(self): bridge_port_id=self.port1_bp, vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_TAGGED) - super(FdbMacMoveTest, self).tearDown() - - def dynamicMacMoveTest(self, static_entry=False): - ''' - Dynamic MAC move test that verify if after receiving packet with known - SMAC, but from other port that on which it was learned previously, - next packets with such DMACs are forwarded to the new port. + super(FdbMacMoveTestHelper, self).tearDown() - The test represents a chain of moves: - - port -> port - - port -> LAG - - LAG -> LAG - - LAG -> port +class dynamicMacMoveTests(FdbMacMoveTestHelper): + ''' + Dynamic MAC move test that verify if after receiving packet with known + SMAC, but from other port that on which it was learned previously, + next packets with such DMACs are forwarded to the new port. + + The test represents a chain of moves: + - port -> port + - port -> LAG + - LAG -> LAG + - LAG -> port + + Args: + entry_type (int): Check move for static fdb entry + ''' + def setUp(self): + super(dynamicMacMoveTests, self).setUp() - Args: - static_entry (bool): Check move for static fdb entry - ''' + def runTest(self): print("\ndynamicMacMoveTest()") + self.dynamicMacMoveTest() + self.dynamicMacMoveTest(entry_type=SAI_FDB_ENTRY_TYPE_STATIC) + # SAI_FDB_ENTRY_TYPE_STATIC_MACMOVE + self.dynamicMacMoveTest(entry_type=SAI_FDB_ENTRY_TYPE_STATIC + 1) + def dynamicMacMoveTest(self, entry_type=SAI_FDB_ENTRY_TYPE_DYNAMIC): # a series of ports representing moving chain: # port->port->LAG->LAG->port port_chain = [self.dev_port0, self.dev_port1, self.dev_port5, @@ -1207,8 +1276,8 @@ def dynamicMacMoveTest(self, static_entry=False): eth_src=self.chck_mac) try: - if static_entry: - # inititally add moving MAC to FDB as static + if entry_type == SAI_FDB_ENTRY_TYPE_STATIC: + # initially add moving MAC to FDB as static moving_fdb_entry = sai_thrift_fdb_entry_t( switch_id=self.switch_id, mac_address=self.moving_mac, @@ -1221,6 +1290,18 @@ def dynamicMacMoveTest(self, static_entry=False): allow_mac_move=True) self.assertEqual(status, SAI_STATUS_SUCCESS) + if entry_type == SAI_FDB_ENTRY_TYPE_STATIC + 1: + # initially add moving MAC to FDB as static_macmove + moving_fdb_entry = sai_thrift_fdb_entry_t( + switch_id=self.switch_id, + mac_address=self.moving_mac, + bv_id=self.vlan10) + status = sai_thrift_create_fdb_entry( + self.client, + moving_fdb_entry, + type=SAI_FDB_ENTRY_TYPE_STATIC + 1, + bridge_port_id=self.port0_bp) + self.assertEqual(status, SAI_STATUS_SUCCESS) for src_port in port_chain: print("Sending packet on port %d, %s -> %s - learn and " "forward to port %d" % (src_port, self.moving_mac, @@ -1249,19 +1330,27 @@ def dynamicMacMoveTest(self, static_entry=False): print("\tVerification complete\n") finally: - if static_entry: + if entry_type != SAI_FDB_ENTRY_TYPE_DYNAMIC: sai_thrift_remove_fdb_entry(self.client, moving_fdb_entry) else: # flush dynamic MACs from FDB sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC) - def staticMacMoveTest(self): - ''' - static MAC move tests. - Changee a bridge port id of some static FDB entry and check that - a packet is forwarded to this new port. - ''' + def tearDown(self): + super(dynamicMacMoveTests, self).tearDown() + + +class staticMacMoveTest(FdbMacMoveTestHelper): + ''' + static MAC move tests. + Changee a bridge port id of some static FDB entry and check that + a packet is forwarded to this new port. + ''' + def setUp(self): + super(staticMacMoveTest, self).setUp() + + def runTest(self): print("\nstaticMacMoveTest()") # a series of ports representing moving chain: @@ -1317,9 +1406,12 @@ def staticMacMoveTest(self): finally: sai_thrift_remove_fdb_entry(self.client, moving_fdb_entry) + def tearDown(self): + super(staticMacMoveTest, self).tearDown() + @group("draft") -class FdbFlushTest(SaiHelper): +class FdbFlushTestHelper(PlatformSaiHelper): ''' MAC flush test that checks flushing functionality for static and dynamic MAC addresses in FDB. @@ -1329,7 +1421,7 @@ class FdbFlushTest(SaiHelper): ''' def setUp(self): - super(FdbFlushTest, self).setUp() + super(FdbFlushTestHelper, self).setUp() # change port1 (VLAN 10) original tagging mode sai_thrift_remove_vlan_member(self.client, self.vlan10_member1) @@ -1406,23 +1498,6 @@ def setUp(self): self.trunk_port_bp = self.port24_bp self.trunk_dev_port = self.dev_port24 - def runTest(self): - self.flushStaticPerVlanTest() - self.flushDynamicPerVlanTest() - self.flushAllPerVlanTest() - self.flushStaticPerPortTest() - self.flushDynamicPerPortTest() - self.flushAllPerPortTest() - self.flushStaticPerLagTest() - self.flushDynamicPerLagTest() - self.flushAllPerLagTest() - self.flushStaticPerVlanAndPortTest() - self.flushDynamicPerVlanAndPortTest() - self.flushAllPerVlanAndPortTest() - self.flushAllStaticTest() - self.flushAllDynamicTest() - self.flushAllMacsTest() - def tearDown(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) @@ -1456,12 +1531,14 @@ def tearDown(self): bridge_port_id=self.lag2_bp, vlan_tagging_mode=SAI_VLAN_TAGGING_MODE_TAGGED) - super(FdbFlushTest, self).tearDown() + super(FdbFlushTestHelper, self).tearDown() # additional helper functions - def _prepareFdb(self): + def _prepareFdb(self, static_fdb_entry_type=SAI_FDB_ENTRY_TYPE_STATIC): ''' Helper function for preparing FDB with a large number of entries + Args: + static_fdb_entry_type (int): FDB entry type to add ''' sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) @@ -1479,7 +1556,7 @@ def _prepareFdb(self): sai_thrift_create_fdb_entry( self.client, getattr(self, "vlan10_fdb_entry%d" % i), - type=SAI_FDB_ENTRY_TYPE_STATIC, + type=static_fdb_entry_type, bridge_port_id=self.vlan10_ports_bp[i]) self.assertEqual(self.status(), SAI_STATUS_SUCCESS) @@ -1492,7 +1569,7 @@ def _prepareFdb(self): sai_thrift_create_fdb_entry( self.client, getattr(self, "vlan20_fdb_entry%d" % i), - type=SAI_FDB_ENTRY_TYPE_STATIC, + type=static_fdb_entry_type, bridge_port_id=self.vlan20_ports_bp[i]) self.assertEqual(self.status(), SAI_STATUS_SUCCESS) @@ -1727,10 +1804,14 @@ def _verifyFlood(self, dst_macs, dst_ports, src_macs, src_ports, break # tests funcions - def flushStaticPerVlanTest(self): - ''' - Verify flushing of static MAC entries by VLAN - ''' +class flushStaticPerVlanTest(FdbFlushTestHelper): + ''' + Verify flushing of static MAC entries by VLAN + ''' + def setUp(self): + super(flushStaticPerVlanTest, self).setUp() + + def runTest(self): print("\nflushStaticPerVlanTest()") self._prepareFdb() @@ -1765,10 +1846,18 @@ def flushStaticPerVlanTest(self): print("\tVerification complete") - def flushDynamicPerVlanTest(self): - ''' - Verify flushing of dynamic MAC entries by VLAN - ''' + def tearDown(self): + super(flushStaticPerVlanTest, self).tearDown() + + +class flushDynamicPerVlanTest(FdbFlushTestHelper): + ''' + Verify flushing of dynamic MAC entries by VLAN + ''' + def setUp(self): + super(flushDynamicPerVlanTest, self).setUp() + + def runTest(self): print("\nflushDynamicPerVlanTest()") self._prepareFdb() @@ -1803,10 +1892,18 @@ def flushDynamicPerVlanTest(self): print("\tVerification complete") - def flushAllPerVlanTest(self): - ''' - Verify flushing of all kinds of MAC entries by VLAN - ''' + def tearDown(self): + super(flushDynamicPerVlanTest, self).tearDown() + + +class flushAllPerVlanTest(FdbFlushTestHelper): + ''' + Verify flushing of all kinds of MAC entries by VLAN + ''' + def setUp(self): + super(flushAllPerVlanTest, self).setUp() + + def runTest(self): print("\nflushAllPerVlanTest()") self._prepareFdb() @@ -1843,10 +1940,18 @@ def flushAllPerVlanTest(self): print("\tVerification complete") - def flushStaticPerPortTest(self): - ''' - Verify flushing of static MAC entries by port - ''' + def tearDown(self): + super(flushAllPerVlanTest, self).tearDown() + + +class flushStaticPerPortTest(FdbFlushTestHelper): + ''' + Verify flushing of static MAC entries by port + ''' + def setUp(self): + super(flushStaticPerPortTest, self).setUp() + + def runTest(self): print("\nflushStaticPerPortTest()") self._prepareFdb() @@ -1896,10 +2001,18 @@ def flushStaticPerPortTest(self): print("\tVerification complete") - def flushDynamicPerPortTest(self): - ''' - Verify flushing of dynamic MAC entries by port - ''' + def tearDown(self): + super(flushStaticPerPortTest, self).tearDown() + + +class flushDynamicPerPortTest(FdbFlushTestHelper): + ''' + Verify flushing of dynamic MAC entries by port + ''' + def setUp(self): + super(flushDynamicPerPortTest, self).setUp() + + def runTest(self): print("\nflushDynamicPerPortTest()") self._prepareFdb() @@ -1949,10 +2062,18 @@ def flushDynamicPerPortTest(self): print("\tVerification complete") - def flushAllPerPortTest(self): - ''' - Verify flushing of all kinds of MAC entries by port - ''' + def tearDown(self): + super(flushDynamicPerPortTest, self).tearDown() + + +class flushAllPerPortTest(FdbFlushTestHelper): + ''' + Verify flushing of all kinds of MAC entries by port + ''' + def setUp(self): + super(flushAllPerPortTest, self).setUp() + + def runTest(self): print("\nflushAllPerPortTest()") self._prepareFdb() @@ -2009,10 +2130,18 @@ def flushAllPerPortTest(self): print("\tVerification complete") - def flushStaticPerLagTest(self): - ''' - Verify flushing of static MAC entries by LAG - ''' + def tearDown(self): + super(flushAllPerPortTest, self).tearDown() + + +class flushStaticPerLagTest(FdbFlushTestHelper): + ''' + Verify flushing of static MAC entries by LAG + ''' + def setUp(self): + super(flushStaticPerLagTest, self).setUp() + + def runTest(self): print("\nflushStaticPerLagTest()") self._prepareFdb() @@ -2063,10 +2192,18 @@ def flushStaticPerLagTest(self): print("\tVerification complete") - def flushDynamicPerLagTest(self): - ''' - Verify flushing of dynamic MAC entries by LAG - ''' + def tearDown(self): + super(flushStaticPerLagTest, self).tearDown() + + +class flushDynamicPerLagTest(FdbFlushTestHelper): + ''' + Verify flushing of dynamic MAC entries by LAG + ''' + def setUp(self): + super(flushDynamicPerLagTest, self).setUp() + + def runTest(self): print("\nflushDynamicPerLagTest()") self._prepareFdb() @@ -2117,10 +2254,18 @@ def flushDynamicPerLagTest(self): print("\tVerification complete") - def flushAllPerLagTest(self): - ''' - Verify flushing of all kinds of MAC entries by LAG - ''' + def tearDown(self): + super(flushDynamicPerLagTest, self).tearDown() + + +class flushAllPerLagTest(FdbFlushTestHelper): + ''' + Verify flushing of all kinds of MAC entries by LAG + ''' + def setUp(self): + super(flushAllPerLagTest, self).setUp() + + def runTest(self): print("\nflushAllPerLagTest()") self._prepareFdb() @@ -2171,10 +2316,18 @@ def flushAllPerLagTest(self): print("\tVerification complete") - def flushStaticPerVlanAndPortTest(self): - ''' - Verify flushing of static MAC entries by VLAN and port - ''' + def tearDown(self): + super(flushAllPerLagTest, self).tearDown() + + +class flushStaticPerVlanAndPortTest(FdbFlushTestHelper): + ''' + Verify flushing of static MAC entries by VLAN and port + ''' + def setUp(self): + super(flushStaticPerVlanAndPortTest, self).setUp() + + def runTest(self): print("\nflushStaticPerVlanAndPortTest()") self._prepareFdb() @@ -2239,10 +2392,18 @@ def flushStaticPerVlanAndPortTest(self): self._tearDownTrunkPort() - def flushDynamicPerVlanAndPortTest(self): - ''' - Verify flushing of dynamic MAC entries by VLAN and port - ''' + def tearDown(self): + super(flushStaticPerVlanAndPortTest, self).tearDown() + + +class flushDynamicPerVlanAndPortTest(FdbFlushTestHelper): + ''' + Verify flushing of dynamic MAC entries by VLAN and port + ''' + def setUp(self): + super(flushDynamicPerVlanAndPortTest, self).setUp() + + def runTest(self): print("\nflushDynamicPerVlanAndPortTest()") self._prepareFdb() @@ -2307,10 +2468,18 @@ def flushDynamicPerVlanAndPortTest(self): self._tearDownTrunkPort() - def flushAllPerVlanAndPortTest(self): - ''' - Verify flushing of all kinds of MAC entries by VLAN and port - ''' + def tearDown(self): + super(flushDynamicPerVlanAndPortTest, self).tearDown() + + +class flushAllPerVlanAndPortTest(FdbFlushTestHelper): + ''' + Verify flushing of all kinds of MAC entries by VLAN and port + ''' + def setUp(self): + super(flushAllPerVlanAndPortTest, self).setUp() + + def runTest(self): print("\nflushAllPerVlanAndPortTest()") self._prepareFdb() @@ -2378,12 +2547,25 @@ def flushAllPerVlanAndPortTest(self): self._tearDownTrunkPort() - def flushAllStaticTest(self): - ''' - Verify flushing of all static MAC entries - ''' + def tearDown(self): + super(flushAllPerVlanAndPortTest, self).tearDown() + + +class flushAllStaticTests(FdbFlushTestHelper): + ''' + Verify flushing of all static MAC entries + Args: + static_fdb_entry_type (int): FDB entry type to add + ''' + def setUp(self): + super(flushAllStaticTests, self).setUp() + + def runTest(self): print("\nflushAllStaticTest()") - self._prepareFdb() + self.flushAllStaticTest() + self.flushAllStaticTest(SAI_FDB_ENTRY_TYPE_STATIC + 1) + def flushAllStaticTest(self, static_fdb_entry_type=SAI_FDB_ENTRY_TYPE_STATIC): + self._prepareFdb(static_fdb_entry_type) print("Flush all static MACs") sai_thrift_flush_fdb_entries( @@ -2414,10 +2596,18 @@ def flushAllStaticTest(self): print("\tVerification complete") - def flushAllDynamicTest(self): - ''' - Verify flushing of all dynamic MAC entries - ''' + def tearDown(self): + super(flushAllStaticTests, self).tearDown() + + +class flushAllDynamicTest(FdbFlushTestHelper): + ''' + Verify flushing of all dynamic MAC entries + ''' + def setUp(self): + super(flushAllDynamicTest, self).setUp() + + def runTest(self): print("\nflushAllDynamicTest()") self._prepareFdb() @@ -2450,10 +2640,18 @@ def flushAllDynamicTest(self): print("\tVerification complete") - def flushAllMacsTest(self): - ''' - Verify flushing of all kinds of MAC entries - ''' + def tearDown(self): + super(flushAllDynamicTest, self).tearDown() + + +class flushAllMacsTest(FdbFlushTestHelper): + ''' + Verify flushing of all kinds of MAC entries + ''' + def setUp(self): + super(flushAllMacsTest, self).setUp() + + def runTest(self): print("\nflushAllMacsTest()") self._prepareFdb() @@ -2489,15 +2687,18 @@ def flushAllMacsTest(self): print("\tVerification complete") + def tearDown(self): + super(flushAllMacsTest, self).tearDown() + @group("draft") -class FdbAgeTest(SaiHelper): +class FdbAgeTestHelper(PlatformSaiHelper): ''' Verify FDB entries aging ''' def setUp(self): - super(FdbAgeTest, self).setUp() + super(FdbAgeTestHelper, self).setUp() # age time used in tests (in sec) self.age_time = 10 @@ -2541,12 +2742,6 @@ def setUp(self): type=SAI_FDB_ENTRY_TYPE_STATIC, bridge_port_id=vrf_port_bp) - def runTest(self): - self.macAgingOnPortTest() - self.macAgingOnLagTest() - self.macAgingAfterMoveTest() - self.macMoveAfterAgingTest() - def tearDown(self): # remove static MAC from FDB sai_thrift_remove_fdb_entry(self.client, self.fdb_entry) @@ -2564,13 +2759,18 @@ def tearDown(self): fdb_aging_time=True) self.assertEqual(sw_attr["fdb_aging_time"], 0) - super(FdbAgeTest, self).tearDown() + super(FdbAgeTestHelper, self).tearDown() - def macAgingOnPortTest(self): - ''' - FDB aging test verifying if dynamic FDB entry associated with port - is removed after the aging interval. - ''' + +class macAgingOnPortTest(FdbAgeTestHelper): + ''' + FDB aging test verifying if dynamic FDB entry associated with port + is removed after the aging interval. + ''' + def setUp(self): + super(macAgingOnPortTest, self).setUp() + + def runTest(self): print("\nmacAgingOnPortTest()") try: @@ -2625,11 +2825,19 @@ def macAgingOnPortTest(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC) - def macAgingOnLagTest(self): - ''' - FDB aging test verifying if dynamic FDB entry associated with LAG - is removed after the aging interval - ''' + def tearDown(self): + super(macAgingOnPortTest, self).tearDown() + + +class macAgingOnLagTest(FdbAgeTestHelper): + ''' + FDB aging test verifying if dynamic FDB entry associated with LAG + is removed after the aging interval + ''' + def setUp(self): + super(macAgingOnLagTest, self).setUp() + + def runTest(self): print("\nmacAgingOnLagTest()") try: @@ -2681,13 +2889,21 @@ def macAgingOnLagTest(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC) - def macAgingAfterMoveTest(self): - ''' - FDB aging test verifying if dynamic FDB entry associated with one port - and then moved to another port is removed after the aging interval - counted starting from the moment of moving the address (not the initial - learning time) - ''' + def tearDown(self): + super(macAgingOnLagTest, self).tearDown() + + +class macAgingAfterMoveTest(FdbAgeTestHelper): + ''' + FDB aging test verifying if dynamic FDB entry associated with one port + and then moved to another port is removed after the aging interval + counted starting from the moment of moving the address (not the initial + learning time) + ''' + def setUp(self): + super(macAgingAfterMoveTest, self).setUp() + + def runTest(self): print("\nmacAgingAfterMoveTest()") try: @@ -2790,13 +3006,21 @@ def macAgingAfterMoveTest(self): sai_thrift_set_switch_attribute(self.client, fdb_aging_time=self.age_time) - def macMoveAfterAgingTest(self): - ''' - FDB aging test verifying if dynamic FDB entry associated with one port - and then aged and moved to another port is removed after the aging - interval counted starting from the moment of moving the address (not - the initial time) - ''' + def tearDown(self): + super(macAgingAfterMoveTest, self).tearDown() + + +class macMoveAfterAgingTest(FdbAgeTestHelper): + ''' + FDB aging test verifying if dynamic FDB entry associated with one port + and then aged and moved to another port is removed after the aging + interval counted starting from the moment of moving the address (not + the initial time) + ''' + def setUp(self): + super(macMoveAfterAgingTest, self).setUp() + + def runTest(self): print("\nmacMoveAfterAgingTest()") try: @@ -2862,15 +3086,18 @@ def macMoveAfterAgingTest(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC) + def tearDown(self): + super(macMoveAfterAgingTest, self).tearDown() + @group("draft") -class FdbMissTest(SaiHelper): +class FdbMissTestHelper(PlatformSaiHelper): ''' Verify actions after missing FDB entry ''' def setUp(self): - super(FdbMissTest, self).setUp() + super(FdbMissTestHelper, self).setUp() self.vlan_id = 100 @@ -2957,17 +3184,6 @@ def setUp(self): pktlen=60, eth_type=0x88cc) - def runTest(self): - self.unicastMissDropActionTest() - self.unicastMissCopyActionTest() - self.unicastMissTrapActionTest() - self.multicastMissDropActionTest() - self.multicastMissCopyActionTest() - self.multicastMissTrapActionTest() - self.broadcastMissDropActionTest() - self.broadcastMissCopyActionTest() - self.broadcastMissTrapActionTest() - def tearDown(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) @@ -2992,13 +3208,18 @@ def tearDown(self): sai_thrift_remove_bridge_port(self.client, self.port25_bp) sai_thrift_remove_bridge_port(self.client, self.port26_bp) - super(FdbMissTest, self).tearDown() + super(FdbMissTestHelper, self).tearDown() - def unicastMissDropActionTest(self): - ''' - Verify if packets, which destination MAC is not stored in FDB, - are dropped after setting miss packet action to drop - ''' + +class unicastMissDropActionTest(FdbMissTestHelper): + ''' + Verify if packets, which destination MAC is not stored in FDB, + are dropped after setting miss packet action to drop + ''' + def setUp(self): + super(unicastMissDropActionTest, self).setUp() + + def runTest(self): print("\nunicastMissDropActionTest()") try: @@ -3038,11 +3259,19 @@ def unicastMissDropActionTest(self): self.assertEqual(sw_attr["fdb_unicast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def unicastMissCopyActionTest(self): - ''' - Verify if packets, which destination MAC is not stored in FDB, - are copied to CPU after setting miss packet action to copy - ''' + def tearDown(self): + super(unicastMissDropActionTest, self).tearDown() + + +class unicastMissCopyActionTest(FdbMissTestHelper): + ''' + Verify if packets, which destination MAC is not stored in FDB, + are copied to CPU after setting miss packet action to copy + ''' + def setUp(self): + super(unicastMissCopyActionTest, self).setUp() + + def runTest(self): print("\nunicastMissCopyActionTest()") try: @@ -3093,11 +3322,19 @@ def unicastMissCopyActionTest(self): self.assertEqual(sw_attr["fdb_unicast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def unicastMissTrapActionTest(self): - ''' - Verify if packets, which destination MAC is not in FDB, - are redirected to CPU after setting action to trap - ''' + def tearDown(self): + super(unicastMissCopyActionTest, self).tearDown() + + +class unicastMissTrapActionTest(FdbMissTestHelper): + ''' + Verify if packets, which destination MAC is not in FDB, + are redirected to CPU after setting action to trap + ''' + def setUp(self): + super(unicastMissTrapActionTest, self).setUp() + + def runTest(self): print("\nunicastMissTrapActionTest()") try: @@ -3147,12 +3384,20 @@ def unicastMissTrapActionTest(self): self.assertEqual(sw_attr["fdb_unicast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def multicastMissDropActionTest(self): - ''' - Verify if multicast packets are dropped after setting miss packet - action to drop. - Verify also if LLDP packets are still redirected to CPU - ''' + def tearDown(self): + super(unicastMissTrapActionTest, self).tearDown() + + +class multicastMissDropActionTest(FdbMissTestHelper): + ''' + Verify if multicast packets are dropped after setting miss packet + action to drop. + Verify also if LLDP packets are still redirected to CPU + ''' + def setUp(self): + super(multicastMissDropActionTest, self).setUp() + + def runTest(self): print("\nmulticastMissDropActionTest()") try: @@ -3210,11 +3455,19 @@ def multicastMissDropActionTest(self): self.assertEqual(sw_attr["fdb_multicast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def multicastMissCopyActionTest(self): - ''' - Verify if multicast packets are copied to CPU after setting miss packet action to copy. - Verify also if LLDP packets are still redirected to CPU - ''' + def tearDown(self): + super(multicastMissDropActionTest, self).tearDown() + + +class multicastMissCopyActionTest(FdbMissTestHelper): + ''' + Verify if multicast packets are copied to CPU after setting miss packet action to copy. + Verify also if LLDP packets are still redirected to CPU + ''' + def setUp(self): + super(multicastMissCopyActionTest, self).setUp() + + def runTest(self): print("\nmulticastMissCopyActionTest()") try: @@ -3283,12 +3536,20 @@ def multicastMissCopyActionTest(self): self.assertEqual(sw_attr["fdb_multicast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def multicastMissTrapActionTest(self): - ''' - Verify if multicast packets are redirected to CPU after setting miss - packet action to trap. - Verify also if LLDP packets are still redirected to CPU. - ''' + def tearDown(self): + super(multicastMissCopyActionTest, self).tearDown() + + +class multicastMissTrapActionTest(FdbMissTestHelper): + ''' + Verify if multicast packets are redirected to CPU after setting miss + packet action to trap. + Verify also if LLDP packets are still redirected to CPU. + ''' + def setUp(self): + super(multicastMissTrapActionTest, self).setUp() + + def runTest(self): print("\nmulticastMissTrapActionTest()") try: @@ -3356,12 +3617,20 @@ def multicastMissTrapActionTest(self): self.assertEqual(sw_attr["fdb_multicast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def broadcastMissDropActionTest(self): - ''' - Verify if broadcast packets are dropped after setting miss packet - action to drop. - Verify also if ARP packets are still redirected to CPU. - ''' + def tearDown(self): + super(multicastMissTrapActionTest, self).tearDown() + + +class broadcastMissDropActionTest(FdbMissTestHelper): + ''' + Verify if broadcast packets are dropped after setting miss packet + action to drop. + Verify also if ARP packets are still redirected to CPU. + ''' + def setUp(self): + super(broadcastMissDropActionTest, self).setUp() + + def runTest(self): print("\nbroadcastMissDropActionTest()") try: @@ -3389,20 +3658,6 @@ def broadcastMissDropActionTest(self): verify_no_other_packets(self) print("\tOK") - time.sleep(4) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - print("Checking if ARP packes are still forwarded to CPU") - print("Sending ARP packet on port %d - will be redirected to CPU" % - (self.send_port)) - send_packet(self, self.send_port, self.arp_pkt) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"] - - pre_stats["SAI_QUEUE_STAT_PACKETS"], - 1) print("\nVerificaion complete") finally: @@ -3418,11 +3673,19 @@ def broadcastMissDropActionTest(self): self.assertEqual(sw_attr["fdb_broadcast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def broadcastMissCopyActionTest(self): - ''' - Verify if broadcast packets are copied to CPU after setting miss packet action to copy. - Verify also if ARP packets are still redirected to CPU. - ''' + def tearDown(self): + super(broadcastMissDropActionTest, self).tearDown() + + +class broadcastMissCopyActionTest(FdbMissTestHelper): + ''' + Verify if broadcast packets are copied to CPU after setting miss packet action to copy. + Verify also if ARP packets are still redirected to CPU. + ''' + def setUp(self): + super(broadcastMissCopyActionTest, self).setUp() + + def runTest(self): print("\nbroadcastMissCopyActionTest()") try: @@ -3461,20 +3724,6 @@ def broadcastMissCopyActionTest(self): 1) print("\tOK") - time.sleep(4) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - print("Checking if ARP packes are still forwarded to CPU") - print("Sending ARP packet on port %d - will be redirected to CPU" % - (self.send_port)) - send_packet(self, self.send_port, self.arp_pkt) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"] - - pre_stats["SAI_QUEUE_STAT_PACKETS"], - 1) print("\nVerificaion complete") finally: @@ -3490,12 +3739,20 @@ def broadcastMissCopyActionTest(self): self.assertEqual(sw_attr["fdb_broadcast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) - def broadcastMissTrapActionTest(self): - ''' - Verify if broacast packets are redirected to CPU after setting miss - packet action to trap. - Verify also if ARP packets are still redirected to CPU. - ''' + def tearDown(self): + super(broadcastMissCopyActionTest, self).tearDown() + + +class broadcastMissTrapActionTest(FdbMissTestHelper): + ''' + Verify if broacast packets are redirected to CPU after setting miss + packet action to trap. + Verify also if ARP packets are still redirected to CPU. + ''' + def setUp(self): + super(broadcastMissTrapActionTest, self).setUp() + + def runTest(self): print("\nbroadcastMissTrapActionTest()") try: @@ -3533,20 +3790,6 @@ def broadcastMissTrapActionTest(self): 1) print("\tOK") - time.sleep(4) - pre_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - print("Checking if ARP packes are still forwarded to CPU") - print("Sending ARP packet on port %d - will be redirected to CPU" % - (self.send_port)) - send_packet(self, self.send_port, self.arp_pkt) - time.sleep(4) - post_stats = sai_thrift_get_queue_stats( - self.client, self.cpu_queue4) - self.assertEqual( - post_stats["SAI_QUEUE_STAT_PACKETS"] - - pre_stats["SAI_QUEUE_STAT_PACKETS"], - 1) print("\nVerificaion complete") finally: @@ -3562,16 +3805,19 @@ def broadcastMissTrapActionTest(self): self.assertEqual(sw_attr["fdb_broadcast_miss_packet_action"], SAI_PACKET_ACTION_FORWARD) + def tearDown(self): + super(broadcastMissTrapActionTest, self).tearDown() + @group("draft") -class FdbEventTest(SaiHelper): +class FdbEventTestHelper(PlatformSaiHelper): ''' Verify correctness of FDB atributes values after events like: learning, aging, moving, flushing, deleting ''' def setUp(self): - super(FdbEventTest, self).setUp() + super(FdbEventTestHelper, self).setUp() self.src_mac = "00:11:11:11:11:11" self.dst_mac = "00:22:22:22:22:22" @@ -3596,23 +3842,21 @@ def setUp(self): mac_address=self.src_mac, bv_id=self.vlan10) - def runTest(self): - self.macLearnEventTest() - self.macAgeEvenTest() - self.macMoveEventTest() - self.macFlushEventTest() - self.macDeleteEventTest() def tearDown(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) - super(FdbEventTest, self).tearDown() + super(FdbEventTestHelper, self).tearDown() - def macLearnEventTest(self): - ''' - Verify MAC learning event for FDB entry - ''' +class macLearnEventTest(FdbEventTestHelper): + ''' + Verify MAC learning event for FDB entry + ''' + def setUp(self): + super(macLearnEventTest, self).setUp() + + def runTest(self): print("\nmacLearnEventTest()") try: @@ -3645,10 +3889,18 @@ def macLearnEventTest(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) - def macAgeEvenTest(self): - ''' - Verify MAC aging event for FDB entry - ''' + def tearDown(self): + super(macLearnEventTest, self).tearDown() + + +class macAgeEvenTest(FdbEventTestHelper): + ''' + Verify MAC aging event for FDB entry + ''' + def setUp(self): + super(macAgeEvenTest, self).setUp() + + def runTest(self): print("\nmacAgeEvenTest()") age_time = 10 @@ -3701,10 +3953,18 @@ def macAgeEvenTest(self): sai_thrift_set_switch_attribute(self.client, fdb_aging_time=0) - def macMoveEventTest(self): - ''' - Verify MAC moving event for FDB entry - ''' + def tearDown(self): + super(macAgeEvenTest, self).tearDown() + + +class macMoveEventTest(FdbEventTestHelper): + ''' + Verify MAC moving event for FDB entry + ''' + def setUp(self): + super(macMoveEventTest, self).setUp() + + def runTest(self): print("\nmacMoveEventTest()") mv_port = self.dev_port4 @@ -3760,10 +4020,18 @@ def macMoveEventTest(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) - def macFlushEventTest(self): - ''' - Verify MAC flushing event for FDB entry - ''' + def tearDown(self): + super(macMoveEventTest, self).tearDown() + + +class macFlushEventTest(FdbEventTestHelper): + ''' + Verify MAC flushing event for FDB entry + ''' + def setUp(self): + super(macFlushEventTest, self).setUp() + + def runTest(self): print("\nmacFlushEventTest()") try: @@ -3809,10 +4077,18 @@ def macFlushEventTest(self): sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) - def macDeleteEventTest(self): - ''' - Verify MAC deletion event for FDB entry - ''' + def tearDown(self): + super(macFlushEventTest, self).tearDown() + + +class macDeleteEventTest(FdbEventTestHelper): + ''' + Verify MAC deletion event for FDB entry + ''' + def setUp(self): + super(macDeleteEventTest, self).setUp() + + def runTest(self): print("\nmacDeleteEventTest()") try: @@ -3855,3 +4131,6 @@ def macDeleteEventTest(self): finally: sai_thrift_flush_fdb_entries( self.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) + + def tearDown(self): + super(macDeleteEventTest, self).tearDown()