From 13347ab0c55167b3deae097d1e7584745af8d4cf Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Fri, 29 Sep 2017 14:02:19 -0700 Subject: [PATCH 1/2] 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 --- orchagent/portsorch.cpp | 91 +++++++++++++++++++++++++++++++++++++++-- orchagent/portsorch.h | 3 +- 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index e67559676c..5431f2c745 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -47,6 +47,11 @@ static const vector 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 @@ -542,6 +547,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 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; @@ -1567,7 +1616,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 @@ -1595,7 +1644,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(); @@ -1607,7 +1656,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; @@ -1621,6 +1670,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; @@ -1672,6 +1726,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()); @@ -1699,6 +1759,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 @@ -1981,6 +2048,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)) { @@ -2013,6 +2089,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(&update)); diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 2ddd84b7b3..ff942baf27 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -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); From 1a473c3f77a81c2bd25851f781c001a22c94e73c Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Wed, 29 Nov 2017 11:04:05 -0800 Subject: [PATCH 2/2] By default vlan tag is stripped, no need to set SAI_HOSTIF_VLAN_TAG_STRIP explicitly at init. Signed-off-by: Jipan Yang --- orchagent/portsorch.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 5431f2c745..550ebc6123 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1670,11 +1670,6 @@ bool PortsOrch::addHostIntfs(Port &port, string alias, sai_object_id_t &host_int 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;