Skip to content

Commit

Permalink
Add special comparison logic for LAG (sonic-net#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and lguohan committed Oct 10, 2018
1 parent 9408686 commit 05ef677
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
112 changes: 112 additions & 0 deletions syncd/syncd_applyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,105 @@ int findAllChildsInDependencyTreeCount(
return count;
}

std::shared_ptr<SaiObj> findCurrentBestMatchForLag(
_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();

/*
* Find not processed LAG members, in both views, since lag member contais
* LAG and PORT, then it should not be processed before LAG itself. But
* since PORT objects on LAG members should be matched at the beggining of
* comparison logic, then we can find batching LAG members based on the
* same VID, since it will be the same in both views.
*/

const auto tmpLagMembersNP = temporaryView.getNotProcessedObjectsByObjectType(SAI_OBJECT_TYPE_LAG_MEMBER);

/*
* First we need to find at least 1 LAG member that belongs to temporary
* object so we could extrac port object.
*/

sai_object_id_t tmpLagVid = temporaryObj->getVid();

sai_object_id_t temporaryLagMemberPortVid = SAI_NULL_OBJECT_ID;

for (const auto &lagMember: tmpLagMembersNP)
{
// lag member attr lag should always exists on
const auto lagMemberLagAttr = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_LAG_ID);

if (lagMemberLagAttr->getSaiAttr()->value.oid == tmpLagVid)
{
SWSS_LOG_NOTICE("found temp LAG member %s which uses temp LAG %s",
temporaryObj->str_object_id.c_str(),
lagMember->str_object_id.c_str());

temporaryLagMemberPortVid = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_PORT_ID)->getSaiAttr()->value.oid;

break;
}
}

if (temporaryLagMemberPortVid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_WARN("failed to find temporary LAG member for LAG %s", sai_serialize_object_id(tmpLagVid).c_str());

return nullptr;
}

/*
* Now since we have port VID which should be the same in both current and
* temporary view, let's find LAG member object that uses this port on
* current view.
*/

const auto curLagMembersNP = currentView.getNotProcessedObjectsByObjectType(SAI_OBJECT_TYPE_LAG_MEMBER);

for (const auto &lagMember: curLagMembersNP)
{
// lag member attr lag should always exists on
const auto lagMemberPortAttr = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_PORT_ID);

if (lagMemberPortAttr->getSaiAttr()->value.oid == temporaryLagMemberPortVid)
{
SWSS_LOG_NOTICE("found current LAG member %s which uses PORT %s",
lagMember->str_object_id.c_str(),
sai_serialize_object_id(temporaryLagMemberPortVid).c_str());

/*
* We found LAG member which uses the same PORT VID, let's extract
* LAG and check if this LAG is on the candidate list.
*/

sai_object_id_t currentLagVid = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_LAG_ID)->getSaiAttr()->value.oid;

for (auto &c: candidateObjects)
{
if (c.obj->getVid() == currentLagVid)
{
SWSS_LOG_NOTICE("found best candidate for temp LAG %s which is current LAG %s using PORT %s",
temporaryObj->str_object_id.c_str(),
sai_serialize_object_id(currentLagVid).c_str(),
sai_serialize_object_id(temporaryLagMemberPortVid).c_str());

return c.obj;
}
}

break;
}
}

SWSS_LOG_NOTICE("failed to find best candidate for LAG using LAG member and port id");

return nullptr;
}

std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
_In_ const AsicView &currentView,
_In_ const AsicView &temporaryView,
Expand All @@ -2190,6 +2289,19 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
{
SWSS_LOG_ENTER();

if (temporaryObj->getObjectType() == SAI_OBJECT_TYPE_LAG)
{
/*
* For lat, let's try find matching LAG member which will be using the
* same port, since we expect that port object can belong only to 1 lag.
*/

std::shared_ptr<SaiObj> candidateLag = findCurrentBestMatchForLag(currentView, temporaryView, temporaryObj, candidateObjects);

if (candidateLag != nullptr)
return candidateLag;
}

/*
* Idea is to count all dependencies that uses this object. this may not
* be a good approach since logic may choose wrong candidate.
Expand Down
12 changes: 12 additions & 0 deletions tests/brcm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,21 @@ sub test_brcm_speed_init_apply
play "speed_apply.rec";
}

sub test_brcm_lag_comparison_logic
{
fresh_start;

# we expect no asic operations on this test
# even do lags looks the same, but are matched
# using lag member and port

play "lag_comparison_logic.rec";
play "lag_comparison_logic.rec";
}

# RUN TESTS

test_brcm_lag_comparison_logic;
test_brcm_speed_init_apply;
test_brcm_start_empty;
test_brcm_start_empty_to_empty;
Expand Down
20 changes: 20 additions & 0 deletions tests/brcm/lag_comparison_logic.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
2018-10-08.16:48:52.023607|#|logrotate on: /var/log/swss/sairedis.rec
2018-10-08.16:48:52.023911|a|INIT_VIEW
2018-10-08.16:48:54.691593|A|SAI_STATUS_SUCCESS
2018-10-08.16:48:54.693204|c|SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000|SAI_SWITCH_ATTR_INIT_SWITCH=true|SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY=0x4270f0|SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY=0x427100|SAI_SWITCH_ATTR_SWITCH_SHUTDOWN_REQUEST_NOTIFY=0x427110|SAI_SWITCH_ATTR_SRC_MAC_ADDRESS=90:B1:1C:F4:A8:53
2018-10-08.16:49:09.052114|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-10-08.16:49:09.065640|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-10-08.16:49:14.343261|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b0|NULL=NULL
2018-10-08.16:49:14.346019|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b1|NULL=NULL
2018-10-08.16:49:14.348974|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b2|NULL=NULL
2018-10-08.16:49:14.351286|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b3|NULL=NULL
2018-10-08.16:49:21.805445|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b000000000644|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b0|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000002
2018-10-08.16:49:21.993270|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b000000000645|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b1|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000006
2018-10-08.16:49:22.033846|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b000000000646|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b0|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000003
2018-10-08.16:49:22.035334|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b000000000647|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b1|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000007
2018-10-08.16:49:25.798741|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b00000000064b|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b2|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000012
2018-10-08.16:49:25.800699|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b00000000064c|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b3|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000016
2018-10-08.16:49:25.804696|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b00000000064d|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b3|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000017
2018-10-08.16:49:45.755558|c|SAI_OBJECT_TYPE_LAG_MEMBER:oid:0x1b00000000064f|SAI_LAG_MEMBER_ATTR_LAG_ID=oid:0x20000000005b2|SAI_LAG_MEMBER_ATTR_PORT_ID=oid:0x1000000000013
2018-10-08.16:49:09.568152|a|APPLY_VIEW
2018-10-08.16:49:09.573294|A|SAI_STATUS_SUCCESS

0 comments on commit 05ef677

Please sign in to comment.