Skip to content

Commit

Permalink
Merge branch 'master' into dynamic_port_counters_support
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-israel authored Nov 22, 2021
2 parents 550fe05 + 4f6cb05 commit 3e72fa4
Show file tree
Hide file tree
Showing 62 changed files with 6,313 additions and 855 deletions.
5 changes: 4 additions & 1 deletion cfgmgr/buffer_check_headroom_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ end
-- Initialize the accumulative size with 4096
-- This is to absorb the possible deviation
local accumulative_size = 4096
-- Egress mirror size: 2 * maximum MTU (10k)
local egress_mirror_size = 20*1024

local appl_db = "0"
local state_db = "6"
Expand Down Expand Up @@ -56,8 +58,9 @@ local pipeline_latency = tonumber(redis.call('HGET', asic_keys[1], 'pipeline_lat
if is_port_with_8lanes(lanes) then
-- The pipeline latency should be adjusted accordingly for ports with 2 buffer units
pipeline_latency = pipeline_latency * 2 - 1
egress_mirror_size = egress_mirror_size * 2
end
accumulative_size = accumulative_size + 2 * pipeline_latency * 1024
accumulative_size = accumulative_size + 2 * pipeline_latency * 1024 + egress_mirror_size

-- Fetch all keys in BUFFER_PG according to the port
redis.call('SELECT', appl_db)
Expand Down
25 changes: 24 additions & 1 deletion cfgmgr/buffer_headroom_mellanox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ local state_db = "6"

local ret = {}

-- pause quanta should be taken for each operating speed is defined in IEEE 802.3 31B.3.7
-- the key of table pause_quanta_per_speed is operating speed at Mb/s
-- the value of table pause_quanta_per_speed is the number of pause_quanta
local pause_quanta_per_speed = {}
pause_quanta_per_speed[400000] = 905
pause_quanta_per_speed[200000] = 453
pause_quanta_per_speed[100000] = 394
pause_quanta_per_speed[50000] = 147
pause_quanta_per_speed[40000] = 118
pause_quanta_per_speed[25000] = 80
pause_quanta_per_speed[10000] = 67
pause_quanta_per_speed[1000] = 2
pause_quanta_per_speed[100] = 1

-- Get pause_quanta from the pause_quanta_per_speed table
local pause_quanta = pause_quanta_per_speed[port_speed]

if gearbox_delay == nil then
gearbox_delay = 0
end
Expand All @@ -55,7 +72,8 @@ for i = 1, #asic_table_content, 2 do
if asic_table_content[i] == "mac_phy_delay" then
mac_phy_delay = tonumber(asic_table_content[i+1]) * 1024
end
if asic_table_content[i] == "peer_response_time" then
-- If failed to get pause_quanta from the table, then use the default peer_response_time stored in state_db
if asic_table_content[i] == "peer_response_time" and pause_quanta == nil then
peer_response_time = tonumber(asic_table_content[i+1]) * 1024
end
end
Expand Down Expand Up @@ -124,6 +142,11 @@ else
bytes_on_gearbox = port_speed * gearbox_delay / (8 * 1024)
end

-- If successfully get pause_quanta from the table, then calculate peer_response_time from it
if pause_quanta ~= nil then
peer_response_time = (pause_quanta) * 512 / 8
end

bytes_on_cable = 2 * cable_length * port_speed * 1000000000 / speed_of_light / (8 * 1024)
propagation_delay = port_mtu + bytes_on_cable + 2 * bytes_on_gearbox + mac_phy_delay + peer_response_time

Expand Down
112 changes: 77 additions & 35 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ 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 @@ -122,9 +133,9 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
}
}
*/
task_process_status BufferMgr::doSpeedUpdateTask(string port)
task_process_status BufferMgr::doSpeedUpdateTask(string port, bool admin_up)
{
vector<FieldValueTuple> fvVector;
vector<FieldValueTuple> fvVectorPg, fvVectorProfile;
string cable;
string speed;

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

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 = 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("Not 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, fvVector);
if (fvVector.size() == 0)
m_cfgBufferProfileTable.get(buffer_profile_key, fvVectorProfile);
// Create record in BUFFER_PROFILE table
if (fvVectorProfile.size() == 0)
{
SWSS_LOG_NOTICE("Creating new profile '%s'", buffer_profile_key.c_str());

Expand All @@ -170,32 +211,24 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port)
// profile threshold field name
mode += "_th";

fvVector.push_back(make_pair("pool", INGRESS_LOSSLESS_PG_POOL_NAME));
fvVector.push_back(make_pair("xon", m_pgProfileLookup[speed][cable].xon));
fvVectorProfile.push_back(make_pair("pool", INGRESS_LOSSLESS_PG_POOL_NAME));
fvVectorProfile.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",
fvVectorProfile.push_back(make_pair("xon_offset",
m_pgProfileLookup[speed][cable].xon_offset));
}
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);
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);
}
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 = buffer_profile_key;

/* Check if PG Mapping is already then log message and return. */
m_cfgBufferPgTable.get(buffer_pg_key, fvVector);

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

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

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

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

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

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: 3 additions & 1 deletion cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class BufferMgr : public Orch
using Orch::doTask;

private:
std::string m_platform;

Table m_cfgPortTable;
Table m_cfgCableLenTable;
Table m_cfgBufferProfileTable;
Expand All @@ -58,7 +60,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);
task_process_status doSpeedUpdateTask(std::string port, bool admin_up);
void doBufferTableTask(Consumer &consumer, ProducerStateTable &applTable);

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

void usage()
{
cout << "Usage: buffermgrd <-l pg_lookup.ini|-a asic_table.json [-p peripheral_table.json]>" << endl;
cout << "Usage: buffermgrd <-l pg_lookup.ini|-a asic_table.json [-p peripheral_table.json] [-z zero_profiles.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 (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;
}

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

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

while ((opt = getopt(argc, argv, "l:a:p:h")) != -1 )
while ((opt = getopt(argc, argv, "l:a:p:z:h")) != -1 )
{
switch (opt)
{
Expand All @@ -131,6 +132,9 @@ 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 @@ -141,7 +145,9 @@ int main(int argc, char **argv)
{
std::vector<Orch *> cfgOrchList;
bool dynamicMode = false;
shared_ptr<vector<KeyOpFieldsValuesTuple>> db_items_ptr;
shared_ptr<vector<KeyOpFieldsValuesTuple>> asic_table_ptr = nullptr;
shared_ptr<vector<KeyOpFieldsValuesTuple>> peripherial_table_ptr = nullptr;
shared_ptr<vector<KeyOpFieldsValuesTuple>> zero_profiles_ptr = nullptr;

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

if (!peripherial_table_file.empty())
{
//Load the json file containing the PERIPHERIAL_TABLE
db_items_ptr = load_json(peripherial_table_file);
if (nullptr != db_items_ptr)
write_to_state_db(db_items_ptr);
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);
}

dynamicMode = true;
Expand All @@ -183,7 +194,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, db_items_ptr));
cfgOrchList.emplace_back(new BufferMgrDynamic(&cfgDb, &stateDb, &applDb, buffer_table_connectors, peripherial_table_ptr, zero_profiles_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 = nullptr) :
BufferMgrDynamic::BufferMgrDynamic(DBConnector *cfgDb, DBConnector *stateDb, DBConnector *applDb, const vector<TableConnector> &tables, shared_ptr<vector<KeyOpFieldsValuesTuple>> gearboxInfo, shared_ptr<vector<KeyOpFieldsValuesTuple>> zeroProfilesInfo) :
Orch(tables),
m_platform(),
m_applDb(applDb),
Expand Down
2 changes: 1 addition & 1 deletion cfgmgr/buffermgrdyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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);
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);
using Orch::doTask;

private:
Expand Down
5 changes: 4 additions & 1 deletion cfgmgr/macsecmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,13 @@ bool MACsecMgr::isPortStateOk(const std::string & port_name)

std::vector<FieldValueTuple> temp;
std::string state;
std::string oper_status;

if (m_statePortTable.get(port_name, temp)
&& get_value(temp, "state", state)
&& state == "ok")
&& state == "ok"
&& get_value(temp, "netdev_oper_status", oper_status)
&& oper_status == "up")
{
SWSS_LOG_DEBUG("Port '%s' is ready", port_name.c_str());
return true;
Expand Down
Loading

0 comments on commit 3e72fa4

Please sign in to comment.