forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 1
Support OTN attenuator and amplifier #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jjin62
wants to merge
4
commits into
sonic-otn:otn_pr
Choose a base branch
from
sonic-molex:otn_pr
base: otn_pr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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); | ||
| } | ||
This file contains hidden or 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 "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); | ||
| }; | ||
|
|
||
| } |
This file contains hidden or 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,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; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,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"; | ||
|
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; | ||
|
|
||
| } | ||
This file contains hidden or 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,9 @@ | ||
| #pragma once | ||
|
|
||
| #include "objectorch.h" | ||
|
|
||
| class AttenuatorOrch: public ObjectOrch | ||
| { | ||
| public: | ||
| AttenuatorOrch(DBConnector *db, const std::vector<std::string> &table_names); | ||
| }; |
This file contains hidden or 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,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; | ||
|
|
||
| } |
This file contains hidden or 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,9 @@ | ||
| #pragma once | ||
|
|
||
| #include "objectorch.h" | ||
|
|
||
| class OaOrch: public ObjectOrch | ||
| { | ||
| public: | ||
| OaOrch(DBConnector *db, const std::vector<std::string> &table_names); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.