Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub intf mtu intf #3

Draft
wants to merge 3 commits into
base: sub_intf_vnet
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,58 @@ bool IntfMgr::isIntfStateOk(const string &alias)
return false;
}

bool IntfMgr::doSubIntfMtuTask(const vector<string>& keys,
const vector<FieldValueTuple> &fvTuples,
const string& op)
{
SWSS_LOG_ENTER();

string parentAlias(keys[0]);

if (op == SET_COMMAND)
{
if (!isIntfStateOk(parentAlias))
{
SWSS_LOG_INFO("Port %s is not ready, pending...", alias.c_str());
return false;
}

string mtu = "";
for (const auto &fv : fvTuples)
{
if (fvField(fv) == "mtu")
{
mtu = fvValue(fv);
}
}
if (!mtu.empty())
{
for (const auto &alias : m_portSubIntfSet[parentAlias])
{
try
{
setHostSubIntfMtu(alias, mtu);
}
catch (const std::runtime_error &e)
{
SWSS_LOG_NOTICE("Sub interface ip link set mtu failure. Runtime error: %s", e.what());
return false;
}
}
}
}
else if (op == DEL_COMMAND)
{
m_portSubIntfSet.erase(parentAlias);
}
else
{
SWSS_LOG_ERROR("Unknown operation: %s", op.c_str());
}

return true;
}

bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
vector<FieldValueTuple> data,
const string& op)
Expand Down Expand Up @@ -534,11 +586,15 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
SWSS_LOG_NOTICE("Sub interface ip link set mtu failure. Runtime error: %s", e.what());
return false;
}

m_portSubIntfSet[parentAlias].erase(alias);
}
else
{
FieldValueTuple fvTuple("mtu", MTU_INHERITANCE);
data.push_back(fvTuple);

m_portSubIntfSet[parentAlias].insert(alias);
}

if (adminStatus.empty())
Expand Down Expand Up @@ -720,7 +776,21 @@ void IntfMgr::doTask(Consumer &consumer)

if (keys.size() == 1)
{
if((table_name == CFG_VOQ_INBAND_INTERFACE_TABLE_NAME) &&
if ((table_name == CFG_PORT_TABLE_NAME)
|| (table_name == CFG_LAG_TABLE_NAME))
{
if (!doSubIntfMtuTask(keys, data, op))
{
it++;
}
else
{
it = consumer.m_toSync.erase(it);
}
continue;
}

if ((table_name == CFG_VOQ_INBAND_INTERFACE_TABLE_NAME) &&
(op == SET_COMMAND))
{
//No further processing needed. Just relay to orchagent
Expand All @@ -730,6 +800,7 @@ void IntfMgr::doTask(Consumer &consumer)
it = consumer.m_toSync.erase(it);
continue;
}

if (!doIntfGeneralTask(keys, data, op))
{
it++;
Expand Down
2 changes: 2 additions & 0 deletions cfgmgr/intfmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int main(int argc, char **argv)
CFG_LOOPBACK_INTERFACE_TABLE_NAME,
CFG_VLAN_SUB_INTF_TABLE_NAME,
CFG_VOQ_INBAND_INTERFACE_TABLE_NAME,
CFG_PORT_TABLE_NAME,
CFG_LAG_TABLE_NAME,
};

DBConnector cfgDb("CONFIG_DB", 0);
Expand Down
42 changes: 42 additions & 0 deletions tests/test_sub_port_intf.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ def _access_function():

wait_for_result(_access_function)

def check_sub_port_intf_mtu_kernel(self, dvs, port_name, mtu):
(ec, out) = dvs.runcmd(['bash', '-c', "ip link show {} | grep 'mtu {}'".format(port_name, mtu)])
assert ec == 0
assert mtu in out

def check_sub_port_intf_vrf_bind_kernel(self, dvs, port_name, vrf_name):
(ec, out) = dvs.runcmd(['bash', '-c', "ip link show {} | grep {}".format(port_name, vrf_name)])
assert ec == 0
Expand Down Expand Up @@ -800,10 +805,44 @@ def _test_sub_port_intf_mtu(self, dvs, sub_port_intf_name, vrf_name=None):

rif_oid = self.get_newly_created_oid(ASIC_RIF_TABLE, old_rif_oids)

# Verify sub port interface mtu in linux kernel
self.check_sub_port_intf_mtu_kernel(dvs, sub_port_intf_name, DEFAULT_MTU)

# Change parent port mtu
mtu = "8888"
dvs.set_mtu(parent_port, mtu)

# Verify sub port interface mtu in linux kernel
self.check_sub_port_intf_mtu_kernel(dvs, sub_port_intf_name, mtu)

# Verify that sub port router interface entry in ASIC_DB has the updated mtu
fv_dict = {
"SAI_ROUTER_INTERFACE_ATTR_MTU": mtu,
"SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID": vrf_oid,
}
self.check_sub_port_intf_fvs(self.asic_db, ASIC_RIF_TABLE, rif_oid, fv_dict)

# Change parent port mtu
mtu = "6666"
dvs.set_mtu(parent_port, mtu)

# Verify sub port interface mtu in linux kernel
self.check_sub_port_intf_mtu_kernel(dvs, sub_port_intf_name, mtu)

# Verify that sub port router interface entry in ASIC_DB has the updated mtu
fv_dict = {
"SAI_ROUTER_INTERFACE_ATTR_MTU": mtu,
"SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID": vrf_oid,
}
self.check_sub_port_intf_fvs(self.asic_db, ASIC_RIF_TABLE, rif_oid, fv_dict)

# Change parent port mtu
mtu = "7777"
dvs.set_mtu(parent_port, mtu)

# Verify sub port interface mtu in linux kernel
self.check_sub_port_intf_mtu_kernel(dvs, sub_port_intf_name, mtu)

# Verify that sub port router interface entry in ASIC_DB has the updated mtu
fv_dict = {
"SAI_ROUTER_INTERFACE_ATTR_MTU": mtu,
Expand All @@ -814,6 +853,9 @@ def _test_sub_port_intf_mtu(self, dvs, sub_port_intf_name, vrf_name=None):
# Restore parent port mtu
dvs.set_mtu(parent_port, DEFAULT_MTU)

# Verify sub port interface mtu in linux kernel
self.check_sub_port_intf_mtu_kernel(dvs, sub_port_intf_name, DEFAULT_MTU)

# Verify that sub port router interface entry in ASIC_DB has the default mtu
fv_dict = {
"SAI_ROUTER_INTERFACE_ATTR_MTU": DEFAULT_MTU,
Expand Down