Skip to content

Commit

Permalink
Orchagent: Host interface tag processing (sonic-net#328)
Browse files Browse the repository at this point in the history
* Host interface tag processing

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.

When a port/LAG is in 1Q bridge, SAI_HOSTIF_VLAN_TAG_KEEP is set for SAI_HOSTIF_ATTR_VLAN_TAG, for all other cases SAI_HOSTIF_VLAN_TAG_STRIP will be used.

Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com>

* By default vlan tag is stripped, no need to set SAI_HOSTIF_VLAN_TAG_STRIP explicitly at init.

Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com>
  • Loading branch information
jipanyang authored and lguohan committed Dec 7, 2017
1 parent b10be94 commit ff90429
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
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());
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;
}
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;
}

/* 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)
{
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

0 comments on commit ff90429

Please sign in to comment.