@@ -15,7 +15,8 @@ extern sai_vlan_api_t *sai_vlan_api;
15
15
extern sai_lag_api_t *sai_lag_api;
16
16
extern sai_hostif_api_t * sai_hostif_api;
17
17
18
- #define VLAN_PREFIX " Vlan"
18
+ #define VLAN_PREFIX " Vlan"
19
+ #define DEFAULT_VLAN_ID 1
19
20
20
21
PortsOrch::PortsOrch (DBConnector *db, vector<string> tableNames) :
21
22
Orch(db, tableNames)
@@ -92,10 +93,10 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
92
93
status = sai_switch_api->get_switch_attribute (1 , &attr);
93
94
if (status != SAI_STATUS_SUCCESS)
94
95
{
95
- SWSS_LOG_ERROR (" \n " );
96
+ SWSS_LOG_ERROR (" Failed to get port list " );
96
97
}
97
98
98
- /* Get port lane info */
99
+ /* Get port hardware lane info */
99
100
for (i = 0 ; i < (int )m_portCount; i++)
100
101
{
101
102
sai_uint32_t lanes[4 ];
@@ -124,7 +125,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
124
125
m_portListLaneMap[tmp_lane_set] = port_list[i];
125
126
}
126
127
127
- /* Set port hardware learn mode */
128
+ /* Set port to hardware learn mode */
128
129
for (i = 0 ; i < (int )m_portCount; i++)
129
130
{
130
131
attr.id = SAI_PORT_ATTR_FDB_LEARNING;
@@ -133,7 +134,29 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
133
134
status = sai_port_api->set_port_attribute (port_list[i], &attr);
134
135
if (status != SAI_STATUS_SUCCESS)
135
136
{
136
- SWSS_LOG_ERROR (" Failed to set port hardware learn mode pid:%llx\n " , port_list[i]);
137
+ SWSS_LOG_ERROR (" Failed to set port to hardware learn mode pid:%llx\n " , port_list[i]);
138
+ }
139
+ }
140
+
141
+ /* Get default VLAN member list */
142
+ sai_object_id_t *vlan_member_list = new sai_object_id_t [m_portCount];
143
+ attr.id = SAI_VLAN_ATTR_MEMBER_LIST;
144
+ attr.value .objlist .count = m_portCount;
145
+ attr.value .objlist .list = vlan_member_list;
146
+
147
+ status = sai_vlan_api->get_vlan_attribute (DEFAULT_VLAN_ID, 1 , &attr);
148
+ if (status != SAI_STATUS_SUCCESS)
149
+ {
150
+ SWSS_LOG_ERROR (" Failed to get default VLAN member list" );
151
+ }
152
+
153
+ /* Remove port from default VLAN */
154
+ for (i = 0 ; i < (int )m_portCount; i++)
155
+ {
156
+ status = sai_vlan_api->remove_vlan_member (vlan_member_list[i]);
157
+ if (status != SAI_STATUS_SUCCESS)
158
+ {
159
+ SWSS_LOG_ERROR (" Failed to remove port from default VLAN %d" , i);
137
160
}
138
161
}
139
162
}
@@ -663,7 +686,21 @@ bool PortsOrch::addVlanMember(Port vlan, Port port)
663
686
SWSS_LOG_NOTICE (" Add member %s to VLAN %s vid:%hu pid%llx" ,
664
687
port.m_alias .c_str (), vlan.m_alias .c_str (), vlan.m_vlan_id , port.m_port_id );
665
688
689
+ attr.id = SAI_PORT_ATTR_PORT_VLAN_ID;
690
+ attr.value .u16 = vlan.m_vlan_id ;
691
+
692
+ status = sai_port_api->set_port_attribute (port.m_port_id , &attr);
693
+ if (status != SAI_STATUS_SUCCESS)
694
+ {
695
+ SWSS_LOG_ERROR (" Failed to set port VLAN ID vid:%hu pid:%llx" ,
696
+ vlan.m_vlan_id , port.m_port_id );
697
+ return false ;
698
+ }
699
+
700
+ SWSS_LOG_NOTICE (" Set port %s VLAN ID to %hu" , port.m_alias .c_str (), vlan.m_vlan_id );
701
+
666
702
port.m_vlan_id = vlan.m_vlan_id ;
703
+ port.m_port_vlan_id = vlan.m_vlan_id ;
667
704
port.m_vlan_member_id = vlan_member_id;
668
705
m_portList[port.m_alias ] = port;
669
706
vlan.m_members .insert (port.m_alias );
@@ -688,7 +725,20 @@ bool PortsOrch::removeVlanMember(Port vlan, Port port)
688
725
SWSS_LOG_ERROR (" Remove member %s from VLAN %s lid:%hx vmid:%llx" ,
689
726
port.m_alias .c_str (), vlan.m_alias .c_str (), vlan.m_vlan_id , port.m_vlan_member_id );
690
727
728
+ sai_attribute_t attr;
729
+ attr.id = SAI_PORT_ATTR_PORT_VLAN_ID;
730
+ attr.value .u16 = DEFAULT_PORT_VLAN_ID;
731
+
732
+ status = sai_port_api->set_port_attribute (port.m_port_id , &attr);
733
+ if (status != SAI_STATUS_SUCCESS)
734
+ {
735
+ SWSS_LOG_ERROR (" Failed to reset port VLAN ID to DEFAULT_PORT_VLAN_ID pid:%llx" ,
736
+ port.m_port_id );
737
+ return false ;
738
+ }
739
+
691
740
port.m_vlan_id = 0 ;
741
+ port.m_port_vlan_id = DEFAULT_PORT_VLAN_ID;
692
742
port.m_vlan_member_id = 0 ;
693
743
m_portList[port.m_alias ] = port;
694
744
vlan.m_members .erase (port.m_alias );
0 commit comments