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
43 changes: 42 additions & 1 deletion Server/src/RedisManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include "RedisManager.h"
#include <algorithm>


/*********************************************************************//**
Expand Down Expand Up @@ -61,7 +62,6 @@ std::string RedisManager::GetKeySeparator() {
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()) {
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);
Expand Down Expand Up @@ -93,6 +93,47 @@ bool RedisManager::RemoveEntityFromBMPTable(const std::vector<std::string>& keys
return true;
}

/**
* RemoveBGPPeerFromBMPTable
*
* \param [in] peer_addr Reference to peer address
*/
bool RedisManager::RemoveBGPPeerFromBMPTable(const std::string& peer_addr) {
for (const auto& enabledTable : enabledTables_) {
ResetBMPTableByPeer(enabledTable, peer_addr);
}
return true;
}

/**
* Reset ResetBMPTableByPeer, this will flush redis
*
* \param [in] table Reference to table name BGP_NEIGHBOR_TABLE/BGP_RIB_OUT_TABLE/BGP_RIB_IN_TABLE
* \param [in] peer_addr Reference to peer address
*/
void RedisManager::ResetBMPTableByPeer(const std::string & table, const std::string& peer_addr) {

std::unique_ptr<swss::Table> stateBMPTable = std::make_unique<swss::Table>(stateDb_.get(), table);
std::vector<std::string> keys;
stateBMPTable->getKeys(keys);

std::string pattern = "|" + peer_addr;
std::vector<std::string> filtered_keys;

std::copy_if(keys.begin(), keys.end(), std::back_inserter(filtered_keys),
[&pattern](const std::string& key) {
return key.size() >= pattern.size() &&
key.compare(key.size() - pattern.size(), pattern.size(), pattern) == 0;
});

for (const auto& key : filtered_keys) {
LOG_INFO("RedisManager ResetBMPTableByPeer del key %s", key);
}

LOG_INFO("RedisManager ResetBMPTableByPeer data size %d", filtered_keys.size());

stateDb_->del(filtered_keys);
}

/**
* ExitRedisManager
Expand Down
15 changes: 15 additions & 0 deletions Server/src/RedisManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class RedisManager {
*/
void ResetBMPTable(const std::string & table);

/**
* Reset ResetBMPTable, this will flush redis
*
* \param [in] table Reference to table name BGP_NEIGHBOR_TABLE/BGP_RIB_OUT_TABLE/BGP_RIB_IN_TABLE
* \param [in] peer_addr Reference to peer address
*/
void ResetBMPTableByPeer(const std::string & table, const std::string& peer_addr);

/**
* WriteBMPTable
*
Expand All @@ -118,6 +126,13 @@ class RedisManager {
*/
bool RemoveEntityFromBMPTable(const std::vector<std::string>& keys);

/**
* RemoveBGPPeerFromBMPTable
*
* \param [in] peer_addr Reference to peer address
*/
bool RemoveBGPPeerFromBMPTable(const std::string& peer_addr);

/**
* Get Key separator for deletion
*
Expand Down
4 changes: 4 additions & 0 deletions Server/src/redis/MsgBusImpl_redis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ void MsgBusImpl_redis::update_Peer(obj_bgp_peer &peer, obj_peer_up_event *up, ob
fieldValues.emplace_back(make_pair("bgp_err_code", to_string(down->bgp_err_code)));
fieldValues.emplace_back(make_pair("bgp_err_subcode", to_string(down->bgp_err_subcode)));
fieldValues.emplace_back(make_pair("error_text", down->error_text));

// clear db entries for bgp peer
std::string bgp_peer(peer.peer_addr);
redisMgr_.RemoveBGPPeerFromBMPTable(bgp_peer);
}
}
break;
Expand Down