@@ -31,29 +31,9 @@ bool PortMgr::setPortMtu(const string &alias, const string &mtu)
31
31
32
32
// Set the port MTU in application database to update both
33
33
// the port MTU and possibly the port based router interface MTU
34
- vector<FieldValueTuple> fvs;
35
- FieldValueTuple fv (" mtu" , mtu);
36
- fvs.push_back (fv);
37
- m_appPortTable.set (alias, fvs);
38
-
39
- return true ;
34
+ return writeConfigToAppDb (alias, " mtu" , mtu);
40
35
}
41
36
42
- bool PortMgr::setPortTpid (const string &alias, const string &tpid)
43
- {
44
- stringstream cmd;
45
- string res;
46
-
47
- // Set the port TPID in application database to update port TPID
48
- vector<FieldValueTuple> fvs;
49
- FieldValueTuple fv (" tpid" , tpid);
50
- fvs.push_back (fv);
51
- m_appPortTable.set (alias, fvs);
52
-
53
- return true ;
54
- }
55
-
56
-
57
37
bool PortMgr::setPortAdminStatus (const string &alias, const bool up)
58
38
{
59
39
stringstream cmd;
@@ -63,23 +43,7 @@ bool PortMgr::setPortAdminStatus(const string &alias, const bool up)
63
43
cmd << IP_CMD << " link set dev " << shellquote (alias) << (up ? " up" : " down" );
64
44
EXEC_WITH_ERROR_THROW (cmd.str (), res);
65
45
66
- vector<FieldValueTuple> fvs;
67
- FieldValueTuple fv (" admin_status" , (up ? " up" : " down" ));
68
- fvs.push_back (fv);
69
- m_appPortTable.set (alias, fvs);
70
-
71
- return true ;
72
- }
73
-
74
- bool PortMgr::setPortLearnMode (const string &alias, const string &learn_mode)
75
- {
76
- // Set the port MAC learn mode in application database
77
- vector<FieldValueTuple> fvs;
78
- FieldValueTuple fv (" learn_mode" , learn_mode);
79
- fvs.push_back (fv);
80
- m_appPortTable.set (alias, fvs);
81
-
82
- return true ;
46
+ return writeConfigToAppDb (alias, " admin_status" , (up ? " up" : " down" ));
83
47
}
84
48
85
49
bool PortMgr::isPortStateOk (const string &alias)
@@ -117,14 +81,14 @@ void PortMgr::doTask(Consumer &consumer)
117
81
118
82
if (op == SET_COMMAND)
119
83
{
120
- if (!isPortStateOk (alias))
121
- {
122
- SWSS_LOG_INFO (" Port %s is not ready, pending..." , alias.c_str ());
123
- it++;
124
- continue ;
125
- }
84
+ /* portOk=true indicates that the port has been created in kernel.
85
+ * We should not call any ip command if portOk=false. However, it is
86
+ * valid to put port configuration to APP DB which will trigger port creation in kernel.
87
+ */
88
+ bool portOk = isPortStateOk (alias);
126
89
127
- string admin_status, mtu, learn_mode, tpid;
90
+ string admin_status, mtu;
91
+ std::vector<FieldValueTuple> field_values;
128
92
129
93
bool configured = (m_portList.find (alias) != m_portList.end ());
130
94
@@ -138,6 +102,11 @@ void PortMgr::doTask(Consumer &consumer)
138
102
139
103
m_portList.insert (alias);
140
104
}
105
+ else if (!portOk)
106
+ {
107
+ it++;
108
+ continue ;
109
+ }
141
110
142
111
for (auto i : kfvFieldsValues (t))
143
112
{
@@ -149,38 +118,42 @@ void PortMgr::doTask(Consumer &consumer)
149
118
{
150
119
admin_status = fvValue (i);
151
120
}
152
- else if (fvField (i) == " learn_mode" )
153
- {
154
- learn_mode = fvValue (i);
155
- }
156
- else if (fvField (i) == " tpid" )
121
+ else
157
122
{
158
- tpid = fvValue (i);
123
+ field_values. emplace_back (i);
159
124
}
160
125
}
161
126
162
- if (!mtu. empty () )
127
+ for ( auto &entry : field_values )
163
128
{
164
- setPortMtu (alias, mtu );
165
- SWSS_LOG_NOTICE (" Configure %s MTU to %s" , alias.c_str (), mtu .c_str ());
129
+ writeConfigToAppDb (alias, fvField (entry), fvValue (entry) );
130
+ SWSS_LOG_NOTICE (" Configure %s %s to %s" , alias.c_str (), fvField (entry). c_str (), fvValue (entry) .c_str ());
166
131
}
167
132
168
- if (!admin_status. empty () )
133
+ if (!portOk )
169
134
{
170
- setPortAdminStatus (alias, admin_status == " up" );
171
- SWSS_LOG_NOTICE (" Configure %s admin status to %s" , alias.c_str (), admin_status.c_str ());
135
+ SWSS_LOG_INFO (" Port %s is not ready, pending..." , alias.c_str ());
136
+
137
+ writeConfigToAppDb (alias, " mtu" , mtu);
138
+ writeConfigToAppDb (alias, " admin_status" , admin_status);
139
+ field_values.clear ();
140
+ field_values.emplace_back (" mtu" , mtu);
141
+ field_values.emplace_back (" admin_status" , admin_status);
142
+ it->second = KeyOpFieldsValuesTuple{alias, SET_COMMAND, field_values};
143
+ it++;
144
+ continue ;
172
145
}
173
146
174
- if (!learn_mode .empty ())
147
+ if (!mtu .empty ())
175
148
{
176
- setPortLearnMode (alias, learn_mode );
177
- SWSS_LOG_NOTICE (" Configure %s MAC learn mode to %s" , alias.c_str (), learn_mode .c_str ());
149
+ setPortMtu (alias, mtu );
150
+ SWSS_LOG_NOTICE (" Configure %s MTU to %s" , alias.c_str (), mtu .c_str ());
178
151
}
179
152
180
- if (!tpid .empty ())
153
+ if (!admin_status .empty ())
181
154
{
182
- setPortTpid (alias, tpid );
183
- SWSS_LOG_NOTICE (" Configure %s TPID to %s" , alias.c_str (), tpid .c_str ());
155
+ setPortAdminStatus (alias, admin_status == " up " );
156
+ SWSS_LOG_NOTICE (" Configure %s admin status to %s" , alias.c_str (), admin_status .c_str ());
184
157
}
185
158
}
186
159
else if (op == DEL_COMMAND)
@@ -193,3 +166,13 @@ void PortMgr::doTask(Consumer &consumer)
193
166
it = consumer.m_toSync .erase (it);
194
167
}
195
168
}
169
+
170
+ bool PortMgr::writeConfigToAppDb (const std::string &alias, const std::string &field, const std::string &value)
171
+ {
172
+ vector<FieldValueTuple> fvs;
173
+ FieldValueTuple fv (field, value);
174
+ fvs.push_back (fv);
175
+ m_appPortTable.set (alias, fvs);
176
+
177
+ return true ;
178
+ }
0 commit comments