Skip to content
Open
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
9 changes: 8 additions & 1 deletion cfgmgr/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3
SAIMETA_LIBS = -lsaimeta -lsaimetadata -lzmq
COMMON_LIBS = -lswsscommon -lpthread

bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd macsecmgrd fabricmgrd stpmgrd
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd macsecmgrd fabricmgrd stpmgrd otnmgrd

cfgmgrdir = $(datadir)/swss

Expand Down Expand Up @@ -107,6 +107,11 @@ stpmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAG
stpmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
stpmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS)

otnmgrd_SOURCES = otnmgrd.cpp otnmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h
otnmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
otnmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
otnmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS)

if GCOV_ENABLED
vlanmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
teammgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
Expand All @@ -123,6 +128,7 @@ coppmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
tunnelmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
macsecmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
stpmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
otnmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
endif

if ASAN_ENABLED
Expand All @@ -141,5 +147,6 @@ tunnelmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
macsecmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
fabricmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
stpmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
otnmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
endif

75 changes: 75 additions & 0 deletions cfgmgr/otnmgr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "otnmgr.h"

using namespace std;
using namespace swss;

OtnMgr::OtnMgr(DBConnector *cfgDb, DBConnector *appDb, const std::vector<std::string> &tableNames, const std::map<std::string, std::string> &tableMaps) :
Orch(cfgDb, tableNames),
m_appl_db(appDb),
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())
{
auto &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 (const auto &value : values)
{
SWSS_LOG_NOTICE("OtnMgr doTask, key=%s, value=%s", value.first.c_str(), value.second.c_str());
}
if (!values.empty())
{
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::vector<FieldValueTuple> &field_values)
{
SWSS_LOG_ENTER();

table->set(alias, field_values);
Comment thread
jjin62 marked this conversation as resolved.
}
29 changes: 29 additions & 0 deletions cfgmgr/otnmgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

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

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

namespace swss {

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

using Orch::doTask;
private:
DBConnector *m_appl_db;
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::vector<FieldValueTuple> &field_values);
};

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

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

using namespace std;
using namespace swss;

#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_ATTENUATOR_TABLE_NAME, APP_OTN_ATTENUATOR_TABLE_NAME },
{ CFG_OTN_OA_TABLE_NAME, APP_OTN_OA_TABLE_NAME },
};

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

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

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

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 = static_cast<Executor *>(sel);
c->execute();
}
}
catch (const exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
return EXIT_FAILURE;
}
8 changes: 7 additions & 1 deletion 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 @@ -171,6 +172,11 @@ orchagent_SOURCES += p4orch/p4orch.cpp \
p4orch/ip_multicast_manager.cpp \
p4orch/ext_tables_manager.cpp

orchagent_SOURCES += otn/otnorchdaemon.cpp \
otn/objectorch.cpp \
otn/attenuatororch.cpp \
otn/oaorch.cpp

orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
orchagent_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lpthread -lsairedis -lsaimeta -lsaimetadata -lswsscommon -lzmq -lprotobuf -ldashapi -ljemalloc
Expand Down
2 changes: 2 additions & 0 deletions orchagent/flex_counter/flex_counter_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lo
{ CounterType::SRV6, SRV6_COUNTER_ID_LIST },
{ CounterType::SWITCH, SWITCH_COUNTER_ID_LIST },
{ CounterType::HA_SET, HA_SET_COUNTER_ID_LIST },
{ CounterType::OTN_ATTENUATOR_ATTR, OTN_ATTENUATOR_ATTR_ID_LIST },
{ CounterType::OTN_OA_ATTR, OTN_OA_ATTR_ID_LIST },
};

FlexManagerDirectory g_FlexManagerDirectory;
Expand Down
2 changes: 2 additions & 0 deletions orchagent/flex_counter/flex_counter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ enum class CounterType
SRV6,
SWITCH,
HA_SET,
OTN_ATTENUATOR_ATTR,
OTN_OA_ATTR,
};

extern bool gTraditionalFlexCounter;
Expand Down
9 changes: 7 additions & 2 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extern "C" {
#include "gearboxutils.h"
#include "macsecpost.h"

#include "otnorchdaemon.h"

using namespace std;
using namespace swss;

Expand Down Expand Up @@ -255,7 +257,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 != "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 @@ -995,7 +997,10 @@ int main(int argc, char **argv)
dpu_app_state_db = make_shared<DBConnector>("DPU_APPL_STATE_DB", 0, true);
orchDaemon = make_shared<DpuOrchDaemon>(&appl_db, &config_db, &state_db, chassis_app_db.get(), dpu_app_db.get(), dpu_app_state_db.get(), zmq_server.get());
}

else if (gMySwitchType == "otn")
{
orchDaemon = make_shared<OtnOrchDaemon>(&appl_db, &config_db, &state_db, chassis_db, zmq_server.get());
}
else if (gMySwitchType != "fabric")
{
orchDaemon = make_shared<OrchDaemon>(&appl_db, &config_db, &state_db, chassis_db, zmq_server.get());
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";
Comment thread
jjin62 marked this conversation as resolved.
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