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

[subintf] Fix kernel mtu inheritance from parent #1874

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
142 changes: 126 additions & 16 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
m_cfgVlanIntfTable(cfgDb, CFG_VLAN_INTF_TABLE_NAME),
m_cfgLagIntfTable(cfgDb, CFG_LAG_INTF_TABLE_NAME),
m_cfgLoopbackIntfTable(cfgDb, CFG_LOOPBACK_INTERFACE_TABLE_NAME),
m_cfgSubIntfTable(cfgDb, CFG_VLAN_SUB_INTF_TABLE_NAME),
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME),
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME),
m_stateVlanTable(stateDb, STATE_VLAN_TABLE_NAME),
m_stateVrfTable(stateDb, STATE_VRF_TABLE_NAME),
m_stateIntfTable(stateDb, STATE_INTERFACE_TABLE_NAME),
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME)
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME),
m_appPortTable(appDb, APP_PORT_TABLE_NAME),
m_appLagTable(appDb, APP_LAG_TABLE_NAME)
{
if (!WarmStart::isWarmStart())
{
Expand Down Expand Up @@ -449,6 +452,107 @@ bool IntfMgr::isIntfStateOk(const string &alias)
return false;
}

bool IntfMgr::doHostSubIntfUpdateTask(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))
{
return false;
}

string mtu = "";
string parentAdminStatus = "";
for (const auto &fv : fvTuples)
{
if (fvField(fv) == "mtu")
{
mtu = fvValue(fv);
}
else if (fvField(fv) == "admin_status")
{
parentAdminStatus = fvValue(fv);
}
}

if (!mtu.empty())
{
for (const auto &alias : m_portSubIntfSet[parentAlias])
{
try
{
setHostSubIntfMtu(alias, mtu);
}
catch (const std::runtime_error &e)
{
SWSS_LOG_DEBUG("Sub interface ip link set mtu %s failure. Runtime error: %s", mtu.c_str(), e.what());
return false;
}
SWSS_LOG_INFO("Sub interface %s ip link set mtu %s succeeded", alias.c_str(), mtu.c_str());
}
}

if (parentAdminStatus == "up")
{
string parentAdminStatusAppDb;
if (!parentAlias.compare(0, strlen(LAG_PREFIX), LAG_PREFIX))
{
m_appLagTable.hget(parentAlias, "admin_status", parentAdminStatusAppDb);
}
else
{
m_appPortTable.hget(parentAlias, "admin_status", parentAdminStatusAppDb);
}
if (parentAdminStatusAppDb != parentAdminStatus)
{
// Parent port admin status has not yet been synced from config db to appl db, which
// indicates that parent port admin status at kernel has not yet been updated from
// down to up by portmgrd.
return false;
}

for (const auto &alias : m_portSubIntfSet[parentAlias])
{
string adminStatus;
if (!m_cfgSubIntfTable.hget(alias, "admin_status", adminStatus))
{
adminStatus = "up";
}

if (adminStatus == "down")
{
try
{
setHostSubIntfAdminStatus(alias, adminStatus);
}
catch (const std::runtime_error &e)
{
SWSS_LOG_DEBUG("Sub interface ip link set admin status %s failure. Runtime error: %s", adminStatus.c_str(), e.what());
return false;
}
SWSS_LOG_INFO("Sub interface %s ip link set admin status %s succeeded", alias.c_str(), adminStatus.c_str());
}
}
}
}
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 @@ -591,25 +695,15 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
}

m_subIntfList.insert(alias);
m_portSubIntfSet[parentAlias].insert(alias);
}

if (!mtu.empty())
{
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
{
FieldValueTuple fvTuple("mtu", MTU_INHERITANCE);
data.push_back(fvTuple);
SWSS_LOG_NOTICE("Sub interface inherits parent port mtu. User mtu %s ignored", mtu.c_str());
}
FieldValueTuple fvTuple("mtu", MTU_INHERITANCE);
data.push_back(fvTuple);

if (adminStatus.empty())
{
Expand Down Expand Up @@ -701,6 +795,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
removeHostSubIntf(alias);
m_subIntfList.erase(alias);
m_portSubIntfSet[parentAlias].erase(alias);

removeSubIntfState(alias);
}
Expand Down Expand Up @@ -789,7 +884,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 (!doHostSubIntfUpdateTask(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 @@ -799,6 +908,7 @@ void IntfMgr::doTask(Consumer &consumer)
it = consumer.m_toSync.erase(it);
continue;
}

if (!doIntfGeneralTask(keys, data, op))
{
it++;
Expand Down
7 changes: 5 additions & 2 deletions cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ class IntfMgr : public Orch

private:
ProducerStateTable m_appIntfTableProducer;
Table m_cfgIntfTable, m_cfgVlanIntfTable, m_cfgLagIntfTable, m_cfgLoopbackIntfTable;
Table m_cfgIntfTable, m_cfgVlanIntfTable, m_cfgLagIntfTable, m_cfgLoopbackIntfTable, m_cfgSubIntfTable;
Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable, m_stateIntfTable;
Table m_appPortTable, m_appLagTable;

std::set<std::string> m_subIntfList;
std::unordered_set<std::string> m_subIntfList;
std::unordered_map<std::string, std::unordered_set<std::string>> m_portSubIntfSet;
std::set<std::string> m_loopbackIntfList;
std::set<std::string> m_pendingReplayIntfList;

Expand All @@ -33,6 +35,7 @@ class IntfMgr : public Orch

bool doIntfGeneralTask(const std::vector<std::string>& keys, std::vector<FieldValueTuple> data, const std::string& op);
bool doIntfAddrTask(const std::vector<std::string>& keys, const std::vector<FieldValueTuple>& data, const std::string& op);
bool doHostSubIntfUpdateTask(const std::vector<std::string>& keys, const std::vector<FieldValueTuple>& data, const std::string& op);
void doTask(Consumer &consumer);

bool isIntfStateOk(const std::string &alias);
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
Loading