Skip to content

Commit e7d766e

Browse files
kcudniklguohan
authored andcommitted
Add acl counter match logic based on acl entry field (#511)
1 parent 58845ce commit e7d766e

File tree

3 files changed

+139
-8
lines changed

3 files changed

+139
-8
lines changed

syncd/syncd_applyview.cpp

+100-7
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,18 @@ class SaiAttr
153153
{
154154
SWSS_LOG_ENTER();
155155

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

161-
return m_attr.value.oid;
161+
if (m_meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID &&
162+
m_attr.value.aclaction.enable)
163+
{
164+
return m_attr.value.aclaction.parameter.oid;
165+
}
166+
167+
SWSS_LOG_THROW("attribute %s is not OID attribute", m_meta->attridname);
162168
}
163169

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

2735+
std::vector<std::shared_ptr<SaiObj>> objs;
2736+
27292737
const auto tmpAclTables = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE);
27302738

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

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

2763-
return c.obj;
2774+
if (objs.size() > 1)
2775+
{
2776+
// in this case more than 1 acl counters has the same acl table associated,
2777+
// try to find best acl counter matching same acl entry field
2778+
2779+
SWSS_LOG_INFO("more than 1 (%zu) best match on acl counter using acl table", objs.size());
2780+
2781+
const auto tmpAclEntries = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_ENTRY);
2782+
2783+
for (auto& tmpAclEntry: tmpAclEntries)
2784+
{
2785+
auto tmpAclEntryActionCounterAttr = tmpAclEntry->tryGetSaiAttr(SAI_ACL_ENTRY_ATTR_ACTION_COUNTER);
2786+
2787+
if (tmpAclEntryActionCounterAttr == nullptr)
2788+
continue; // skip acl entries with no counter
2789+
2790+
if (tmpAclEntryActionCounterAttr->getOid() != temporaryObj->getVid())
2791+
continue; // not the counter we are looking for
2792+
2793+
for (auto&attr: tmpAclEntry->getAllAttributes())
2794+
{
2795+
auto*meta = attr.second->getAttrMetadata();
2796+
2797+
if (!meta->isaclfield)
2798+
continue; // looking only for acl fields
2799+
2800+
if (meta->isoidattribute)
2801+
continue; // only non oid fields
2802+
2803+
auto tmpValue = attr.second->getStrAttrValue();
2804+
2805+
const auto curAclEntries = currentView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_ENTRY);
2806+
2807+
for (auto& curAclEntry: curAclEntries)
2808+
{
2809+
auto curAclEntryAclFieldAttr = curAclEntry->tryGetSaiAttr(meta->attrid);
2810+
2811+
if (curAclEntryAclFieldAttr == nullptr)
2812+
continue; // this field is missing from current view
2813+
2814+
if (curAclEntryAclFieldAttr->getStrAttrValue() != tmpValue)
2815+
continue; // values are different, keep looking
2816+
2817+
auto curAclEntryActionCounterAttr = curAclEntry->tryGetSaiAttr(SAI_ACL_ENTRY_ATTR_ACTION_COUNTER);
2818+
2819+
if (curAclEntryActionCounterAttr == nullptr)
2820+
continue; // no counter
2821+
2822+
auto curAclCounter = currentView.oOids.at(curAclEntryActionCounterAttr->getOid());
2823+
2824+
if (curAclCounter->getObjectStatus() != SAI_OBJECT_STATUS_NOT_PROCESSED)
2825+
continue;
2826+
2827+
for (auto c: candidateObjects)
2828+
{
2829+
if (c.obj->getVid() == curAclCounter->getVid())
2830+
{
2831+
SWSS_LOG_NOTICE("found best ACL counter match based on ACL entry field: %s, %s",
2832+
c.obj->str_object_id.c_str(),
2833+
meta->attridname);
2834+
return c.obj;
2835+
}
2836+
}
2837+
}
2838+
}
27642839
}
2840+
2841+
}
2842+
2843+
if (objs.size())
2844+
{
2845+
SWSS_LOG_NOTICE("found best ACL counter match based on ACL table: %s", objs.at(0)->str_object_id.c_str());
2846+
2847+
return objs.at(0);
27652848
}
27662849

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

4104-
SWSS_LOG_DEBUG("ob equal %s %s, %s: %s",
4187+
SWSS_LOG_INFO("ob equal %s %s, %s: %s",
41054188
temporaryObj->str_object_id.c_str(),
41064189
currentObj->str_object_id.c_str(),
41074190
attr.second->getStrAttrId().c_str(),
41084191
attr.second->getStrAttrValue().c_str());
41094192
}
41104193
else
41114194
{
4112-
SWSS_LOG_DEBUG("ob not equal %s %s, %s: %s",
4195+
SWSS_LOG_INFO("ob not equal %s %s, %s: %s",
41134196
temporaryObj->str_object_id.c_str(),
41144197
currentObj->str_object_id.c_str(),
41154198
attr.second->getStrAttrId().c_str(),
@@ -4311,6 +4394,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
43114394
* lets choose that object as our best match.
43124395
*/
43134396

4397+
SWSS_LOG_INFO("eq attributes: %ld vs %ld",
4398+
candidateObjects.at(0).equal_attributes,
4399+
candidateObjects.at(1).equal_attributes);
4400+
43144401
return candidateObjects.begin()->obj;
43154402
}
43164403

@@ -5845,6 +5932,12 @@ bool performObjectSetTransition(
58455932

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

5935+
SWSS_LOG_INFO("compare attr value curr %s vs temp %s",
5936+
currentBestMatch->getSaiAttr(attr.id)->getStrAttrValue().c_str(),
5937+
temporaryObj->getSaiAttr(attr.id)->getStrAttrValue().c_str());
5938+
5939+
5940+
58485941
if (hasEqualAttribute(currentView, temporaryView, currentBestMatch, temporaryObj, attr.id))
58495942
{
58505943
/*

tests/brcm.pl

+13-1
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,20 @@ sub test_acl_counter
464464
play "acl_counter.rec", 0;
465465
}
466466

467-
# RUN TESTS
467+
sub test_acl_counter2
468+
{
469+
fresh_start;
468470

471+
play "acl_counter2.rec";
472+
play "acl_counter2.rec", 0;
473+
play "acl_counter2.rec", 0;
474+
play "acl_counter2.rec", 0;
475+
play "acl_counter2.rec", 0;
476+
play "acl_counter2.rec", 0;
477+
}
478+
479+
# RUN TESTS
480+
test_acl_counter2;
469481
test_acl_counter;
470482
test_tunnel_map;
471483
test_bridge_create;

tests/brcm/acl_counter2.rec

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2019-09-06.20:17:08.004784|a|INIT_VIEW
2+
2019-09-06.20:17:10.301724|A|SAI_STATUS_SUCCESS
3+
2019-09-06.20:17:10.301994|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true
4+
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
5+
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
6+
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
7+
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
8+
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
9+
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
10+
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
11+
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
12+
2019-09-06.20:17:19.915627|a|APPLY_VIEW
13+
2019-09-06.20:17:19.916165|A|SAI_STATUS_SUCCESS
14+
2019-09-06.20:25:06.872229|a|INIT_VIEW
15+
2019-09-06.20:25:19.375314|A|SAI_STATUS_SUCCESS
16+
2019-09-06.20:25:19.389431|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true
17+
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
18+
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
19+
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
20+
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
21+
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
22+
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
23+
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
24+
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
25+
2019-09-06.20:25:26.617138|a|APPLY_VIEW
26+
2019-09-06.20:17:19.916165|A|SAI_STATUS_SUCCESS

0 commit comments

Comments
 (0)