diff --git a/orchagent/bfdorch.cpp b/orchagent/bfdorch.cpp index f40782ba2b4e..e3cab2581a8c 100644 --- a/orchagent/bfdorch.cpp +++ b/orchagent/bfdorch.cpp @@ -59,6 +59,17 @@ BfdOrch::BfdOrch(DBConnector *db, string tableName, TableConnector stateDbBfdSes DBConnector *notificationsDb = new DBConnector("ASIC_DB", 0); m_bfdStateNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS"); auto bfdStateNotificatier = new Notifier(m_bfdStateNotificationConsumer, this, "BFD_STATE_NOTIFICATIONS"); + + // Clean up state database BFD entries + vector keys; + + m_stateBfdSessionTable.getKeys(keys); + + for (auto alias : keys) + { + m_stateBfdSessionTable.del(alias); + } + Orch::addExecutor(bfdStateNotificatier); register_state_change_notif = false; } diff --git a/tests/test_bfd.py b/tests/test_bfd.py index 0e8b16736043..2feef60acb92 100644 --- a/tests/test_bfd.py +++ b/tests/test_bfd.py @@ -464,3 +464,23 @@ def test_multipleBfdSessions(self, dvs): self.adb.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", session3) self.remove_bfd_session(key4) self.adb.wait_for_deleted_entry("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", session4) + + def test_bfd_state_db_clear(self, dvs): + self.setup_db(dvs) + + bfdSessions = self.get_exist_bfd_session() + + # Create BFD session + fieldValues = {"local_addr": "10.0.0.1", "type": "demand_active"} + self.create_bfd_session("default:default:10.0.0.2", fieldValues) + self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", len(bfdSessions) + 1) + + # Checked created BFD session in ASIC_DB + createdSessions = self.get_exist_bfd_session() - bfdSessions + assert len(createdSessions) == 1 + dvs.stop_swss() + dvs.start_swss() + + time.sleep(5) + keys = self.sdb.get_keys("BFD_SESSION_TABLE") + assert len(keys) == 0