@@ -451,117 +451,145 @@ void PortsOrch::doVlanTask(Consumer &consumer)
451
451
/* Ensure the key starts with "Vlan" otherwise ignore */
452
452
if (strncmp (key.c_str (), VLAN_PREFIX, 4 ))
453
453
{
454
+ SWSS_LOG_ERROR (" Invalid key format. No 'Vlan' prefix: %s" , key.c_str ());
454
455
it = consumer.m_toSync .erase (it);
455
456
continue ;
456
457
}
457
458
458
- key = key.substr (4 );
459
- size_t found = key.find (' :' );
460
459
int vlan_id;
461
- string vlan_alias, port_alias;
462
- if (found == string::npos)
463
- vlan_id = stoi (key);
464
- else
465
- {
466
- vlan_id = stoi (key.substr (0 , found));
467
- port_alias = key.substr (found+1 );
468
- }
460
+ vlan_id = stoi (key.substr (4 )); // FIXME: might raise exception
469
461
462
+ string vlan_alias, port_alias;
470
463
vlan_alias = VLAN_PREFIX + to_string (vlan_id);
471
464
string op = kfvOp (t);
472
465
473
- /* Manipulate VLAN when port_alias is empty */
474
- if (port_alias == " " )
466
+ if (op == SET_COMMAND)
475
467
{
476
- if (op == SET_COMMAND)
468
+ /* Duplicate entry */
469
+ if (m_portList.find (vlan_alias) != m_portList.end ())
477
470
{
478
- /* Duplicate entry */
479
- if (m_portList.find (vlan_alias) != m_portList.end ())
480
- {
481
- it = consumer.m_toSync .erase (it);
482
- continue ;
483
- }
484
-
485
- if (addVlan (vlan_alias))
486
- it = consumer.m_toSync .erase (it);
487
- else
488
- it++;
471
+ it = consumer.m_toSync .erase (it);
472
+ continue ;
489
473
}
490
- else if (op == DEL_COMMAND)
491
- {
492
- Port vlan;
493
- getPort (vlan_alias, vlan);
494
474
495
- if (removeVlan (vlan))
496
- it = consumer.m_toSync .erase (it);
497
- else
498
- it++;
499
- }
475
+ if (addVlan (vlan_alias))
476
+ it = consumer.m_toSync .erase (it);
500
477
else
501
- {
502
- SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
478
+ it++;
479
+ }
480
+ else if (op == DEL_COMMAND)
481
+ {
482
+ Port vlan;
483
+ getPort (vlan_alias, vlan);
484
+
485
+ if (removeVlan (vlan))
503
486
it = consumer.m_toSync .erase (it);
504
- }
487
+ else
488
+ it++;
505
489
}
506
- /* Manipulate member */
507
490
else
508
491
{
509
- assert (m_portList.find (vlan_alias) != m_portList.end ());
510
- Port vlan, port;
492
+ SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
493
+ it = consumer.m_toSync .erase (it);
494
+ }
495
+ }
496
+ }
511
497
512
- /* When VLAN member is to be created before VLAN is created */
513
- if (!getPort (vlan_alias, vlan))
514
- {
515
- SWSS_LOG_INFO (" Failed to locate VLAN %s" , vlan_alias.c_str ());
516
- it++;
517
- continue ;
518
- }
498
+ void PortsOrch::doVlanMemberTask (Consumer &consumer)
499
+ {
500
+ if (!isInitDone ())
501
+ return ;
502
+
503
+ auto it = consumer.m_toSync .begin ();
504
+ while (it != consumer.m_toSync .end ())
505
+ {
506
+ auto &t = it->second ;
507
+
508
+ string key = kfvKey (t);
509
+
510
+ /* Ensure the key starts with "Vlan" otherwise ignore */
511
+ if (strncmp (key.c_str (), VLAN_PREFIX, 4 ))
512
+ {
513
+ SWSS_LOG_ERROR (" Invalid key format. No 'Vlan' prefix: %s" , key.c_str ());
514
+ it = consumer.m_toSync .erase (it);
515
+ continue ;
516
+ }
517
+
518
+ key = key.substr (4 );
519
+ size_t found = key.find (' :' );
520
+ int vlan_id;
521
+ string vlan_alias, port_alias;
522
+ if (found != string::npos)
523
+ {
524
+ vlan_id = stoi (key.substr (0 , found)); // FIXME: might raise exception
525
+ port_alias = key.substr (found+1 );
526
+ }
527
+ else
528
+ {
529
+ SWSS_LOG_ERROR (" Invalid key format. No member port is presented: %s" ,
530
+ kfvKey (t).c_str ());
531
+ it = consumer.m_toSync .erase (it);
532
+ continue ;
533
+ }
519
534
520
- if (!getPort (port_alias, port))
535
+ vlan_alias = VLAN_PREFIX + to_string (vlan_id);
536
+ string op = kfvOp (t);
537
+
538
+ assert (m_portList.find (vlan_alias) != m_portList.end ());
539
+ Port vlan, port;
540
+
541
+ /* When VLAN member is to be created before VLAN is created */
542
+ if (!getPort (vlan_alias, vlan))
543
+ {
544
+ SWSS_LOG_INFO (" Failed to locate VLAN %s" , vlan_alias.c_str ());
545
+ it++;
546
+ continue ;
547
+ }
548
+
549
+ if (!getPort (port_alias, port))
550
+ {
551
+ SWSS_LOG_ERROR (" Failed to locate port %s" , port_alias.c_str ());
552
+ it = consumer.m_toSync .erase (it);
553
+ continue ;
554
+ }
555
+
556
+ if (op == SET_COMMAND)
557
+ {
558
+ /* Duplicate entry */
559
+ if (vlan.m_members .find (port_alias) != vlan.m_members .end ())
521
560
{
522
- SWSS_LOG_ERROR (" Failed to locate port %s" , port_alias.c_str ());
523
561
it = consumer.m_toSync .erase (it);
524
562
continue ;
525
563
}
526
564
527
- if (op == SET_COMMAND)
528
- {
529
- /* Duplicate entry */
530
- if (vlan.m_members .find (port_alias) != vlan.m_members .end ())
531
- {
532
- it = consumer.m_toSync .erase (it);
533
- continue ;
534
- }
565
+ /* Assert the port doesn't belong to any VLAN */
566
+ assert (!port.m_vlan_id && !port.m_vlan_member_id );
535
567
536
- /* Assert the port doesn't belong to any VLAN */
537
- assert (!port.m_vlan_id && !port.m_vlan_member_id );
568
+ if (addVlanMember (vlan, port))
569
+ it = consumer.m_toSync .erase (it);
570
+ else
571
+ it++;
572
+ }
573
+ else if (op == DEL_COMMAND)
574
+ {
575
+ if (vlan.m_members .find (port_alias) != vlan.m_members .end ())
576
+ {
577
+ /* Assert the port belongs the a VLAN */
578
+ assert (port.m_vlan_id && port.m_vlan_member_id );
538
579
539
- if (addVlanMember (vlan, port))
580
+ if (removeVlanMember (vlan, port))
540
581
it = consumer.m_toSync .erase (it);
541
582
else
542
583
it++;
543
584
}
544
- else if (op == DEL_COMMAND)
545
- {
546
- if (vlan.m_members .find (port_alias) != vlan.m_members .end ())
547
- {
548
- /* Assert the port belongs the a VLAN */
549
- assert (port.m_vlan_id && port.m_vlan_member_id );
550
-
551
- if (removeVlanMember (vlan, port))
552
- it = consumer.m_toSync .erase (it);
553
- else
554
- it++;
555
- }
556
- else
557
- /* Cannot locate the VLAN */
558
- it = consumer.m_toSync .erase (it);
559
- }
560
585
else
561
- {
562
- SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
586
+ /* Cannot locate the VLAN */
563
587
it = consumer.m_toSync .erase (it);
564
- }
588
+ }
589
+ else
590
+ {
591
+ SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
592
+ it = consumer.m_toSync .erase (it);
565
593
}
566
594
}
567
595
}
@@ -732,6 +760,8 @@ void PortsOrch::doTask(Consumer &consumer)
732
760
doPortTask (consumer);
733
761
else if (table_name == APP_VLAN_TABLE_NAME)
734
762
doVlanTask (consumer);
763
+ else if (table_name == APP_VLAN_MEMBER_TABLE_NAME)
764
+ doVlanMemberTask (consumer);
735
765
else if (table_name == APP_LAG_TABLE_NAME)
736
766
doLagTask (consumer);
737
767
else if (table_name == APP_LAG_MEMBER_TABLE_NAME)
0 commit comments