Skip to content

Commit

Permalink
Add best candidate search for acl table (sonic-net#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Nov 7, 2018
1 parent d1e26c3 commit 248a095
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 6 deletions.
207 changes: 201 additions & 6 deletions syncd/syncd_applyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2641,8 +2641,8 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForAclTableGroup(
if (c.obj->getVid() == atgVid)
{
SWSS_LOG_INFO("found ALC table group candidate %s using port %s",
port->str_object_id.c_str(),
c.obj->str_object_id.c_str());
c.obj->str_object_id.c_str(),
port->str_object_id.c_str());

return c.obj;
}
Expand Down Expand Up @@ -2736,6 +2736,101 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForAclTableGroup(
return nullptr;
}

std::shared_ptr<SaiObj> findCurrentBestMatchForAclTable(
_In_ const AsicView &currentView,
_In_ const AsicView &temporaryView,
_In_ const std::shared_ptr<const SaiObj> &temporaryObj,
_In_ const std::vector<sai_object_compare_info_t> &candidateObjects)
{
SWSS_LOG_ENTER();

/*
* For acl table we can go to acl table group member and then to acl table group and port.
*/

const auto tmpAclTableGroupMembers = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER);

for (auto tmpAclTableGroupMember: tmpAclTableGroupMembers)
{
auto tmpAclTableId = tmpAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID);

if (tmpAclTableId->getOid() != temporaryObj->getVid())
{
// this is not the expected alc table group member
continue;
}

auto tmpAclTableGroupId = tmpAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID);

/*
* We have acl table group id, search on which port it's set, not let's
* find on which port it's set.
*/

const auto tmpPorts = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_PORT);

for (auto tmpPort: tmpPorts)
{
if (!tmpPort->hasAttr(SAI_PORT_ATTR_INGRESS_ACL))
continue;

auto tmpInACL = tmpPort->getSaiAttr(SAI_PORT_ATTR_INGRESS_ACL);

if (tmpInACL->getOid() != tmpAclTableGroupId->getOid())
continue;

auto curPort = currentView.oOids.at(tmpPort->getVid());

if (!curPort->hasAttr(SAI_PORT_ATTR_INGRESS_ACL))
continue;

auto curInACL = curPort->getSaiAttr(SAI_PORT_ATTR_INGRESS_ACL);

/*
* We found current InACL, now let's find acl table group members
* that use this acl table group.
*/

const auto curAclTableGroupMembers = currentView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER);

for (auto curAclTableGroupMember: curAclTableGroupMembers)
{
auto curAclTableGroupId = curAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID);

if (curAclTableGroupId->getOid() != curInACL->getOid())
{
// this member uses different acl table group
continue;
}

auto curAclTableId = curAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID);

/*
* We found possible current acl table ID, let's see if it's on
* candidate list. Note, it could be possible that many
* different paths will lead multiple possible candidates.
*/

for (auto c: candidateObjects)
{
if (c.obj->getVid() == curAclTableId->getOid())
{
SWSS_LOG_INFO("found ALC table candidate %s using port %s",
c.obj->str_object_id.c_str(),
tmpPort->str_object_id.c_str());

return c.obj;
}
}
}
}
}

SWSS_LOG_NOTICE("failed to find best candidate for ACL table using port");

return nullptr;
}

std::shared_ptr<SaiObj> findCurrentBestMatchForRouterInterface(
_In_ const AsicView &currentView,
_In_ const AsicView &temporaryView,
Expand Down Expand Up @@ -3154,6 +3249,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
candidate = findCurrentBestMatchForHostifTrapGroup(currentView, temporaryView, temporaryObj, candidateObjects);
break;

case SAI_OBJECT_TYPE_ACL_TABLE:
candidate = findCurrentBestMatchForAclTable(currentView, temporaryView, temporaryObj, candidateObjects);
break;

default:
break;
}
Expand Down Expand Up @@ -3203,6 +3302,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
return selectRandomCandidate(candidateObjects);
}

std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(
_In_ const AsicView &currentView,
_In_ const sai_attr_metadata_t &meta);

std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
_In_ const AsicView &currentView,
_In_ const AsicView &temporaryView,
Expand Down Expand Up @@ -3314,6 +3417,13 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(

bool has_different_create_only_attr = false;

/*
* NOTE: we only iterate by attributes that are present in temporary
* view. It may happen that current view has some additional attributes
* set that are create only and value can't be updated then, so in that
* case such object must be disqualified from being candidate.
*/

for (const auto &attr: attrs)
{
sai_attr_id_t attrId = attr.first;
Expand Down Expand Up @@ -3378,6 +3488,85 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(

break;
}

if (SAI_HAS_FLAG_CREATE_ONLY(meta->flags) && !currentObj->hasAttr(attrId))
{
/*
* This attribute exists only on temporary view and it's
* create only. If it has default value, check if it's the
* same as current.
*/

auto curDefault = getSaiAttrFromDefaultValue(currentView, *meta);

if (curDefault != nullptr)
{
if (curDefault->getStrAttrValue() != attr.second->getStrAttrValue())
{
has_different_create_only_attr = true;

SWSS_LOG_INFO("obj has not equal create only attributes %s (default): %s",
temporaryObj->str_object_id.c_str(),
meta->attridname);
break;
}
else
{
SWSS_LOG_INFO("obj has equal create only value %s (default): %s",
temporaryObj->str_object_id.c_str(),
meta->attridname);
}
}
}
}
}

/*
* Before we add this object as candidate, see if there are some create
* only attributes which are not present in temporary object but
* present in current, and if there is default value that is the same.
*/

const auto curAttrs = currentObj->getAllAttributes();

for (auto curAttr: curAttrs)
{
if (attrs.find(curAttr.first) != attrs.end())
{
// attr exists in both objects.
continue;
}

const sai_attr_metadata_t* meta = curAttr.second->getAttrMetadata();

if (SAI_HAS_FLAG_CREATE_ONLY(meta->flags) && !temporaryObj->hasAttr(curAttr.first))
{
/*
* This attribute exists only on current view and it's
* create only. If it has default value, check if it's the
* same as current.
*/

auto tmpDefault = getSaiAttrFromDefaultValue(temporaryView, *meta);

if (tmpDefault != nullptr)
{
if (tmpDefault->getStrAttrValue() != curAttr.second->getStrAttrValue())
{
has_different_create_only_attr = true;

SWSS_LOG_INFO("obj has not equal create only attributes %s (default): %s",
currentObj->str_object_id.c_str(),
meta->attridname);
break;
}
else
{
SWSS_LOG_INFO("obj has equal create only value %s (default): %s",
temporaryObj->str_object_id.c_str(),
meta->attridname);
}
}
}
}

Expand Down Expand Up @@ -4019,10 +4208,6 @@ void procesObjectAttributesForViewTransition(
}
}

std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(
_In_ const AsicView &currentView,
_In_ const sai_attr_metadata_t &meta);

void bringNonRemovableObjectToDefaultState(
_In_ AsicView &currentView,
_In_ const std::shared_ptr<SaiObj> &currentObj)
Expand Down Expand Up @@ -4885,6 +5070,14 @@ std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(

return nullptr;

case SAI_DEFAULT_VALUE_TYPE_NONE:

/*
* No default value present.
*/

return nullptr;

default:

SWSS_LOG_ERROR("default value type %d is not supported yet for %s, FIXME",
Expand Down Expand Up @@ -5479,6 +5672,8 @@ void processObjectForViewTransition(
return;
}

SWSS_LOG_DEBUG("processing: %s:%s", temporaryObj->str_object_type.c_str(), temporaryObj->str_object_id.c_str());

procesObjectAttributesForViewTransition(currentView, temporaryView, temporaryObj);

/*
Expand Down
15 changes: 15 additions & 0 deletions tests/brcm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,23 @@ sub test_brcm_qos_map_order
play "qos_map_order.rec", 0;
}

sub test_brcm_acl_tables
{
fresh_start;

# we expect no asic operation on lag's that has no members

play "acl_tables.rec";
play "acl_tables.rec", 0;
play "acl_tables.rec", 0;
play "acl_tables.rec", 0;
play "acl_tables.rec", 0;
play "acl_tables.rec", 0;
}

# RUN TESTS

test_brcm_acl_tables;
test_brcm_qos_map_order;
test_brcm_lag_no_members;
test_brcm_rif_loopback;
Expand Down
19 changes: 19 additions & 0 deletions tests/brcm/acl_tables.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
2018-11-05.23:53:46.072382|#|recording on: /var/log/swss/sairedis.rec
2018-11-05.23:53:46.072861|#|logrotate on: /var/log/swss/sairedis.rec
2018-11-05.23:53:46.072964|a|INIT_VIEW
2018-11-05.23:54:14.728951|A|SAI_STATUS_SUCCESS
2018-11-05.23:54:14.730851|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x429e60|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x429e70|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x429e80|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=00:E0:EC:7B:B9:32
2018-11-05.23:54:14.743415|g|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_PORT_LIST=32:oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0,oid:0x0
2018-11-05.23:54:14.749126|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_PORT_LIST=32:oid:0x1000000000002,oid:0x1000000000003,oid:0x1000000000004,oid:0x1000000000005,oid:0x1000000000006,oid:0x1000000000007,oid:0x1000000000008,oid:0x1000000000009,oid:0x100000000000a,oid:0x100000000000b,oid:0x100000000000c,oid:0x100000000000d,oid:0x100000000000e,oid:0x100000000000f,oid:0x1000000000010,oid:0x1000000000011,oid:0x1000000000012,oid:0x1000000000013,oid:0x1000000000014,oid:0x1000000000015,oid:0x1000000000016,oid:0x1000000000017,oid:0x1000000000018,oid:0x1000000000019,oid:0x100000000001a,oid:0x100000000001b,oid:0x100000000001c,oid:0x100000000001d,oid:0x100000000001e,oid:0x100000000001f,oid:0x1000000000020,oid:0x1000000000021
2018-11-05.23:54:17.365439|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000ab2|SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST=2:SAI_ACL_BIND_POINT_TYPE_PORT,SAI_ACL_BIND_POINT_TYPE_LAG|SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL=true|SAI_ACL_TABLE_ATTR_FIELD_SRC_IP=true|SAI_ACL_TABLE_ATTR_FIELD_DST_IP=true|SAI_ACL_TABLE_ATTR_FIELD_L4_SRC_PORT=true|SAI_ACL_TABLE_ATTR_FIELD_L4_DST_PORT=true|SAI_ACL_TABLE_ATTR_FIELD_TCP_FLAGS=true|SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE=2:SAI_ACL_RANGE_TYPE_L4_DST_PORT_RANGE,SAI_ACL_RANGE_TYPE_L4_SRC_PORT_RANGE|SAI_ACL_TABLE_ATTR_ACL_STAGE=SAI_ACL_STAGE_INGRESS
2018-11-05.23:54:17.389869|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000ad3|SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST=2:SAI_ACL_BIND_POINT_TYPE_PORT,SAI_ACL_BIND_POINT_TYPE_LAG|SAI_ACL_TABLE_ATTR_FIELD_ETHER_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_IP_PROTOCOL=true|SAI_ACL_TABLE_ATTR_FIELD_SRC_IP=true|SAI_ACL_TABLE_ATTR_FIELD_DST_IP=true|SAI_ACL_TABLE_ATTR_FIELD_L4_SRC_PORT=true|SAI_ACL_TABLE_ATTR_FIELD_L4_DST_PORT=true|SAI_ACL_TABLE_ATTR_FIELD_TCP_FLAGS=true|SAI_ACL_TABLE_ATTR_FIELD_ACL_RANGE_TYPE=2:SAI_ACL_RANGE_TYPE_L4_DST_PORT_RANGE,SAI_ACL_RANGE_TYPE_L4_SRC_PORT_RANGE|SAI_ACL_TABLE_ATTR_ACL_STAGE=SAI_ACL_STAGE_INGRESS|SAI_ACL_TABLE_ATTR_FIELD_DSCP=true
2018-11-05.23:54:17.366170|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP:oid:0xb000000000ab3|SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE=SAI_ACL_STAGE_INGRESS|SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST=1:SAI_ACL_BIND_POINT_TYPE_PORT|SAI_ACL_TABLE_GROUP_ATTR_TYPE=SAI_ACL_TABLE_GROUP_TYPE_PARALLEL
2018-11-05.23:54:17.367466|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP:oid:0xb000000000ab5|SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE=SAI_ACL_STAGE_INGRESS|SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST=1:SAI_ACL_BIND_POINT_TYPE_PORT|SAI_ACL_TABLE_GROUP_ATTR_TYPE=SAI_ACL_TABLE_GROUP_TYPE_PARALLEL
2018-11-05.23:54:17.366718|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc000000000ab4|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID=oid:0xb000000000ab3|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID=oid:0x7000000000ab2|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY=100
2018-11-05.23:54:17.367926|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc000000000ab6|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID=oid:0xb000000000ab5|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID=oid:0x7000000000ab2|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY=100
2018-11-05.23:54:17.390931|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc000000000ad4|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID=oid:0xb000000000ab3|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID=oid:0x7000000000ad3|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY=100
2018-11-05.23:54:17.391548|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc000000000ad5|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID=oid:0xb000000000ab5|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID=oid:0x7000000000ad3|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY=100
2018-11-05.23:54:17.366422|s|SAI_OBJECT_TYPE_PORT:oid:0x1000000000002|SAI_PORT_ATTR_INGRESS_ACL=oid:0xb000000000ab3
2018-11-05.23:54:17.367676|s|SAI_OBJECT_TYPE_PORT:oid:0x1000000000003|SAI_PORT_ATTR_INGRESS_ACL=oid:0xb000000000ab5
2018-11-05.23:54:23.726116|a|APPLY_VIEW
2018-11-06.00:01:09.702164|A|SAI_STATUS_SUCCESS

0 comments on commit 248a095

Please sign in to comment.