Skip to content

Commit 248a095

Browse files
authored
Add best candidate search for acl table (sonic-net#371)
1 parent d1e26c3 commit 248a095

File tree

3 files changed

+235
-6
lines changed

3 files changed

+235
-6
lines changed

syncd/syncd_applyview.cpp

+201-6
Original file line numberDiff line numberDiff line change
@@ -2641,8 +2641,8 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForAclTableGroup(
26412641
if (c.obj->getVid() == atgVid)
26422642
{
26432643
SWSS_LOG_INFO("found ALC table group candidate %s using port %s",
2644-
port->str_object_id.c_str(),
2645-
c.obj->str_object_id.c_str());
2644+
c.obj->str_object_id.c_str(),
2645+
port->str_object_id.c_str());
26462646

26472647
return c.obj;
26482648
}
@@ -2736,6 +2736,101 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForAclTableGroup(
27362736
return nullptr;
27372737
}
27382738

2739+
std::shared_ptr<SaiObj> findCurrentBestMatchForAclTable(
2740+
_In_ const AsicView &currentView,
2741+
_In_ const AsicView &temporaryView,
2742+
_In_ const std::shared_ptr<const SaiObj> &temporaryObj,
2743+
_In_ const std::vector<sai_object_compare_info_t> &candidateObjects)
2744+
{
2745+
SWSS_LOG_ENTER();
2746+
2747+
/*
2748+
* For acl table we can go to acl table group member and then to acl table group and port.
2749+
*/
2750+
2751+
const auto tmpAclTableGroupMembers = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER);
2752+
2753+
for (auto tmpAclTableGroupMember: tmpAclTableGroupMembers)
2754+
{
2755+
auto tmpAclTableId = tmpAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID);
2756+
2757+
if (tmpAclTableId->getOid() != temporaryObj->getVid())
2758+
{
2759+
// this is not the expected alc table group member
2760+
continue;
2761+
}
2762+
2763+
auto tmpAclTableGroupId = tmpAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID);
2764+
2765+
/*
2766+
* We have acl table group id, search on which port it's set, not let's
2767+
* find on which port it's set.
2768+
*/
2769+
2770+
const auto tmpPorts = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_PORT);
2771+
2772+
for (auto tmpPort: tmpPorts)
2773+
{
2774+
if (!tmpPort->hasAttr(SAI_PORT_ATTR_INGRESS_ACL))
2775+
continue;
2776+
2777+
auto tmpInACL = tmpPort->getSaiAttr(SAI_PORT_ATTR_INGRESS_ACL);
2778+
2779+
if (tmpInACL->getOid() != tmpAclTableGroupId->getOid())
2780+
continue;
2781+
2782+
auto curPort = currentView.oOids.at(tmpPort->getVid());
2783+
2784+
if (!curPort->hasAttr(SAI_PORT_ATTR_INGRESS_ACL))
2785+
continue;
2786+
2787+
auto curInACL = curPort->getSaiAttr(SAI_PORT_ATTR_INGRESS_ACL);
2788+
2789+
/*
2790+
* We found current InACL, now let's find acl table group members
2791+
* that use this acl table group.
2792+
*/
2793+
2794+
const auto curAclTableGroupMembers = currentView.getObjectsByObjectType(SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER);
2795+
2796+
for (auto curAclTableGroupMember: curAclTableGroupMembers)
2797+
{
2798+
auto curAclTableGroupId = curAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID);
2799+
2800+
if (curAclTableGroupId->getOid() != curInACL->getOid())
2801+
{
2802+
// this member uses different acl table group
2803+
continue;
2804+
}
2805+
2806+
auto curAclTableId = curAclTableGroupMember->getSaiAttr(SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID);
2807+
2808+
/*
2809+
* We found possible current acl table ID, let's see if it's on
2810+
* candidate list. Note, it could be possible that many
2811+
* different paths will lead multiple possible candidates.
2812+
*/
2813+
2814+
for (auto c: candidateObjects)
2815+
{
2816+
if (c.obj->getVid() == curAclTableId->getOid())
2817+
{
2818+
SWSS_LOG_INFO("found ALC table candidate %s using port %s",
2819+
c.obj->str_object_id.c_str(),
2820+
tmpPort->str_object_id.c_str());
2821+
2822+
return c.obj;
2823+
}
2824+
}
2825+
}
2826+
}
2827+
}
2828+
2829+
SWSS_LOG_NOTICE("failed to find best candidate for ACL table using port");
2830+
2831+
return nullptr;
2832+
}
2833+
27392834
std::shared_ptr<SaiObj> findCurrentBestMatchForRouterInterface(
27402835
_In_ const AsicView &currentView,
27412836
_In_ const AsicView &temporaryView,
@@ -3154,6 +3249,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
31543249
candidate = findCurrentBestMatchForHostifTrapGroup(currentView, temporaryView, temporaryObj, candidateObjects);
31553250
break;
31563251

3252+
case SAI_OBJECT_TYPE_ACL_TABLE:
3253+
candidate = findCurrentBestMatchForAclTable(currentView, temporaryView, temporaryObj, candidateObjects);
3254+
break;
3255+
31573256
default:
31583257
break;
31593258
}
@@ -3203,6 +3302,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
32033302
return selectRandomCandidate(candidateObjects);
32043303
}
32053304

3305+
std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(
3306+
_In_ const AsicView &currentView,
3307+
_In_ const sai_attr_metadata_t &meta);
3308+
32063309
std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
32073310
_In_ const AsicView &currentView,
32083311
_In_ const AsicView &temporaryView,
@@ -3314,6 +3417,13 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
33143417

33153418
bool has_different_create_only_attr = false;
33163419

3420+
/*
3421+
* NOTE: we only iterate by attributes that are present in temporary
3422+
* view. It may happen that current view has some additional attributes
3423+
* set that are create only and value can't be updated then, so in that
3424+
* case such object must be disqualified from being candidate.
3425+
*/
3426+
33173427
for (const auto &attr: attrs)
33183428
{
33193429
sai_attr_id_t attrId = attr.first;
@@ -3378,6 +3488,85 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
33783488

33793489
break;
33803490
}
3491+
3492+
if (SAI_HAS_FLAG_CREATE_ONLY(meta->flags) && !currentObj->hasAttr(attrId))
3493+
{
3494+
/*
3495+
* This attribute exists only on temporary view and it's
3496+
* create only. If it has default value, check if it's the
3497+
* same as current.
3498+
*/
3499+
3500+
auto curDefault = getSaiAttrFromDefaultValue(currentView, *meta);
3501+
3502+
if (curDefault != nullptr)
3503+
{
3504+
if (curDefault->getStrAttrValue() != attr.second->getStrAttrValue())
3505+
{
3506+
has_different_create_only_attr = true;
3507+
3508+
SWSS_LOG_INFO("obj has not equal create only attributes %s (default): %s",
3509+
temporaryObj->str_object_id.c_str(),
3510+
meta->attridname);
3511+
break;
3512+
}
3513+
else
3514+
{
3515+
SWSS_LOG_INFO("obj has equal create only value %s (default): %s",
3516+
temporaryObj->str_object_id.c_str(),
3517+
meta->attridname);
3518+
}
3519+
}
3520+
}
3521+
}
3522+
}
3523+
3524+
/*
3525+
* Before we add this object as candidate, see if there are some create
3526+
* only attributes which are not present in temporary object but
3527+
* present in current, and if there is default value that is the same.
3528+
*/
3529+
3530+
const auto curAttrs = currentObj->getAllAttributes();
3531+
3532+
for (auto curAttr: curAttrs)
3533+
{
3534+
if (attrs.find(curAttr.first) != attrs.end())
3535+
{
3536+
// attr exists in both objects.
3537+
continue;
3538+
}
3539+
3540+
const sai_attr_metadata_t* meta = curAttr.second->getAttrMetadata();
3541+
3542+
if (SAI_HAS_FLAG_CREATE_ONLY(meta->flags) && !temporaryObj->hasAttr(curAttr.first))
3543+
{
3544+
/*
3545+
* This attribute exists only on current view and it's
3546+
* create only. If it has default value, check if it's the
3547+
* same as current.
3548+
*/
3549+
3550+
auto tmpDefault = getSaiAttrFromDefaultValue(temporaryView, *meta);
3551+
3552+
if (tmpDefault != nullptr)
3553+
{
3554+
if (tmpDefault->getStrAttrValue() != curAttr.second->getStrAttrValue())
3555+
{
3556+
has_different_create_only_attr = true;
3557+
3558+
SWSS_LOG_INFO("obj has not equal create only attributes %s (default): %s",
3559+
currentObj->str_object_id.c_str(),
3560+
meta->attridname);
3561+
break;
3562+
}
3563+
else
3564+
{
3565+
SWSS_LOG_INFO("obj has equal create only value %s (default): %s",
3566+
temporaryObj->str_object_id.c_str(),
3567+
meta->attridname);
3568+
}
3569+
}
33813570
}
33823571
}
33833572

@@ -4019,10 +4208,6 @@ void procesObjectAttributesForViewTransition(
40194208
}
40204209
}
40214210

4022-
std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(
4023-
_In_ const AsicView &currentView,
4024-
_In_ const sai_attr_metadata_t &meta);
4025-
40264211
void bringNonRemovableObjectToDefaultState(
40274212
_In_ AsicView &currentView,
40284213
_In_ const std::shared_ptr<SaiObj> &currentObj)
@@ -4885,6 +5070,14 @@ std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(
48855070

48865071
return nullptr;
48875072

5073+
case SAI_DEFAULT_VALUE_TYPE_NONE:
5074+
5075+
/*
5076+
* No default value present.
5077+
*/
5078+
5079+
return nullptr;
5080+
48885081
default:
48895082

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

5675+
SWSS_LOG_DEBUG("processing: %s:%s", temporaryObj->str_object_type.c_str(), temporaryObj->str_object_id.c_str());
5676+
54825677
procesObjectAttributesForViewTransition(currentView, temporaryView, temporaryObj);
54835678

54845679
/*

tests/brcm.pl

+15
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,23 @@ sub test_brcm_qos_map_order
277277
play "qos_map_order.rec", 0;
278278
}
279279

280+
sub test_brcm_acl_tables
281+
{
282+
fresh_start;
283+
284+
# we expect no asic operation on lag's that has no members
285+
286+
play "acl_tables.rec";
287+
play "acl_tables.rec", 0;
288+
play "acl_tables.rec", 0;
289+
play "acl_tables.rec", 0;
290+
play "acl_tables.rec", 0;
291+
play "acl_tables.rec", 0;
292+
}
293+
280294
# RUN TESTS
281295

296+
test_brcm_acl_tables;
282297
test_brcm_qos_map_order;
283298
test_brcm_lag_no_members;
284299
test_brcm_rif_loopback;

tests/brcm/acl_tables.rec

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2018-11-05.23:53:46.072382|#|recording on: /var/log/swss/sairedis.rec
2+
2018-11-05.23:53:46.072861|#|logrotate on: /var/log/swss/sairedis.rec
3+
2018-11-05.23:53:46.072964|a|INIT_VIEW
4+
2018-11-05.23:54:14.728951|A|SAI_STATUS_SUCCESS
5+
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
6+
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
7+
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
8+
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
9+
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
10+
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
11+
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
12+
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
13+
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
14+
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
15+
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
16+
2018-11-05.23:54:17.366422|s|SAI_OBJECT_TYPE_PORT:oid:0x1000000000002|SAI_PORT_ATTR_INGRESS_ACL=oid:0xb000000000ab3
17+
2018-11-05.23:54:17.367676|s|SAI_OBJECT_TYPE_PORT:oid:0x1000000000003|SAI_PORT_ATTR_INGRESS_ACL=oid:0xb000000000ab5
18+
2018-11-05.23:54:23.726116|a|APPLY_VIEW
19+
2018-11-06.00:01:09.702164|A|SAI_STATUS_SUCCESS

0 commit comments

Comments
 (0)