55#include < sstream>
66#include < set>
77
8+ #include < netinet/if_ether.h>
89#include " net/if.h"
910
1011#include " logger.h"
@@ -223,6 +224,25 @@ bool PortsOrch::setPortAdminStatus(sai_object_id_t id, bool up)
223224 return true ;
224225}
225226
227+ bool PortsOrch::setPortMtu (sai_object_id_t id, sai_uint32_t mtu)
228+ {
229+ SWSS_LOG_ENTER ();
230+
231+ sai_attribute_t attr;
232+ attr.id = SAI_PORT_ATTR_MTU;
233+ /* mtu + 14 + 4 + 4 = 22 bytes */
234+ attr.value .u32 = mtu + sizeof (struct ether_header ) + FCS_LEN + VLAN_TAG_LEN;
235+
236+ sai_status_t status = sai_port_api->set_port_attribute (id, &attr);
237+ if (status != SAI_STATUS_SUCCESS)
238+ {
239+ SWSS_LOG_ERROR (" Failed to set MTU %u to port pid:%lx" , attr.value .u32 , id);
240+ return false ;
241+ }
242+ SWSS_LOG_INFO (" Set MTU %u to port pid:%lx" , attr.value .u32 , id);
243+ return true ;
244+ }
245+
226246bool PortsOrch::setHostIntfsOperStatus (sai_object_id_t port_id, bool up)
227247{
228248 SWSS_LOG_ENTER ();
@@ -303,6 +323,8 @@ void PortsOrch::doPortTask(Consumer &consumer)
303323 {
304324 set<int > lane_set;
305325 string admin_status;
326+ uint32_t mtu = 0 ;
327+
306328 for (auto i : kfvFieldsValues (t))
307329 {
308330 /* Get lane information of a physical port and initialize the port */
@@ -322,6 +344,10 @@ void PortsOrch::doPortTask(Consumer &consumer)
322344 /* Set port admin status */
323345 if (fvField (i) == " admin_status" )
324346 admin_status = fvValue (i);
347+
348+ /* Set port mtu */
349+ if (fvField (i) == " mtu" )
350+ mtu = stoul (fvValue (i));
325351 }
326352
327353 if (lane_set.size ())
@@ -385,6 +411,24 @@ void PortsOrch::doPortTask(Consumer &consumer)
385411 else
386412 SWSS_LOG_ERROR (" Failed to get port id by alias:%s" , alias.c_str ());
387413 }
414+
415+ if (mtu != 0 )
416+ {
417+ Port p;
418+ if (getPort (alias, p))
419+ {
420+ if (setPortMtu (p.m_port_id , mtu))
421+ SWSS_LOG_NOTICE (" Set port %s MTU to %u" , alias.c_str (), mtu);
422+ else
423+ {
424+ SWSS_LOG_ERROR (" Failed to set port %s MTU to %u" , alias.c_str (), mtu);
425+ it++;
426+ continue ;
427+ }
428+ }
429+ else
430+ SWSS_LOG_ERROR (" Failed to get port id by alias:%s" , alias.c_str ());
431+ }
388432 }
389433 else
390434 SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
0 commit comments