From 0baff3c3c1c37de5d95d530b101334c540bd06d8 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 26 Aug 2022 19:22:49 +0000 Subject: [PATCH] [BFD]Clean up state_db BFD entries on swss restart --- orchagent/bfdorch.cpp | 11 +++++++++++ tests/test_bfd.py | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/orchagent/bfdorch.cpp b/orchagent/bfdorch.cpp index f40782ba2b..e3cab2581a 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 0e8b167360..2feef60acb 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