@@ -2182,6 +2182,105 @@ int findAllChildsInDependencyTreeCount(
21822182 return count;
21832183}
21842184
2185+ std::shared_ptr<SaiObj> findCurrentBestMatchForLag (
2186+ _In_ const AsicView ¤tView,
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+
21852284std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic (
21862285 _In_ const AsicView ¤tView,
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.
0 commit comments