Skip to content

Commit

Permalink
[Buffermgr]Graceful handling of buffer model change
Browse files Browse the repository at this point in the history
  • Loading branch information
dgsudharsan committed Oct 12, 2021
1 parent da49332 commit 8e87cd9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
51 changes: 51 additions & 0 deletions cfgmgr/buffermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BufferMgr::BufferMgr(DBConnector *cfgDb, DBConnector *applDb, string pg_lookup_f
m_applBufferEgressProfileListTable(applDb, APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME)
{
readPgProfileLookupFile(pg_lookup_file);
dynamic_buffer_model = false;
}

//# speed, cable, size, xon, xoff, threshold, xon_offset
Expand Down Expand Up @@ -273,12 +274,62 @@ void BufferMgr::doBufferTableTask(Consumer &consumer, ProducerStateTable &applTa
}
}

void BufferMgr::doBufferMetaTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;
string key = kfvKey(t);

string op = kfvOp(t);
if (op == SET_COMMAND)
{
vector<FieldValueTuple> fvVector;

for (auto i : kfvFieldsValues(t))
{
if (fvField(i) == "buffer_model")
{
if (fvValue(i) == "dynamic")
{
dynamic_buffer_model = true;
}
else
{
dynamic_buffer_model = false;
}
break;
}
}
}
else if (op == DEL_COMMAND)
{
dynamic_buffer_model = false;
}
it = consumer.m_toSync.erase(it);
}
}

void BufferMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

string table_name = consumer.getTableName();

if (table_name == CFG_DEVICE_METADATA_TABLE_NAME)
{
doBufferMetaTask(consumer);
return;
}

if (dynamic_buffer_model)
{
SWSS_LOG_DEBUG("Dynamic buffer model enabled. Skipping further processing");
return;
}
if (table_name == CFG_BUFFER_POOL_TABLE_NAME)
{
doBufferTableTask(consumer, m_applBufferPoolTable);
Expand Down
2 changes: 2 additions & 0 deletions cfgmgr/buffermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BufferMgr : public Orch
ProducerStateTable m_applBufferEgressProfileListTable;

bool m_pgfile_processed;
bool dynamic_buffer_model;

pg_profile_lookup_t m_pgProfileLookup;
port_cable_length_t m_cableLenLookup;
Expand All @@ -63,6 +64,7 @@ class BufferMgr : public Orch
void transformSeperator(std::string &name);

void doTask(Consumer &consumer);
void doBufferMetaTask(Consumer &consumer);
};

}
Expand Down
3 changes: 2 additions & 1 deletion cfgmgr/buffermgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ int main(int argc, char **argv)
CFG_BUFFER_PG_TABLE_NAME,
CFG_BUFFER_QUEUE_TABLE_NAME,
CFG_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME,
CFG_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME
CFG_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME,
CFG_DEVICE_METADATA_TABLE_NAME
};
cfgOrchList.emplace_back(new BufferMgr(&cfgDb, &applDb, pg_lookup_file, cfg_buffer_tables));
}
Expand Down
13 changes: 13 additions & 0 deletions tests/test_buffer_mode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import pytest
import time

class TestBufferModel(object):
def test_bufferModel(self, dvs, testlog):
config_db = dvs.get_config_db()
metadata = config_db.get_entry("DEVICE_METADATA", "localhost")
assert metadata["buffer_model"] == "traditional"

def test_update_bufferModel(self, dvs, testlog):
config_db = dvs.get_config_db()
app_db = dvs.get_app_db()
keys = app_db.get_keys("BUFFER_POOL_TABLE")
num_keys = len(keys)
fvs = {'buffer_model' : 'dynamic'}
config_db.update_entry("DEVICE_METADATA", "localhost", fvs)
fvs = {'mode':'dynamic', 'type':'egress'}
config_db.update_entry("BUFFER_POOL", "temp_pool", fvs)
time.sleep(2)
app_db.wait_for_n_keys("BUFFER_POOL_TABLE", num_keys)

0 comments on commit 8e87cd9

Please sign in to comment.