@@ -745,35 +745,15 @@ bool PortsOrch::getPort(sai_object_id_t id, Port &port)
745
745
{
746
746
SWSS_LOG_ENTER ();
747
747
748
- for (const auto & portIter: m_portList)
748
+ auto itr = saiOidToAlias.find (id);
749
+ if (itr == saiOidToAlias.end ())
749
750
{
750
- switch (portIter.second .m_type )
751
- {
752
- case Port::PHY:
753
- case Port::SYSTEM:
754
- if (portIter.second .m_port_id == id)
755
- {
756
- port = portIter.second ;
757
- return true ;
758
- }
759
- break ;
760
- case Port::LAG:
761
- if (portIter.second .m_lag_id == id)
762
- {
763
- port = portIter.second ;
764
- return true ;
765
- }
766
- break ;
767
- case Port::VLAN:
768
- if (portIter.second .m_vlan_info .vlan_oid == id)
769
- {
770
- port = portIter.second ;
771
- return true ;
772
- }
773
- break ;
774
- default :
775
- continue ;
776
- }
751
+ return false ;
752
+ }
753
+ else
754
+ {
755
+ getPort (itr->second , port);
756
+ return true ;
777
757
}
778
758
779
759
return false ;
@@ -813,13 +793,15 @@ bool PortsOrch::getPortByBridgePortId(sai_object_id_t bridge_port_id, Port &port
813
793
{
814
794
SWSS_LOG_ENTER ();
815
795
816
- for (auto &it: m_portList)
796
+ auto itr = saiOidToAlias.find (bridge_port_id);
797
+ if (itr == saiOidToAlias.end ())
817
798
{
818
- if (it.second .m_bridge_port_id == bridge_port_id)
819
- {
820
- port = it.second ;
821
- return true ;
822
- }
799
+ return false ;
800
+ }
801
+ else
802
+ {
803
+ getPort (itr->second , port);
804
+ return true ;
823
805
}
824
806
825
807
return false ;
@@ -2358,6 +2340,7 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
2358
2340
2359
2341
/* Add port to port list */
2360
2342
m_portList[alias] = p;
2343
+ saiOidToAlias[id] = alias;
2361
2344
m_port_ref_count[alias] = 0 ;
2362
2345
m_portOidToIndex[id] = index ;
2363
2346
@@ -3558,7 +3541,7 @@ void PortsOrch::doVlanMemberTask(Consumer &consumer)
3558
3541
{
3559
3542
if (removeVlanMember (vlan, port))
3560
3543
{
3561
- if (port.m_vlan_members .empty ())
3544
+ if (m_portVlanMember[ port.m_alias ] .empty ())
3562
3545
{
3563
3546
removeBridgePort (port);
3564
3547
}
@@ -3661,7 +3644,6 @@ void PortsOrch::doLagTask(Consumer &consumer)
3661
3644
switch_id = -1 ;
3662
3645
}
3663
3646
3664
- // Create a new LAG when the new alias comes
3665
3647
if (m_portList.find (alias) == m_portList.end ())
3666
3648
{
3667
3649
if (!addLag (alias, lag_id, switch_id))
@@ -4331,6 +4313,7 @@ bool PortsOrch::addBridgePort(Port &port)
4331
4313
return false ;
4332
4314
}
4333
4315
m_portList[port.m_alias ] = port;
4316
+ saiOidToAlias[port.m_bridge_port_id ] = port.m_alias ;
4334
4317
SWSS_LOG_NOTICE (" Add bridge port %s to default 1Q bridge" , port.m_alias .c_str ());
4335
4318
4336
4319
PortUpdate update = { port, true };
@@ -4387,6 +4370,7 @@ bool PortsOrch::removeBridgePort(Port &port)
4387
4370
return parseHandleSaiStatusFailure (handle_status);
4388
4371
}
4389
4372
}
4373
+ saiOidToAlias.erase (port.m_bridge_port_id );
4390
4374
port.m_bridge_port_id = SAI_NULL_OBJECT_ID;
4391
4375
4392
4376
/* Remove bridge port */
@@ -4460,7 +4444,7 @@ bool PortsOrch::addVlan(string vlan_alias)
4460
4444
}
4461
4445
}
4462
4446
4463
- SWSS_LOG_NOTICE (" Create an empty VLAN %s vid:%hu" , vlan_alias.c_str (), vlan_id);
4447
+ SWSS_LOG_NOTICE (" Create an empty VLAN %s vid:%hu vlan_oid:% " PRIx64 , vlan_alias.c_str (), vlan_id, vlan_oid );
4464
4448
4465
4449
Port vlan (vlan_alias, Port::VLAN);
4466
4450
vlan.m_vlan_info .vlan_oid = vlan_oid;
@@ -4470,6 +4454,7 @@ bool PortsOrch::addVlan(string vlan_alias)
4470
4454
vlan.m_members = set<string>();
4471
4455
m_portList[vlan_alias] = vlan;
4472
4456
m_port_ref_count[vlan_alias] = 0 ;
4457
+ saiOidToAlias[vlan_oid] = vlan_alias;
4473
4458
4474
4459
return true ;
4475
4460
}
@@ -4478,6 +4463,13 @@ bool PortsOrch::removeVlan(Port vlan)
4478
4463
{
4479
4464
SWSS_LOG_ENTER ();
4480
4465
4466
+ /* If there are still fdb entries associated with the VLAN,
4467
+ return false for retry */
4468
+ if (vlan.m_fdb_count > 0 )
4469
+ {
4470
+ SWSS_LOG_NOTICE (" VLAN %s still has assiciated FDB entries" , vlan.m_alias .c_str ());
4471
+ return false ;
4472
+ }
4481
4473
if (m_port_ref_count[vlan.m_alias ] > 0 )
4482
4474
{
4483
4475
SWSS_LOG_ERROR (" Failed to remove ref count %d VLAN %s" ,
@@ -4525,6 +4517,7 @@ bool PortsOrch::removeVlan(Port vlan)
4525
4517
SWSS_LOG_NOTICE (" Remove VLAN %s vid:%hu" , vlan.m_alias .c_str (),
4526
4518
vlan.m_vlan_info .vlan_id );
4527
4519
4520
+ saiOidToAlias.erase (vlan.m_vlan_info .vlan_oid );
4528
4521
m_portList.erase (vlan.m_alias );
4529
4522
m_port_ref_count.erase (vlan.m_alias );
4530
4523
@@ -4614,7 +4607,7 @@ bool PortsOrch::addVlanMember(Port &vlan, Port &port, string &tagging_mode, stri
4614
4607
4615
4608
/* a physical port may join multiple vlans */
4616
4609
VlanMemberEntry vme = {vlan_member_id, sai_tagging_mode};
4617
- port.m_vlan_members [vlan.m_vlan_info .vlan_id ] = vme;
4610
+ m_portVlanMember[ port.m_alias ] [vlan.m_vlan_info .vlan_id ] = vme;
4618
4611
m_portList[port.m_alias ] = port;
4619
4612
vlan.m_members .insert (port.m_alias );
4620
4613
m_portList[vlan.m_alias ] = vlan;
@@ -4625,6 +4618,12 @@ bool PortsOrch::addVlanMember(Port &vlan, Port &port, string &tagging_mode, stri
4625
4618
return true ;
4626
4619
}
4627
4620
4621
+ bool PortsOrch::getPortVlanMembers (Port &port, vlan_members_t &vlan_members)
4622
+ {
4623
+ vlan_members = m_portVlanMember[port.m_alias ];
4624
+ return true ;
4625
+ }
4626
+
4628
4627
bool PortsOrch::addVlanFloodGroups (Port &vlan, Port &port, string end_point_ip)
4629
4628
{
4630
4629
SWSS_LOG_ENTER ();
@@ -4844,10 +4843,10 @@ bool PortsOrch::removeVlanMember(Port &vlan, Port &port, string end_point_ip)
4844
4843
}
4845
4844
sai_object_id_t vlan_member_id;
4846
4845
sai_vlan_tagging_mode_t sai_tagging_mode;
4847
- auto vlan_member = port.m_vlan_members .find (vlan.m_vlan_info .vlan_id );
4846
+ auto vlan_member = m_portVlanMember[ port.m_alias ] .find (vlan.m_vlan_info .vlan_id );
4848
4847
4849
4848
/* Assert the port belongs to this VLAN */
4850
- assert (vlan_member != port.m_vlan_members .end ());
4849
+ assert (vlan_member != m_portVlanMember[ port.m_alias ] .end ());
4851
4850
sai_tagging_mode = vlan_member->second .vlan_mode ;
4852
4851
vlan_member_id = vlan_member->second .vlan_member_id ;
4853
4852
@@ -4862,7 +4861,11 @@ bool PortsOrch::removeVlanMember(Port &vlan, Port &port, string end_point_ip)
4862
4861
return parseHandleSaiStatusFailure (handle_status);
4863
4862
}
4864
4863
}
4865
- port.m_vlan_members .erase (vlan_member);
4864
+ m_portVlanMember[port.m_alias ].erase (vlan_member);
4865
+ if (m_portVlanMember[port.m_alias ].empty ())
4866
+ {
4867
+ m_portVlanMember.erase (port.m_alias );
4868
+ }
4866
4869
SWSS_LOG_NOTICE (" Remove member %s from VLAN %s lid:%hx vmid:%" PRIx64,
4867
4870
port.m_alias .c_str (), vlan.m_alias .c_str (), vlan.m_vlan_info .vlan_id , vlan_member_id);
4868
4871
@@ -4905,6 +4908,20 @@ bool PortsOrch::addLag(string lag_alias, uint32_t spa_id, int32_t switch_id)
4905
4908
{
4906
4909
SWSS_LOG_ENTER ();
4907
4910
4911
+ auto lagport = m_portList.find (lag_alias);
4912
+ if (lagport != m_portList.end ())
4913
+ {
4914
+ /* The deletion of bridgeport attached to the lag may still be
4915
+ * pending due to fdb entries still present on the lag. Wait
4916
+ * until the cleanup is done.
4917
+ */
4918
+ if (m_portList[lag_alias].m_bridge_port_id != SAI_NULL_OBJECT_ID)
4919
+ {
4920
+ return false ;
4921
+ }
4922
+ return true ;
4923
+ }
4924
+
4908
4925
vector<sai_attribute_t > lag_attrs;
4909
4926
string system_lag_alias = lag_alias;
4910
4927
@@ -4956,6 +4973,7 @@ bool PortsOrch::addLag(string lag_alias, uint32_t spa_id, int32_t switch_id)
4956
4973
lag.m_members = set<string>();
4957
4974
m_portList[lag_alias] = lag;
4958
4975
m_port_ref_count[lag_alias] = 0 ;
4976
+ saiOidToAlias[lag_id] = lag_alias;
4959
4977
4960
4978
PortUpdate update = { lag, true };
4961
4979
notify (SUBJECT_TYPE_PORT_CHANGE, static_cast <void *>(&update));
@@ -5004,12 +5022,17 @@ bool PortsOrch::removeLag(Port lag)
5004
5022
SWSS_LOG_ERROR (" Failed to remove non-empty LAG %s" , lag.m_alias .c_str ());
5005
5023
return false ;
5006
5024
}
5007
- if (lag.m_vlan_members .size () > 0 )
5025
+ if (m_portVlanMember[ lag.m_alias ] .size () > 0 )
5008
5026
{
5009
5027
SWSS_LOG_ERROR (" Failed to remove LAG %s, it is still in VLAN" , lag.m_alias .c_str ());
5010
5028
return false ;
5011
5029
}
5012
5030
5031
+ if (lag.m_bridge_port_id != SAI_NULL_OBJECT_ID)
5032
+ {
5033
+ return false ;
5034
+ }
5035
+
5013
5036
sai_status_t status = sai_lag_api->remove_lag (lag.m_lag_id );
5014
5037
if (status != SAI_STATUS_SUCCESS)
5015
5038
{
@@ -5023,6 +5046,7 @@ bool PortsOrch::removeLag(Port lag)
5023
5046
5024
5047
SWSS_LOG_NOTICE (" Remove LAG %s lid:%" PRIx64, lag.m_alias .c_str (), lag.m_lag_id );
5025
5048
5049
+ saiOidToAlias.erase (lag.m_lag_id );
5026
5050
m_portList.erase (lag.m_alias );
5027
5051
m_port_ref_count.erase (lag.m_alias );
5028
5052
0 commit comments