1
- #include < string>
2
-
3
1
#include " logger.h"
4
2
#include " dbconnector.h"
5
3
#include " producerstatetable.h"
@@ -15,57 +13,27 @@ using namespace swss;
15
13
PortMgr::PortMgr (DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) :
16
14
Orch(cfgDb, tableNames),
17
15
m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME),
18
- m_cfgLagTable (cfgDb, CFG_LAG_TABLE_NAME ),
16
+ m_cfgLagMemberTable (cfgDb, CFG_LAG_MEMBER_TABLE_NAME ),
19
17
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME),
20
- m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME),
21
- m_appPortTable(appDb, APP_PORT_TABLE_NAME),
22
- m_appLagTable(appDb, APP_LAG_TABLE_NAME)
18
+ m_appPortTable(appDb, APP_PORT_TABLE_NAME)
23
19
{
24
20
}
25
21
26
- bool PortMgr::setPortMtu (const string &table, const string & alias, const string &mtu)
22
+ bool PortMgr::setPortMtu (const string &alias, const string &mtu)
27
23
{
28
24
stringstream cmd;
29
25
string res;
30
26
27
+ // ip link set dev <port_name> mtu <mtu>
31
28
cmd << IP_CMD << " link set dev " << alias << " mtu " << mtu;
32
29
EXEC_WITH_ERROR_THROW (cmd.str (), res);
33
30
34
- if (table == CFG_PORT_TABLE_NAME)
35
- {
36
- // Set the port MTU in application database to update both
37
- // the port MTU and possibly the port based router interface MTU
38
- vector<FieldValueTuple> fvs;
39
- FieldValueTuple fv (" mtu" , mtu);
40
- fvs.push_back (fv);
41
- m_appPortTable.set (alias, fvs);
42
- }
43
- else if (table == CFG_LAG_TABLE_NAME)
44
- {
45
- // Set the port channel MTU in application database to update
46
- // the LAG based router interface MTU in orchagent
47
- vector<FieldValueTuple> fvs;
48
- FieldValueTuple fv (" mtu" , mtu);
49
- fvs.push_back (fv);
50
- m_appLagTable.set (alias, fvs);
51
-
52
- m_cfgLagTable.get (alias, fvs);
53
- for (auto fv: fvs)
54
- {
55
- // Set the port channel members MTU in application database
56
- // to update the port MTU in orchagent
57
- if (fvField (fv) == " members" )
58
- {
59
- for (auto member : tokenize (fvValue (fv), ' ,' ))
60
- {
61
- vector<FieldValueTuple> member_fvs;
62
- FieldValueTuple member_fv (" mtu" , mtu);
63
- member_fvs.push_back (member_fv);
64
- m_appPortTable.set (member, member_fvs);
65
- }
66
- }
67
- }
68
- }
31
+ // Set the port MTU in application database to update both
32
+ // the port MTU and possibly the port based router interface MTU
33
+ vector<FieldValueTuple> fvs;
34
+ FieldValueTuple fv (" mtu" , mtu);
35
+ fvs.push_back (fv);
36
+ m_appPortTable.set (alias, fvs);
69
37
70
38
return true ;
71
39
}
@@ -75,31 +43,26 @@ bool PortMgr::setPortAdminStatus(const string &alias, const bool up)
75
43
stringstream cmd;
76
44
string res;
77
45
46
+ // ip link set dev <port_name> [up|down]
78
47
cmd << IP_CMD << " link set dev " << alias << (up ? " up" : " down" );
79
48
EXEC_WITH_ERROR_THROW (cmd.str (), res);
80
49
50
+ vector<FieldValueTuple> fvs;
51
+ FieldValueTuple fv (" admin_status" , (up ? " up" : " down" ));
52
+ fvs.push_back (fv);
53
+ m_appPortTable.set (alias, fvs);
54
+
81
55
return true ;
82
56
}
83
57
84
- bool PortMgr::isPortStateOk (const string &table, const string & alias)
58
+ bool PortMgr::isPortStateOk (const string &alias)
85
59
{
86
60
vector<FieldValueTuple> temp;
87
61
88
- if (table == CFG_PORT_TABLE_NAME)
89
- {
90
- if (m_statePortTable.get (alias, temp))
91
- {
92
- SWSS_LOG_INFO (" Port %s is ready" , alias.c_str ());
93
- return true ;
94
- }
95
- }
96
- else if (table == CFG_LAG_TABLE_NAME)
62
+ if (m_statePortTable.get (alias, temp))
97
63
{
98
- if (m_stateLagTable.get (alias, temp))
99
- {
100
- SWSS_LOG_INFO (" Lag %s is ready" , alias.c_str ());
101
- return true ;
102
- }
64
+ SWSS_LOG_INFO (" Port %s is ready" , alias.c_str ());
65
+ return true ;
103
66
}
104
67
105
68
return false ;
@@ -119,9 +82,25 @@ void PortMgr::doTask(Consumer &consumer)
119
82
string alias = kfvKey (t);
120
83
string op = kfvOp (t);
121
84
85
+ // Skip port which is a member of a port channel
86
+ vector<string> keys;
87
+ m_cfgLagMemberTable.getKeys (keys);
88
+
89
+ for (auto key : keys)
90
+ {
91
+ auto tokens = tokenize (key, ' |' );
92
+ auto member = tokens[1 ];
93
+
94
+ if (alias == member)
95
+ {
96
+ it = consumer.m_toSync .erase (it);
97
+ continue ;
98
+ }
99
+ }
100
+
122
101
if (op == SET_COMMAND)
123
102
{
124
- if (!isPortStateOk (table, alias))
103
+ if (!isPortStateOk (alias))
125
104
{
126
105
SWSS_LOG_INFO (" Port %s is not ready, pending..." , alias.c_str ());
127
106
it++;
@@ -133,7 +112,7 @@ void PortMgr::doTask(Consumer &consumer)
133
112
if (fvField (i) == " mtu" )
134
113
{
135
114
auto mtu = fvValue (i);
136
- setPortMtu (table, alias, mtu);
115
+ setPortMtu (alias, mtu);
137
116
SWSS_LOG_NOTICE (" Configure %s MTU to %s" ,
138
117
alias.c_str (), mtu.c_str ());
139
118
}
0 commit comments