@@ -47,6 +47,11 @@ static const vector<sai_queue_stat_t> queueStatIds =
47
47
SAI_QUEUE_STAT_DROPPED_BYTES
48
48
};
49
49
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
+ };
50
55
/*
51
56
* Initialize PortsOrch
52
57
* 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)
563
568
return true ;
564
569
}
565
570
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
+
566
615
bool PortsOrch::validatePortSpeed (sai_object_id_t port_id, sai_uint32_t speed)
567
616
{
568
617
sai_attribute_t attr;
@@ -1633,7 +1682,7 @@ bool PortsOrch::initializePort(Port &p)
1633
1682
initializeQueues (p);
1634
1683
1635
1684
/* 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 );
1637
1686
1638
1687
#if 0
1639
1688
// TODO: Assure if_nametoindex(p.m_alias.c_str()) != 0
@@ -1661,7 +1710,7 @@ bool PortsOrch::initializePort(Port &p)
1661
1710
return true ;
1662
1711
}
1663
1712
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)
1665
1714
{
1666
1715
SWSS_LOG_ENTER ();
1667
1716
@@ -1673,7 +1722,7 @@ bool PortsOrch::addHostIntfs(sai_object_id_t id, string alias, sai_object_id_t &
1673
1722
attrs.push_back (attr);
1674
1723
1675
1724
attr.id = SAI_HOSTIF_ATTR_OBJ_ID;
1676
- attr.value .oid = id ;
1725
+ attr.value .oid = port. m_port_id ;
1677
1726
attrs.push_back (attr);
1678
1727
1679
1728
attr.id = SAI_HOSTIF_ATTR_NAME;
@@ -1738,6 +1787,12 @@ bool PortsOrch::addBridgePort(Port &port)
1738
1787
return false ;
1739
1788
}
1740
1789
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
+ }
1741
1796
m_portList[port.m_alias ] = port;
1742
1797
SWSS_LOG_NOTICE (" Add bridge port %s to default 1Q bridge" , port.m_alias .c_str ());
1743
1798
@@ -1765,6 +1820,13 @@ bool PortsOrch::removeBridgePort(Port &port)
1765
1820
return false ;
1766
1821
}
1767
1822
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
+
1768
1830
/* Flush FDB entries pointing to this bridge port */
1769
1831
// TODO: Remove all FDB entries associated with this bridge port before
1770
1832
// removing the bridge port itself
@@ -2047,6 +2109,15 @@ bool PortsOrch::addLagMember(Port &lag, Port &port)
2047
2109
2048
2110
m_portList[lag.m_alias ] = lag;
2049
2111
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
+ }
2050
2121
sai_uint32_t pvid;
2051
2122
if (getPortPvid (lag, pvid))
2052
2123
{
@@ -2079,6 +2150,15 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port)
2079
2150
lag.m_members .erase (port.m_alias );
2080
2151
m_portList[lag.m_alias ] = lag;
2081
2152
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
+ }
2082
2162
LagMemberUpdate update = { lag, port, false };
2083
2163
notify (SUBJECT_TYPE_LAG_MEMBER_CHANGE, static_cast <void *>(&update));
2084
2164
0 commit comments