From c0d99472c194afcd486b45477ceefd619e4a351f Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Fri, 13 Mar 2020 18:18:26 +0100 Subject: [PATCH] [vs] Fix setting correct port mtu value (#573) --- vslib/src/SwitchStateBase.cpp | 21 +++++++++++++++++++++ vslib/src/SwitchStateBaseHostif.cpp | 20 +++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/vslib/src/SwitchStateBase.cpp b/vslib/src/SwitchStateBase.cpp index 1a92ac8254ae..8ac4c6486a86 100644 --- a/vslib/src/SwitchStateBase.cpp +++ b/vslib/src/SwitchStateBase.cpp @@ -393,6 +393,27 @@ sai_status_t SwitchStateBase::setPort( } } } + else if (attr && attr->id == SAI_PORT_ATTR_MTU && m_switchConfig->m_useTapDevice) + { + uint32_t mtu = attr->value.u32; + + std::string name; + + if (getTapNameFromPortId(portId, name)) + { + SWSS_LOG_INFO("setting new MTU: %d on %s", mtu, name.c_str()); + + std::string vname = vs_get_veth_name(name, portId); + + if (vs_set_dev_mtu(name.c_str(), mtu) < 0 || vs_set_dev_mtu(vname.c_str(), mtu) < 0) + { + SWSS_LOG_ERROR("failed to set MTU on portId %s", + sai_serialize_object_id(portId).c_str()); + + return SAI_STATUS_FAILURE; + } + } + } auto sid = sai_serialize_object_id(portId); diff --git a/vslib/src/SwitchStateBaseHostif.cpp b/vslib/src/SwitchStateBaseHostif.cpp index fff2d0286626..1d25afd7817b 100644 --- a/vslib/src/SwitchStateBaseHostif.cpp +++ b/vslib/src/SwitchStateBaseHostif.cpp @@ -634,15 +634,29 @@ sai_status_t SwitchStateBase::vs_create_hostif_tap_interface( return SAI_STATUS_FAILURE; } - vs_set_dev_mtu(name.c_str(), ETH_FRAME_BUFFER_SIZE); + std::string vname = vs_get_veth_name(name, obj_id); + + int mtu = ETH_FRAME_BUFFER_SIZE; + + sai_attribute_t attrmtu; + + attrmtu.id = SAI_PORT_ATTR_MTU; + + if (get(SAI_OBJECT_TYPE_PORT, obj_id, 1, &attrmtu) == SAI_STATUS_SUCCESS) + { + mtu = attrmtu.value.u32; + + SWSS_LOG_INFO("setting new MTU: %d on %s", mtu, vname.c_str()); + } + + vs_set_dev_mtu(name.c_str(), mtu); + vs_set_dev_mtu(vname.c_str(), mtu); if (!hostif_create_tap_veth_forwarding(name, tapfd, obj_id)) { SWSS_LOG_ERROR("forwarding rule on %s was not added", name.c_str()); } - std::string vname = vs_get_veth_name(name, obj_id); - SWSS_LOG_INFO("mapping interface %s to port id %s", vname.c_str(), sai_serialize_object_id(obj_id).c_str());