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

Orchagent: Host interface tag processing #328

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 83 additions & 3 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ static const vector<sai_queue_stat_t> queueStatIds =
SAI_QUEUE_STAT_DROPPED_BYTES
};

static char* hostif_vlan_tag[] = {
[SAI_HOSTIF_VLAN_TAG_STRIP] = "SAI_HOSTIF_VLAN_TAG_STRIP",
[SAI_HOSTIF_VLAN_TAG_KEEP] = "SAI_HOSTIF_VLAN_TAG_KEEP",
[SAI_HOSTIF_VLAN_TAG_ORIGINAL] = "SAI_HOSTIF_VLAN_TAG_ORIGINAL"
};
/*
* Initialize PortsOrch
* 0) By default, a switch has one CPU port, one 802.1Q bridge, and one default
Expand Down Expand Up @@ -563,6 +568,50 @@ bool PortsOrch::getPortPvid(Port &port, sai_uint32_t &pvid)
return true;
}

bool PortsOrch::setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip)
{
SWSS_LOG_ENTER();
vector<Port> portv;

/*
* Before SAI_HOSTIF_VLAN_TAG_ORIGINAL is supported by libsai from all asic vendors,
* the VLAN tag on hostif is explicitly controlled with SAI_HOSTIF_VLAN_TAG_STRIP &
* SAI_HOSTIF_VLAN_TAG_KEEP attributes.
*/
if (port.m_type == Port::PHY)
{
portv.push_back(port);
}
else if (port.m_type == Port::LAG)
{
getLagMember(port, portv);
}
else
{
SWSS_LOG_ERROR("port type %d not supported", port.m_type);
return false;
}

for (const auto p: portv)
{
sai_attribute_t attr;
attr.id = SAI_HOSTIF_ATTR_VLAN_TAG;
attr.value.s32 = strip;

sai_status_t status = sai_hostif_api->set_hostif_attribute(p.m_hif_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set %s to host interface %s",
hostif_vlan_tag[strip], p.m_alias.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

align the spaces, or just use 8 spaces. same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return false;
}
SWSS_LOG_NOTICE("Set %s to host interface: %s",
hostif_vlan_tag[strip], p.m_alias.c_str());
}

return true;
}

bool PortsOrch::validatePortSpeed(sai_object_id_t port_id, sai_uint32_t speed)
{
sai_attribute_t attr;
Expand Down Expand Up @@ -1633,7 +1682,7 @@ bool PortsOrch::initializePort(Port &p)
initializeQueues(p);

/* Create host interface */
addHostIntfs(p.m_port_id, p.m_alias, p.m_hif_id);
addHostIntfs(p, p.m_alias, p.m_hif_id);

#if 0
// TODO: Assure if_nametoindex(p.m_alias.c_str()) != 0
Expand Down Expand Up @@ -1661,7 +1710,7 @@ bool PortsOrch::initializePort(Port &p)
return true;
}

bool PortsOrch::addHostIntfs(sai_object_id_t id, string alias, sai_object_id_t &host_intfs_id)
bool PortsOrch::addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id)
{
SWSS_LOG_ENTER();

Expand All @@ -1673,7 +1722,7 @@ bool PortsOrch::addHostIntfs(sai_object_id_t id, string alias, sai_object_id_t &
attrs.push_back(attr);

attr.id = SAI_HOSTIF_ATTR_OBJ_ID;
attr.value.oid = id;
attr.value.oid = port.m_port_id;
attrs.push_back(attr);

attr.id = SAI_HOSTIF_ATTR_NAME;
Expand Down Expand Up @@ -1738,6 +1787,12 @@ bool PortsOrch::addBridgePort(Port &port)
return false;
}

if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_KEEP))
{
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s",
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_KEEP], port.m_alias.c_str());
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this to addVlanMember(), in the untagged mode, we do not need to call KEEP.

m_portList[port.m_alias] = port;
SWSS_LOG_NOTICE("Add bridge port %s to default 1Q bridge", port.m_alias.c_str());

Expand Down Expand Up @@ -1765,6 +1820,13 @@ bool PortsOrch::removeBridgePort(Port &port)
return false;
}

if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_STRIP))
{
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s",
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_STRIP], port.m_alias.c_str());
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to removeVlanMember()


/* Flush FDB entries pointing to this bridge port */
// TODO: Remove all FDB entries associated with this bridge port before
// removing the bridge port itself
Expand Down Expand Up @@ -2047,6 +2109,15 @@ bool PortsOrch::addLagMember(Port &lag, Port &port)

m_portList[lag.m_alias] = lag;

if (lag.m_bridge_port_id > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

also check if the port belongs to multiple vlans or not, if yes then add keep, otherwise do not need to do anything.

{
if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_KEEP))
{
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s which is in LAG %s",
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_KEEP], port.m_alias.c_str(), lag.m_alias.c_str());
return false;
}
}
sai_uint32_t pvid;
if (getPortPvid(lag, pvid))
{
Expand Down Expand Up @@ -2079,6 +2150,15 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
lag.m_members.erase(port.m_alias);
m_portList[lag.m_alias] = lag;

if (lag.m_bridge_port_id > 0)
{
if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_STRIP))
{
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s which is leaving LAG %s",
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_STRIP], port.m_alias.c_str(), lag.m_alias.c_str());
return false;
}
}
LagMemberUpdate update = { lag, port, false };
notify(SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast<void *>(&update));

Expand Down
3 changes: 2 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class PortsOrch : public Orch, public Subject
void initializePriorityGroups(Port &port);
void initializeQueues(Port &port);

bool addHostIntfs(sai_object_id_t router_intfs_id, string alias, sai_object_id_t &host_intfs_id);
bool addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id);
bool setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip);

bool addBridgePort(Port &port);
bool removeBridgePort(Port &port);
Expand Down