Skip to content

Commit

Permalink
Move common files and files for traditional model out of the PR
Browse files Browse the repository at this point in the history
Make them as independent PRs
  • Loading branch information
stephenxs committed Nov 19, 2021
1 parent 0d21a95 commit 124a6c8
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 306 deletions.
120 changes: 39 additions & 81 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *applDb, string pg_lookup_f
m_applBufferEgressProfileListTable(applDb, APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME)
{
readPgProfileLookupFile(pg_lookup_file);

char *platform = getenv("ASIC_VENDOR");
if (NULL == platform)
{
SWSS_LOG_WARN("Platform environment variable is not defined");
}
else
{
m_platform = platform;
}

dynamic_buffer_model = false;
}

Expand Down Expand Up @@ -133,9 +122,9 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
}
}
*/
task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
task_process_status BufferMgr::doSpeedUpdateTask(string port)
{
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
vector<FieldValueTuple> fvVector;
string cable;
string speed;

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

speed = m_speedLookup[port];

string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + LOSSLESS_PGS;
// key format is pg_lossless_<speed>_<cable>_profile
string buffer_profile_key = "pg_lossless_" + speed + "_" + cable + "_profile";
string profile_ref = string("[") +
CFG_BUFFER_PROFILE_TABLE_NAME +
m_cfgBufferPgTable.getTableNameSeparator() +
buffer_profile_key +
"]";

m_cfgBufferPgTable.get(buffer_pg_key, fvVectorPg);

if (!admin_up && m_platform == "mellanox")
{
// Remove the entry in BUFFER_PG table if any
if (!fvVectorPg.empty())
{
for (auto &prop : fvVectorPg)
{
if (fvField(prop) == "profile")
{
if (fvValue(prop) == profile_ref)
{
SWSS_LOG_NOTICE("Removing PG %s from port %s which is administrative down", buffer_pg_key.c_str(), port.c_str());
m_cfgBufferPgTable.del(buffer_pg_key);
}
else
{
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());
}
}
}
}

return task_process_status::task_success;
}

if (m_pgProfileLookup.count(speed) == 0 || m_pgProfileLookup[speed].count(cable) == 0)
{
SWSS_LOG_ERROR("Unable to create/update PG profile for port %s. No PG profile configured for speed %s and cable length %s",
port.c_str(), speed.c_str(), cable.c_str());
return task_process_status::task_invalid_entry;
}

// Crete record in BUFFER_PROFILE table
// key format is pg_lossless_<speed>_<cable>_profile
string buffer_profile_key = "pg_lossless_" + speed + "_" + cable + "_profile";

// check if profile already exists - if yes - skip creation
m_cfgBufferProfileTable.get(buffer_profile_key, fvVectorProfile);
// Create record in BUFFER_PROFILE table
if (fvVectorProfile.size() == 0)
m_cfgBufferProfileTable.get(buffer_profile_key, fvVector);
if (fvVector.size() == 0)
{
SWSS_LOG_NOTICE("Creating new profile '%s'", buffer_profile_key.c_str());

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

fvVectorProfile.push_back(make_pair("pool", "[" + pg_pool_reference + "]"));
fvVectorProfile.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
fvVector.push_back(make_pair("pool", "[" + pg_pool_reference + "]"));
fvVector.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
if (m_pgProfileLookup[speed][cable].xon_offset.length() > 0) {
fvVectorProfile.push_back(make_pair("xon_offset",
fvVector.push_back(make_pair("xon_offset",
m_pgProfileLookup[speed][cable].xon_offset));
}
fvVectorProfile.push_back(make_pair("xoff", m_pgProfileLookup[speed][cable].xoff));
fvVectorProfile.push_back(make_pair("size", m_pgProfileLookup[speed][cable].size));
fvVectorProfile.push_back(make_pair(mode, m_pgProfileLookup[speed][cable].threshold));
m_cfgBufferProfileTable.set(buffer_profile_key, fvVectorProfile);
fvVector.push_back(make_pair("xoff", m_pgProfileLookup[speed][cable].xoff));
fvVector.push_back(make_pair("size", m_pgProfileLookup[speed][cable].size));
fvVector.push_back(make_pair(mode, m_pgProfileLookup[speed][cable].threshold));
m_cfgBufferProfileTable.set(buffer_profile_key, fvVector);
}
else
{
SWSS_LOG_NOTICE("Reusing existing profile '%s'", buffer_profile_key.c_str());
}

fvVector.clear();

string buffer_pg_key = port + m_cfgBufferPgTable.getTableNameSeparator() + LOSSLESS_PGS;

string profile_ref = string("[") +
CFG_BUFFER_PROFILE_TABLE_NAME +
m_cfgBufferPgTable.getTableNameSeparator() +
buffer_profile_key +
"]";

/* Check if PG Mapping is already then log message and return. */
for (auto& prop : fvVectorPg)
m_cfgBufferPgTable.get(buffer_pg_key, fvVector);

for (auto& prop : fvVector)
{
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
{
Expand All @@ -244,10 +211,10 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
}
}

fvVectorPg.clear();
fvVector.clear();

fvVectorPg.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVectorPg);
fvVector.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVector);
return task_process_status::task_success;
}

Expand Down Expand Up @@ -453,35 +420,26 @@ void BufferMgr::doTask(Consumer &consumer)
task_process_status task_status = task_process_status::task_success;
if (op == SET_COMMAND)
{
if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME)
for (auto i : kfvFieldsValues(t))
{
// receive and cache cable length table
for (auto i : kfvFieldsValues(t))
if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME)
{
// receive and cache cable length table
task_status = doCableTask(fvField(i), fvValue(i));
}
}
else if (m_pgfile_processed && table_name == CFG_PORT_TABLE_NAME)
{
bool admin_up = false;
for (auto i : kfvFieldsValues(t))
if (m_pgfile_processed && table_name == CFG_PORT_TABLE_NAME && (fvField(i) == "speed" || fvField(i) == "admin_status"))
{
if (fvField(i) == "speed")
{
m_speedLookup[port] = fvValue(i);
}
if (fvField(i) == "admin_status")

if (m_speedLookup.count(port) != 0)
{
admin_up = ("up" == fvValue(i));
// create/update profile for port
task_status = doSpeedUpdateTask(port);
}
}

if (m_speedLookup.count(port) != 0)
{
// create/update profile for port
task_status = doSpeedUpdateTask(port, admin_up);
}

if (task_status != task_process_status::task_success)
{
break;
Expand Down
4 changes: 1 addition & 3 deletions cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class BufferMgr : public Orch
using Orch::doTask;

private:
std::string m_platform;

Table m_cfgPortTable;
Table m_cfgCableLenTable;
Table m_cfgBufferProfileTable;
Expand All @@ -60,7 +58,7 @@ class BufferMgr : public Orch
std::string getPgPoolMode();
void readPgProfileLookupFile(std::string);
task_process_status doCableTask(std::string port, std::string cable_length);
task_process_status doSpeedUpdateTask(std::string port, bool admin_up);
task_process_status doSpeedUpdateTask(std::string port);
void doBufferTableTask(Consumer &consumer, ProducerStateTable &applTable);

void transformSeperator(std::string &name);
Expand Down
37 changes: 13 additions & 24 deletions cfgmgr/buffermgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ mutex gDbMutex;

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

void dump_db_item(KeyOpFieldsValuesTuple &db_item)
Expand Down Expand Up @@ -111,13 +110,13 @@ int main(int argc, char **argv)
string pg_lookup_file = "";
string asic_table_file = "";
string peripherial_table_file = "";
string zero_profile_file = "";
string json_file = "";
Logger::linkToDbNative("buffermgrd");
SWSS_LOG_ENTER();

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

while ((opt = getopt(argc, argv, "l:a:p:z:h")) != -1 )
while ((opt = getopt(argc, argv, "l:a:p:h")) != -1 )
{
switch (opt)
{
Expand All @@ -133,9 +132,6 @@ int main(int argc, char **argv)
case 'p':
peripherial_table_file = optarg;
break;
case 'z':
zero_profile_file = optarg;
break;
default: /* '?' */
usage();
return EXIT_FAILURE;
Expand All @@ -146,9 +142,7 @@ int main(int argc, char **argv)
{
std::vector<Orch *> cfgOrchList;
bool dynamicMode = false;
shared_ptr<vector<KeyOpFieldsValuesTuple>> asic_table_ptr = nullptr;
shared_ptr<vector<KeyOpFieldsValuesTuple>> peripherial_table_ptr = nullptr;
shared_ptr<vector<KeyOpFieldsValuesTuple>> zero_profiles_ptr = nullptr;
shared_ptr<vector<KeyOpFieldsValuesTuple>> db_items_ptr;

DBConnector cfgDb("CONFIG_DB", 0);
DBConnector stateDb("STATE_DB", 0);
Expand All @@ -157,23 +151,18 @@ int main(int argc, char **argv)
if (!asic_table_file.empty())
{
// Load the json file containing the SWITCH_TABLE
asic_table_ptr = load_json(asic_table_file);
if (nullptr != asic_table_ptr)
db_items_ptr = load_json(asic_table_file);
if (nullptr != db_items_ptr)
{
write_to_state_db(asic_table_ptr);
write_to_state_db(db_items_ptr);
db_items_ptr.reset();

if (!peripherial_table_file.empty())
{
//Load the json file containing the PERIPHERIAL_TABLE
peripherial_table_ptr = load_json(peripherial_table_file);
if (nullptr != peripherial_table_ptr)
write_to_state_db(peripherial_table_ptr);
}

if (!zero_profile_file.empty())
{
//Load the json file containing the zero profiles
zero_profiles_ptr = load_json(zero_profile_file);
db_items_ptr = load_json(peripherial_table_file);
if (nullptr != db_items_ptr)
write_to_state_db(db_items_ptr);
}

dynamicMode = true;
Expand All @@ -198,7 +187,7 @@ int main(int argc, char **argv)
TableConnector(&stateDb, STATE_BUFFER_MAXIMUM_VALUE_TABLE),
TableConnector(&stateDb, STATE_PORT_TABLE_NAME)
};
cfgOrchList.emplace_back(new BufferMgrDynamic(&cfgDb, &stateDb, &applDb, buffer_table_connectors, peripherial_table_ptr, zero_profiles_ptr));
cfgOrchList.emplace_back(new BufferMgrDynamic(&cfgDb, &stateDb, &applDb, buffer_table_connectors, db_items_ptr));
}
else if (!pg_lookup_file.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/buffermgrdyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using namespace std;
using namespace swss;

BufferMgrDynamic::BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const vector<TableConnector> &tables, shared_ptr<vector<KeyOpFieldsValuesTuple>> gearboxInfo, shared_ptr<vector<KeyOpFieldsValuesTuple>> zeroProfilesInfo) :
BufferMgrDynamic::BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const vector<TableConnector> &tables, shared_ptr<vector<KeyOpFieldsValuesTuple>> gearboxInfo = nullptr) :
Orch(tables),
m_platform(),
m_bufferDirections({BUFFER_INGRESS, BUFFER_EGRESS}),
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/buffermgrdyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ typedef std::map<std::string, std::string> gearbox_delay_t;
class BufferMgrDynamic : public Orch
{
public:
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);
BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const std::vector<TableConnector> &tables, std::shared_ptr<std::vector<KeyOpFieldsValuesTuple>> gearboxInfo);
using Orch::doTask;

private:
Expand Down
Loading

0 comments on commit 124a6c8

Please sign in to comment.