-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SAI] Add support for dash configuration from sai interface
- Loading branch information
Showing
6 changed files
with
257 additions
and
17 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
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,127 @@ | ||
#include "config.h" | ||
#include "logger.h" | ||
#include "saidash.h" | ||
|
||
#include <cstdlib> | ||
#include <sstream> | ||
|
||
using namespace dash; | ||
|
||
Config::Config(): | ||
m_grpcTarget(DEFAULT_GRPC_TARGET), | ||
m_pipelineJson(DEFAULT_PIPELINE_JSON), | ||
m_pipelineProto(DEFAULT_PIPELINE_PROTO), | ||
m_deviceId(DEFAULT_DEVICE_ID), | ||
m_bmv2NumPorts(DEFAULT_BMV2_NUM_PORTS) | ||
{ | ||
DASH_LOG_ENTER(); | ||
|
||
// empty intentionally | ||
} | ||
|
||
std::shared_ptr<Config> Config::getDefaultConfig() | ||
{ | ||
DASH_LOG_ENTER(); | ||
|
||
return std::make_shared<Config>(); | ||
} | ||
|
||
std::shared_ptr<Config> Config::getConfig( | ||
const sai_service_method_table_t* serviceMethodTable) | ||
{ | ||
DASH_LOG_ENTER(); | ||
|
||
auto cfg = getDefaultConfig(); | ||
|
||
if (serviceMethodTable == nullptr) | ||
{ | ||
DASH_LOG_NOTICE("service method table is null, returning default config"); | ||
|
||
return cfg; | ||
} | ||
|
||
if (serviceMethodTable->profile_get_value == nullptr) | ||
{ | ||
DASH_LOG_NOTICE("profile_get_value member is null, returning default config"); | ||
|
||
return cfg; | ||
} | ||
|
||
auto grpcTarget = serviceMethodTable->profile_get_value(0, SAI_KEY_DASH_GRPC_TARGET); | ||
|
||
if (grpcTarget) | ||
{ | ||
DASH_LOG_NOTICE("%s: %s", SAI_KEY_DASH_GRPC_TARGET, grpcTarget); | ||
|
||
cfg->m_grpcTarget = grpcTarget; | ||
} | ||
|
||
auto pipelineJson = serviceMethodTable->profile_get_value(0, SAI_KEY_DASH_PIPELINE_JSON); | ||
|
||
if (pipelineJson) | ||
{ | ||
DASH_LOG_NOTICE("%s: %s", SAI_KEY_DASH_PIPELINE_JSON, pipelineJson); | ||
|
||
cfg->m_pipelineJson = pipelineJson; | ||
} | ||
|
||
auto pipelineProto = serviceMethodTable->profile_get_value(0, SAI_KEY_DASH_PIPELINE_PROTO); | ||
|
||
if (pipelineProto) | ||
{ | ||
DASH_LOG_NOTICE("%s: %s", SAI_KEY_DASH_PIPELINE_JSON, pipelineProto); | ||
|
||
cfg->m_pipelineProto = pipelineProto; | ||
} | ||
|
||
auto deviceId = serviceMethodTable->profile_get_value(0, SAI_KEY_DASH_DEVICE_ID); | ||
|
||
if (deviceId) | ||
{ | ||
int devId = atoi(deviceId); | ||
|
||
cfg->m_deviceId = devId; | ||
|
||
DASH_LOG_NOTICE("%s: %s (%d)", SAI_KEY_DASH_DEVICE_ID, deviceId, devId); | ||
} | ||
|
||
auto numPorts = serviceMethodTable->profile_get_value(0, SAI_KEY_DASH_BMV2_NUM_PORTS); | ||
|
||
if (numPorts) | ||
{ | ||
uint32_t num = (uint32_t)atoi(numPorts); | ||
|
||
if (num > MAX_BMV2_NUM_PORTS) | ||
{ | ||
DASH_LOG_ERROR("%s: %s (%u > %u), setting to default %u", | ||
SAI_KEY_DASH_BMV2_NUM_PORTS, | ||
numPorts, | ||
num, | ||
MAX_BMV2_NUM_PORTS, | ||
DEFAULT_BMV2_NUM_PORTS); | ||
|
||
num = DEFAULT_BMV2_NUM_PORTS; | ||
} | ||
|
||
cfg->m_bmv2NumPorts = num; | ||
|
||
DASH_LOG_NOTICE("%s: %s (%u)", SAI_KEY_DASH_BMV2_NUM_PORTS, numPorts, num); | ||
} | ||
|
||
return cfg; | ||
} | ||
|
||
std::string Config::getConfigString() const | ||
{ | ||
DASH_LOG_ENTER(); | ||
|
||
std::stringstream ss; | ||
|
||
ss << " GrpcTarget=" << m_grpcTarget; | ||
ss << " PipelineJson=" << m_pipelineJson; | ||
ss << " PipelineProto=" << m_pipelineProto; | ||
ss << " DeviceId=" << m_deviceId; | ||
ss << " Bmv2NumPorts=" << m_bmv2NumPorts; | ||
|
||
return ss.str(); | ||
} |
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,52 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
#include <sai.h> | ||
} | ||
|
||
#include <string> | ||
#include <memory> | ||
|
||
namespace dash | ||
{ | ||
constexpr char DEFAULT_GRPC_TARGET[] = "0.0.0.0:9559"; | ||
|
||
constexpr char DEFAULT_PIPELINE_JSON[] = "/etc/dash/dash_pipeline.json"; | ||
|
||
constexpr char DEFAULT_PIPELINE_PROTO[] = "/etc/dash/dash_pipeline_p4rt.txt"; | ||
|
||
constexpr int DEFAULT_DEVICE_ID = 0; | ||
|
||
constexpr uint32_t DEFAULT_BMV2_NUM_PORTS = 2; | ||
|
||
constexpr uint32_t MAX_BMV2_NUM_PORTS = 64; | ||
|
||
class Config | ||
{ | ||
public: | ||
|
||
Config(); | ||
~Config() = default; | ||
|
||
public: | ||
|
||
static std::shared_ptr<Config> getDefaultConfig(); | ||
|
||
static std::shared_ptr<Config> getConfig( | ||
const sai_service_method_table_t* serviceMethodTable); | ||
|
||
std::string getConfigString() const; | ||
|
||
public: | ||
|
||
std::string m_grpcTarget; | ||
|
||
std::string m_pipelineJson; | ||
|
||
std::string m_pipelineProto; | ||
|
||
int m_deviceId; | ||
|
||
uint32_t m_bmv2NumPorts; | ||
}; | ||
} |
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,48 @@ | ||
#pragma once | ||
|
||
/** | ||
* @def SAI_KEY_DASH_GRPC_TARGET | ||
* | ||
* Specifies GRPC target in format IP:port. | ||
* | ||
* Example: 0.0.0.0:9559 | ||
*/ | ||
#define SAI_KEY_DASH_GRPC_TARGET "SAI_DASH_GRPC_TARGET" | ||
|
||
/** | ||
* @def SAI_KEY_DASH_PIPELINE_JSON | ||
* | ||
* Specifies pipeline json file path. | ||
* | ||
* Example: /etc/dash/dash_pipeline.json | ||
*/ | ||
#define SAI_KEY_DASH_PIPELINE_JSON "SAI_DASH_PIPELINE_JSON" | ||
|
||
/** | ||
* @def SAI_KEY_DASH_PIPELINE_PROTO | ||
* | ||
* Specifies pipeline proto p4rt file path. | ||
* | ||
* Example: /etc/dash/dash_pipeline_p4rt.txt | ||
*/ | ||
#define SAI_KEY_DASH_PIPELINE_PROTO "SAI_DASH_PIPELINE_PROTO" | ||
|
||
/** Below defines could be depreacated if multiple asic will appear */ | ||
|
||
/** | ||
* @def SAI_KEY_DASH_DEVICE_ID | ||
* | ||
* Specifies device ID as integer. | ||
* | ||
* Example: 0 | ||
*/ | ||
#define SAI_KEY_DASH_DEVICE_ID "SAI_DASH_DEVICE_ID" | ||
|
||
/** | ||
* @def SAI_KEY_DASH_BMV2_NUM_PORTS | ||
* | ||
* Specifies number of ports in bmv2 as unsigned integer. | ||
* | ||
* Example: 2 | ||
*/ | ||
#define SAI_KEY_DASH_BMV2_NUM_PORTS "SAI_DASH_BMV2_NUM_PORTS" |
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