From 1a7ca5f7bb2fc1a7e0fdb9787da146e8eaa0b80d Mon Sep 17 00:00:00 2001 From: Nischal Sheth Date: Thu, 13 Aug 2015 17:56:17 -0700 Subject: [PATCH] Add another test for replicator TableState deletion Change-Id: Id07dd046e4ab10463cca83cbf7969c36a15e98c3 Closes-Bug: 1482277 --- .../routing-instance/routepath_replicator.h | 2 +- src/bgp/test/routepath_replicator_test.cc | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/bgp/routing-instance/routepath_replicator.h b/src/bgp/routing-instance/routepath_replicator.h index f53101f79d0..29ea2b9da19 100644 --- a/src/bgp/routing-instance/routepath_replicator.h +++ b/src/bgp/routing-instance/routepath_replicator.h @@ -53,6 +53,7 @@ class TableState { void ManagedDelete(); bool MayDelete() const; + void RetryDelete(); LifetimeActor *deleter(); const LifetimeActor *deleter() const; @@ -89,7 +90,6 @@ class TableState { return table_; } - void RetryDelete(); private: class DeleteActor; RoutePathReplicator *replicator_; diff --git a/src/bgp/test/routepath_replicator_test.cc b/src/bgp/test/routepath_replicator_test.cc index 55ceff054a8..ea8a9853892 100644 --- a/src/bgp/test/routepath_replicator_test.cc +++ b/src/bgp/test/routepath_replicator_test.cc @@ -525,6 +525,18 @@ class ReplicationTest : public ::testing::Test { TASK_UTIL_EXPECT_EQ(count, (vpn_ts ? vpn_ts->route_count() : 0)); } + void DisableBulkSync() { + RoutePathReplicator *replicator = + bgp_server_->replicator(Address::INETVPN); + replicator->walk_trigger_->set_disable(); + } + + void EnableBulkSync() { + RoutePathReplicator *replicator = + bgp_server_->replicator(Address::INETVPN); + replicator->walk_trigger_->set_enable(); + } + EventManager evm_; DB config_db_; DBGraph config_graph_; @@ -2390,6 +2402,8 @@ TEST_F(ReplicationTest, DeleteInstanceWithReplicatedRoute_2) { VerifyTableNoExists("red.inet.0"); } +// Verify that TableState does not get deleted if the BgpTable is not marked +// deleted, even if all other conditions are met. TEST_F(ReplicationTest, TableStateOnVRFWithNoImportExportRT) { vector instance_names = list_of("blue")("red"); multimap connections = map_list_of("blue", "red"); @@ -2442,6 +2456,70 @@ TEST_F(ReplicationTest, TableStateOnVRFWithNoImportExportRT) { VerifyVRFTableStateExists("red", false); } +// Verify that TableState does not get deleted if the BgpTable is on the +// bulk sync list, even if all other conditions are met. +TEST_F(ReplicationTest, TableStateOnVRFInBulkSyncList) { + vector instance_names = list_of("blue")("red"); + multimap connections = map_list_of("blue", "red"); + NetworkConfig(instance_names, connections); + task_util::WaitForIdle(); + + boost::system::error_code ec; + peers_.push_back( + new BgpPeerMock(Ip4Address::from_string("192.168.0.1", ec))); + + // Add route to blue table + AddInetRoute(peers_[0], "blue", "10.0.1.1/32", 100); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_TRUE(InetRouteLookup("red", "10.0.1.1/32") != NULL); + + const TableState *ts_blue = VerifyVRFTableStateExists("blue", true); + const TableState *ts_red = VerifyVRFTableStateExists("red", true); + TASK_UTIL_EXPECT_EQ(1, ts_blue->route_count()); + TASK_UTIL_EXPECT_EQ(0, ts_red->route_count()); + + DisableBulkSync(); + + RemoveInstanceRouteTarget("blue", "target:64496:1"); + RemoveInstanceRouteTarget("red", "target:64496:2"); + + TASK_UTIL_EXPECT_EQ(0, GetInstanceImportRouteTargetList("red").size()); + TASK_UTIL_EXPECT_EQ(0, GetInstanceImportRouteTargetList("blue").size()); + TASK_UTIL_EXPECT_EQ(0, GetInstanceExportRouteTargetList("red").size()); + TASK_UTIL_EXPECT_EQ(0, GetInstanceExportRouteTargetList("blue").size()); + + ts_blue = VerifyVRFTableStateExists("blue", true); + ts_red = VerifyVRFTableStateExists("red", true); + + TASK_UTIL_EXPECT_TRUE(ts_red->empty()); + TASK_UTIL_EXPECT_TRUE(ts_blue->empty()); + TASK_UTIL_EXPECT_EQ(1, ts_blue->route_count()); + TASK_UTIL_EXPECT_EQ(0, ts_red->route_count()); + + DeleteInetRoute(peers_[0], "blue", "10.0.1.1/32"); + task_util::WaitForIdle(); + + DeleteRoutingInstance("blue", "target:64496:1"); + DeleteRoutingInstance("red", "target:64496:2"); + ifmap_test_util::IFMapMsgUnlink(&config_db_, + "routing-instance", "blue", + "routing-instance", "red", + "connection"); + task_util::WaitForIdle(); + + ts_blue = VerifyVRFTableStateExists("blue", true); + ts_red = VerifyVRFTableStateExists("red", true); + TASK_UTIL_EXPECT_EQ(0, ts_blue->route_count()); + TASK_UTIL_EXPECT_EQ(0, ts_red->route_count()); + TASK_UTIL_EXPECT_TRUE(ts_blue->table()->IsDeleted()); + TASK_UTIL_EXPECT_TRUE(ts_red->table()->IsDeleted()); + + EnableBulkSync(); + + VerifyVRFTableStateExists("blue", false); + VerifyVRFTableStateExists("red", false); +} class TestEnvironment : public ::testing::Environment { virtual ~TestEnvironment() { }