Skip to content

Commit

Permalink
Add acl counter match logic based on acl entry field (sonic-net#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and lguohan committed Sep 9, 2019
1 parent 58845ce commit e7d766e
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 8 deletions.
107 changes: 100 additions & 7 deletions syncd/syncd_applyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,18 @@ class SaiAttr
{
SWSS_LOG_ENTER();

if (m_meta->attrvaluetype != SAI_ATTR_VALUE_TYPE_OBJECT_ID)
if (m_meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_ID)
{
SWSS_LOG_THROW("attribute %s is not OID attribute", m_meta->attridname);
return m_attr.value.oid;
}

return m_attr.value.oid;
if (m_meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID &&
m_attr.value.aclaction.enable)
{
return m_attr.value.aclaction.parameter.oid;
}

SWSS_LOG_THROW("attribute %s is not OID attribute", m_meta->attridname);
}

/**
Expand Down Expand Up @@ -2726,6 +2732,8 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForAclCounter(
* counter since if set, then table id will be matched previously.
*/

std::vector<std::shared_ptr<SaiObj>> objs;

const auto tmpAclTables = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE);

for (auto& tmpAclTable: tmpAclTables)
Expand Down Expand Up @@ -2758,10 +2766,85 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForAclCounter(
if (curAclCounterTableIdAttr->getOid() != curAclTableVid)
continue;

SWSS_LOG_INFO("found best ACL counter match based on ACL table: %s", c.obj->str_object_id.c_str());
objs.push_back(c.obj);
continue;
}
}

return c.obj;
if (objs.size() > 1)
{
// in this case more than 1 acl counters has the same acl table associated,
// try to find best acl counter matching same acl entry field

SWSS_LOG_INFO("more than 1 (%zu) best match on acl counter using acl table", objs.size());

const auto tmpAclEntries = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_ENTRY);

for (auto& tmpAclEntry: tmpAclEntries)
{
auto tmpAclEntryActionCounterAttr = tmpAclEntry->tryGetSaiAttr(SAI_ACL_ENTRY_ATTR_ACTION_COUNTER);

if (tmpAclEntryActionCounterAttr == nullptr)
continue; // skip acl entries with no counter

if (tmpAclEntryActionCounterAttr->getOid() != temporaryObj->getVid())
continue; // not the counter we are looking for

for (auto&attr: tmpAclEntry->getAllAttributes())
{
auto*meta = attr.second->getAttrMetadata();

if (!meta->isaclfield)
continue; // looking only for acl fields

if (meta->isoidattribute)
continue; // only non oid fields

auto tmpValue = attr.second->getStrAttrValue();

const auto curAclEntries = currentView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_ENTRY);

for (auto& curAclEntry: curAclEntries)
{
auto curAclEntryAclFieldAttr = curAclEntry->tryGetSaiAttr(meta->attrid);

if (curAclEntryAclFieldAttr == nullptr)
continue; // this field is missing from current view

if (curAclEntryAclFieldAttr->getStrAttrValue() != tmpValue)
continue; // values are different, keep looking

auto curAclEntryActionCounterAttr = curAclEntry->tryGetSaiAttr(SAI_ACL_ENTRY_ATTR_ACTION_COUNTER);

if (curAclEntryActionCounterAttr == nullptr)
continue; // no counter

auto curAclCounter = currentView.oOids.at(curAclEntryActionCounterAttr->getOid());

if (curAclCounter->getObjectStatus() != SAI_OBJECT_STATUS_NOT_PROCESSED)
continue;

for (auto c: candidateObjects)
{
if (c.obj->getVid() == curAclCounter->getVid())
{
SWSS_LOG_NOTICE("found best ACL counter match based on ACL entry field: %s, %s",
c.obj->str_object_id.c_str(),
meta->attridname);
return c.obj;
}
}
}
}
}

}

if (objs.size())
{
SWSS_LOG_NOTICE("found best ACL counter match based on ACL table: %s", objs.at(0)->str_object_id.c_str());

return objs.at(0);
}

SWSS_LOG_NOTICE("failed to find best candidate for ACL_COUNTER using ACL table");
Expand Down Expand Up @@ -4101,15 +4184,15 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
{
soci.equal_attributes++;

SWSS_LOG_DEBUG("ob equal %s %s, %s: %s",
SWSS_LOG_INFO("ob equal %s %s, %s: %s",
temporaryObj->str_object_id.c_str(),
currentObj->str_object_id.c_str(),
attr.second->getStrAttrId().c_str(),
attr.second->getStrAttrValue().c_str());
}
else
{
SWSS_LOG_DEBUG("ob not equal %s %s, %s: %s",
SWSS_LOG_INFO("ob not equal %s %s, %s: %s",
temporaryObj->str_object_id.c_str(),
currentObj->str_object_id.c_str(),
attr.second->getStrAttrId().c_str(),
Expand Down Expand Up @@ -4311,6 +4394,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
* lets choose that object as our best match.
*/

SWSS_LOG_INFO("eq attributes: %ld vs %ld",
candidateObjects.at(0).equal_attributes,
candidateObjects.at(1).equal_attributes);

return candidateObjects.begin()->obj;
}

Expand Down Expand Up @@ -5845,6 +5932,12 @@ bool performObjectSetTransition(

auto currentAttr = currentBestMatch->getSaiAttr(attr.id);

SWSS_LOG_INFO("compare attr value curr %s vs temp %s",
currentBestMatch->getSaiAttr(attr.id)->getStrAttrValue().c_str(),
temporaryObj->getSaiAttr(attr.id)->getStrAttrValue().c_str());



if (hasEqualAttribute(currentView, temporaryView, currentBestMatch, temporaryObj, attr.id))
{
/*
Expand Down
14 changes: 13 additions & 1 deletion tests/brcm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,20 @@ sub test_acl_counter
play "acl_counter.rec", 0;
}

# RUN TESTS
sub test_acl_counter2
{
fresh_start;

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

# RUN TESTS
test_acl_counter2;
test_acl_counter;
test_tunnel_map;
test_bridge_create;
Expand Down
26 changes: 26 additions & 0 deletions tests/brcm/acl_counter2.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
2019-09-06.20:17:08.004784|a|INIT_VIEW
2019-09-06.20:17:10.301724|A|SAI_STATUS_SUCCESS
2019-09-06.20:17:10.301994|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true
2019-06-06.22:52:22.467126|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
2019-06-06.22:52:22.468669|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_PORT_LIST=32:oid:0x1000000000405,oid:0x1000000000406,oid:0x1000000000407,oid:0x1000000000408,oid:0x1000000000409,oid:0x1000000000419,oid:0x100000000041a,oid:0x100000000041b,oid:0x100000000041c,oid:0x100000000041d,oid:0x100000000040a,oid:0x100000000041e,oid:0x100000000040b,oid:0x100000000040c,oid:0x100000000040d,oid:0x100000000040e,oid:0x100000000040f,oid:0x1000000000410,oid:0x1000000000411,oid:0x1000000000412,oid:0x1000000000413,oid:0x100000000041f,oid:0x1000000000420,oid:0x1000000000421,oid:0x1000000000422,oid:0x1000000000423,oid:0x1000000000414,oid:0x1000000000424,oid:0x1000000000415,oid:0x1000000000416,oid:0x1000000000417,oid:0x1000000000418
2019-09-06.20:17:21.277023|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000ba8|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_ICMP_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE=true|SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6=true|SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6=true|SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_CODE=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
2019-09-06.20:24:19.214888|c|SAI_OBJECT_TYPE_MIRROR_SESSION:oid:0xe000000000df1|SAI_MIRROR_SESSION_ATTR_MONITOR_PORT=oid:0x1000000000405|SAI_MIRROR_SESSION_ATTR_TYPE=SAI_MIRROR_SESSION_TYPE_ENHANCED_REMOTE|SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE=SAI_ERSPAN_ENCAPSULATION_TYPE_MIRROR_L3_GRE_TUNNEL|SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION=4|SAI_MIRROR_SESSION_ATTR_TOS=32|SAI_MIRROR_SESSION_ATTR_TTL=255|SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS=25.92.94.21|SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS=100.126.126.196|SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS=74:83:EF:A6:52:14|SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS=74:83:EF:2C:39:3E|SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE=35006
2019-09-06.20:24:19.216031|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x9000000000df2|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x7000000000ba8|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-09-06.20:24:19.216269|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000df3|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x7000000000ba8|SAI_ACL_ENTRY_ATTR_PRIORITY=8887|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x9000000000df2|SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE=135&mask:0xff|SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS=1:oid:0xe000000000df1
2019-09-06.20:24:19.216617|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x9000000000df4|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x7000000000ba8|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-09-06.20:24:19.216845|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000df5|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x7000000000ba8|SAI_ACL_ENTRY_ATTR_PRIORITY=8888|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x9000000000df4|SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE=2054&mask:0xffff|SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS=1:oid:0xe000000000df1
2019-09-06.20:17:19.915627|a|APPLY_VIEW
2019-09-06.20:17:19.916165|A|SAI_STATUS_SUCCESS
2019-09-06.20:25:06.872229|a|INIT_VIEW
2019-09-06.20:25:19.375314|A|SAI_STATUS_SUCCESS
2019-09-06.20:25:19.389431|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true
2019-06-06.22:52:22.467126|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
2019-06-06.22:52:22.468669|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_PORT_LIST=32:oid:0x1000000000405,oid:0x1000000000406,oid:0x1000000000407,oid:0x1000000000408,oid:0x1000000000409,oid:0x1000000000419,oid:0x100000000041a,oid:0x100000000041b,oid:0x100000000041c,oid:0x100000000041d,oid:0x100000000040a,oid:0x100000000041e,oid:0x100000000040b,oid:0x100000000040c,oid:0x100000000040d,oid:0x100000000040e,oid:0x100000000040f,oid:0x1000000000410,oid:0x1000000000411,oid:0x1000000000412,oid:0x1000000000413,oid:0x100000000041f,oid:0x1000000000420,oid:0x1000000000421,oid:0x1000000000422,oid:0x1000000000423,oid:0x1000000000414,oid:0x1000000000424,oid:0x1000000000415,oid:0x1000000000416,oid:0x1000000000417,oid:0x1000000000418
2019-09-06.20:25:20.545234|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000ea7|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_ICMP_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_ICMP_CODE=true|SAI_ACL_TABLE_ATTR_FIELD_SRC_IPV6=true|SAI_ACL_TABLE_ATTR_FIELD_DST_IPV6=true|SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_TYPE=true|SAI_ACL_TABLE_ATTR_FIELD_ICMPV6_CODE=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
2019-09-06.20:25:26.615846|c|SAI_OBJECT_TYPE_MIRROR_SESSION:oid:0xe00000000103c|SAI_MIRROR_SESSION_ATTR_MONITOR_PORT=oid:0x1000000000405|SAI_MIRROR_SESSION_ATTR_TYPE=SAI_MIRROR_SESSION_TYPE_ENHANCED_REMOTE|SAI_MIRROR_SESSION_ATTR_ERSPAN_ENCAPSULATION_TYPE=SAI_ERSPAN_ENCAPSULATION_TYPE_MIRROR_L3_GRE_TUNNEL|SAI_MIRROR_SESSION_ATTR_IPHDR_VERSION=4|SAI_MIRROR_SESSION_ATTR_TOS=32|SAI_MIRROR_SESSION_ATTR_TTL=255|SAI_MIRROR_SESSION_ATTR_SRC_IP_ADDRESS=25.92.94.21|SAI_MIRROR_SESSION_ATTR_DST_IP_ADDRESS=100.126.126.196|SAI_MIRROR_SESSION_ATTR_SRC_MAC_ADDRESS=74:83:EF:A6:52:14|SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS=74:83:EF:2C:39:3E|SAI_MIRROR_SESSION_ATTR_GRE_PROTOCOL_TYPE=35006
2019-09-06.20:25:26.616043|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x900000000103d|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x7000000000ea7|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-09-06.20:25:26.616170|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x800000000103e|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x7000000000ea7|SAI_ACL_ENTRY_ATTR_PRIORITY=8888|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x900000000103d|SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE=2054&mask:0xffff|SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS=1:oid:0xe00000000103c
2019-09-06.20:25:26.616289|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x900000000103f|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x7000000000ea7|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-09-06.20:25:26.616380|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000001040|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x7000000000ea7|SAI_ACL_ENTRY_ATTR_PRIORITY=8887|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x900000000103f|SAI_ACL_ENTRY_ATTR_FIELD_ICMPV6_TYPE=135&mask:0xff|SAI_ACL_ENTRY_ATTR_ACTION_MIRROR_INGRESS=1:oid:0xe00000000103c
2019-09-06.20:25:26.617138|a|APPLY_VIEW
2019-09-06.20:17:19.916165|A|SAI_STATUS_SUCCESS

0 comments on commit e7d766e

Please sign in to comment.