Skip to content

Commit

Permalink
[vs] Add CRM SAI attributes to virtual switch interface (#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Allen <[email protected]>
  • Loading branch information
daall authored Oct 20, 2020
1 parent 609445a commit 02a57a6
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 15 deletions.
29 changes: 29 additions & 0 deletions vslib/inc/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<FdbInfo> m_fdb_info_set;
Expand Down
97 changes: 82 additions & 15 deletions vslib/src/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<sai_switch_attr_t, int> 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<sai_acl_resource_t> 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<uint32_t>(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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 02a57a6

Please sign in to comment.