Skip to content

Commit ff90429

Browse files
jipanyanglguohan
authored andcommitted
Orchagent: Host interface tag processing (sonic-net#328)
* 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 <[email protected]> * By default vlan tag is stripped, no need to set SAI_HOSTIF_VLAN_TAG_STRIP explicitly at init. Signed-off-by: Jipan Yang <[email protected]>
1 parent b10be94 commit ff90429

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

orchagent/portsorch.cpp

+83-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ static const vector<sai_queue_stat_t> queueStatIds =
4747
SAI_QUEUE_STAT_DROPPED_BYTES
4848
};
4949

50+
static char* hostif_vlan_tag[] = {
51+
[SAI_HOSTIF_VLAN_TAG_STRIP] = "SAI_HOSTIF_VLAN_TAG_STRIP",
52+
[SAI_HOSTIF_VLAN_TAG_KEEP] = "SAI_HOSTIF_VLAN_TAG_KEEP",
53+
[SAI_HOSTIF_VLAN_TAG_ORIGINAL] = "SAI_HOSTIF_VLAN_TAG_ORIGINAL"
54+
};
5055
/*
5156
* Initialize PortsOrch
5257
* 0) By default, a switch has one CPU port, one 802.1Q bridge, and one default
@@ -563,6 +568,50 @@ bool PortsOrch::getPortPvid(Port &port, sai_uint32_t &pvid)
563568
return true;
564569
}
565570

571+
bool PortsOrch::setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip)
572+
{
573+
SWSS_LOG_ENTER();
574+
vector<Port> portv;
575+
576+
/*
577+
* Before SAI_HOSTIF_VLAN_TAG_ORIGINAL is supported by libsai from all asic vendors,
578+
* the VLAN tag on hostif is explicitly controlled with SAI_HOSTIF_VLAN_TAG_STRIP &
579+
* SAI_HOSTIF_VLAN_TAG_KEEP attributes.
580+
*/
581+
if (port.m_type == Port::PHY)
582+
{
583+
portv.push_back(port);
584+
}
585+
else if (port.m_type == Port::LAG)
586+
{
587+
getLagMember(port, portv);
588+
}
589+
else
590+
{
591+
SWSS_LOG_ERROR("port type %d not supported", port.m_type);
592+
return false;
593+
}
594+
595+
for (const auto p: portv)
596+
{
597+
sai_attribute_t attr;
598+
attr.id = SAI_HOSTIF_ATTR_VLAN_TAG;
599+
attr.value.s32 = strip;
600+
601+
sai_status_t status = sai_hostif_api->set_hostif_attribute(p.m_hif_id, &attr);
602+
if (status != SAI_STATUS_SUCCESS)
603+
{
604+
SWSS_LOG_ERROR("Failed to set %s to host interface %s",
605+
hostif_vlan_tag[strip], p.m_alias.c_str());
606+
return false;
607+
}
608+
SWSS_LOG_NOTICE("Set %s to host interface: %s",
609+
hostif_vlan_tag[strip], p.m_alias.c_str());
610+
}
611+
612+
return true;
613+
}
614+
566615
bool PortsOrch::validatePortSpeed(sai_object_id_t port_id, sai_uint32_t speed)
567616
{
568617
sai_attribute_t attr;
@@ -1633,7 +1682,7 @@ bool PortsOrch::initializePort(Port &p)
16331682
initializeQueues(p);
16341683

16351684
/* Create host interface */
1636-
addHostIntfs(p.m_port_id, p.m_alias, p.m_hif_id);
1685+
addHostIntfs(p, p.m_alias, p.m_hif_id);
16371686

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

1664-
bool PortsOrch::addHostIntfs(sai_object_id_t id, string alias, sai_object_id_t &host_intfs_id)
1713+
bool PortsOrch::addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id)
16651714
{
16661715
SWSS_LOG_ENTER();
16671716

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

16751724
attr.id = SAI_HOSTIF_ATTR_OBJ_ID;
1676-
attr.value.oid = id;
1725+
attr.value.oid = port.m_port_id;
16771726
attrs.push_back(attr);
16781727

16791728
attr.id = SAI_HOSTIF_ATTR_NAME;
@@ -1738,6 +1787,12 @@ bool PortsOrch::addBridgePort(Port &port)
17381787
return false;
17391788
}
17401789

1790+
if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_KEEP))
1791+
{
1792+
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s",
1793+
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_KEEP], port.m_alias.c_str());
1794+
return false;
1795+
}
17411796
m_portList[port.m_alias] = port;
17421797
SWSS_LOG_NOTICE("Add bridge port %s to default 1Q bridge", port.m_alias.c_str());
17431798

@@ -1765,6 +1820,13 @@ bool PortsOrch::removeBridgePort(Port &port)
17651820
return false;
17661821
}
17671822

1823+
if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_STRIP))
1824+
{
1825+
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s",
1826+
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_STRIP], port.m_alias.c_str());
1827+
return false;
1828+
}
1829+
17681830
/* Flush FDB entries pointing to this bridge port */
17691831
// TODO: Remove all FDB entries associated with this bridge port before
17701832
// removing the bridge port itself
@@ -2047,6 +2109,15 @@ bool PortsOrch::addLagMember(Port &lag, Port &port)
20472109

20482110
m_portList[lag.m_alias] = lag;
20492111

2112+
if (lag.m_bridge_port_id > 0)
2113+
{
2114+
if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_KEEP))
2115+
{
2116+
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s which is in LAG %s",
2117+
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_KEEP], port.m_alias.c_str(), lag.m_alias.c_str());
2118+
return false;
2119+
}
2120+
}
20502121
sai_uint32_t pvid;
20512122
if (getPortPvid(lag, pvid))
20522123
{
@@ -2079,6 +2150,15 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
20792150
lag.m_members.erase(port.m_alias);
20802151
m_portList[lag.m_alias] = lag;
20812152

2153+
if (lag.m_bridge_port_id > 0)
2154+
{
2155+
if (!setHostIntfsStripTag(port, SAI_HOSTIF_VLAN_TAG_STRIP))
2156+
{
2157+
SWSS_LOG_ERROR("Failed to set %s for hostif of port %s which is leaving LAG %s",
2158+
hostif_vlan_tag[SAI_HOSTIF_VLAN_TAG_STRIP], port.m_alias.c_str(), lag.m_alias.c_str());
2159+
return false;
2160+
}
2161+
}
20822162
LagMemberUpdate update = { lag, port, false };
20832163
notify(SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast<void *>(&update));
20842164

orchagent/portsorch.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class PortsOrch : public Orch, public Subject
9696
void initializePriorityGroups(Port &port);
9797
void initializeQueues(Port &port);
9898

99-
bool addHostIntfs(sai_object_id_t router_intfs_id, string alias, sai_object_id_t &host_intfs_id);
99+
bool addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id);
100+
bool setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip);
100101

101102
bool addBridgePort(Port &port);
102103
bool removeBridgePort(Port &port);

0 commit comments

Comments
 (0)