Skip to content

Commit

Permalink
Remove ports from default VLAN at start and set port VLAN ID afterwar…
Browse files Browse the repository at this point in the history
…ds (sonic-net#43)

* orchagent: Adding logic to remove all ports from default VLAN

* orchagent: Adding set SAI_PORT_ATTR_PORT_VLAN_ID logic
- When joining a VLAN, set the port VLAN ID to VLAN ID
- When departing from a VLAN, reset the port VLAN ID to default 1
  • Loading branch information
stcheng authored Jul 11, 2016
1 parent f00fad6 commit 5b7e784
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
3 changes: 3 additions & 0 deletions orchagent/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extern "C" {
#include <set>
#include <string>

#define DEFAULT_PORT_VLAN_ID 1

namespace swss {

class Port
Expand Down Expand Up @@ -49,6 +51,7 @@ class Port
int m_ifindex = 0;
sai_object_id_t m_port_id = 0;
sai_vlan_id_t m_vlan_id = 0;
sai_vlan_id_t m_port_vlan_id = DEFAULT_PORT_VLAN_ID; // Port VLAN ID
sai_object_id_t m_vlan_member_id = 0;
sai_object_id_t m_rif_id = 0;
sai_object_id_t m_hif_id = 0;
Expand Down
60 changes: 55 additions & 5 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ extern sai_vlan_api_t *sai_vlan_api;
extern sai_lag_api_t *sai_lag_api;
extern sai_hostif_api_t* sai_hostif_api;

#define VLAN_PREFIX "Vlan"
#define VLAN_PREFIX "Vlan"
#define DEFAULT_VLAN_ID 1

PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
Orch(db, tableNames)
Expand Down Expand Up @@ -92,10 +93,10 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
status = sai_switch_api->get_switch_attribute(1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("\n");
SWSS_LOG_ERROR("Failed to get port list");
}

/* Get port lane info */
/* Get port hardware lane info */
for (i = 0; i < (int)m_portCount; i++)
{
sai_uint32_t lanes[4];
Expand Down Expand Up @@ -124,7 +125,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
m_portListLaneMap[tmp_lane_set] = port_list[i];
}

/* Set port hardware learn mode */
/* Set port to hardware learn mode */
for (i = 0; i < (int)m_portCount; i++)
{
attr.id = SAI_PORT_ATTR_FDB_LEARNING;
Expand All @@ -133,7 +134,29 @@ PortsOrch::PortsOrch(DBConnector *db, vector<string> tableNames) :
status = sai_port_api->set_port_attribute(port_list[i], &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set port hardware learn mode pid:%llx\n", port_list[i]);
SWSS_LOG_ERROR("Failed to set port to hardware learn mode pid:%llx\n", port_list[i]);
}
}

/* Get default VLAN member list */
sai_object_id_t *vlan_member_list = new sai_object_id_t[m_portCount];
attr.id = SAI_VLAN_ATTR_MEMBER_LIST;
attr.value.objlist.count = m_portCount;
attr.value.objlist.list = vlan_member_list;

status = sai_vlan_api->get_vlan_attribute(DEFAULT_VLAN_ID, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get default VLAN member list");
}

/* Remove port from default VLAN */
for (i = 0; i < (int)m_portCount; i++)
{
status = sai_vlan_api->remove_vlan_member(vlan_member_list[i]);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove port from default VLAN %d", i);
}
}
}
Expand Down Expand Up @@ -663,7 +686,21 @@ bool PortsOrch::addVlanMember(Port vlan, Port port)
SWSS_LOG_NOTICE("Add member %s to VLAN %s vid:%hu pid%llx",
port.m_alias.c_str(), vlan.m_alias.c_str(), vlan.m_vlan_id, port.m_port_id);

attr.id = SAI_PORT_ATTR_PORT_VLAN_ID;
attr.value.u16 = vlan.m_vlan_id;

status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set port VLAN ID vid:%hu pid:%llx",
vlan.m_vlan_id, port.m_port_id);
return false;
}

SWSS_LOG_NOTICE("Set port %s VLAN ID to %hu", port.m_alias.c_str(), vlan.m_vlan_id);

port.m_vlan_id = vlan.m_vlan_id;
port.m_port_vlan_id = vlan.m_vlan_id;
port.m_vlan_member_id = vlan_member_id;
m_portList[port.m_alias] = port;
vlan.m_members.insert(port.m_alias);
Expand All @@ -688,7 +725,20 @@ bool PortsOrch::removeVlanMember(Port vlan, Port port)
SWSS_LOG_ERROR("Remove member %s from VLAN %s lid:%hx vmid:%llx",
port.m_alias.c_str(), vlan.m_alias.c_str(), vlan.m_vlan_id, port.m_vlan_member_id);

sai_attribute_t attr;
attr.id = SAI_PORT_ATTR_PORT_VLAN_ID;
attr.value.u16 = DEFAULT_PORT_VLAN_ID;

status = sai_port_api->set_port_attribute(port.m_port_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to reset port VLAN ID to DEFAULT_PORT_VLAN_ID pid:%llx",
port.m_port_id);
return false;
}

port.m_vlan_id = 0;
port.m_port_vlan_id = DEFAULT_PORT_VLAN_ID;
port.m_vlan_member_id = 0;
m_portList[port.m_alias] = port;
vlan.m_members.erase(port.m_alias);
Expand Down

0 comments on commit 5b7e784

Please sign in to comment.