-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sairedis] Client/Server support zmq configuration file (#845)
- Loading branch information
Showing
9 changed files
with
250 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "swss/sal.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace sairedis | ||
{ | ||
class ClientConfig | ||
{ | ||
public: | ||
|
||
ClientConfig(); | ||
|
||
virtual ~ClientConfig(); | ||
|
||
public: | ||
|
||
static std::shared_ptr<ClientConfig> loadFromFile( | ||
_In_ const char* path); | ||
|
||
public: | ||
|
||
std::string m_zmqEndpoint; | ||
|
||
std::string m_zmqNtfEndpoint; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "swss/sal.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace sairedis | ||
{ | ||
class ServerConfig | ||
{ | ||
public: | ||
|
||
ServerConfig(); | ||
|
||
virtual ~ServerConfig(); | ||
|
||
public: | ||
|
||
static std::shared_ptr<ServerConfig> loadFromFile( | ||
_In_ const char* path); | ||
|
||
public: | ||
|
||
std::string m_zmqEndpoint; | ||
|
||
std::string m_zmqNtfEndpoint; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "ClientConfig.h" | ||
|
||
#include "swss/logger.h" | ||
#include "swss/json.hpp" | ||
|
||
#include <cstring> | ||
#include <fstream> | ||
|
||
using json = nlohmann::json; | ||
|
||
using namespace sairedis; | ||
|
||
ClientConfig::ClientConfig(): | ||
m_zmqEndpoint("ipc:///tmp/saiServer"), | ||
m_zmqNtfEndpoint("ipc:///tmp/saiServerNtf") | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// empty intentionally | ||
} | ||
|
||
ClientConfig::~ClientConfig() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// empty intentionally | ||
} | ||
|
||
std::shared_ptr<ClientConfig> ClientConfig::loadFromFile( | ||
_In_ const char* path) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (path == nullptr || strlen(path) == 0) | ||
{ | ||
SWSS_LOG_NOTICE("no client config specified, will load default"); | ||
|
||
return std::make_shared<ClientConfig>(); | ||
} | ||
|
||
std::ifstream ifs(path); | ||
|
||
if (!ifs.good()) | ||
{ | ||
SWSS_LOG_ERROR("failed to read '%s', err: %s, returning default", path, strerror(errno)); | ||
|
||
return std::make_shared<ClientConfig>(); | ||
} | ||
|
||
try | ||
{ | ||
json j; | ||
ifs >> j; | ||
|
||
auto cc = std::make_shared<ClientConfig>(); | ||
|
||
cc->m_zmqEndpoint = j["zmq_endpoint"]; | ||
cc->m_zmqNtfEndpoint = j["zmq_endpoint_ntf"]; | ||
|
||
SWSS_LOG_NOTICE("client config: %s, %s", | ||
cc->m_zmqEndpoint.c_str(), | ||
cc->m_zmqNtfEndpoint.c_str()); | ||
|
||
SWSS_LOG_NOTICE("loaded %s client config", path); | ||
|
||
return cc; | ||
} | ||
catch (const std::exception& e) | ||
{ | ||
SWSS_LOG_ERROR("Failed to load '%s': %s, returning default", path, e.what()); | ||
|
||
return std::make_shared<ClientConfig>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "ServerConfig.h" | ||
|
||
#include "swss/logger.h" | ||
#include "swss/json.hpp" | ||
|
||
#include <cstring> | ||
#include <fstream> | ||
|
||
using json = nlohmann::json; | ||
|
||
using namespace sairedis; | ||
|
||
ServerConfig::ServerConfig(): | ||
m_zmqEndpoint("ipc:///tmp/saiServer"), | ||
m_zmqNtfEndpoint("ipc:///tmp/saiServerNtf") | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// empty intentionally | ||
} | ||
|
||
ServerConfig::~ServerConfig() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// empty intentionally | ||
} | ||
|
||
std::shared_ptr<ServerConfig> ServerConfig::loadFromFile( | ||
_In_ const char* path) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (path == nullptr || strlen(path) == 0) | ||
{ | ||
SWSS_LOG_NOTICE("no server config specified, will load default"); | ||
|
||
return std::make_shared<ServerConfig>(); | ||
} | ||
|
||
std::ifstream ifs(path); | ||
|
||
if (!ifs.good()) | ||
{ | ||
SWSS_LOG_ERROR("failed to read '%s', err: %s, returning default", path, strerror(errno)); | ||
|
||
return std::make_shared<ServerConfig>(); | ||
} | ||
|
||
try | ||
{ | ||
json j; | ||
ifs >> j; | ||
|
||
auto cc = std::make_shared<ServerConfig>(); | ||
|
||
cc->m_zmqEndpoint = j["zmq_endpoint"]; | ||
cc->m_zmqNtfEndpoint = j["zmq_endpoint_ntf"]; | ||
|
||
SWSS_LOG_NOTICE("server config: %s, %s", | ||
cc->m_zmqEndpoint.c_str(), | ||
cc->m_zmqNtfEndpoint.c_str()); | ||
|
||
SWSS_LOG_NOTICE("loaded %s server config", path); | ||
|
||
return cc; | ||
} | ||
catch (const std::exception& e) | ||
{ | ||
SWSS_LOG_ERROR("Failed to load '%s': %s, returning default", path, e.what()); | ||
|
||
return std::make_shared<ServerConfig>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"zmq_endpoint": "ipc:///tmp/saiServer", | ||
"zmq_ntf_endpoint": "ipc:///tmp/saiServerNtf" | ||
} |