Skip to content

Commit

Permalink
Follow name convention of APPL_DB and STATE_DB: adding suffix "_TABLE…
Browse files Browse the repository at this point in the history
…" on the table name

Signed-off-by: Stephen Sun <[email protected]>
  • Loading branch information
stephenxs committed Sep 10, 2020
1 parent 0cf885d commit 6c60a7d
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 65 deletions.
4 changes: 2 additions & 2 deletions cfgmgr/buffer_check_headroom_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
-- Fetch the threshold from STATE_DB
redis.call('SELECT', state_db)

local max_headroom_size = tonumber(redis.call('HGET', 'BUFFER_MAX_PARAM|' .. port, 'max_headroom_size'))
local max_headroom_size = tonumber(redis.call('HGET', 'BUFFER_MAX_PARAM_TABLE|' .. port, 'max_headroom_size'))
if max_headroom_size == nil then
return default_ret
end
Expand All @@ -66,7 +66,7 @@ end

-- Fetch all the PGs, accumulate the sizes
-- Assume there is only one lossless profile configured among all PGs on each port
local pg_keys = redis.call('KEYS', 'BUFFER_PG:' .. port .. '*')
local pg_keys = redis.call('KEYS', 'BUFFER_PG_TABLE:' .. port .. '*')
for i = 1, #pg_keys do
profile = string.sub(redis.call('HGET', pg_keys[i], 'profile'), 2, -2)
if lossless_profile_name ~= nil then
Expand Down
8 changes: 4 additions & 4 deletions cfgmgr/buffer_pool_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ local function iterate_all_items(all_items)
end
profiles[index][2] = profiles[index][2] + size
local speed = redis.call('HGET', 'PORT_TABLE:'..port, 'speed')
if speed == '400000' and profile == '[BUFFER_PROFILE:ingress_lossy_profile]' then
if speed == '400000' and profile == '[BUFFER_PROFILE_TABLE:ingress_lossy_profile]' then
lossypg_400g = lossypg_400g + size
end
end
Expand Down Expand Up @@ -107,10 +107,10 @@ for i = 1, #profiles, 1 do
if profiles[i][1] ~= "BUFFER_PROFILE_KEY_SET" and profiles[i][1] ~= "BUFFER_PROFILE_DEL_SET" then
local size = tonumber(redis.call('HGET', profiles[i][1], 'size'))
if size ~= nil then
if profiles[i][1] == "BUFFER_PROFILE:ingress_lossy_profile" then
if profiles[i][1] == "BUFFER_PROFILE_TABLE:ingress_lossy_profile" then
size = size + lossypg_reserved
end
if profiles[i][1] == "BUFFER_PROFILE:egress_lossy_profile" then
if profiles[i][1] == "BUFFER_PROFILE_TABLE:egress_lossy_profile" then
profiles[i][2] = count_up_port
end
if size ~= 0 then
Expand All @@ -131,7 +131,7 @@ accumulative_occupied_buffer = accumulative_occupied_buffer + accumulative_egres

-- Fetch mmu_size
redis.call('SELECT', state_db)
local mmu_size = tonumber(redis.call('HGET', 'BUFFER_MAX_PARAM|global', 'mmu_size'))
local mmu_size = tonumber(redis.call('HGET', 'BUFFER_MAX_PARAM_TABLE|global', 'mmu_size'))
if mmu_size == nil then
mmu_size = tonumber(egress_lossless_pool_size)
end
Expand Down
36 changes: 32 additions & 4 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using namespace std;
using namespace swss;

BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, string pg_lookup_file, const vector<string> &tableNames) :
BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *applDb, string pg_lookup_file, const vector<string> &tableNames) :
Orch(cfgDb, tableNames),
m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME),
m_cfgCableLenTable(cfgDb, CFG_PORT_CABLE_LEN_TABLE_NAME),
Expand Down Expand Up @@ -215,6 +215,33 @@ void BufferMgr::transformSeperator(string &name)
while ((pos = name.find("|")) != string::npos)
name.replace(pos, 1, ":");
}

void BufferMgr::transformReference(string &name)
{
auto references = tokenize(name, list_item_delimiter);
int ref_index = 0;

name = "";

for (auto &reference : references)
{
if (ref_index != 0)
name += list_item_delimiter;
ref_index ++;

auto keys = tokenize(reference, config_db_key_delimiter);
int key_index = 0;
for (auto &key : keys)
{
if (key_index == 0)
name += key + "_TABLE";
else
name += delimiter + key;
key_index ++;
}
}
}

/*
* This function copies the data from tables in CONFIG_DB to APPL_DB.
* With dynamically buffer calculation supported, the following tables
Expand Down Expand Up @@ -256,13 +283,14 @@ void BufferMgr::doBufferTableTask(Consumer &consumer, ProducerStateTable &applTa

for (auto i : kfvFieldsValues(t))
{
SWSS_LOG_INFO("Inserting field %s value %s", fvField(i).c_str(), fvValue(i).c_str());
//transform the separator in values from "|" to ":"
if (fvField(i) == "pool")
transformSeperator(fvValue(i));
transformReference(fvValue(i));
if (fvField(i) == "profile")
transformSeperator(fvValue(i));
transformReference(fvValue(i));
if (fvField(i) == "profile_list")
transformSeperator(fvValue(i));
transformReference(fvValue(i));
fvVector.emplace_back(FieldValueTuple(fvField(i), fvValue(i)));
SWSS_LOG_INFO("Inserting field %s value %s", fvField(i).c_str(), fvValue(i).c_str());
}
Expand Down
3 changes: 2 additions & 1 deletion cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef std::map<std::string, std::string> port_cable_length_t;
class BufferMgr : public Orch
{
public:
BufferMgr(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, std::string pg_lookup_file, const std::vector<std::string> &tableNames);
BufferMgr(DBConnector *cfgDb, DBConnector *applDb, std::string pg_lookup_file, const std::vector<std::string> &tableNames);
using Orch::doTask;

private:
Expand Down Expand Up @@ -59,6 +59,7 @@ class BufferMgr : public Orch
void doBufferTableTask(Consumer &consumer, ProducerStateTable &applTable);

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

void doTask(Consumer &consumer);
};
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/buffermgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int main(int argc, char **argv)
CFG_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME,
CFG_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME
};
cfgOrchList.emplace_back(new BufferMgr(&cfgDb, &stateDb, &applDb, pg_lookup_file, cfg_buffer_tables));
cfgOrchList.emplace_back(new BufferMgr(&cfgDb, &applDb, pg_lookup_file, cfg_buffer_tables));
}
else
{
Expand Down
38 changes: 32 additions & 6 deletions cfgmgr/buffermgrdyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,36 @@ void BufferMgrDynamic::transformSeperator(string &name)
name.replace(pos, 1, ":");
}

void BufferMgrDynamic::transformReference(string &name)
{
auto references = tokenize(name, list_item_delimiter);
int ref_index = 0;

name = "";

for (auto &reference : references)
{
if (ref_index != 0)
name += list_item_delimiter;
ref_index ++;

auto keys = tokenize(reference, config_db_key_delimiter);
int key_index = 0;
for (auto &key : keys)
{
if (key_index == 0)
name += key + "_TABLE";
else
name += delimiter + key;
key_index ++;
}
}
}

// For string "TABLE_NAME|objectname", returns "objectname"
string BufferMgrDynamic::parseObjectNameFromKey(const string &key, size_t pos = 0)
{
auto keys = tokenize(key, ':');
auto keys = tokenize(key, delimiter);
if (pos >= keys.size())
{
SWSS_LOG_ERROR("Failed to fetch %lu-th sector of key %s", pos, key.c_str());
Expand Down Expand Up @@ -1177,7 +1203,7 @@ task_process_status BufferMgrDynamic::handleBufferProfileTable(Consumer &consume
{
if (!value.empty())
{
transformSeperator(value);
transformReference(value);
auto poolName = parseObjectNameFromReference(value);
auto poolRef = m_bufferPoolLookup.find(poolName);
if (poolRef == m_bufferPoolLookup.end())
Expand Down Expand Up @@ -1332,7 +1358,7 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
{
// Headroom override
pureDynamic = false;
transformSeperator(value);
transformReference(value);
string profileName = parseObjectNameFromReference(value);
auto searchRef = m_bufferProfileLookup.find(profileName);
if (searchRef == m_bufferProfileLookup.end())
Expand Down Expand Up @@ -1511,11 +1537,11 @@ task_process_status BufferMgrDynamic::doBufferTableTask(Consumer &consumer, Prod
{
//transform the separator in values from "|" to ":"
if (fvField(i) == "pool")
transformSeperator(fvValue(i));
transformReference(fvValue(i));
if (fvField(i) == "profile")
transformSeperator(fvValue(i));
transformReference(fvValue(i));
if (fvField(i) == "profile_list")
transformSeperator(fvValue(i));
transformReference(fvValue(i));
fvVector.emplace_back(FieldValueTuple(fvField(i), fvValue(i)));
SWSS_LOG_INFO("Inserting field %s value %s", fvField(i).c_str(), fvValue(i).c_str());
}
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/buffermgrdyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class BufferMgrDynamic : public Orch
// Tool functions to parse keys and references
std::string getPgPoolMode();
void transformSeperator(std::string &name);
void transformReference(std::string &name);
std::string parseObjectNameFromKey(const std::string &key, size_t pos/* = 1*/);
std::string parseObjectNameFromReference(const std::string &reference);
std::string getDynamicProfileName(const std::string &speed, const std::string &cable, const std::string &mtu, const std::string &threshold, const std::string &gearbox_model);
Expand Down
12 changes: 6 additions & 6 deletions tests/mock_tests/portsorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace portsorch_test
});

// Create test buffer profile
profileTable.set("test_profile", { { "pool", "[BUFFER_POOL:test_pool]" },
profileTable.set("test_profile", { { "pool", "[BUFFER_POOL_TABLE:test_pool]" },
{ "xon", "14832" },
{ "xoff", "14832" },
{ "size", "35000" },
Expand All @@ -124,7 +124,7 @@ namespace portsorch_test
{
std::ostringstream ossAppl, ossCfg;
ossAppl << it.first << ":3-4";
pgTable.set(ossAppl.str(), { { "profile", "[BUFFER_PROFILE:test_profile]" } });
pgTable.set(ossAppl.str(), { { "profile", "[BUFFER_PROFILE_TABLE:test_profile]" } });
ossCfg << it.first << "|3-4";
pgTableCfg.set(ossCfg.str(), { { "profile", "[BUFFER_PROFILE|test_profile]" } });
}
Expand Down Expand Up @@ -233,7 +233,7 @@ namespace portsorch_test
});

// Create test buffer profile
profileTable.set("test_profile", { { "pool", "[BUFFER_POOL:test_pool]" },
profileTable.set("test_profile", { { "pool", "[BUFFER_POOL_TABLE:test_pool]" },
{ "xon", "14832" },
{ "xoff", "14832" },
{ "size", "35000" },
Expand All @@ -244,7 +244,7 @@ namespace portsorch_test
{
std::ostringstream oss;
oss << it.first << ":3-4";
pgTable.set(oss.str(), { { "profile", "[BUFFER_PROFILE:test_profile]" } });
pgTable.set(oss.str(), { { "profile", "[BUFFER_PROFILE_TABLE:test_profile]" } });
}

// Populate pot table with SAI ports
Expand Down Expand Up @@ -399,7 +399,7 @@ namespace portsorch_test
});

// Create test buffer profile
profileTable.set("test_profile", { { "pool", "[BUFFER_POOL:test_pool]" },
profileTable.set("test_profile", { { "pool", "[BUFFER_POOL_TABLE:test_pool]" },
{ "xon", "14832" },
{ "xoff", "14832" },
{ "size", "35000" },
Expand All @@ -410,7 +410,7 @@ namespace portsorch_test
{
std::ostringstream oss;
oss << it.first << ":3-4";
pgTable.set(oss.str(), { { "profile", "[BUFFER_PROFILE:test_profile]" } });
pgTable.set(oss.str(), { { "profile", "[BUFFER_PROFILE_TABLE:test_profile]" } });
}
gBufferOrch->addExistingData(&pgTable);
gBufferOrch->addExistingData(&poolTable);
Expand Down
Loading

0 comments on commit 6c60a7d

Please sign in to comment.