Skip to content

Commit

Permalink
Add specific comparison logic for ACL counter (sonic-net#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Jul 16, 2019
1 parent 49f36ce commit 580cab5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
60 changes: 60 additions & 0 deletions syncd/syncd_applyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,62 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForNextHopGroup(
return nullptr;
}

std::shared_ptr<SaiObj> findCurrentBestMatchForAclCounter(
_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 counter we use SAI_ACL_COUNTER_ATTR_TABLE_ID to match exact
* counter since if set, then table id will be matched previously.
*/

const auto tmpAclTables = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE);

for (auto& tmpAclTable: tmpAclTables)
{
auto tmpAclCounterTableIdAttr = temporaryObj->tryGetSaiAttr(SAI_ACL_COUNTER_ATTR_TABLE_ID);

if (tmpAclCounterTableIdAttr == nullptr)
continue;

if (tmpAclCounterTableIdAttr->getOid() == SAI_NULL_OBJECT_ID)
continue;

if (tmpAclTable->getVid() != tmpAclCounterTableIdAttr->getOid())
continue; // not this table

if (tmpAclTable->getObjectStatus() != SAI_OBJECT_STATUS_FINAL)
continue; // not processed

sai_object_id_t aclTableRid = temporaryView.vidToRid.at(tmpAclTable->getVid());

sai_object_id_t curAclTableVid = currentView.ridToVid.at(aclTableRid);

for (auto c: candidateObjects)
{
auto curAclCounterTableIdAttr = c.obj->tryGetSaiAttr(SAI_ACL_COUNTER_ATTR_TABLE_ID);

if (curAclCounterTableIdAttr == nullptr)
continue;

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());

return c.obj;
}
}

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

return nullptr;
}

std::shared_ptr<SaiObj> findCurrentBestMatchForAclTableGroup(
_In_ const AsicView &currentView,
_In_ const AsicView &temporaryView,
Expand Down Expand Up @@ -3808,6 +3864,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingGraph(
candidate = findCurrentBestMatchForAclTableGroup(currentView, temporaryView, temporaryObj, candidateObjects);
break;

case SAI_OBJECT_TYPE_ACL_COUNTER:
candidate = findCurrentBestMatchForAclCounter(currentView, temporaryView, temporaryObj, candidateObjects);
break;

case SAI_OBJECT_TYPE_ROUTER_INTERFACE:
candidate = findCurrentBestMatchForRouterInterface(currentView, temporaryView, temporaryObj, candidateObjects);
break;
Expand Down
12 changes: 12 additions & 0 deletions tests/brcm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,21 @@ sub test_tunnel_map
play "tunnel_map.rec", 0;
}

sub test_acl_counter
{
fresh_start;

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

# RUN TESTS

test_acl_counter;
test_tunnel_map;
test_bridge_create;
test_ntf;
Expand Down
26 changes: 26 additions & 0 deletions tests/brcm/acl_counter.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
2019-06-06.22:51:50.087674|a|INIT_VIEW
2019-06-06.22:51:52.783261|A|SAI_STATUS_SUCCESS
2019-06-06.22:51:52.784929|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x42ca90|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x42caa0|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x42cab0|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=E0:0E:DA:A8:CB:2B
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-06-06.22:52:22.545502|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000469|SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST=1:SAI_ACL_BIND_POINT_TYPE_PORT|SAI_ACL_TABLE_ATTR_ACL_STAGE=SAI_ACL_STAGE_INGRESS|SAI_ACL_TABLE_ATTR_FIELD_ECN=true|SAI_ACL_TABLE_ATTR_FIELD_DSCP=true
2019-06-06.22:52:22.545710|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x800000000046a|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x7000000000469|SAI_ACL_ENTRY_ATTR_PRIORITY=1000|SAI_ACL_ENTRY_ATTR_FIELD_ECN=0&mask:0x3|SAI_ACL_ENTRY_ATTR_FIELD_DSCP=8&mask:0x3f|SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR=SAI_PACKET_COLOR_YELLOW
2019-06-06.22:52:22.545928|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x800000000046b|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x7000000000469|SAI_ACL_ENTRY_ATTR_PRIORITY=999|SAI_ACL_ENTRY_ATTR_FIELD_ECN=0&mask:0x3|SAI_ACL_ENTRY_ATTR_FIELD_DSCP=0&mask:0x3f|SAI_ACL_ENTRY_ATTR_ACTION_SET_PACKET_COLOR=SAI_PACKET_COLOR_YELLOW
2019-06-06.22:52:22.861363|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x70000000004ce|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_EGRESS
2019-06-06.22:52:22.861644|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP:oid:0xb0000000004cf|SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE=SAI_ACL_STAGE_EGRESS|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
2019-06-06.22:52:22.861772|s|SAI_OBJECT_TYPE_PORT:oid:0x100000000040c|SAI_PORT_ATTR_EGRESS_ACL=oid:0xb0000000004cf
2019-06-06.22:52:22.861966|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc0000000004d0|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID=oid:0xb0000000004cf|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID=oid:0x70000000004ce|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY=100
2019-06-06.22:52:22.862310|c|SAI_OBJECT_TYPE_ACL_TABLE:oid:0x70000000004d1|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
2019-06-06.22:52:22.862587|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP:oid:0xb0000000004d2|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
2019-06-06.22:52:22.862693|s|SAI_OBJECT_TYPE_PORT:oid:0x100000000040b|SAI_PORT_ATTR_INGRESS_ACL=oid:0xb0000000004d2
2019-06-06.22:52:22.862856|c|SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc0000000004d3|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID=oid:0xb0000000004d2|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID=oid:0x70000000004d1|SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY=100
2019-06-06.22:52:27.507695|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x90000000004d4|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-06-06.22:52:27.507840|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x80000000004d5|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_ENTRY_ATTR_PRIORITY=1|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x90000000004d4|SAI_ACL_ENTRY_ATTR_FIELD_ETHER_TYPE=2048&mask:0xffff|SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION=SAI_PACKET_ACTION_DROP
2019-06-06.22:52:27.508036|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x90000000004d6|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-06-06.22:52:27.508169|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x80000000004d7|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_ENTRY_ATTR_PRIORITY=9999|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x90000000004d6|SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP=10.0.0.2&mask:255.255.255.255|SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION=SAI_PACKET_ACTION_DROP
2019-06-06.22:52:27.508362|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x90000000004d8|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-06-06.22:52:27.508493|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x80000000004d9|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_ENTRY_ATTR_PRIORITY=9998|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x90000000004d8|SAI_ACL_ENTRY_ATTR_FIELD_DST_IP=192.168.0.16&mask:255.255.255.255|SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION=SAI_PACKET_ACTION_DROP
2019-06-06.22:52:27.508677|c|SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x90000000004da|SAI_ACL_COUNTER_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_COUNTER_ATTR_ENABLE_BYTE_COUNT=true|SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT=true
2019-06-06.22:52:27.508808|c|SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x80000000004db|SAI_ACL_ENTRY_ATTR_TABLE_ID=oid:0x70000000004d1|SAI_ACL_ENTRY_ATTR_PRIORITY=9997|SAI_ACL_ENTRY_ATTR_ADMIN_STATE=true|SAI_ACL_ENTRY_ATTR_ACTION_COUNTER=oid:0x90000000004da|SAI_ACL_ENTRY_ATTR_FIELD_L4_SRC_PORT=4661&mask:0xffff|SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION=SAI_PACKET_ACTION_DROP
2019-06-06.22:52:22.564771|a|APPLY_VIEW
2019-06-06.22:52:22.565244|A|SAI_STATUS_SUCCESS

0 comments on commit 580cab5

Please sign in to comment.