Skip to content

Commit

Permalink
Host interface tag processing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jipanyang committed Oct 18, 2017
1 parent 8a26cf6 commit 6385898
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
91 changes: 88 additions & 3 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ extern sai_object_id_t gSwitchId;
#define VLAN_PREFIX "Vlan"
#define DEFAULT_VLAN_ID 1

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 @@ -413,6 +418,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("PortsOrch::setPortPvid 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 @@ -1358,7 +1407,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 @@ -1386,7 +1435,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 @@ -1398,7 +1447,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 All @@ -1412,6 +1461,11 @@ bool PortsOrch::addHostIntfs(sai_object_id_t id, string alias, sai_object_id_t &
return false;
}

/*
* Port has been removed from 1q bridge at PortsOrch constructor,
* also start stripping off VLAN tag.
*/
setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_STRIP);
SWSS_LOG_NOTICE("Create host interface for port %s", alias.c_str());

return true;
Expand Down Expand Up @@ -1463,6 +1517,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 @@ -1490,6 +1550,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 @@ -1772,6 +1839,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 @@ -1804,6 +1880,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 @@ -90,7 +90,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 6385898

Please sign in to comment.