Skip to content

Commit 9c23389

Browse files
authored
[BFD]Clean up state_db BFD entries on swss restart (#2434)
*[BFD]Clean up state_db BFD entries on swss restart (#2434)
1 parent d41aebf commit 9c23389

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

orchagent/bfdorch.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ BfdOrch::BfdOrch(DBConnector *db, string tableName, TableConnector stateDbBfdSes
5959
DBConnector *notificationsDb = new DBConnector("ASIC_DB", 0);
6060
m_bfdStateNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS");
6161
auto bfdStateNotificatier = new Notifier(m_bfdStateNotificationConsumer, this, "BFD_STATE_NOTIFICATIONS");
62+
63+
// Clean up state database BFD entries
64+
vector<string> keys;
65+
66+
m_stateBfdSessionTable.getKeys(keys);
67+
68+
for (auto alias : keys)
69+
{
70+
m_stateBfdSessionTable.del(alias);
71+
}
72+
6273
Orch::addExecutor(bfdStateNotificatier);
6374
register_state_change_notif = false;
6475
}

tests/test_bfd.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,23 @@ def test_multipleBfdSessions(self, dvs):
464464
self.adb.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", session3)
465465
self.remove_bfd_session(key4)
466466
self.adb.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", session4)
467+
468+
def test_bfd_state_db_clear(self, dvs):
469+
self.setup_db(dvs)
470+
471+
bfdSessions = self.get_exist_bfd_session()
472+
473+
# Create BFD session
474+
fieldValues = {"local_addr": "10.0.0.1", "type": "demand_active"}
475+
self.create_bfd_session("default:default:10.0.0.2", fieldValues)
476+
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", len(bfdSessions) + 1)
477+
478+
# Checked created BFD session in ASIC_DB
479+
createdSessions = self.get_exist_bfd_session() - bfdSessions
480+
assert len(createdSessions) == 1
481+
dvs.stop_swss()
482+
dvs.start_swss()
483+
484+
time.sleep(5)
485+
keys = self.sdb.get_keys("BFD_SESSION_TABLE")
486+
assert len(keys) == 0

0 commit comments

Comments
 (0)