@@ -1932,6 +1932,55 @@ bool PortsOrch::setHostIntfsOperStatus(const Port& port, bool isUp) const
1932
1932
return true ;
1933
1933
}
1934
1934
1935
+ bool PortsOrch::createVlanHostIntf (Port& vl, string hostif_name)
1936
+ {
1937
+ SWSS_LOG_ENTER ();
1938
+
1939
+ if (vl.m_vlan_info .host_intf_id != SAI_NULL_OBJECT_ID)
1940
+ {
1941
+ SWSS_LOG_ERROR (" Host interface already assigned to VLAN %d" , vl.m_vlan_info .vlan_id );
1942
+ return false ;
1943
+ }
1944
+
1945
+ vector<sai_attribute_t > attrs;
1946
+ sai_attribute_t attr;
1947
+
1948
+ attr.id = SAI_HOSTIF_ATTR_TYPE;
1949
+ attr.value .s32 = SAI_HOSTIF_TYPE_NETDEV;
1950
+ attrs.push_back (attr);
1951
+
1952
+ attr.id = SAI_HOSTIF_ATTR_OBJ_ID;
1953
+ attr.value .oid = vl.m_vlan_info .vlan_oid ;
1954
+ attrs.push_back (attr);
1955
+
1956
+ attr.id = SAI_HOSTIF_ATTR_NAME;
1957
+ strncpy (attr.value .chardata , hostif_name.c_str (), sizeof (attr.value .chardata ));
1958
+ attrs.push_back (attr);
1959
+
1960
+ sai_status_t status = sai_hostif_api->create_hostif (&vl.m_vlan_info .host_intf_id , gSwitchId , (uint32_t )attrs.size (), attrs.data ());
1961
+ if (status != SAI_STATUS_SUCCESS)
1962
+ {
1963
+ SWSS_LOG_ERROR (" Failed to create host interface %s for VLAN %d" , hostif_name.c_str (), vl.m_vlan_info .vlan_id );
1964
+ return false ;
1965
+ }
1966
+
1967
+ m_portList[vl.m_alias ] = vl;
1968
+
1969
+ return true ;
1970
+ }
1971
+
1972
+ bool PortsOrch::removeVlanHostIntf (Port vl)
1973
+ {
1974
+ sai_status_t status = sai_hostif_api->remove_hostif (vl.m_vlan_info .host_intf_id );
1975
+ if (status != SAI_STATUS_SUCCESS)
1976
+ {
1977
+ SWSS_LOG_ERROR (" Failed to remove VLAN %d host interface" , vl.m_vlan_info .vlan_id );
1978
+ return false ;
1979
+ }
1980
+
1981
+ return true ;
1982
+ }
1983
+
1935
1984
void PortsOrch::updateDbPortOperStatus (const Port& port, sai_port_oper_status_t status) const
1936
1985
{
1937
1986
SWSS_LOG_ENTER ();
@@ -2870,6 +2919,7 @@ void PortsOrch::doVlanTask(Consumer &consumer)
2870
2919
// Retrieve attributes
2871
2920
uint32_t mtu = 0 ;
2872
2921
MacAddress mac;
2922
+ string hostif_name = " " ;
2873
2923
for (auto i : kfvFieldsValues (t))
2874
2924
{
2875
2925
if (fvField (i) == " mtu" )
@@ -2880,6 +2930,10 @@ void PortsOrch::doVlanTask(Consumer &consumer)
2880
2930
{
2881
2931
mac = MacAddress (fvValue (i));
2882
2932
}
2933
+ if (fvField (i) == " hostif_name" )
2934
+ {
2935
+ hostif_name = fvValue (i);
2936
+ }
2883
2937
}
2884
2938
2885
2939
/*
@@ -2922,6 +2976,16 @@ void PortsOrch::doVlanTask(Consumer &consumer)
2922
2976
gIntfsOrch ->setRouterIntfsMac (vl);
2923
2977
}
2924
2978
}
2979
+ if (!hostif_name.empty ())
2980
+ {
2981
+ if (!createVlanHostIntf (vl, hostif_name))
2982
+ {
2983
+ // No need to fail in case of error as this is for monitoring VLAN.
2984
+ // Error message is printed by "createVlanHostIntf" so just handle failure gracefully.
2985
+ it = consumer.m_toSync .erase (it);
2986
+ continue ;
2987
+ }
2988
+ }
2925
2989
}
2926
2990
2927
2991
it = consumer.m_toSync .erase (it);
@@ -3914,6 +3978,13 @@ bool PortsOrch::removeVlan(Port vlan)
3914
3978
return false ;
3915
3979
}
3916
3980
3981
+
3982
+ if (vlan.m_vlan_info .host_intf_id && !removeVlanHostIntf (vlan))
3983
+ {
3984
+ SWSS_LOG_ERROR (" Failed to remove VLAN %d host interface" , vlan.m_vlan_info .vlan_id );
3985
+ return false ;
3986
+ }
3987
+
3917
3988
sai_status_t status = sai_vlan_api->remove_vlan (vlan.m_vlan_info .vlan_oid );
3918
3989
if (status != SAI_STATUS_SUCCESS)
3919
3990
{
0 commit comments