From 687268253f8c48a6f10bf91e81c3638fd0f56506 Mon Sep 17 00:00:00 2001 From: Prakash M Bailkeri Date: Wed, 25 Nov 2015 19:18:42 +0530 Subject: [PATCH] UT cases for routing policy config code 1. Added config listener tests 2. Added config ifmap tests Related-bug: #1500698 Change-Id: I3dc8c72d7f0df67d343bdab1985994593749a5c9 --- src/bgp/bgp_config.h | 3 +- src/bgp/bgp_config_ifmap.cc | 5 +- src/bgp/bgp_config_ifmap.h | 1 + src/bgp/test/bgp_config_listener_test.cc | 309 ++++++++++++++++++ src/bgp/test/bgp_ifmap_config_manager_test.cc | 269 +++++++++++++++ src/bgp/testdata/config_listener_test_10.xml | 28 ++ src/bgp/testdata/config_listener_test_11.xml | 20 ++ src/bgp/testdata/config_listener_test_9.xml | 36 ++ src/bgp/testdata/config_listener_test_9a.xml | 8 + src/bgp/testdata/routing_policy_0a.xml | 13 + src/bgp/testdata/routing_policy_0b.xml | 21 ++ src/bgp/testdata/routing_policy_3.xml | 19 ++ src/bgp/testdata/routing_policy_3a.xml | 31 ++ src/bgp/testdata/routing_policy_3b.xml | 11 + src/bgp/testdata/routing_policy_3c.xml | 8 + src/bgp/testdata/routing_policy_3d.xml | 32 ++ src/bgp/testdata/routing_policy_4.xml | 31 ++ src/bgp/testdata/routing_policy_4a.xml | 31 ++ 18 files changed, 872 insertions(+), 4 deletions(-) create mode 100644 src/bgp/testdata/config_listener_test_10.xml create mode 100644 src/bgp/testdata/config_listener_test_11.xml create mode 100644 src/bgp/testdata/config_listener_test_9.xml create mode 100644 src/bgp/testdata/config_listener_test_9a.xml create mode 100644 src/bgp/testdata/routing_policy_0a.xml create mode 100644 src/bgp/testdata/routing_policy_0b.xml create mode 100644 src/bgp/testdata/routing_policy_3.xml create mode 100644 src/bgp/testdata/routing_policy_3a.xml create mode 100644 src/bgp/testdata/routing_policy_3b.xml create mode 100644 src/bgp/testdata/routing_policy_3c.xml create mode 100644 src/bgp/testdata/routing_policy_3d.xml create mode 100644 src/bgp/testdata/routing_policy_4.xml create mode 100644 src/bgp/testdata/routing_policy_4a.xml diff --git a/src/bgp/bgp_config.h b/src/bgp/bgp_config.h index 48f84a249e3..508e240f26e 100644 --- a/src/bgp/bgp_config.h +++ b/src/bgp/bgp_config.h @@ -312,9 +312,10 @@ class BgpRoutingPolicyConfig { const std::string &name() const { return name_; } void set_last_change_at(uint64_t tstamp) const { last_change_at_ = tstamp; } - void add_term(RoutingPolicyTerm term) { + void add_term(const RoutingPolicyTerm &term) { terms_.push_back(term); } + const RoutingPolicyTermList &terms() const { return terms_;} void Clear(); private: diff --git a/src/bgp/bgp_config_ifmap.cc b/src/bgp/bgp_config_ifmap.cc index 6e995c46695..d3ba9144e91 100644 --- a/src/bgp/bgp_config_ifmap.cc +++ b/src/bgp/bgp_config_ifmap.cc @@ -80,9 +80,8 @@ void BgpIfmapRoutingPolicyLinkConfig::SetNodeProxy(IFMapNodeProxy *proxy) { } } -bool -BgpIfmapRoutingPolicyLinkConfig::GetRoutingInstanceRoutingPolicyPair(DBGraph *graph, - IFMapNode *node, pair *pair) { +bool BgpIfmapRoutingPolicyLinkConfig::GetRoutingInstanceRoutingPolicyPair( + DBGraph *graph, IFMapNode *node, pair *pair) { IFMapNode *routing_instance = NULL; IFMapNode *routing_policy = NULL; diff --git a/src/bgp/bgp_config_ifmap.h b/src/bgp/bgp_config_ifmap.h index 2ce6990db78..5b229ae9d8b 100644 --- a/src/bgp/bgp_config_ifmap.h +++ b/src/bgp/bgp_config_ifmap.h @@ -308,6 +308,7 @@ class BgpIfmapRoutingPolicyConfig { void AddInstance(BgpIfmapInstanceConfig *rti); void RemoveInstance(BgpIfmapInstanceConfig *rti); + private: friend class BgpConfigManagerTest; diff --git a/src/bgp/test/bgp_config_listener_test.cc b/src/bgp/test/bgp_config_listener_test.cc index edf67a728cf..07a09f706d9 100644 --- a/src/bgp/test/bgp_config_listener_test.cc +++ b/src/bgp/test/bgp_config_listener_test.cc @@ -1492,6 +1492,315 @@ TEST_F(BgpConfigListenerTest, VirtualNetworkUninterestingLinkChange) { TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); } +// +// Validate that routing policy update triggers both routing-instance and +// routing-policy change +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_0) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_11.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + string id_name = "basic_0"; + ifmap_test_util::IFMapNodeNotify(&db_, "routing-policy", id_name); + task_util::WaitForIdle(); + + // Routing policy is added to change list + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(3, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(2, GetChangeListCount("routing-policy")); + // routing-instance is added to change list + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// Update of routing instance doesn't trigger routing-policy +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_1) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_11.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + string id_name = "test"; + ifmap_test_util::IFMapNodeNotify(&db_, "routing-instance", id_name); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// Update of routing-instance-routing-policy triggers routing-instance, +// routing-policy and routing-instance-routing-policy +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_2) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + content = ReadFile("controller/src/bgp/testdata/config_listener_test_9a.xml"); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(3, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// If routing policy is linked to multiple routing instances, +// a change of routing-policy will put both routing instances into change list +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_3) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_10.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + // Trigger change on routing-policy which is linked to routing instance + string id_name = "basic_0"; + ifmap_test_util::IFMapNodeNotify(&db_, "routing-policy", id_name); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(4, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(2, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(2, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// Trigger edge change between routing policy and routing instance +// Validate both routing instance and routing policy are added to change list +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_4) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + string id_name = "attr(basic_0,test)"; + ifmap_test_util::IFMapLinkNotify(&db_, &graph_, + "routing-instance-routing-policy", id_name, "routing-policy", "basic_0"); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(2, GetEdgeListCount("routing-instance-routing-policy")); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(2, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// Trigger edge change between routing policy and routing instance +// Validate both routing instance and routing policy are added to change list +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_5) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + string id_name = "attr(basic_0,test)"; + ifmap_test_util::IFMapLinkNotify(&db_, &graph_, + "routing-instance-routing-policy", id_name, "routing-instance", "test"); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(2, GetEdgeListCount("routing-instance-routing-policy")); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(2, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// Update of IFMapNode representing the routing-instance-routing-policy, +// puts routing-instance and routing-policy to change list along with +// routing-instance-routing-policy +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_6) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + string id_name = "attr(basic_0,test)"; + ifmap_test_util::IFMapNodeNotify(&db_, "routing-instance-routing-policy", + id_name); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(3, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// If multiple routing policies are linked to a routing instance, +// a change of routing-policy will put only routing instance and routing policy +// to change list +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_7) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + // Trigger change on routing-policy which is linked to routing instance + string id_name = "basic_0"; + ifmap_test_util::IFMapNodeNotify(&db_, "routing-policy", id_name); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(1, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(3, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(2, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + +// +// +// If multiple routing policies are linked to a routing instance, +// a change of routing-instance will not put routing policies +// to change list +// +TEST_F(BgpConfigListenerTest, RoutingPolicyUpdate_8) { + string content = ReadFile("controller/src/bgp/testdata/config_listener_test_9.xml"); + EXPECT_TRUE(parser_.Parse(content)); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + PauseChangeListPropagation(); + // Trigger change on routing-policy which is linked to routing instance + string id_name = "test"; + ifmap_test_util::IFMapNodeNotify(&db_, "routing-instance", id_name); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetNodeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount()); + + PerformChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount()); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-policy")); + TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance")); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount("routing-instance-routing-policy")); + + ResumeChangeListPropagation(); + TASK_UTIL_EXPECT_EQ(0, GetChangeListCount()); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); +} + int main(int argc, char **argv) { bgp_log_test::init(); ControlNode::SetDefaultSchedulingPolicy(); diff --git a/src/bgp/test/bgp_ifmap_config_manager_test.cc b/src/bgp/test/bgp_ifmap_config_manager_test.cc index 102a33a189f..c08aad88b9b 100644 --- a/src/bgp/test/bgp_ifmap_config_manager_test.cc +++ b/src/bgp/test/bgp_ifmap_config_manager_test.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include "base/test/task_test_util.h" #include "bgp/bgp_config_parser.h" @@ -25,6 +26,7 @@ #include "schema/bgp_schema_types.h" #include "schema/vnc_cfg_types.h" +using boost::assign::map_list_of; using namespace std; static string FileRead(const string &filename) { @@ -91,6 +93,16 @@ class BgpIfmapConfigManagerTest : public ::testing::Test { return config_manager_->config()->FindPeering(peering_name); } + const BgpIfmapRoutingPolicyConfig * + FindRoutingPolicyIfmapConfig(const string policy_name) { + return config_manager_->config()->FindRoutingPolicy(policy_name); + } + + const BgpRoutingPolicyConfig * + FindRoutingPolicyBgpConfig(const string policy_name) { + return config_manager_->FindRoutingPolicy(policy_name); + } + DB db_; DBGraph db_graph_; std::auto_ptr config_manager_; @@ -1771,6 +1783,263 @@ TEST_F(BgpIfmapConfigManagerTest, RemoveParentLinkBeforeBgpRouter) { //TASK_UTIL_EXPECT_EQ("127.0.0.100", router_params.address); } +// +// Add and delete routing policy config +// Validate the BgpRoutingPolicyConfig +// +TEST_F(BgpIfmapConfigManagerTest, RoutingPolicyAddDelete) { + string content_a = FileRead("controller/src/bgp/testdata/routing_policy_0a.xml"); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + + const BgpRoutingPolicyConfig *policy_cfg = + config_manager_->FindRoutingPolicy("basic"); + ASSERT_TRUE(policy_cfg != NULL); + + ASSERT_EQ(policy_cfg->terms().size(), 1); + boost::replace_all(content_a, "", ""); + boost::replace_all(content_a, "", ""); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); +} + +// +// Update routing policy config +// Validate the BgpRoutingPolicyConfig +// +TEST_F(BgpIfmapConfigManagerTest, RoutingPolicyUpdate) { + string content_a = FileRead("controller/src/bgp/testdata/routing_policy_0a.xml"); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + + const BgpRoutingPolicyConfig *policy_cfg = + config_manager_->FindRoutingPolicy("basic"); + ASSERT_TRUE(policy_cfg != NULL); + ASSERT_EQ(policy_cfg->terms().size(), 1); + + // Update the routing policy with additional term + string content_b = FileRead("controller/src/bgp/testdata/routing_policy_0b.xml"); + EXPECT_TRUE(parser_.Parse(content_b)); + task_util::WaitForIdle(); + policy_cfg = config_manager_->FindRoutingPolicy("basic"); + ASSERT_TRUE(policy_cfg != NULL); + ASSERT_EQ(policy_cfg->terms().size(), 2); + + boost::replace_all(content_a, "", ""); + boost::replace_all(content_a, "", ""); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); +} + +// +// Create routing instance and routing policy +// Associate routing-policy to routing-instance +// Validate the routing instance and associate policy in BgpInstanceConfig +// Add one more routing policy link to routing-instance +// Validate the routing instance and associate policy in BgpInstanceConfig +// +TEST_F(BgpIfmapConfigManagerTest, RoutingInstanceRoutingPolicy_0) { + string content_a = FileRead("controller/src/bgp/testdata/routing_policy_3.xml"); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + + const BgpRoutingPolicyConfig *policy_cfg = + config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg != NULL); + + const BgpInstanceConfig *test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 1); + ASSERT_TRUE(test_ri->routing_policy_list().front().routing_policy_ == "basic_0"); + ASSERT_TRUE(test_ri->routing_policy_list().front().sequence_ == "1.0"); + + // Update the routing instance with two route policy + string content_b = FileRead("controller/src/bgp/testdata/routing_policy_3d.xml"); + EXPECT_TRUE(parser_.Parse(content_b)); + task_util::WaitForIdle(); + policy_cfg = config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg != NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_1"); + ASSERT_TRUE(policy_cfg != NULL); + + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 2); + BgpInstanceConfig::RoutingPolicyList list = test_ri->routing_policy_list(); + + map expect_list = map_list_of("basic_0", "1.0")("basic_1", "2.0"); + map current_list; + BOOST_FOREACH(RoutingPolicyAttachInfo info, list) { + current_list.insert(pair(info.routing_policy_, + info.sequence_)); + } + + ASSERT_TRUE(current_list.size() == expect_list.size()); + ASSERT_TRUE(std::equal(expect_list.begin(), expect_list.end(), + current_list.begin())); + + + boost::replace_all(content_b, "", ""); + boost::replace_all(content_b, "", ""); + EXPECT_TRUE(parser_.Parse(content_b)); + task_util::WaitForIdle(); + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri == NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg == NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_1"); + ASSERT_TRUE(policy_cfg == NULL); +} + +// +// Create routing instance and two routing policies +// Associate routing-policies to routing-instance +// Validate the routing instance and associate policy in BgpInstanceConfig +// Update the sequence of routing policies on routing instance +// Validate the routing instance and associate policy in BgpInstanceConfig +// +TEST_F(BgpIfmapConfigManagerTest, RoutingInstanceRoutingPolicy_1) { + string content_a = FileRead("controller/src/bgp/testdata/routing_policy_4.xml"); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + + const BgpInstanceConfig *test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + + const BgpRoutingPolicyConfig *policy_cfg = + config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg != NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_1"); + ASSERT_TRUE(policy_cfg != NULL); + + ASSERT_TRUE(test_ri->routing_policy_list().size() == 2); + BgpInstanceConfig::RoutingPolicyList list = test_ri->routing_policy_list(); + + map expect_list = map_list_of("basic_0", "1.0")("basic_1", "2.0"); + map current_list; + BOOST_FOREACH(RoutingPolicyAttachInfo info, list) { + current_list.insert(pair(info.routing_policy_, + info.sequence_)); + } + + ASSERT_TRUE(current_list.size() == expect_list.size()); + ASSERT_TRUE(std::equal(expect_list.begin(), expect_list.end(), + current_list.begin())); + + + // Update the routing instance to update the order of routing policy + string content_b = FileRead("controller/src/bgp/testdata/routing_policy_4a.xml"); + EXPECT_TRUE(parser_.Parse(content_b)); + task_util::WaitForIdle(); + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 2); + list = test_ri->routing_policy_list(); + + expect_list = map_list_of("basic_0", "2.0")("basic_1", "1.0"); + current_list.clear(); + BOOST_FOREACH(RoutingPolicyAttachInfo info, list) { + current_list.insert(pair(info.routing_policy_, + info.sequence_)); + } + + ASSERT_TRUE(current_list.size() == expect_list.size()); + ASSERT_TRUE(std::equal(expect_list.begin(), expect_list.end(), + current_list.begin())); + + boost::replace_all(content_b, "", ""); + boost::replace_all(content_b, "", ""); + EXPECT_TRUE(parser_.Parse(content_b)); + task_util::WaitForIdle(); + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri == NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg == NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_1"); + ASSERT_TRUE(policy_cfg == NULL); +} + +// +// Create routing instance and routing policy +// Associate routing-policy to routing-instance +// Validate the routing instance and associate policy in BgpInstanceConfig +// Remove the routing policy from routing instance +// Validate that routing instance is not associated any routing instance +// +TEST_F(BgpIfmapConfigManagerTest, RoutingInstanceRoutingPolicy_2) { + string content_a = FileRead("controller/src/bgp/testdata/routing_policy_3.xml"); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + + const BgpRoutingPolicyConfig *policy_cfg = + config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg != NULL); + + const BgpInstanceConfig *test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 1); + ASSERT_TRUE(test_ri->routing_policy_list().front().routing_policy_ == "basic_0"); + ASSERT_TRUE(test_ri->routing_policy_list().front().sequence_ == "1.0"); + + // Remove the link between the routing-instance and the routing-policy. + ifmap_test_util::IFMapMsgUnlink(&db_, + "routing-instance", "test", + "routing-policy", "basic_0", "routing-instance-routing-policy"); + task_util::WaitForIdle(); + + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 0); + + boost::replace_all(content_a, "", ""); + boost::replace_all(content_a, "", ""); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri == NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg == NULL); +} + +// +// Create routing instance and routing policy +// Associate routing-policy to routing-instance +// Validate the routing instance and associate policy in BgpInstanceConfig +// Remove the routing policy from routing instance +// Validate that routing instance is not associated any routing instance +// +TEST_F(BgpIfmapConfigManagerTest, RoutingInstanceRoutingPolicy_3) { + string content_a = FileRead("controller/src/bgp/testdata/routing_policy_3.xml"); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + + const BgpRoutingPolicyConfig *policy_cfg = + config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg != NULL); + + const BgpInstanceConfig *test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 1); + ASSERT_TRUE(test_ri->routing_policy_list().front().routing_policy_ == "basic_0"); + ASSERT_TRUE(test_ri->routing_policy_list().front().sequence_ == "1.0"); + + string content_b = FileRead("controller/src/bgp/testdata/routing_policy_3c.xml"); + EXPECT_TRUE(parser_.Parse(content_b)); + task_util::WaitForIdle(); + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri != NULL); + ASSERT_TRUE(test_ri->routing_policy_list().size() == 0); + + boost::replace_all(content_a, "", ""); + boost::replace_all(content_a, "", ""); + EXPECT_TRUE(parser_.Parse(content_a)); + task_util::WaitForIdle(); + test_ri = FindInstanceConfig("test"); + ASSERT_TRUE(test_ri == NULL); + policy_cfg = config_manager_->FindRoutingPolicy("basic_0"); + ASSERT_TRUE(policy_cfg == NULL); +} + class IFMapConfigTest : public ::testing::Test { protected: IFMapConfigTest() diff --git a/src/bgp/testdata/config_listener_test_10.xml b/src/bgp/testdata/config_listener_test_10.xml new file mode 100644 index 00000000000..304df61bdfd --- /dev/null +++ b/src/bgp/testdata/config_listener_test_10.xml @@ -0,0 +1,28 @@ + + + + + + 23:13 + + + + 102 + + accept + + + + + + 1.0 + + target:1:103 + + + + 2.0 + + target:1:103 + + diff --git a/src/bgp/testdata/config_listener_test_11.xml b/src/bgp/testdata/config_listener_test_11.xml new file mode 100644 index 00000000000..a77c079d6ec --- /dev/null +++ b/src/bgp/testdata/config_listener_test_11.xml @@ -0,0 +1,20 @@ + + + + + + + 23:13 + + + accept + + + + + + 1.0 + + target:1:103 + + diff --git a/src/bgp/testdata/config_listener_test_9.xml b/src/bgp/testdata/config_listener_test_9.xml new file mode 100644 index 00000000000..487ead35580 --- /dev/null +++ b/src/bgp/testdata/config_listener_test_9.xml @@ -0,0 +1,36 @@ + + + + + + 23:13 + + + + 102 + + accept + + + + + + + 23:11 + + + reject + + + + + + + 1.0 + + + 1.1 + + target:1:103 + + diff --git a/src/bgp/testdata/config_listener_test_9a.xml b/src/bgp/testdata/config_listener_test_9a.xml new file mode 100644 index 00000000000..b772bb0693d --- /dev/null +++ b/src/bgp/testdata/config_listener_test_9a.xml @@ -0,0 +1,8 @@ + + + + + 1.1 + + + diff --git a/src/bgp/testdata/routing_policy_0a.xml b/src/bgp/testdata/routing_policy_0a.xml new file mode 100644 index 00000000000..0862ed8427d --- /dev/null +++ b/src/bgp/testdata/routing_policy_0a.xml @@ -0,0 +1,13 @@ + + + + + + 11:13 + + + accept + + + + diff --git a/src/bgp/testdata/routing_policy_0b.xml b/src/bgp/testdata/routing_policy_0b.xml new file mode 100644 index 00000000000..d8b292fccdb --- /dev/null +++ b/src/bgp/testdata/routing_policy_0b.xml @@ -0,0 +1,21 @@ + + + + + + 11:13 + + + accept + + + + + 22:13 + + + reject + + + + diff --git a/src/bgp/testdata/routing_policy_3.xml b/src/bgp/testdata/routing_policy_3.xml new file mode 100644 index 00000000000..c56de6cc390 --- /dev/null +++ b/src/bgp/testdata/routing_policy_3.xml @@ -0,0 +1,19 @@ + + + + + + 11:13 + + + reject + + + + + + 1.0 + + target:1:103 + + diff --git a/src/bgp/testdata/routing_policy_3a.xml b/src/bgp/testdata/routing_policy_3a.xml new file mode 100644 index 00000000000..e76fa39adbe --- /dev/null +++ b/src/bgp/testdata/routing_policy_3a.xml @@ -0,0 +1,31 @@ + + + + + + 22:13 + + + reject + + + + + + + 11:13 + + + reject + + + + + + 1.0 + + + 2.0 + + + diff --git a/src/bgp/testdata/routing_policy_3b.xml b/src/bgp/testdata/routing_policy_3b.xml new file mode 100644 index 00000000000..236bfcffe95 --- /dev/null +++ b/src/bgp/testdata/routing_policy_3b.xml @@ -0,0 +1,11 @@ + + + + + 1.0 + + + 2.0 + + + diff --git a/src/bgp/testdata/routing_policy_3c.xml b/src/bgp/testdata/routing_policy_3c.xml new file mode 100644 index 00000000000..052c2421fb4 --- /dev/null +++ b/src/bgp/testdata/routing_policy_3c.xml @@ -0,0 +1,8 @@ + + + + + 1.0 + + + diff --git a/src/bgp/testdata/routing_policy_3d.xml b/src/bgp/testdata/routing_policy_3d.xml new file mode 100644 index 00000000000..e163b34d921 --- /dev/null +++ b/src/bgp/testdata/routing_policy_3d.xml @@ -0,0 +1,32 @@ + + + + + + 22:13 + + + reject + + + + + + + 11:13 + + + reject + + + + + + 1.0 + + + 2.0 + + target:1:103 + + diff --git a/src/bgp/testdata/routing_policy_4.xml b/src/bgp/testdata/routing_policy_4.xml new file mode 100644 index 00000000000..e76fa39adbe --- /dev/null +++ b/src/bgp/testdata/routing_policy_4.xml @@ -0,0 +1,31 @@ + + + + + + 22:13 + + + reject + + + + + + + 11:13 + + + reject + + + + + + 1.0 + + + 2.0 + + + diff --git a/src/bgp/testdata/routing_policy_4a.xml b/src/bgp/testdata/routing_policy_4a.xml new file mode 100644 index 00000000000..2aeaf19afaf --- /dev/null +++ b/src/bgp/testdata/routing_policy_4a.xml @@ -0,0 +1,31 @@ + + + + + + 22:13 + + + reject + + + + + + + 11:13 + + + reject + + + + + + 2.0 + + + 1.0 + + +