Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle default VLAN create and delete #929

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 33 additions & 5 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,21 @@ PortsOrch::PortsOrch(DBConnector *db, vector<table_name_with_pri_t> &tableNames)
}

m_default1QBridge = attrs[0].value.oid;
m_defaultVlan = attrs[1].value.oid;
m_defaultVlan_ObjId = attrs[1].value.oid;

memset(&attr, 0x00, sizeof(attr));
attr.id = SAI_VLAN_ATTR_VLAN_ID;

/* Get the VLAN ID associated with the default VLAN object */
status = sai_vlan_api->get_vlan_attribute(m_defaultVlan_ObjId, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get default VLAN ID, rv:%d", status);
throw runtime_error("PortsOrch initialization failure");
}

m_defaultVlan_Id = attr.value.u16;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you put the default VLAN into the m_portList? Then we don't need to handle special case in the function addVlan.


removeDefaultVlanMembers();
removeDefaultBridgePorts();
Expand All @@ -318,7 +332,7 @@ void PortsOrch::removeDefaultVlanMembers()
attr.value.objlist.count = (uint32_t)vlan_member_list.size();
attr.value.objlist.list = vlan_member_list.data();

sai_status_t status = sai_vlan_api->get_vlan_attribute(m_defaultVlan, 1, &attr);
sai_status_t status = sai_vlan_api->get_vlan_attribute(m_defaultVlan_ObjId, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get VLAN member list in default VLAN, rv:%d", status);
Expand Down Expand Up @@ -2578,7 +2592,17 @@ bool PortsOrch::addVlan(string vlan_alias)
sai_attribute_t attr;
attr.id = SAI_VLAN_ATTR_VLAN_ID;
attr.value.u16 = vlan_id;
sai_status_t status = sai_vlan_api->create_vlan(&vlan_oid, gSwitchId, 1, &attr);
sai_status_t status = SAI_STATUS_SUCCESS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default VLAN is in the m_portList, there's no need to modify this function.


/* Do not create default VLAN. It is already created by default */
if (vlan_id != m_defaultVlan_Id)
{
status = sai_vlan_api->create_vlan(&vlan_oid, gSwitchId, 1, &attr);
}
else
{
vlan_oid = m_defaultVlan_ObjId; /* use the default VLAN object id instead */
}

if (status != SAI_STATUS_SUCCESS)
{
Expand Down Expand Up @@ -2608,12 +2632,16 @@ bool PortsOrch::removeVlan(Port vlan)
return false;
}

sai_status_t status = sai_vlan_api->remove_vlan(vlan.m_vlan_info.vlan_oid);
if (status != SAI_STATUS_SUCCESS)
/* Do not delete default VLAN from driver, but clear internal state */
if (vlan.m_vlan_info.vlan_id != m_defaultVlan_Id)
{
sai_status_t status = sai_vlan_api->remove_vlan(vlan.m_vlan_info.vlan_oid);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove VLAN %s vid:%hu",
vlan.m_alias.c_str(), vlan.m_vlan_info.vlan_id);
return false;
}
}

removeAclTableGroup(vlan);
Expand Down
3 changes: 2 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class PortsOrch : public Orch, public Subject
Port m_cpuPort;
// TODO: Add Bridge/Vlan class
sai_object_id_t m_default1QBridge;
sai_object_id_t m_defaultVlan;
sai_object_id_t m_defaultVlan_ObjId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the PR. The logic looks valid to me. Could you modify the type of the current m_defaultVlan to type Port? Then you could use m_vlan_info to store both the oid and the id of the VLAN. This would prevent having more private variables.

sai_vlan_id_t m_defaultVlan_Id;

bool m_portConfigDone = false;
sai_uint32_t m_portCount;
Expand Down