-
Notifications
You must be signed in to change notification settings - Fork 11
Make openbmp support redis subscription/population on sonic. #7
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
Changes from all commits
f3dc99b
d37c454
5130a39
c02fb34
3e81104
846efdd
32e46c9
3d318b0
3055ca0
8f9bcbe
306b26d
18f9d20
70d036e
83edca5
3d1a087
81f3699
fdc7809
b37ad43
c5cde33
b336f7a
1a12e1b
ea2b2e5
73f7499
d92e3ac
ebb2ba0
b7e0993
2d9436d
ab30185
6cadfc6
19eaffb
2d1d221
f096dee
46a9d86
ff7be6d
d472ae2
253e05c
1c8f4b1
18ed8d8
770b83c
c9b4930
7227b99
17d178d
3335281
76904f7
f35b88f
55593d6
dc3d240
cb079df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /* | ||
| * Copyright (c) 2024 Microsoft, Inc. and others. All rights reserved. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v1.0 which accompanies this distribution, | ||
| * and is available at http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| */ | ||
|
|
||
| #include "RedisManager.h" | ||
|
|
||
|
|
||
| /*********************************************************************//** | ||
| * Constructor for class | ||
| ***********************************************************************/ | ||
| RedisManager::RedisManager() { | ||
| exit_ = false; | ||
| } | ||
|
|
||
| /*********************************************************************//** | ||
| * Constructor for class | ||
| ***********************************************************************/ | ||
| RedisManager::~RedisManager() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no resource to be cleanup now and could be used as place holder. |
||
| } | ||
|
|
||
|
|
||
| /********************************************************************* | ||
| * Setup for this class | ||
| * | ||
| * \param [in] logPtr logger pointer | ||
| ***********************************************************************/ | ||
| void RedisManager::Setup(Logger *logPtr) { | ||
| logger = logPtr; | ||
| if (!swss::SonicDBConfig::isInit()) { | ||
| swss::SonicDBConfig::initialize(); | ||
| } | ||
|
|
||
| stateDb_ = std::make_shared<swss::DBConnector>(BMP_DB_NAME, 0, false); | ||
| separator_ = swss::SonicDBConfig::getSeparator(BMP_DB_NAME); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * Get Key separator for deletion | ||
| * | ||
| * \param [in] N/A | ||
| */ | ||
| std::string RedisManager::GetKeySeparator() { | ||
| return separator_; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * WriteBMPTable | ||
| * | ||
| * \param [in] table Reference to table name | ||
| * \param [in] key Reference to various keys list | ||
| * \param [in] fieldValues Reference to field-value pairs | ||
| */ | ||
| bool RedisManager::WriteBMPTable(const std::string& table, const std::vector<std::string>& keys, const std::vector<swss::FieldValueTuple> fieldValues) { | ||
|
|
||
| if (enabledTables_.find(table) == enabledTables_.end()) { | ||
FengPan-Frank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| LOG_INFO("RedisManager %s is disabled", table.c_str()); | ||
| return false; | ||
| } | ||
| std::unique_ptr<swss::Table> stateBMPTable = std::make_unique<swss::Table>(stateDb_.get(), table); | ||
| std::ostringstream oss; | ||
| for (const auto& key : keys) { | ||
| oss << key << separator_; | ||
| } | ||
| std::string fullKey = oss.str(); | ||
| fullKey.pop_back(); | ||
|
|
||
| DEBUG("RedisManager WriteBMPTable key = %s", fullKey.c_str()); | ||
|
|
||
| stateBMPTable->set(fullKey, fieldValues); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added more debug log into MsgBusImpl_redis class for more constructive looking, which triggers this WriteBMPTable() |
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * RemoveEntityFromBMPTable | ||
| * | ||
| * \param [in] keys Reference to various keys | ||
| */ | ||
| bool RedisManager::RemoveEntityFromBMPTable(const std::vector<std::string>& keys) { | ||
|
|
||
| for (const auto& key : keys) { | ||
| DEBUG("RedisManager RemoveEntityFromBMPTable key = %s", key.c_str()); | ||
| } | ||
| stateDb_->del(keys); | ||
FengPan-Frank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * ExitRedisManager | ||
| * | ||
| * \param [in] N/A | ||
| */ | ||
| void RedisManager::ExitRedisManager() { | ||
| exit_ = true; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * InitBMPConfig, read config_db for table enablement setting. | ||
| * | ||
| * \param [in] N/A | ||
| */ | ||
| bool RedisManager::InitBMPConfig() { | ||
| std::shared_ptr<swss::DBConnector> cfgDb = | ||
| std::make_shared<swss::DBConnector>("CONFIG_DB", 0, false); | ||
| std::unique_ptr<swss::Table> cfgTable = std::make_unique<swss::Table>(cfgDb.get(), BMP_CFG_TABLE_NAME); | ||
| std::vector<swss::FieldValueTuple> fvt; | ||
| cfgTable->get(BMP_CFG_TABLE_KEY, fvt); | ||
| for (const auto& item : fvt) { | ||
| if (item.second == "true") { | ||
| enabledTables_.insert(item.first); | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Reset ResetBMPTable, this will flush redis | ||
| * | ||
| * \param [in] table Reference to table name BGP_NEIGHBOR_TABLE/BGP_RIB_OUT_TABLE/BGP_RIB_IN_TABLE | ||
| */ | ||
| void RedisManager::ResetBMPTable(const std::string & table) { | ||
|
|
||
| LOG_INFO("RedisManager ResetBMPTable %s", table.c_str()); | ||
| std::unique_ptr<swss::Table> stateBMPTable = std::make_unique<swss::Table>(stateDb_.get(), table); | ||
| std::vector<std::string> keys; | ||
| stateBMPTable->getKeys(keys); | ||
| stateDb_->del(keys); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * Reset all Tables once FRR reconnects to BMP, this will not disable table population | ||
| * | ||
| * \param [in] N/A | ||
| */ | ||
| void RedisManager::ResetAllTables() { | ||
| LOG_INFO("RedisManager ResetAllTables"); | ||
|
|
||
| for (const auto& enabledTable : enabledTables_) { | ||
| ResetBMPTable(enabledTable); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.