Skip to content

Commit

Permalink
UT cases for routing policy config code
Browse files Browse the repository at this point in the history
   1. Added config listener tests
   2. Added config ifmap tests

Related-bug: #1500698

Change-Id: I3dc8c72d7f0df67d343bdab1985994593749a5c9
  • Loading branch information
bailkeri committed Nov 25, 2015
1 parent 0534b51 commit 6872682
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/bgp/bgp_config.h
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions src/bgp/bgp_config_ifmap.cc
Expand Up @@ -80,9 +80,8 @@ void BgpIfmapRoutingPolicyLinkConfig::SetNodeProxy(IFMapNodeProxy *proxy) {
}
}

bool
BgpIfmapRoutingPolicyLinkConfig::GetRoutingInstanceRoutingPolicyPair(DBGraph *graph,
IFMapNode *node, pair<IFMapNode *, IFMapNode *> *pair) {
bool BgpIfmapRoutingPolicyLinkConfig::GetRoutingInstanceRoutingPolicyPair(
DBGraph *graph, IFMapNode *node, pair<IFMapNode *, IFMapNode *> *pair) {
IFMapNode *routing_instance = NULL;
IFMapNode *routing_policy = NULL;

Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_config_ifmap.h
Expand Up @@ -308,6 +308,7 @@ class BgpIfmapRoutingPolicyConfig {

void AddInstance(BgpIfmapInstanceConfig *rti);
void RemoveInstance(BgpIfmapInstanceConfig *rti);

private:
friend class BgpConfigManagerTest;

Expand Down
309 changes: 309 additions & 0 deletions src/bgp/test/bgp_config_listener_test.cc
Expand Up @@ -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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
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, "<config>", "<delete>");
boost::replace_all(content, "</config>", "</delete>");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
}

int main(int argc, char **argv) {
bgp_log_test::init();
ControlNode::SetDefaultSchedulingPolicy();
Expand Down

0 comments on commit 6872682

Please sign in to comment.