@@ -269,7 +269,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
269269 auto it = consumer.m_toSync .begin ();
270270 while (it != consumer.m_toSync .end ())
271271 {
272- KeyOpFieldsValuesTuple t = it->second ;
272+ auto & t = it->second ;
273273
274274 string alias = kfvKey (t);
275275 string op = kfvOp (t);
@@ -397,7 +397,7 @@ void PortsOrch::doVlanTask(Consumer &consumer)
397397 auto it = consumer.m_toSync .begin ();
398398 while (it != consumer.m_toSync .end ())
399399 {
400- KeyOpFieldsValuesTuple t = it->second ;
400+ auto & t = it->second ;
401401
402402 string key = kfvKey (t);
403403
@@ -527,144 +527,150 @@ void PortsOrch::doLagTask(Consumer &consumer)
527527 auto it = consumer.m_toSync .begin ();
528528 while (it != consumer.m_toSync .end ())
529529 {
530- KeyOpFieldsValuesTuple t = it->second ;
530+ auto & t = it->second ;
531531
532+ string lag_alias = kfvKey (t);
533+ string op = kfvOp (t);
534+
535+ if (op == SET_COMMAND)
536+ {
537+ /* Duplicate entry */
538+ if (m_portList.find (lag_alias) != m_portList.end ())
539+ {
540+ it = consumer.m_toSync .erase (it);
541+ continue ;
542+ }
543+
544+ if (addLag (lag_alias))
545+ it = consumer.m_toSync .erase (it);
546+ else
547+ it++;
548+ }
549+ else if (op == DEL_COMMAND)
550+ {
551+ Port lag;
552+ /* Cannot locate LAG */
553+ if (!getPort (lag_alias, lag))
554+ {
555+ it = consumer.m_toSync .erase (it);
556+ continue ;
557+ }
558+
559+ if (removeLag (lag))
560+ it = consumer.m_toSync .erase (it);
561+ else
562+ it++;
563+ }
564+ else
565+ {
566+ SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
567+ it = consumer.m_toSync .erase (it);
568+ }
569+ }
570+ }
571+
572+ void PortsOrch::doLagMemberTask (Consumer &consumer)
573+ {
574+ if (!isInitDone ())
575+ return ;
576+
577+ auto it = consumer.m_toSync .begin ();
578+ while (it != consumer.m_toSync .end ())
579+ {
580+ auto &t = it->second ;
581+
582+ /* Retrieve LAG alias and LAG member alias from key */
532583 string key = kfvKey (t);
533584 size_t found = key.find (' :' );
534- string lag_alias, port_alias;
585+ /* Return if the format of key is wrong */
535586 if (found == string::npos)
536- lag_alias = key;
537- else
538587 {
539- lag_alias = key.substr ( 0 , found );
540- port_alias = key. substr (found+ 1 ) ;
588+ SWSS_LOG_ERROR ( " Failed to parse %s " , key.c_str () );
589+ return ;
541590 }
591+ string lag_alias = key.substr (0 , found);
592+ string port_alias = key.substr (found+1 );
542593
543594 string op = kfvOp (t);
544595
545- /* Manipulate LAG when port_alias is empty */
546- if (port_alias == " " )
596+ Port lag, port;
597+ if (! getPort (lag_alias, lag) )
547598 {
548- if (op == SET_COMMAND)
599+ SWSS_LOG_INFO (" Failed to locate LAG %s" , lag_alias.c_str ());
600+ it++;
601+ continue ;
602+ }
603+
604+ if (!getPort (port_alias, port))
605+ {
606+ SWSS_LOG_ERROR (" Failed to locate port %s" , port_alias.c_str ());
607+ it = consumer.m_toSync .erase (it);
608+ continue ;
609+ }
610+
611+ /* Update a LAG member */
612+ if (op == SET_COMMAND)
613+ {
614+ string status;
615+ for (auto i : kfvFieldsValues (t))
616+ {
617+ if (fvField (i) == " status" )
618+ status = fvValue (i);
619+ }
620+
621+ /* Sync an enabled member */
622+ if (status == " enabled" )
549623 {
550624 /* Duplicate entry */
551- if (m_portList. find (lag_alias ) != m_portList .end ())
625+ if (lag. m_members . find (port_alias ) != lag. m_members .end ())
552626 {
553627 it = consumer.m_toSync .erase (it);
554628 continue ;
555629 }
556630
557- if (addLag (lag_alias))
631+ /* Assert the port doesn't belong to any LAG */
632+ assert (!port.m_lag_id && !port.m_lag_member_id );
633+
634+ if (addLagMember (lag, port))
558635 it = consumer.m_toSync .erase (it);
559636 else
560637 it++;
561638 }
562- else if (op == DEL_COMMAND)
639+ /* Sync an disabled member */
640+ else /* status == "disabled" */
563641 {
564- Port lag;
565- /* Cannot locate LAG */
566- if (!getPort (lag_alias, lag) )
642+ /* "status" is "disabled" at start when m_lag_id and
643+ * m_lag_member_id are absent */
644+ if (!port. m_lag_id || !port. m_lag_member_id )
567645 {
568646 it = consumer.m_toSync .erase (it);
569647 continue ;
570648 }
571649
572- if (removeLag (lag))
650+ if (removeLagMember (lag, port ))
573651 it = consumer.m_toSync .erase (it);
574652 else
575653 it++;
576654 }
577- else
578- {
579- SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
580- it = consumer.m_toSync .erase (it);
581- }
582655 }
583- /* Manipulate a LAG member */
584- else
656+ /* Remove a LAG member */
657+ else if (op == DEL_COMMAND)
585658 {
586- assert (m_portList. find (lag_alias) != m_portList. end ());
587- Port lag, port ;
659+ /* Assert the LAG member exists */
660+ assert ( lag. m_members . find (port_alias) != lag. m_members . end ()) ;
588661
589- /* When LAG member is to be created before LAG is created */
590- if (!getPort (lag_alias, lag))
591- {
592- SWSS_LOG_INFO (" Failed to locate LAG %s" , lag_alias.c_str ());
593- it++;
594- continue ;
595- }
662+ /* Assert the port belongs to a LAG */
663+ assert (port.m_lag_id && port.m_lag_member_id );
596664
597- if (!getPort (port_alias, port))
598- {
599- SWSS_LOG_ERROR (" Failed to locate port %s" , port_alias.c_str ());
665+ if (removeLagMember (lag, port))
600666 it = consumer.m_toSync .erase (it);
601- continue ;
602- }
603-
604- /* Add a LAG member */
605- if (op == SET_COMMAND)
606- {
607- string status;
608- for (auto i : kfvFieldsValues (t))
609- {
610- if (fvField (i) == " status" )
611- status = fvValue (i);
612- }
613-
614- /* Sync an enabled member */
615- if (status == " enabled" )
616- {
617- /* Duplicate entry */
618- if (lag.m_members .find (port_alias) != lag.m_members .end ())
619- {
620- it = consumer.m_toSync .erase (it);
621- continue ;
622- }
623-
624- /* Assert the port doesn't belong to any LAG */
625- assert (!port.m_lag_id && !port.m_lag_member_id );
626-
627- if (addLagMember (lag, port))
628- it = consumer.m_toSync .erase (it);
629- else
630- it++;
631- }
632- /* Sync an disabled member */
633- else /* status == "disabled" */
634- {
635- /* "status" is "disabled" at start when m_lag_id and
636- * m_lag_member_id are absent */
637- if (!port.m_lag_id || !port.m_lag_member_id )
638- {
639- it = consumer.m_toSync .erase (it);
640- continue ;
641- }
642-
643- if (removeLagMember (lag, port))
644- it = consumer.m_toSync .erase (it);
645- else
646- it++;
647- }
648- }
649- /* Remove a LAG member */
650- else if (op == DEL_COMMAND)
651- {
652- /* Assert the LAG member exists */
653- assert (lag.m_members .find (port_alias) != lag.m_members .end ());
654-
655- /* Assert the port belongs to a LAG */
656- assert (port.m_lag_id && port.m_lag_member_id );
657-
658- if (removeLagMember (lag, port))
659- it = consumer.m_toSync .erase (it);
660- else
661- it++;
662- }
663667 else
664- {
665- SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
666- it = consumer.m_toSync .erase (it);
667- }
668+ it++;
669+ }
670+ else
671+ {
672+ SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
673+ it = consumer.m_toSync .erase (it);
668674 }
669675 }
670676}
@@ -681,6 +687,8 @@ void PortsOrch::doTask(Consumer &consumer)
681687 doVlanTask (consumer);
682688 else if (table_name == APP_LAG_TABLE_NAME)
683689 doLagTask (consumer);
690+ else if (table_name == APP_LAG_MEMBER_TABLE_NAME)
691+ doLagMemberTask (consumer);
684692}
685693
686694void PortsOrch::initializeQueues (Port &port)
0 commit comments