From 02a57a6a539f52b6eb22cbe5295eebfc91d9d5cc Mon Sep 17 00:00:00 2001 From: Danny Allen Date: Tue, 20 Oct 2020 13:18:45 -0700 Subject: [PATCH] [vs] Add CRM SAI attributes to virtual switch interface (#673) Signed-off-by: Danny Allen --- vslib/inc/SwitchStateBase.h | 29 +++++++++++ vslib/src/SwitchStateBase.cpp | 97 +++++++++++++++++++++++++++++------ 2 files changed, 111 insertions(+), 15 deletions(-) diff --git a/vslib/inc/SwitchStateBase.h b/vslib/inc/SwitchStateBase.h index 1d037c48e107..1c7a6054f358 100644 --- a/vslib/inc/SwitchStateBase.h +++ b/vslib/inc/SwitchStateBase.h @@ -82,6 +82,12 @@ namespace saivs virtual sai_status_t set_number_of_ecmp_groups(); + virtual sai_status_t set_static_crm_values(); + + virtual sai_status_t set_static_acl_resource_list( + _In_ sai_switch_attr_t acl_resource, + _In_ int max_count); + public: virtual sai_status_t initialize_default_objects(); @@ -409,6 +415,29 @@ namespace saivs sai_object_id_t m_default_bridge_port_1q_router; sai_object_id_t m_default_vlan_id; + protected: + + constexpr static const int m_maxIPv4RouteEntries = 100000; + constexpr static const int m_maxIPv6RouteEntries = 10000; + + constexpr static const int m_maxIPv4NextHopEntries = 32000; + constexpr static const int m_maxIPv6NextHopEntries = 32000; + + constexpr static const int m_maxIPv4NeighborEntries = 4000; + constexpr static const int m_maxIPv6NeighborEntries = 2000; + + constexpr static const int m_maxNextHopGroupMemberEntries = 16000; + constexpr static const int m_maxNextHopGroupEntries = 400; + + constexpr static const int m_maxFdbEntries = 800; + + constexpr static const int m_maxSNATEntries = 100; + constexpr static const int m_maxDNATEntries = 100; + constexpr static const int m_maxDoubleNATEntries = 50; /* Half of single NAT entry */ + + constexpr static const int m_maxAclTables = 3; + constexpr static const int m_maxAclTableGroups = 200; + public: // TODO private std::set m_fdb_info_set; diff --git a/vslib/src/SwitchStateBase.cpp b/vslib/src/SwitchStateBase.cpp index 0713ae58cada..9bd0a68b3833 100644 --- a/vslib/src/SwitchStateBase.cpp +++ b/vslib/src/SwitchStateBase.cpp @@ -701,21 +701,6 @@ sai_status_t SwitchStateBase::set_switch_default_attributes() sai_attribute_t attr; - attr.id = SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY; - attr.value.u32 = 100; - - CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); - - attr.id = SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY; - attr.value.u32 = 100; - - CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); - - attr.id = SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAT_ENTRY; - attr.value.u32 = 50; /* Half of single NAT entry */ - - CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); - attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY; attr.value.ptr = NULL; @@ -746,6 +731,76 @@ sai_status_t SwitchStateBase::set_switch_default_attributes() return set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr); } +sai_status_t SwitchStateBase::set_static_crm_values() +{ + SWSS_LOG_ENTER(); + + std::map crm_resource_lookup = { + { SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY, m_maxIPv4RouteEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY, m_maxIPv6RouteEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY, m_maxIPv4NextHopEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY, m_maxIPv6NextHopEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY, m_maxIPv4NeighborEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY, m_maxIPv6NeighborEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY, m_maxNextHopGroupMemberEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY, m_maxNextHopGroupEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY, m_maxFdbEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY, m_maxSNATEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY, m_maxDNATEntries }, + { SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAT_ENTRY, m_maxDoubleNATEntries } + }; + + for (auto const &resource: crm_resource_lookup) + { + sai_attribute_t attr; + attr.id = resource.first; + attr.value.u32 = resource.second; + CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr)); + } + + CHECK_STATUS(set_static_acl_resource_list(SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE, m_maxAclTables)); + + return set_static_acl_resource_list(SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP, m_maxAclTableGroups); +} + +sai_status_t SwitchStateBase::set_static_acl_resource_list( + _In_ sai_switch_attr_t acl_resource, + _In_ int max_count) +{ + auto acl_stages = {SAI_ACL_STAGE_INGRESS, SAI_ACL_STAGE_EGRESS}; + auto acl_bind_points = { + SAI_ACL_BIND_POINT_TYPE_PORT, + SAI_ACL_BIND_POINT_TYPE_LAG, + SAI_ACL_BIND_POINT_TYPE_VLAN, + SAI_ACL_BIND_POINT_TYPE_ROUTER_INTERFACE, + SAI_ACL_BIND_POINT_TYPE_SWITCH + }; + + std::vector acl_resource_list; + for (auto stage: acl_stages) + { + for (auto bp: acl_bind_points) + { + sai_acl_resource_t acl_resource_count; + acl_resource_count.stage = stage; + acl_resource_count.bind_point = bp; + acl_resource_count.avail_num = max_count; + + acl_resource_list.push_back(acl_resource_count); + } + } + + sai_acl_resource_list_t available_acl_resources; + available_acl_resources.count = static_cast(acl_resource_list.size()); + available_acl_resources.list = acl_resource_list.data(); + + sai_attribute_t attr; + attr.id = acl_resource; + attr.value.aclresource = available_acl_resources; + + return set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr); +} + sai_status_t SwitchStateBase::create_default_vlan() { SWSS_LOG_ENTER(); @@ -1261,6 +1316,7 @@ sai_status_t SwitchStateBase::initialize_default_objects() CHECK_STATUS(set_number_of_ecmp_groups()); CHECK_STATUS(set_switch_default_attributes()); CHECK_STATUS(create_scheduler_groups()); + CHECK_STATUS(set_static_crm_values()); return SAI_STATUS_SUCCESS; } @@ -1576,6 +1632,17 @@ sai_status_t SwitchStateBase::refresh_read_only( case SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_CHILDS_PER_SCHEDULER_GROUP: return SAI_STATUS_SUCCESS; + case SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY: + case SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE: + case SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP: case SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY: case SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY: case SAI_SWITCH_ATTR_AVAILABLE_DOUBLE_NAT_ENTRY: