Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions cfgmgr/otnmgr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "logger.h"
#include "dbconnector.h"
#include "tokenize.h"
#include "ipprefix.h"
#include "otnmgr.h"
#include "exec.h"
#include "shellcmd.h"
#include <swss/redisutility.h>

using namespace std;
using namespace swss;

OtnMgr::OtnMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector<std::string> &tableNames, const std::map<std::string, std::string> &tableMaps) :
Orch(cfgDb, tableNames),
m_appl_db(appDb),
m_state_db(stateDb),
m_tableMaps(tableMaps)
{
}

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

string cfgName = consumer.getTableName();

/* get app table by name */
auto itApp = m_tableMaps.find(cfgName);
if (itApp == m_tableMaps.end())
{
SWSS_LOG_ERROR("OtnMgr|%s is invalid", cfgName.c_str());
return;
}
const string &appName = itApp->second;
shared_ptr<ProducerStateTable> appTable;
auto itTable = m_appTables.find(appName);
if (itTable == m_appTables.end())
{
appTable = make_shared<ProducerStateTable>(m_appl_db, appName);
m_appTables[appName] = appTable;
}
else
{
appTable = itTable->second;
}

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

SWSS_LOG_NOTICE("OtnMgr doTask, cfg=%s, app=%s, key=%s, op=%s", cfgName.c_str(), appName.c_str(), alias.c_str(), op.c_str());

if (op == SET_COMMAND)
{
auto values = kfvFieldsValues(t);
for (auto value : values)
{
SWSS_LOG_NOTICE("OtnMgr doTask, key=%s, value=%s", value.first.c_str(), value.second.c_str());
}
if (values.size())
{
writeConfigToAppDb(appTable, alias, values);
}
}
else if (op == DEL_COMMAND)
{
SWSS_LOG_NOTICE("Delete component: %s", alias.c_str());
appTable->del(alias);
}

it = consumer.m_toSync.erase(it);
}
}

void OtnMgr::writeConfigToAppDb(std::shared_ptr<ProducerStateTable> &table, const std::string &alias, const std::string &field, const std::string &value)
{
SWSS_LOG_ENTER();

vector<FieldValueTuple> fvs;
FieldValueTuple fv(field, value);
fvs.push_back(fv);
table->set(alias, fvs);
}

void OtnMgr::writeConfigToAppDb(std::shared_ptr<ProducerStateTable> &table, const std::string &alias, std::vector<FieldValueTuple> &field_values)
{
SWSS_LOG_ENTER();

table->set(alias, field_values);
}
30 changes: 30 additions & 0 deletions cfgmgr/otnmgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "dbconnector.h"
#include "orch.h"
#include "producerstatetable.h"

#include <map>
#include <string>
#include <memory>

namespace swss {

class OtnMgr : public Orch
{
public:
OtnMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const std::vector<std::string> &tableNames, const std::map<std::string, std::string> &tableMaps);

using Orch::doTask;
private:
DBConnector *m_appl_db;
DBConnector *m_state_db;
const std::map<std::string, std::string> &m_tableMaps;
std::map<std::string, std::shared_ptr<ProducerStateTable>> m_appTables;

void doTask(Consumer &consumer);
void writeConfigToAppDb(std::shared_ptr<ProducerStateTable> &table, const std::string &alias, const std::string &field, const std::string &value);
void writeConfigToAppDb(std::shared_ptr<ProducerStateTable> &table, const std::string &alias, std::vector<FieldValueTuple> &field_values);
};

}
84 changes: 84 additions & 0 deletions cfgmgr/otnmgrd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <fstream>
#include <iostream>
#include <mutex>
#include <unistd.h>
#include <vector>

#include "exec.h"
#include "otnmgr.h"
#include "schema.h"
#include "select.h"

using namespace std;
using namespace swss;

/* select() function timeout retry time, in millisecond */
#define SELECT_TIMEOUT 1000

int main(int argc, char **argv)
{
Logger::linkToDbNative("OtnMgrd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting OtnMgrd ---");

try
{
map<string, string> cfg_maps =
{
{ CFG_OTN_DEVICE_TABLE_NAME, APP_OTN_DEVICE_TABLE_NAME },
{ CFG_OTN_ATTENUATOR_TABLE_NAME, APP_OTN_ATTENUATOR_TABLE_NAME },
{ CFG_OTN_OA_TABLE_NAME, APP_OTN_OA_TABLE_NAME },
{ CFG_OTN_OCM_TABLE_NAME, APP_OTN_OCM_TABLE_NAME },
{ CFG_OTN_OCM_CHANNEL_TABLE_NAME, APP_OTN_OCM_CHANNEL_TABLE_NAME },
{ CFG_OTN_OSC_TABLE_NAME, APP_OTN_OSC_TABLE_NAME }
};

vector<string> cfg_tables;
for (auto const &it : cfg_maps)
{
cfg_tables.push_back(it.first);
}

DBConnector cfgDb("CONFIG_DB", 0);
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

OtnMgr otnMgr(&cfgDb, &appDb, &stateDb, cfg_tables, cfg_maps);

// TODO: add tables in stateDB which interface depends on to monitor list
vector<Orch *> cfgOrchList = { &otnMgr };

swss::Select s;
for (Orch *o : cfgOrchList)
{
s.addSelectables(o->getSelectables());
}

while (true)
{
Selectable *sel;
int ret;

ret = s.select(&sel, SELECT_TIMEOUT);
if (ret == Select::ERROR)
{
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
continue;
}
if (ret == Select::TIMEOUT)
{
otnMgr.doTask();
continue;
}

auto *c = (Executor *)sel;
c->execute();
}
}
catch (const exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
return -1;
}
13 changes: 11 additions & 2 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ INCLUDES = -I $(top_srcdir)/lib \
-I debug_counter \
-I port \
-I pbh \
-I nhg
-I nhg \
-I otn

SUBDIRS = p4orch/tests

Expand Down Expand Up @@ -138,7 +139,15 @@ orchagent_SOURCES = \
high_frequency_telemetry/hftelprofile.cpp \
high_frequency_telemetry/counternameupdater.cpp \
high_frequency_telemetry/hftelutils.cpp \
high_frequency_telemetry/hftelgroup.cpp
high_frequency_telemetry/hftelgroup.cpp \
otn/otnhelper.cpp \
otn/objectorch.cpp \
otn/attenuatororch.cpp \
otn/oaorch.cpp \
otn/ocmorch.cpp \
otn/oscorch.cpp \
otn/otndeviceorch.cpp \
otn/otnorchdaemon.cpp

orchagent_SOURCES += flex_counter/flex_counter_manager.cpp flex_counter/flex_counter_stat_manager.cpp flex_counter/flow_counter_handler.cpp flex_counter/flowcounterrouteorch.cpp
orchagent_SOURCES += debug_counter/debug_counter.cpp debug_counter/drop_counter.cpp
Expand Down
32 changes: 31 additions & 1 deletion orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ extern "C" {
#include "gearboxutils.h"
#include "macsecpost.h"

#include "otnhelper.h"
#include "otnorchdaemon.h"

using namespace std;
using namespace swss;

Expand Down Expand Up @@ -201,7 +204,7 @@ void getCfgSwitchType(DBConnector *cfgDb, string &switch_type, string &switch_su
switch_type = "switch";
}

if (switch_type != "voq" && switch_type != "fabric" && switch_type != "chassis-packet" && switch_type != "switch" && switch_type != "dpu")
if (switch_type != "voq" && switch_type != "fabric" && switch_type != "chassis-packet" && switch_type != "switch" && switch_type != "dpu" && switch_type != SWITCH_TYPE_OTN)
{
SWSS_LOG_ERROR("Invalid switch type %s configured", switch_type.c_str());
//If configured switch type is none of the supported, assume regular switch
Expand Down Expand Up @@ -584,6 +587,33 @@ int main(int argc, char **argv)
// Get switch_type
getCfgSwitchType(&config_db, gMySwitchType, gMySwitchSubType);

/* Initialize sairedis */
if (gMySwitchType == SWITCH_TYPE_OTN) {
SWSS_LOG_NOTICE("OTN platform detected, initializing OTN API");
initOtnApi();
} else {
initSaiApi();
}

initSaiRedis();
initFlexCounterTables();

/* Initialize remaining recorder parameters */
Recorder::Instance().swss.setRecord(
(record_type & SWSS_RECORD_ENABLE) == SWSS_RECORD_ENABLE
);
Recorder::Instance().swss.setLocation(record_location);
Recorder::Instance().swss.setFileName(swss_rec_filename);
Recorder::Instance().swss.startRec(true);

Recorder::Instance().respub.setRecord(
(record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) ==
RESPONSE_PUBLISHER_RECORD_ENABLE
);
Recorder::Instance().respub.setLocation(record_location);
Recorder::Instance().respub.setFileName(responsepublisher_rec_filename);
Recorder::Instance().respub.startRec(false);

sai_attribute_t attr;
vector<sai_attribute_t> attrs;

Expand Down
39 changes: 39 additions & 0 deletions orchagent/otn/attenuatororch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "attenuatororch.h"
#include "schema.h"


extern sai_otn_attenuator_api_t *sai_otn_attenuator_api;

#define OTN_ATTENUATOR_NOTIFICATION "OTN_ATTENUATOR_NOTIFICATION"
#define OTN_ATTENUATOR_REPLY "OTN_ATTENUATOR_REPLY"
#define OTN_ATTENUATOR_FLEX_COUNTER_GROUP "OTN_ATTENUATOR_FLEX_COUNTER"
#define OTN_ATTENUATOR_PLUGIN_DEFAULT_POLLING_INTERVAL_MS 1000 // ms
#define OTN_ATTENUATOR_PLUGIN_DEFAULT_ENABLED_STATE true

AttenuatorOrch::AttenuatorOrch(DBConnector *db, const std::vector<std::string> &table_names) :
ObjectOrch(db, table_names, (sai_object_type_t)SAI_OBJECT_TYPE_OTN_ATTENUATOR, CounterType::OTN_ATTENUATOR_ATTR)
{
SWSS_LOG_ENTER();

std::string scriptPath = "otn_attenuator_pluggin.lua";
createFlexCounter(scriptPath,
OTN_ATTENUATOR_PLUGIN_FIELD,
OTN_ATTENUATOR_FLEX_COUNTER_GROUP,
StatsMode::READ,
OTN_ATTENUATOR_PLUGIN_DEFAULT_POLLING_INTERVAL_MS,
OTN_ATTENUATOR_PLUGIN_DEFAULT_ENABLED_STATE);

m_stateTable = std::unique_ptr<Table>(new Table(m_stateDb.get(), STATE_OTN_ATTENUATOR_TABLE_NAME));
m_nameMapTable = std::unique_ptr<Table>(new Table(m_countersDb.get(), COUNTERS_OTN_ATTENUATOR_NAME_MAP));

m_notificationConsumer = new NotificationConsumer(db, OTN_ATTENUATOR_NOTIFICATION);
auto notifier = new Notifier(m_notificationConsumer, this, OTN_ATTENUATOR_NOTIFICATION);
Orch::addExecutor(notifier);
m_notificationProducer = new NotificationProducer(db, OTN_ATTENUATOR_REPLY);

m_createFunc = sai_otn_attenuator_api->create_otn_attenuator;
m_removeFunc = sai_otn_attenuator_api->remove_otn_attenuator;
m_setFunc = sai_otn_attenuator_api->set_otn_attenuator_attribute;
m_getFunc = sai_otn_attenuator_api->get_otn_attenuator_attribute;

}
9 changes: 9 additions & 0 deletions orchagent/otn/attenuatororch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "objectorch.h"

class AttenuatorOrch: public ObjectOrch
{
public:
AttenuatorOrch(DBConnector *db, const std::vector<std::string> &table_names);
};
39 changes: 39 additions & 0 deletions orchagent/otn/oaorch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "oaorch.h"
#include "schema.h"


extern sai_otn_oa_api_t *sai_otn_oa_api;

#define OTN_OA_NOTIFICATION "OTN_OA_NOTIFICATION"
#define OTN_OA_REPLY "OTN_OA_REPLY"
#define OTN_OA_FLEX_COUNTER_GROUP "OTN_OA_FLEX_COUNTER"
#define OTN_OA_DEFAULT_POLLING_INTERVAL_MS 1000 // ms
#define OTN_OA_DEFAULT_ENABLED_STATE true

OaOrch::OaOrch(DBConnector *db, const std::vector<std::string> &table_names) :
ObjectOrch(db, table_names, (sai_object_type_t)SAI_OBJECT_TYPE_OTN_OA, CounterType::OTN_OA_ATTR)
{
SWSS_LOG_ENTER();

std::string scriptPath = "otn_oa_pluggin.lua";
createFlexCounter(scriptPath,
OTN_OA_PLUGIN_FIELD,
OTN_OA_FLEX_COUNTER_GROUP,
StatsMode::READ,
OTN_OA_DEFAULT_POLLING_INTERVAL_MS,
OTN_OA_DEFAULT_ENABLED_STATE);

m_stateTable = std::unique_ptr<Table>(new Table(m_stateDb.get(), STATE_OTN_OA_TABLE_NAME));
m_nameMapTable = std::unique_ptr<Table>(new Table(m_countersDb.get(), COUNTERS_OTN_OA_NAME_MAP));

m_notificationConsumer = new NotificationConsumer(db, OTN_OA_NOTIFICATION);
auto notifier = new Notifier(m_notificationConsumer, this, OTN_OA_NOTIFICATION);
Orch::addExecutor(notifier);
m_notificationProducer = new NotificationProducer(db, OTN_OA_REPLY);

m_createFunc = sai_otn_oa_api->create_otn_oa;
m_removeFunc = sai_otn_oa_api->remove_otn_oa;
m_setFunc = sai_otn_oa_api->set_otn_oa_attribute;
m_getFunc = sai_otn_oa_api->get_otn_oa_attribute;

}
9 changes: 9 additions & 0 deletions orchagent/otn/oaorch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "objectorch.h"

class OaOrch: public ObjectOrch
{
public:
OaOrch(DBConnector *db, const std::vector<std::string> &table_names);
};
Loading