Skip to content

Commit

Permalink
[vs] Fix setting correct port mtu value (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Mar 13, 2020
1 parent fe94170 commit c0d9947
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
21 changes: 21 additions & 0 deletions vslib/src/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 17 additions & 3 deletions vslib/src/SwitchStateBaseHostif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c0d9947

Please sign in to comment.