Skip to content

Commit

Permalink
Merge branch 'master' of github.com:azure/sonic-swss into acl-fc
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanblyschak committed Oct 4, 2021
2 parents 1a08896 + da49332 commit 4eef944
Show file tree
Hide file tree
Showing 52 changed files with 1,037 additions and 498 deletions.
6 changes: 3 additions & 3 deletions cfgmgr/buffer_check_headroom_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ end
table.insert(debuginfo, 'debug:other overhead:' .. accumulative_size)
local pg_keys = redis.call('KEYS', 'BUFFER_PG_TABLE:' .. port .. ':*')
for i = 1, #pg_keys do
local profile = string.sub(redis.call('HGET', pg_keys[i], 'profile'), 2, -2)
local profile = redis.call('HGET', pg_keys[i], 'profile')
local current_profile_size
if profile ~= 'BUFFER_PROFILE_TABLE:ingress_lossy_profile' and (no_input_pg or new_pg ~= pg_keys[i]) then
if profile ~= 'ingress_lossy_profile' and (no_input_pg or new_pg ~= pg_keys[i]) then
if profile ~= input_profile_name and not no_input_pg then
local referenced_profile = redis.call('HGETALL', profile)
local referenced_profile = redis.call('HGETALL', 'BUFFER_PROFILE_TABLE:' .. profile)
for j = 1, #referenced_profile, 2 do
if referenced_profile[j] == 'size' then
current_profile_size = tonumber(referenced_profile[j+1])
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/buffer_pool_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local function iterate_all_items(all_items, check_lossless)
if not profile_name then
return 1
end
profile_name = string.sub(profile_name, 2, -2)
profile_name = "BUFFER_PROFILE_TABLE:" .. profile_name
local profile_ref_count = profiles[profile_name]
if profile_ref_count == nil then
-- Indicate an error in case the referenced profile hasn't been inserted or has been removed
Expand Down
49 changes: 4 additions & 45 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
"BUFFER_PROFILE": {
"pg_lossless_100G_300m_profile": {
"pool":"[BUFFER_POOL_TABLE:ingress_lossless_pool]",
"pool":"ingress_lossless_pool",
"xon":"18432",
"xon_offset":"2496",
"xoff":"165888",
Expand All @@ -117,7 +117,7 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
}
"BUFFER_PG" :{
Ethernet44|3-4": {
"profile" : "[BUFFER_PROFILE:pg_lossless_100000_300m_profile]"
"profile" : "pg_lossless_100000_300m_profile"
}
}
*/
Expand Down Expand Up @@ -168,11 +168,8 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)

// profile threshold field name
mode += "_th";
string pg_pool_reference = string(CFG_BUFFER_POOL_TABLE_NAME) +
m_cfgBufferProfileTable.getTableNameSeparator() +
INGRESS_LOSSLESS_PG_POOL_NAME;

fvVector.push_back(make_pair("pool", "[" + pg_pool_reference + "]"));
fvVector.push_back(make_pair("pool", INGRESS_LOSSLESS_PG_POOL_NAME));
fvVector.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
if (m_pgProfileLookup[speed][cable].xon_offset.length() > 0) {
fvVector.push_back(make_pair("xon_offset",
Expand All @@ -192,11 +189,7 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)

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 +
"]";
string profile_ref = buffer_profile_key;

/* Check if PG Mapping is already then log message and return. */
m_cfgBufferPgTable.get(buffer_pg_key, fvVector);
Expand Down Expand Up @@ -224,32 +217,6 @@ void BufferMgr::transformSeperator(string &name)
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 @@ -292,14 +259,6 @@ 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")
transformReference(fvValue(i));
if (fvField(i) == "profile")
transformReference(fvValue(i));
if (fvField(i) == "profile_list")
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: 0 additions & 1 deletion cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ 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
60 changes: 4 additions & 56 deletions cfgmgr/buffermgrdyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,32 +202,6 @@ 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)
{
Expand All @@ -240,13 +214,6 @@ string BufferMgrDynamic::parseObjectNameFromKey(const string &key, size_t pos =
return keys[pos];
}

// For string "[foo]", returns "foo"
string BufferMgrDynamic::parseObjectNameFromReference(const string &reference)
{
auto objName = reference.substr(1, reference.size() - 2);
return parseObjectNameFromKey(objName, 1);
}

string BufferMgrDynamic::getDynamicProfileName(const string &speed, const string &cable, const string &mtu, const string &threshold, const string &gearbox_model, long lane_count)
{
string buffer_profile_key;
Expand Down Expand Up @@ -619,17 +586,14 @@ void BufferMgrDynamic::updateBufferProfileToDb(const string &name, const buffer_

// profile threshold field name
mode += "_th";
string pg_pool_reference = string(APP_BUFFER_POOL_TABLE_NAME) +
m_applBufferProfileTable.getTableNameSeparator() +
INGRESS_LOSSLESS_PG_POOL_NAME;

fvVector.emplace_back("xon", profile.xon);
if (!profile.xon_offset.empty()) {
fvVector.emplace_back("xon_offset", profile.xon_offset);
}
fvVector.emplace_back("xoff", profile.xoff);
fvVector.emplace_back("size", profile.size);
fvVector.emplace_back("pool", "[" + pg_pool_reference + "]");
fvVector.emplace_back("pool", INGRESS_LOSSLESS_PG_POOL_NAME);
fvVector.emplace_back(mode, profile.threshold);

m_applBufferProfileTable.set(name, fvVector);
Expand All @@ -646,15 +610,7 @@ void BufferMgrDynamic::updateBufferPgToDb(const string &key, const string &profi

fvVector.clear();

string profile_ref = string("[") +
APP_BUFFER_PROFILE_TABLE_NAME +
m_applBufferPgTable.getTableNameSeparator() +
profile +
"]";

fvVector.clear();

fvVector.push_back(make_pair("profile", profile_ref));
fvVector.push_back(make_pair("profile", profile));
m_applBufferPgTable.set(key, fvVector);
}
else
Expand Down Expand Up @@ -1779,8 +1735,7 @@ task_process_status BufferMgrDynamic::handleBufferProfileTable(KeyOpFieldsValues
{
if (!value.empty())
{
transformReference(value);
auto poolName = parseObjectNameFromReference(value);
auto poolName = value;
if (poolName.empty())
{
SWSS_LOG_ERROR("BUFFER_PROFILE: Invalid format of reference to pool: %s", value.c_str());
Expand Down Expand Up @@ -1953,8 +1908,7 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
{
// Headroom override
pureDynamic = false;
transformReference(value);
string profileName = parseObjectNameFromReference(value);
string profileName = value;
if (profileName.empty())
{
SWSS_LOG_ERROR("BUFFER_PG: Invalid format of reference to profile: %s", value.c_str());
Expand Down Expand Up @@ -2170,12 +2124,6 @@ task_process_status BufferMgrDynamic::doBufferTableTask(KeyOpFieldsValuesTuple &
for (auto i : kfvFieldsValues(tuple))
{
// Transform the separator in values from "|" to ":"
if (fvField(i) == "pool")
transformReference(fvValue(i));
if (fvField(i) == "profile")
transformReference(fvValue(i));
if (fvField(i) == "profile_list")
transformReference(fvValue(i));
fvVector.emplace_back(fvField(i), fvValue(i));
SWSS_LOG_INFO("Inserting field %s value %s", fvField(i).c_str(), fvValue(i).c_str());
}
Expand Down
2 changes: 0 additions & 2 deletions cfgmgr/buffermgrdyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,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, long lane_count);
inline bool isNonZero(const std::string &value) const
{
Expand Down
45 changes: 40 additions & 5 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,53 @@ void TeamMgr::doTask(Consumer &consumer)
}
}


void TeamMgr::cleanTeamProcesses()
{
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("Cleaning up LAGs during shutdown...");
for (const auto& it: m_lagList)

std::unordered_map<std::string, pid_t> aliasPidMap;

for (const auto& alias: m_lagList)
{
std::string res;
pid_t pid;

{
std::stringstream cmd;
cmd << "cat " << shellquote("/var/run/teamd/" + alias + ".pid");
EXEC_WITH_ERROR_THROW(cmd.str(), res);

pid = static_cast<pid_t>(std::stoul(res, nullptr, 10));
aliasPidMap[alias] = pid;

SWSS_LOG_INFO("Read port channel %s pid %d", alias.c_str(), pid);
}

{
std::stringstream cmd;
cmd << "kill -TERM " << pid;
EXEC_WITH_ERROR_THROW(cmd.str(), res);

SWSS_LOG_INFO("Sent SIGTERM to port channel %s pid %d", alias.c_str(), pid);
}
}

for (const auto& cit: aliasPidMap)
{
//This will call team -k kill -t <teamdevicename> which internally send SIGTERM
removeLag(it);
const auto &alias = cit.first;
const auto &pid = cit.second;

std::stringstream cmd;
std::string res;

SWSS_LOG_NOTICE("Waiting for port channel %s pid %d to stop...", alias.c_str(), pid);

cmd << "tail -f --pid=" << pid << " /dev/null";
EXEC_WITH_ERROR_THROW(cmd.str(), res);
}

return;
SWSS_LOG_NOTICE("LAGs cleanup is done");
}

void TeamMgr::doLagTask(Consumer &consumer)
Expand Down
2 changes: 0 additions & 2 deletions cfgmgr/teammgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TeamMgr : public Orch
ProducerStateTable m_appLagTable;

std::set<std::string> m_lagList;
std::map<std::string, pid_t> m_lagPIDList;

MacAddress m_mac;

Expand All @@ -50,7 +49,6 @@ class TeamMgr : public Orch
bool setLagMtu(const std::string &alias, const std::string &mtu);
bool setLagLearnMode(const std::string &alias, const std::string &learn_mode);
bool setLagTpid(const std::string &alias, const std::string &tpid);


bool isPortEnslaved(const std::string &);
bool findPortMaster(std::string &, const std::string &);
Expand Down
5 changes: 3 additions & 2 deletions cfgmgr/teammgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char **argv)
}

while (!received_sigterm)
{
{
Selectable *sel;
int ret;

Expand All @@ -91,7 +91,8 @@ int main(int argc, char **argv)
catch (const exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
return EXIT_FAILURE;
}

return -1;
return EXIT_SUCCESS;
}
Loading

0 comments on commit 4eef944

Please sign in to comment.