Skip to content

Commit 124a6c8

Browse files
committed
Move common files and files for traditional model out of the PR
Make them as independent PRs
1 parent 0d21a95 commit 124a6c8

File tree

11 files changed

+76
-306
lines changed

11 files changed

+76
-306
lines changed

cfgmgr/buffermgr.cpp

Lines changed: 39 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *applDb, string pg_lookup_f
3030
m_applBufferEgressProfileListTable(applDb, APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME)
3131
{
3232
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-
4433
dynamic_buffer_model = false;
4534
}
4635

@@ -133,9 +122,9 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
133122
}
134123
}
135124
*/
136-
task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
125+
task_process_status BufferMgr::doSpeedUpdateTask(string port)
137126
{
138-
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
127+
vector<FieldValueTuple> fvVector;
139128
string cable;
140129
string speed;
141130

@@ -153,54 +142,20 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
153142
}
154143

155144
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 = string("[") +
161-
CFG_BUFFER_PROFILE_TABLE_NAME +
162-
m_cfgBufferPgTable.getTableNameSeparator() +
163-
buffer_profile_key +
164-
"]";
165-
166-
m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);
167-
168-
if (!admin_up && m_platform == "mellanox")
169-
{
170-
// Remove the entry in BUFFER_PG table if any
171-
if (!fvVectorPg.empty())
172-
{
173-
for (auto &prop : fvVectorPg)
174-
{
175-
if (fvField(prop) == "profile")
176-
{
177-
if (fvValue(prop) == profile_ref)
178-
{
179-
SWSS_LOG_NOTICE("Removing PG %s from port %s which is administrative down", buffer_pg_key.c_str(), port.c_str());
180-
m_cfgBufferPgTable.del(buffer_pg_key);
181-
}
182-
else
183-
{
184-
SWSS_LOG_NOTICE("None default profile %s is configured on PG %s, won't reclaim buffer", fvValue(prop).c_str(), buffer_pg_key.c_str());
185-
}
186-
}
187-
}
188-
}
189-
190-
return task_process_status::task_success;
191-
}
192-
193145
if (m_pgProfileLookup.count(speed) == 0 || m_pgProfileLookup[speed].count(cable) == 0)
194146
{
195147
SWSS_LOG_ERROR("Unable to create/update PG profile for port %s. No PG profile configured for speed %s and cable length %s",
196148
port.c_str(), speed.c_str(), cable.c_str());
197149
return task_process_status::task_invalid_entry;
198150
}
199151

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+
200156
// check if profile already exists - if yes - skip creation
201-
m_cfgBufferProfileTable.get(buffer_profile_key, fvVectorProfile);
202-
// Create record in BUFFER_PROFILE table
203-
if (fvVectorProfile.size() == 0)
157+
m_cfgBufferProfileTable.get(buffer_profile_key, fvVector);
158+
if (fvVector.size() == 0)
204159
{
205160
SWSS_LOG_NOTICE("Creating new profile '%s'", buffer_profile_key.c_str());
206161

@@ -218,24 +173,36 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
218173
m_cfgBufferProfileTable.getTableNameSeparator() +
219174
INGRESS_LOSSLESS_PG_POOL_NAME;
220175

221-
fvVectorProfile.push_back(make_pair("pool", "[" + pg_pool_reference + "]"));
222-
fvVectorProfile.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
176+
fvVector.push_back(make_pair("pool", "[" + pg_pool_reference + "]"));
177+
fvVector.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
223178
if (m_pgProfileLookup[speed][cable].xon_offset.length() > 0) {
224-
fvVectorProfile.push_back(make_pair("xon_offset",
179+
fvVector.push_back(make_pair("xon_offset",
225180
m_pgProfileLookup[speed][cable].xon_offset));
226181
}
227-
fvVectorProfile.push_back(make_pair("xoff", m_pgProfileLookup[speed][cable].xoff));
228-
fvVectorProfile.push_back(make_pair("size", m_pgProfileLookup[speed][cable].size));
229-
fvVectorProfile.push_back(make_pair(mode, m_pgProfileLookup[speed][cable].threshold));
230-
m_cfgBufferProfileTable.set(buffer_profile_key, fvVectorProfile);
182+
fvVector.push_back(make_pair("xoff", m_pgProfileLookup[speed][cable].xoff));
183+
fvVector.push_back(make_pair("size", m_pgProfileLookup[speed][cable].size));
184+
fvVector.push_back(make_pair(mode, m_pgProfileLookup[speed][cable].threshold));
185+
m_cfgBufferProfileTable.set(buffer_profile_key, fvVector);
231186
}
232187
else
233188
{
234189
SWSS_LOG_NOTICE("Reusing existing profile '%s'", buffer_profile_key.c_str());
235190
}
236191

192+
fvVector.clear();
193+
194+
string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + LOSSLESS_PGS;
195+
196+
string profile_ref = string("[") +
197+
CFG_BUFFER_PROFILE_TABLE_NAME +
198+
m_cfgBufferPgTable.getTableNameSeparator() +
199+
buffer_profile_key +
200+
"]";
201+
237202
/* Check if PG Mapping is already then log message and return. */
238-
for (auto& prop : fvVectorPg)
203+
m_cfgBufferPgTable.get(buffer_pg_key, fvVector);
204+
205+
for (auto& prop : fvVector)
239206
{
240207
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
241208
{
@@ -244,10 +211,10 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
244211
}
245212
}
246213

247-
fvVectorPg.clear();
214+
fvVector.clear();
248215

249-
fvVectorPg.push_back(make_pair("profile", profile_ref));
250-
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
216+
fvVector.push_back(make_pair("profile", profile_ref));
217+
m_cfgBufferPgTable.set(buffer_pg_key, fvVector);
251218
return task_process_status::task_success;
252219
}
253220

@@ -453,35 +420,26 @@ void BufferMgr::doTask(Consumer &consumer)
453420
task_process_status task_status = task_process_status::task_success;
454421
if (op == SET_COMMAND)
455422
{
456-
if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME)
423+
for (auto i : kfvFieldsValues(t))
457424
{
458-
// receive and cache cable length table
459-
for (auto i : kfvFieldsValues(t))
425+
if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME)
460426
{
427+
// receive and cache cable length table
461428
task_status = doCableTask(fvField(i), fvValue(i));
462429
}
463-
}
464-
else if (m_pgfile_processed && table_name == CFG_PORT_TABLE_NAME)
465-
{
466-
bool admin_up = false;
467-
for (auto i : kfvFieldsValues(t))
430+
if (m_pgfile_processed && table_name == CFG_PORT_TABLE_NAME && (fvField(i) == "speed" || fvField(i) == "admin_status"))
468431
{
469432
if (fvField(i) == "speed")
470433
{
471434
m_speedLookup[port] = fvValue(i);
472435
}
473-
if (fvField(i) == "admin_status")
436+
437+
if (m_speedLookup.count(port) != 0)
474438
{
475-
admin_up = ("up" == fvValue(i));
439+
// create/update profile for port
440+
task_status = doSpeedUpdateTask(port);
476441
}
477442
}
478-
479-
if (m_speedLookup.count(port) != 0)
480-
{
481-
// create/update profile for port
482-
task_status = doSpeedUpdateTask(port, admin_up);
483-
}
484-
485443
if (task_status != task_process_status::task_success)
486444
{
487445
break;

cfgmgr/buffermgr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class BufferMgr : public Orch
3636
using Orch::doTask;
3737

3838
private:
39-
std::string m_platform;
40-
4139
Table m_cfgPortTable;
4240
Table m_cfgCableLenTable;
4341
Table m_cfgBufferProfileTable;
@@ -60,7 +58,7 @@ class BufferMgr : public Orch
6058
std::string getPgPoolMode();
6159
void readPgProfileLookupFile(std::string);
6260
task_process_status doCableTask(std::string port, std::string cable_length);
63-
task_process_status doSpeedUpdateTask(std::string port, bool admin_up);
61+
task_process_status doSpeedUpdateTask(std::string port);
6462
void doBufferTableTask(Consumer &consumer, ProducerStateTable &applTable);
6563

6664
void transformSeperator(std::string &name);

cfgmgr/buffermgrd.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ mutex gDbMutex;
3939

4040
void usage()
4141
{
42-
cout << "Usage: buffermgrd <-l pg_lookup.ini|-a asic_table.json [-p peripheral_table.json] [-z zero_profiles.json]>" << endl;
42+
cout << "Usage: buffermgrd <-l pg_lookup.ini|-a asic_table.json [-p peripheral_table.json]>" << endl;
4343
cout << " -l pg_lookup.ini: PG profile look up table file (mandatory for static mode)" << endl;
4444
cout << " format: csv" << endl;
4545
cout << " values: 'speed, cable, size, xon, xoff, dynamic_threshold, xon_offset'" << endl;
4646
cout << " -a asic_table.json: ASIC-specific parameters definition (mandatory for dynamic mode)" << endl;
47-
cout << " -p peripheral_table.json: Peripheral (eg. gearbox) parameters definition (optional for dynamic mode)" << endl;
48-
cout << " -z zero_profiles.json: Zero profiles definition for reclaiming unused buffers (optional for dynamic mode)" << endl;
47+
cout << " -p peripheral_table.json: Peripheral (eg. gearbox) parameters definition (mandatory for dynamic mode)" << endl;
4948
}
5049

5150
void dump_db_item(KeyOpFieldsValuesTuple &db_item)
@@ -111,13 +110,13 @@ int main(int argc, char **argv)
111110
string pg_lookup_file = "";
112111
string asic_table_file = "";
113112
string peripherial_table_file = "";
114-
string zero_profile_file = "";
113+
string json_file = "";
115114
Logger::linkToDbNative("buffermgrd");
116115
SWSS_LOG_ENTER();
117116

118117
SWSS_LOG_NOTICE("--- Starting buffermgrd ---");
119118

120-
while ((opt = getopt(argc, argv, "l:a:p:z:h")) != -1 )
119+
while ((opt = getopt(argc, argv, "l:a:p:h")) != -1 )
121120
{
122121
switch (opt)
123122
{
@@ -133,9 +132,6 @@ int main(int argc, char **argv)
133132
case 'p':
134133
peripherial_table_file = optarg;
135134
break;
136-
case 'z':
137-
zero_profile_file = optarg;
138-
break;
139135
default: /* '?' */
140136
usage();
141137
return EXIT_FAILURE;
@@ -146,9 +142,7 @@ int main(int argc, char **argv)
146142
{
147143
std::vector<Orch *> cfgOrchList;
148144
bool dynamicMode = false;
149-
shared_ptr<vector<KeyOpFieldsValuesTuple>> asic_table_ptr = nullptr;
150-
shared_ptr<vector<KeyOpFieldsValuesTuple>> peripherial_table_ptr = nullptr;
151-
shared_ptr<vector<KeyOpFieldsValuesTuple>> zero_profiles_ptr = nullptr;
145+
shared_ptr<vector<KeyOpFieldsValuesTuple>> db_items_ptr;
152146

153147
DBConnector cfgDb("CONFIG_DB", 0);
154148
DBConnector stateDb("STATE_DB", 0);
@@ -157,23 +151,18 @@ int main(int argc, char **argv)
157151
if (!asic_table_file.empty())
158152
{
159153
// Load the json file containing the SWITCH_TABLE
160-
asic_table_ptr = load_json(asic_table_file);
161-
if (nullptr != asic_table_ptr)
154+
db_items_ptr = load_json(asic_table_file);
155+
if (nullptr != db_items_ptr)
162156
{
163-
write_to_state_db(asic_table_ptr);
157+
write_to_state_db(db_items_ptr);
158+
db_items_ptr.reset();
164159

165160
if (!peripherial_table_file.empty())
166161
{
167162
//Load the json file containing the PERIPHERIAL_TABLE
168-
peripherial_table_ptr = load_json(peripherial_table_file);
169-
if (nullptr != peripherial_table_ptr)
170-
write_to_state_db(peripherial_table_ptr);
171-
}
172-
173-
if (!zero_profile_file.empty())
174-
{
175-
//Load the json file containing the zero profiles
176-
zero_profiles_ptr = load_json(zero_profile_file);
163+
db_items_ptr = load_json(peripherial_table_file);
164+
if (nullptr != db_items_ptr)
165+
write_to_state_db(db_items_ptr);
177166
}
178167

179168
dynamicMode = true;
@@ -198,7 +187,7 @@ int main(int argc, char **argv)
198187
TableConnector(&stateDb, STATE_BUFFER_MAXIMUM_VALUE_TABLE),
199188
TableConnector(&stateDb, STATE_PORT_TABLE_NAME)
200189
};
201-
cfgOrchList.emplace_back(new BufferMgrDynamic(&cfgDb, &stateDb, &applDb, buffer_table_connectors, peripherial_table_ptr, zero_profiles_ptr));
190+
cfgOrchList.emplace_back(new BufferMgrDynamic(&cfgDb, &stateDb, &applDb, buffer_table_connectors, db_items_ptr));
202191
}
203192
else if (!pg_lookup_file.empty())
204193
{

cfgmgr/buffermgrdyn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
using namespace std;
2828
using namespace swss;
2929

30-
BufferMgrDynamic::BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const vector<TableConnector> &tables, shared_ptr<vector<KeyOpFieldsValuesTuple>> gearboxInfo, shared_ptr<vector<KeyOpFieldsValuesTuple>> zeroProfilesInfo) :
30+
BufferMgrDynamic::BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const vector<TableConnector> &tables, shared_ptr<vector<KeyOpFieldsValuesTuple>> gearboxInfo = nullptr) :
3131
Orch(tables),
3232
m_platform(),
3333
m_bufferDirections({BUFFER_INGRESS, BUFFER_EGRESS}),

cfgmgr/buffermgrdyn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ typedef std::map<std::string, std::string> gearbox_delay_t;
146146
class BufferMgrDynamic : public Orch
147147
{
148148
public:
149-
BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const std::vector<TableConnector> &tables, std::shared_ptr<std::vector<KeyOpFieldsValuesTuple>> gearboxInfo, std::shared_ptr<std::vector<KeyOpFieldsValuesTuple>> zeroProfilesInfo);
149+
BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const std::vector<TableConnector> &tables, std::shared_ptr<std::vector<KeyOpFieldsValuesTuple>> gearboxInfo);
150150
using Orch::doTask;
151151

152152
private:

0 commit comments

Comments
 (0)