Skip to content

Commit 6f30ddd

Browse files
Remove update of mgmt oper status in swss (#3439)
Currently operational status of mgmt interface is not present or correct for multi-asic devices. Why I did it Initial PR that added mgmt oper status feature in swss: #630 sonic-net/sonic-buildimage#21245 adds a script to update oper status of management interface periodically. In doing so, we no longer need to update oper status of mgmt interface in swss. --------- Signed-off-by: Suvarna Meenakshi <[email protected]>
1 parent 381c014 commit 6f30ddd

File tree

3 files changed

+3
-97
lines changed

3 files changed

+3
-97
lines changed

portsyncd/linksync.cpp

+2-61
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ using namespace swss;
2727
#define VLAN_DRV_NAME "bridge"
2828
#define TEAM_DRV_NAME "team"
2929

30-
const string MGMT_PREFIX = "eth";
3130
const string INTFS_PREFIX = "Ethernet";
3231
const string LAG_PREFIX = "PortChannel";
3332

@@ -38,57 +37,11 @@ extern string g_switchType;
3837
LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
3938
m_portTableProducer(appl_db, APP_PORT_TABLE_NAME),
4039
m_portTable(appl_db, APP_PORT_TABLE_NAME),
41-
m_statePortTable(state_db, STATE_PORT_TABLE_NAME),
42-
m_stateMgmtPortTable(state_db, STATE_MGMT_PORT_TABLE_NAME)
40+
m_statePortTable(state_db, STATE_PORT_TABLE_NAME)
4341
{
4442
std::shared_ptr<struct if_nameindex> if_ni(if_nameindex(), if_freenameindex);
4543
struct if_nameindex *idx_p;
4644

47-
for (idx_p = if_ni.get();
48-
idx_p != NULL && idx_p->if_index != 0 && idx_p->if_name != NULL;
49-
idx_p++)
50-
{
51-
string key = idx_p->if_name;
52-
53-
/* Explicitly store management ports oper status into the state database.
54-
* This piece of information is used by SNMP. */
55-
if (!key.compare(0, MGMT_PREFIX.length(), MGMT_PREFIX))
56-
{
57-
ostringstream cmd;
58-
string res;
59-
cmd << "cat /sys/class/net/" << shellquote(key) << "/operstate";
60-
try
61-
{
62-
EXEC_WITH_ERROR_THROW(cmd.str(), res);
63-
}
64-
catch (...)
65-
{
66-
SWSS_LOG_WARN("Failed to get %s oper status", key.c_str());
67-
continue;
68-
}
69-
70-
/* Remove the trailing newline */
71-
if (res.length() >= 1 && res.at(res.length() - 1) == '\n')
72-
{
73-
res.erase(res.length() - 1);
74-
/* The value of operstate will be either up or down */
75-
if (res != "up" && res != "down")
76-
{
77-
SWSS_LOG_WARN("Unknown %s oper status %s",
78-
key.c_str(), res.c_str());
79-
}
80-
FieldValueTuple fv("oper_status", res);
81-
vector<FieldValueTuple> fvs;
82-
fvs.push_back(fv);
83-
84-
m_stateMgmtPortTable.set(key, fvs);
85-
SWSS_LOG_INFO("Store %s oper status %s to state DB",
86-
key.c_str(), res.c_str());
87-
}
88-
continue;
89-
}
90-
}
91-
9245
if (!WarmStart::isWarmStart())
9346
{
9447
/* See the comments for g_portSet in portsyncd.cpp */
@@ -168,8 +121,7 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
168121
string key = rtnl_link_get_name(link);
169122

170123
if (key.compare(0, INTFS_PREFIX.length(), INTFS_PREFIX) &&
171-
key.compare(0, LAG_PREFIX.length(), LAG_PREFIX) &&
172-
key.compare(0, MGMT_PREFIX.length(), MGMT_PREFIX))
124+
key.compare(0, LAG_PREFIX.length(), LAG_PREFIX))
173125
{
174126
return;
175127
}
@@ -197,17 +149,6 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
197149
nlmsg_type, key.c_str(), admin, oper, addrStr, ifindex, master);
198150
}
199151

200-
if (!key.compare(0, MGMT_PREFIX.length(), MGMT_PREFIX))
201-
{
202-
FieldValueTuple fv("oper_status", oper ? "up" : "down");
203-
vector<FieldValueTuple> fvs;
204-
fvs.push_back(fv);
205-
m_stateMgmtPortTable.set(key, fvs);
206-
SWSS_LOG_INFO("Store %s oper status %s to state DB",
207-
key.c_str(), oper ? "up" : "down");
208-
return;
209-
}
210-
211152
/* teamd instances are dealt in teamsyncd */
212153
if (type && !strcmp(type, TEAM_DRV_NAME))
213154
{

portsyncd/linksync.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LinkSync : public NetMsg
2020

2121
private:
2222
ProducerStateTable m_portTableProducer;
23-
Table m_portTable, m_statePortTable, m_stateMgmtPortTable;
23+
Table m_portTable, m_statePortTable;
2424

2525
std::map<unsigned int, std::string> m_ifindexNameMap;
2626
std::map<unsigned int, std::string> m_ifindexOldNameMap;

tests/mock_tests/portsyncd/portsyncd_ut.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,6 @@ namespace portsyncd_ut
187187

188188
namespace portsyncd_ut
189189
{
190-
TEST_F(PortSyncdTest, test_linkSyncInit)
191-
{
192-
if_ni_mock = populateNetDev();
193-
mockCmdStdcout = "up\n";
194-
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
195-
std::vector<std::string> keys;
196-
sync.m_stateMgmtPortTable.getKeys(keys);
197-
ASSERT_EQ(keys.size(), 1);
198-
ASSERT_EQ(keys.back(), "eth0");
199-
ASSERT_EQ(mockCallArgs.back(), "cat /sys/class/net/\"eth0\"/operstate");
200-
}
201-
202190
TEST_F(PortSyncdTest, test_cacheOldIfaces)
203191
{
204192
if_ni_mock = populateNetDevAdvanced();
@@ -295,29 +283,6 @@ namespace portsyncd_ut
295283
ASSERT_EQ(sync.m_statePortTable.get("Ethernet0", ovalues), false);
296284
}
297285

298-
TEST_F(PortSyncdTest, test_onMsgMgmtIface){
299-
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
300-
301-
/* Generate a netlink notification about the eth0 netdev iface */
302-
std::vector<unsigned int> flags = {IFF_UP};
303-
struct nl_object* msg = draft_nlmsg("eth0",
304-
flags,
305-
"",
306-
"00:50:56:28:0e:4a",
307-
16222,
308-
9100,
309-
0);
310-
sync.onMsg(RTM_NEWLINK, msg);
311-
312-
/* Verify if the update has been written to State DB */
313-
std::string oper_status;
314-
ASSERT_EQ(sync.m_stateMgmtPortTable.hget("eth0", "oper_status", oper_status), true);
315-
ASSERT_EQ(oper_status, "down");
316-
317-
/* Free Nl_object */
318-
free_nlobj(msg);
319-
}
320-
321286
TEST_F(PortSyncdTest, test_onMsgIgnoreOldNetDev){
322287
if_ni_mock = populateNetDevAdvanced();
323288
swss::LinkSync sync(m_app_db.get(), m_state_db.get());

0 commit comments

Comments
 (0)