Skip to content

Commit 05ef677

Browse files
kcudniklguohan
authored andcommitted
Add special comparison logic for LAG (sonic-net#351)
1 parent 9408686 commit 05ef677

3 files changed

Lines changed: 144 additions & 0 deletions

File tree

syncd/syncd_applyview.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,105 @@ int findAllChildsInDependencyTreeCount(
21822182
return count;
21832183
}
21842184

2185+
std::shared_ptr<SaiObj> findCurrentBestMatchForLag(
2186+
_In_ const AsicView &currentView,
2187+
_In_ const AsicView &temporaryView,
2188+
_In_ const std::shared_ptr<const SaiObj> &temporaryObj,
2189+
_In_ const std::vector<sai_object_compare_info_t> &candidateObjects)
2190+
{
2191+
SWSS_LOG_ENTER();
2192+
2193+
/*
2194+
* Find not processed LAG members, in both views, since lag member contais
2195+
* LAG and PORT, then it should not be processed before LAG itself. But
2196+
* since PORT objects on LAG members should be matched at the beggining of
2197+
* comparison logic, then we can find batching LAG members based on the
2198+
* same VID, since it will be the same in both views.
2199+
*/
2200+
2201+
const auto tmpLagMembersNP = temporaryView.getNotProcessedObjectsByObjectType(SAI_OBJECT_TYPE_LAG_MEMBER);
2202+
2203+
/*
2204+
* First we need to find at least 1 LAG member that belongs to temporary
2205+
* object so we could extrac port object.
2206+
*/
2207+
2208+
sai_object_id_t tmpLagVid = temporaryObj->getVid();
2209+
2210+
sai_object_id_t temporaryLagMemberPortVid = SAI_NULL_OBJECT_ID;
2211+
2212+
for (const auto &lagMember: tmpLagMembersNP)
2213+
{
2214+
// lag member attr lag should always exists on
2215+
const auto lagMemberLagAttr = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_LAG_ID);
2216+
2217+
if (lagMemberLagAttr->getSaiAttr()->value.oid == tmpLagVid)
2218+
{
2219+
SWSS_LOG_NOTICE("found temp LAG member %s which uses temp LAG %s",
2220+
temporaryObj->str_object_id.c_str(),
2221+
lagMember->str_object_id.c_str());
2222+
2223+
temporaryLagMemberPortVid = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_PORT_ID)->getSaiAttr()->value.oid;
2224+
2225+
break;
2226+
}
2227+
}
2228+
2229+
if (temporaryLagMemberPortVid == SAI_NULL_OBJECT_ID)
2230+
{
2231+
SWSS_LOG_WARN("failed to find temporary LAG member for LAG %s", sai_serialize_object_id(tmpLagVid).c_str());
2232+
2233+
return nullptr;
2234+
}
2235+
2236+
/*
2237+
* Now since we have port VID which should be the same in both current and
2238+
* temporary view, let's find LAG member object that uses this port on
2239+
* current view.
2240+
*/
2241+
2242+
const auto curLagMembersNP = currentView.getNotProcessedObjectsByObjectType(SAI_OBJECT_TYPE_LAG_MEMBER);
2243+
2244+
for (const auto &lagMember: curLagMembersNP)
2245+
{
2246+
// lag member attr lag should always exists on
2247+
const auto lagMemberPortAttr = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_PORT_ID);
2248+
2249+
if (lagMemberPortAttr->getSaiAttr()->value.oid == temporaryLagMemberPortVid)
2250+
{
2251+
SWSS_LOG_NOTICE("found current LAG member %s which uses PORT %s",
2252+
lagMember->str_object_id.c_str(),
2253+
sai_serialize_object_id(temporaryLagMemberPortVid).c_str());
2254+
2255+
/*
2256+
* We found LAG member which uses the same PORT VID, let's extract
2257+
* LAG and check if this LAG is on the candidate list.
2258+
*/
2259+
2260+
sai_object_id_t currentLagVid = lagMember->getSaiAttr(SAI_LAG_MEMBER_ATTR_LAG_ID)->getSaiAttr()->value.oid;
2261+
2262+
for (auto &c: candidateObjects)
2263+
{
2264+
if (c.obj->getVid() == currentLagVid)
2265+
{
2266+
SWSS_LOG_NOTICE("found best candidate for temp LAG %s which is current LAG %s using PORT %s",
2267+
temporaryObj->str_object_id.c_str(),
2268+
sai_serialize_object_id(currentLagVid).c_str(),
2269+
sai_serialize_object_id(temporaryLagMemberPortVid).c_str());
2270+
2271+
return c.obj;
2272+
}
2273+
}
2274+
2275+
break;
2276+
}
2277+
}
2278+
2279+
SWSS_LOG_NOTICE("failed to find best candidate for LAG using LAG member and port id");
2280+
2281+
return nullptr;
2282+
}
2283+
21852284
std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
21862285
_In_ const AsicView &currentView,
21872286
_In_ const AsicView &temporaryView,
@@ -2190,6 +2289,19 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
21902289
{
21912290
SWSS_LOG_ENTER();
21922291

2292+
if (temporaryObj->getObjectType() == SAI_OBJECT_TYPE_LAG)
2293+
{
2294+
/*
2295+
* For lat, let's try find matching LAG member which will be using the
2296+
* same port, since we expect that port object can belong only to 1 lag.
2297+
*/
2298+
2299+
std::shared_ptr<SaiObj> candidateLag = findCurrentBestMatchForLag(currentView, temporaryView, temporaryObj, candidateObjects);
2300+
2301+
if (candidateLag != nullptr)
2302+
return candidateLag;
2303+
}
2304+
21932305
/*
21942306
* Idea is to count all dependencies that uses this object. this may not
21952307
* be a good approach since logic may choose wrong candidate.

tests/brcm.pl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,21 @@ sub test_brcm_speed_init_apply
177177
play "speed_apply.rec";
178178
}
179179

180+
sub test_brcm_lag_comparison_logic
181+
{
182+
fresh_start;
183+
184+
# we expect no asic operations on this test
185+
# even do lags looks the same, but are matched
186+
# using lag member and port
187+
188+
play "lag_comparison_logic.rec";
189+
play "lag_comparison_logic.rec";
190+
}
180191

181192
# RUN TESTS
182193

194+
test_brcm_lag_comparison_logic;
183195
test_brcm_speed_init_apply;
184196
test_brcm_start_empty;
185197
test_brcm_start_empty_to_empty;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2018-10-08.16:48:52.023607|#|logrotate on: /var/log/swss/sairedis.rec
2+
2018-10-08.16:48:52.023911|a|INIT_VIEW
3+
2018-10-08.16:48:54.691593|A|SAI_STATUS_SUCCESS
4+
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
5+
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
6+
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
7+
2018-10-08.16:49:14.343261|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b0|NULL=NULL
8+
2018-10-08.16:49:14.346019|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b1|NULL=NULL
9+
2018-10-08.16:49:14.348974|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b2|NULL=NULL
10+
2018-10-08.16:49:14.351286|c|SAI_OBJECT_TYPE_LAG:oid:0x20000000005b3|NULL=NULL
11+
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
12+
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
13+
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
14+
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
15+
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
16+
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
17+
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
18+
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
19+
2018-10-08.16:49:09.568152|a|APPLY_VIEW
20+
2018-10-08.16:49:09.573294|A|SAI_STATUS_SUCCESS

0 commit comments

Comments
 (0)