Skip to content

Commit 6007e7f

Browse files
stepanblyschakShuotian Cheng
authored and
Shuotian Cheng
committed
[portmgrd]: Fix setting default port admin status and MTU (sonic-net#691)
This commit moves setting of default admin status and mtu to portmgrd to be aligned with other managers (e.g. teammgrd). It also fixes "N/A" admin status in "show interface status" output for ports which have no 'admin_status' field in config DB. Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 6c70f6d commit 6007e7f

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

cfgmgr/portmgr.cpp

+33-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
using namespace std;
1111
using namespace swss;
1212

13+
/* Port default admin status is down */
14+
#define DEFAULT_ADMIN_STATUS_STR "down"
15+
#define DEFAULT_MTU_STR "9100"
16+
1317
PortMgr::PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) :
1418
Orch(cfgDb, tableNames),
1519
m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME),
@@ -91,23 +95,44 @@ void PortMgr::doTask(Consumer &consumer)
9195
continue;
9296
}
9397

98+
string admin_status, mtu;
99+
100+
bool configured = (m_portList.find(alias) != m_portList.end());
101+
102+
/* If this is the first time we set port settings
103+
* assign default admin status and mtu
104+
*/
105+
if (!configured)
106+
{
107+
admin_status = DEFAULT_ADMIN_STATUS_STR;
108+
mtu = DEFAULT_MTU_STR;
109+
110+
m_portList.insert(alias);
111+
}
112+
94113
for (auto i : kfvFieldsValues(t))
95114
{
96115
if (fvField(i) == "mtu")
97116
{
98-
auto mtu = fvValue(i);
99-
setPortMtu(alias, mtu);
100-
SWSS_LOG_NOTICE("Configure %s MTU to %s",
101-
alias.c_str(), mtu.c_str());
117+
mtu = fvValue(i);
102118
}
103119
else if (fvField(i) == "admin_status")
104120
{
105-
auto status = fvValue(i);
106-
setPortAdminStatus(alias, status == "up");
107-
SWSS_LOG_NOTICE("Configure %s %s",
108-
alias.c_str(), status.c_str());
121+
admin_status = fvValue(i);
109122
}
110123
}
124+
125+
if (!mtu.empty())
126+
{
127+
setPortMtu(alias, mtu);
128+
SWSS_LOG_NOTICE("Configure %s MTU to %s", alias.c_str(), mtu.c_str());
129+
}
130+
131+
if (!admin_status.empty())
132+
{
133+
setPortAdminStatus(alias, admin_status == "up");
134+
SWSS_LOG_NOTICE("Configure %s admin status to %s", alias.c_str(), admin_status.c_str());
135+
}
111136
}
112137

113138
it = consumer.m_toSync.erase(it);

cfgmgr/portmgr.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class PortMgr : public Orch
2222
Table m_statePortTable;
2323
ProducerStateTable m_appPortTable;
2424

25+
set<string> m_portList;
26+
2527
void doTask(Consumer &consumer);
2628
bool setPortMtu(const string &alias, const string &mtu);
2729
bool setPortAdminStatus(const string &alias, const bool up);

cfgmgr/teammgr.h

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class TeamMgr : public Orch
2828
ProducerStateTable m_appPortTable;
2929
ProducerStateTable m_appLagTable;
3030

31-
set<string> m_portList;
3231
set<string> m_lagList;
3332

3433
MacAddress m_mac;

orchagent/portsorch.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -2286,12 +2286,6 @@ bool PortsOrch::initializePort(Port &p)
22862286
}
22872287
SWSS_LOG_DEBUG("initializePort %s with admin %s and oper %s", p.m_alias.c_str(), adminStatus.c_str(), operStatus.c_str());
22882288

2289-
/* Set port admin status to DOWN if attr missing */
2290-
if (adminStatus != "up")
2291-
{
2292-
setPortAdminStatus(p.m_port_id, false);
2293-
}
2294-
22952289
/**
22962290
* Create database port oper status as DOWN if attr missing
22972291
* This status will be updated when receiving port_oper_status_notification.

0 commit comments

Comments
 (0)