@@ -30,6 +30,17 @@ BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *applDb, string pg_lookup_f
30
30
m_applBufferEgressProfileListTable(applDb, APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME)
31
31
{
32
32
readPgProfileLookupFile (pg_lookup_file);
33
+
34
+ char *platform = getenv (" ASIC_VENDOR" );
35
+ if (NULL == platform)
36
+ {
37
+ SWSS_LOG_WARN (" Platform environment variable is not defined" );
38
+ }
39
+ else
40
+ {
41
+ m_platform = platform;
42
+ }
43
+
33
44
dynamic_buffer_model = false ;
34
45
}
35
46
@@ -122,9 +133,9 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
122
133
}
123
134
}
124
135
*/
125
- task_process_status BufferMgr::doSpeedUpdateTask (string port)
136
+ task_process_status BufferMgr::doSpeedUpdateTask (string port, bool admin_up )
126
137
{
127
- vector<FieldValueTuple> fvVector ;
138
+ vector<FieldValueTuple> fvVectorPg, fvVectorProfile ;
128
139
string cable;
129
140
string speed;
130
141
@@ -142,20 +153,50 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
142
153
}
143
154
144
155
speed = m_speedLookup[port];
156
+
157
+ string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator () + LOSSLESS_PGS;
158
+ // key format is pg_lossless_<speed>_<cable>_profile
159
+ string buffer_profile_key = " pg_lossless_" + speed + " _" + cable + " _profile" ;
160
+ string profile_ref = buffer_profile_key;
161
+
162
+ m_cfgBufferPgTable.get (buffer_pg_key, fvVectorPg);
163
+
164
+ if (!admin_up && m_platform == " mellanox" )
165
+ {
166
+ // Remove the entry in BUFFER_PG table if any
167
+ if (!fvVectorPg.empty ())
168
+ {
169
+ for (auto &prop : fvVectorPg)
170
+ {
171
+ if (fvField (prop) == " profile" )
172
+ {
173
+ if (fvValue (prop) == profile_ref)
174
+ {
175
+ SWSS_LOG_NOTICE (" Removing PG %s from port %s which is administrative down" , buffer_pg_key.c_str (), port.c_str ());
176
+ m_cfgBufferPgTable.del (buffer_pg_key);
177
+ }
178
+ else
179
+ {
180
+ SWSS_LOG_NOTICE (" Not default profile %s is configured on PG %s, won't reclaim buffer" , fvValue (prop).c_str (), buffer_pg_key.c_str ());
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ return task_process_status::task_success;
187
+ }
188
+
145
189
if (m_pgProfileLookup.count (speed) == 0 || m_pgProfileLookup[speed].count (cable) == 0 )
146
190
{
147
191
SWSS_LOG_ERROR (" Unable to create/update PG profile for port %s. No PG profile configured for speed %s and cable length %s" ,
148
192
port.c_str (), speed.c_str (), cable.c_str ());
149
193
return task_process_status::task_invalid_entry;
150
194
}
151
195
152
- // Crete record in BUFFER_PROFILE table
153
- // key format is pg_lossless_<speed>_<cable>_profile
154
- string buffer_profile_key = " pg_lossless_" + speed + " _" + cable + " _profile" ;
155
-
156
196
// check if profile already exists - if yes - skip creation
157
- m_cfgBufferProfileTable.get (buffer_profile_key, fvVector);
158
- if (fvVector.size () == 0 )
197
+ m_cfgBufferProfileTable.get (buffer_profile_key, fvVectorProfile);
198
+ // Create record in BUFFER_PROFILE table
199
+ if (fvVectorProfile.size () == 0 )
159
200
{
160
201
SWSS_LOG_NOTICE (" Creating new profile '%s'" , buffer_profile_key.c_str ());
161
202
@@ -170,32 +211,24 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
170
211
// profile threshold field name
171
212
mode += " _th" ;
172
213
173
- fvVector .push_back (make_pair (" pool" , INGRESS_LOSSLESS_PG_POOL_NAME));
174
- fvVector .push_back (make_pair (" xon" , m_pgProfileLookup[speed][cable].xon ));
214
+ fvVectorProfile .push_back (make_pair (" pool" , INGRESS_LOSSLESS_PG_POOL_NAME));
215
+ fvVectorProfile .push_back (make_pair (" xon" , m_pgProfileLookup[speed][cable].xon ));
175
216
if (m_pgProfileLookup[speed][cable].xon_offset .length () > 0 ) {
176
- fvVector .push_back (make_pair (" xon_offset" ,
217
+ fvVectorProfile .push_back (make_pair (" xon_offset" ,
177
218
m_pgProfileLookup[speed][cable].xon_offset ));
178
219
}
179
- fvVector .push_back (make_pair (" xoff" , m_pgProfileLookup[speed][cable].xoff ));
180
- fvVector .push_back (make_pair (" size" , m_pgProfileLookup[speed][cable].size ));
181
- fvVector .push_back (make_pair (mode, m_pgProfileLookup[speed][cable].threshold ));
182
- m_cfgBufferProfileTable.set (buffer_profile_key, fvVector );
220
+ fvVectorProfile .push_back (make_pair (" xoff" , m_pgProfileLookup[speed][cable].xoff ));
221
+ fvVectorProfile .push_back (make_pair (" size" , m_pgProfileLookup[speed][cable].size ));
222
+ fvVectorProfile .push_back (make_pair (mode, m_pgProfileLookup[speed][cable].threshold ));
223
+ m_cfgBufferProfileTable.set (buffer_profile_key, fvVectorProfile );
183
224
}
184
225
else
185
226
{
186
227
SWSS_LOG_NOTICE (" Reusing existing profile '%s'" , buffer_profile_key.c_str ());
187
228
}
188
229
189
- fvVector.clear ();
190
-
191
- string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator () + LOSSLESS_PGS;
192
-
193
- string profile_ref = buffer_profile_key;
194
-
195
230
/* Check if PG Mapping is already then log message and return. */
196
- m_cfgBufferPgTable.get (buffer_pg_key, fvVector);
197
-
198
- for (auto & prop : fvVector)
231
+ for (auto & prop : fvVectorPg)
199
232
{
200
233
if ((fvField (prop) == " profile" ) && (profile_ref == fvValue (prop)))
201
234
{
@@ -204,10 +237,10 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
204
237
}
205
238
}
206
239
207
- fvVector .clear ();
240
+ fvVectorPg .clear ();
208
241
209
- fvVector .push_back (make_pair (" profile" , profile_ref));
210
- m_cfgBufferPgTable.set (buffer_pg_key, fvVector );
242
+ fvVectorPg .push_back (make_pair (" profile" , profile_ref));
243
+ m_cfgBufferPgTable.set (buffer_pg_key, fvVectorPg );
211
244
return task_process_status::task_success;
212
245
}
213
246
@@ -379,26 +412,35 @@ void BufferMgr::doTask(Consumer &consumer)
379
412
task_process_status task_status = task_process_status::task_success;
380
413
if (op == SET_COMMAND)
381
414
{
382
- for ( auto i : kfvFieldsValues (t) )
415
+ if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME )
383
416
{
384
- if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME)
417
+ // receive and cache cable length table
418
+ for (auto i : kfvFieldsValues (t))
385
419
{
386
- // receive and cache cable length table
387
420
task_status = doCableTask (fvField (i), fvValue (i));
388
421
}
389
- if (m_pgfile_processed && table_name == CFG_PORT_TABLE_NAME && (fvField (i) == " speed" || fvField (i) == " admin_status" ))
422
+ }
423
+ else if (m_pgfile_processed && table_name == CFG_PORT_TABLE_NAME)
424
+ {
425
+ bool admin_up = false ;
426
+ for (auto i : kfvFieldsValues (t))
390
427
{
391
428
if (fvField (i) == " speed" )
392
429
{
393
430
m_speedLookup[port] = fvValue (i);
394
431
}
395
-
396
- if (m_speedLookup.count (port) != 0 )
432
+ if (fvField (i) == " admin_status" )
397
433
{
398
- // create/update profile for port
399
- task_status = doSpeedUpdateTask (port);
434
+ admin_up = (" up" == fvValue (i));
400
435
}
401
436
}
437
+
438
+ if (m_speedLookup.count (port) != 0 )
439
+ {
440
+ // create/update profile for port
441
+ task_status = doSpeedUpdateTask (port, admin_up);
442
+ }
443
+
402
444
if (task_status != task_process_status::task_success)
403
445
{
404
446
break ;
0 commit comments