Skip to content

Commit

Permalink
[proxy] Support load profile map from file (sonic-net#1389)
Browse files Browse the repository at this point in the history
Implement load config.ini to profile map.

Remove unused proxy header
  • Loading branch information
kcudnik authored Jun 10, 2024
1 parent 1f2c861 commit 4f0fcaf
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 451 deletions.
25 changes: 24 additions & 1 deletion meta/DummySaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,33 @@ void DummySaiInterface::setStatus(

sai_status_t DummySaiInterface::apiInitialize(
_In_ uint64_t flags,
_In_ const sai_service_method_table_t *service_method_table)
_In_ const sai_service_method_table_t *smt)
{
SWSS_LOG_ENTER();

if (smt)
{
if (smt->profile_get_value)
{
SWSS_LOG_NOTICE("Dummy: profile_get_value(NULL): %s", smt->profile_get_value(0, NULL));
SWSS_LOG_NOTICE("Dummy: profile_get_value(FOO): %s", smt->profile_get_value(0, "FOO"));
SWSS_LOG_NOTICE("Dummy: profile_get_value(FOO): %s", smt->profile_get_value(0, "CAR"));
}

if (smt->profile_get_next_value)
{

const char *var = NULL;
const char *val = NULL;

SWSS_LOG_NOTICE("Dummy: profile_get_next_value: %d", smt->profile_get_next_value(0, NULL, NULL));
SWSS_LOG_NOTICE("Dummy: profile_get_next_value: %d", smt->profile_get_next_value(0, NULL, &val));
SWSS_LOG_NOTICE("Dummy: profile_get_next_value: %d", smt->profile_get_next_value(0, &var, NULL));
SWSS_LOG_NOTICE("Dummy: profile_get_next_value: %d", smt->profile_get_next_value(0, &var, &val));
SWSS_LOG_NOTICE("Dummy: profile_get_next_value: %d", smt->profile_get_next_value(0, &var, &val));
}
}

return SAI_STATUS_SUCCESS;
}

Expand Down
47 changes: 47 additions & 0 deletions proxylib/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ Proxy::Proxy(
{
SWSS_LOG_ENTER();

m_configFile = "config.ini"; // TODO to command line

// TODO to move hard coded addresses to config

m_selectableChannel = std::make_shared<sairedis::ZeroMQSelectableChannel>("tcp://127.0.0.1:5555");
m_notifications = std::make_shared<syncd::ZeroMQNotificationProducer>("tcp://127.0.0.1:5556");

loadProfileMap();

m_smt.profileGetValue = std::bind(&Proxy::profileGetValue, this, _1, _2);
m_smt.profileGetNextValue = std::bind(&Proxy::profileGetNextValue, this, _1, _2, _3);

Expand All @@ -55,6 +59,8 @@ Proxy::~Proxy()
{
SWSS_LOG_ENTER();

// TODO call stop()

if (m_apiInitialized)
{
SWSS_LOG_NOTICE("calling api uninitialize");
Expand All @@ -73,6 +79,47 @@ Proxy::~Proxy()
m_notifications = nullptr;
}

void Proxy::loadProfileMap()
{
SWSS_LOG_ENTER();

std::ifstream profile(m_configFile.c_str());

if (!profile.is_open())
{
SWSS_LOG_WARN("failed to open profile map file: %s: %s",
m_configFile.c_str(),
strerror(errno));

return;
}

std::string line;

while (getline(profile, line))
{
if (line.size() > 0 && (line[0] == '#' || line[0] == ';'))
{
continue;
}

size_t pos = line.find("=");

if (pos == std::string::npos)
{
SWSS_LOG_WARN("not found '=' in line %s", line.c_str());
continue;
}

std::string key = line.substr(0, pos);
std::string value = line.substr(pos + 1);

m_profileMap[key] = value;

SWSS_LOG_NOTICE("insert: %s:%s", key.c_str(), value.c_str());
}
}

const char* Proxy::profileGetValue(
_In_ sai_switch_profile_id_t profile_id,
_In_ const char* variable)
Expand Down
7 changes: 7 additions & 0 deletions proxylib/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ namespace saiproxy

void processClearStats(
_In_ const swss::KeyOpFieldsValuesTuple &kco);

private:

void loadProfileMap();

private:

syncd::ServiceMethodTable m_smt;
Expand All @@ -116,6 +121,8 @@ namespace saiproxy

std::shared_ptr<syncd::NotificationProducerBase> m_notifications;

std::string m_configFile;

/**
* @brief Mutex for synchronizing api execution and notifications
*/
Expand Down
Loading

0 comments on commit 4f0fcaf

Please sign in to comment.