diff --git a/src/bgp/test/SConscript b/src/bgp/test/SConscript index 946505606da..70e4d87dd1b 100644 --- a/src/bgp/test/SConscript +++ b/src/bgp/test/SConscript @@ -220,6 +220,16 @@ bgp_sg_test = env.UnitTest('bgp_sg_test', ['bgp_sg_test.cc']) env.Alias('src/bgp:bgp_sg_test', bgp_sg_test) +bgp_show_evpn_table_test = env.UnitTest('bgp_show_evpn_table_test', + ['bgp_show_evpn_table_test.cc']) +env.Alias('src/bgp:bgp_show_evpn_table_test', + bgp_show_evpn_table_test) + +bgp_show_instance_config_test = env.UnitTest('bgp_show_instance_config_test', + ['bgp_show_instance_config_test.cc']) +env.Alias('src/bgp:bgp_show_instance_config_test', + bgp_show_instance_config_test) + bgp_show_neighbor_test = env.UnitTest('bgp_show_neighbor_test', ['bgp_show_neighbor_test.cc']) env.Alias('src/bgp:bgp_show_neighbor_test', @@ -396,6 +406,8 @@ test_suite = [ bgp_server_test, bgp_session_test, bgp_sg_test, + bgp_show_evpn_table_test, + bgp_show_instance_config_test, bgp_show_neighbor_test, bgp_show_route_summary_test, bgp_show_routing_instance_test, diff --git a/src/bgp/test/bgp_show_evpn_table_test.cc b/src/bgp/test/bgp_show_evpn_table_test.cc new file mode 100644 index 00000000000..34c4d8bea90 --- /dev/null +++ b/src/bgp/test/bgp_show_evpn_table_test.cc @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. + */ + +#include "bgp/test/bgp_show_instance_or_table_test.h" + +typedef TypeDefinition< + ShowEvpnTableReq, + ShowEvpnTableReqIterate, + ShowEvpnTableResp> RegularReq; + +typedef TypeDefinition< + ShowEvpnTableSummaryReq, + ShowEvpnTableSummaryReqIterate, + ShowEvpnTableSummaryResp> SummaryReq; + +// Common routine for regular and summary requests. +static void AddEvpnTableName(vector *names, const string &name) { + string table_name; + if (name == BgpConfigManager::kMasterInstance) { + table_name = "bgp.evpn.0"; + } else { + table_name = name + ".evpn.0"; + } + names->push_back(table_name); +} + +// Specialization of AddInstanceOrTableName for regular request. +template<> +void BgpShowInstanceOrTableTest::AddInstanceOrTableName( + vector *names, const string &name) { + AddEvpnTableName(names, name); +} + +// Specialization of AddInstanceOrTableName for summary request. +template<> +void BgpShowInstanceOrTableTest::AddInstanceOrTableName( + vector *names, const string &name) { + AddEvpnTableName(names, name); +} + +// Common routine for regular and summary requests. +template +static void ValidateEvpnResponse(Sandesh *sandesh, vector &result, + const string &next_batch) { + RespT *resp = dynamic_cast(sandesh); + TASK_UTIL_EXPECT_TRUE(resp != NULL); + TASK_UTIL_EXPECT_EQ(result.size(), resp->get_tables().size()); + TASK_UTIL_EXPECT_EQ(next_batch, resp->get_next_batch()); + for (size_t i = 0; i < resp->get_tables().size(); ++i) { + TASK_UTIL_EXPECT_EQ(result[i], resp->get_tables()[i].get_name()); + cout << resp->get_tables()[i].log() << endl; + } +} + +// Specialization of ValidateResponse for regular request. +template<> +void BgpShowInstanceOrTableTest::ValidateResponse( + Sandesh *sandesh, vector &result, const string &next_batch) { + ValidateEvpnResponse(sandesh, result, next_batch); + validate_done_ = true; +} + +// Specialization of ValidateResponse for summary request. +template<> +void BgpShowInstanceOrTableTest::ValidateResponse( + Sandesh *sandesh, vector &result, const string &next_batch) { + ValidateEvpnResponse(sandesh, result, next_batch); + validate_done_ = true; +} + +// Instantiate all test patterns for ShowEvpnTableReq. +INSTANTIATE_TYPED_TEST_CASE_P(Regular, BgpShowInstanceOrTableTest, RegularReq); + +// Instantiate all test patterns for ShowEvpnTableSummaryReq. +INSTANTIATE_TYPED_TEST_CASE_P(Summary, BgpShowInstanceOrTableTest, SummaryReq); + +class TestEnvironment : public ::testing::Environment { + virtual ~TestEnvironment() { } +}; + +static void SetUp() { + ControlNode::SetDefaultSchedulingPolicy(); + BgpServerTest::GlobalSetUp(); + XmppObjectFactory::Register( + boost::factory()); + BgpObjectFactory::Register( + boost::factory()); +} + +static void TearDown() { + task_util::WaitForIdle(); + TaskScheduler *scheduler = TaskScheduler::GetInstance(); + scheduler->Terminate(); +} + +int main(int argc, char **argv) { + bgp_log_test::init(); + ::testing::InitGoogleTest(&argc, argv); + ::testing::AddGlobalTestEnvironment(new TestEnvironment()); + SetUp(); + int result = RUN_ALL_TESTS(); + TearDown(); + return result; +} diff --git a/src/bgp/test/bgp_show_instance_config_test.cc b/src/bgp/test/bgp_show_instance_config_test.cc new file mode 100644 index 00000000000..0703ed7dd29 --- /dev/null +++ b/src/bgp/test/bgp_show_instance_config_test.cc @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. + */ + +#include "bgp/test/bgp_show_instance_or_table_test.h" + +typedef TypeDefinition< + ShowBgpInstanceConfigReq, + ShowBgpInstanceConfigReqIterate, + ShowBgpInstanceConfigResp> ConfigReq; + +// Specialization to identify config request. +template<> +bool BgpShowInstanceOrTableTest::RequestIsConfig() const { + return true; +} + +// Instantiate all test patterns for ShowBgpInstanceConfigReq. +INSTANTIATE_TYPED_TEST_CASE_P(Config, BgpShowInstanceOrTableTest, ConfigReq); + +class TestEnvironment : public ::testing::Environment { + virtual ~TestEnvironment() { } +}; + +static void SetUp() { + ControlNode::SetDefaultSchedulingPolicy(); + BgpServerTest::GlobalSetUp(); + XmppObjectFactory::Register( + boost::factory()); + BgpObjectFactory::Register( + boost::factory()); +} + +static void TearDown() { + task_util::WaitForIdle(); + TaskScheduler *scheduler = TaskScheduler::GetInstance(); + scheduler->Terminate(); +} + +int main(int argc, char **argv) { + bgp_log_test::init(); + ::testing::InitGoogleTest(&argc, argv); + ::testing::AddGlobalTestEnvironment(new TestEnvironment()); + SetUp(); + int result = RUN_ALL_TESTS(); + TearDown(); + return result; +} diff --git a/src/bgp/test/bgp_show_instance_or_table_test.h b/src/bgp/test/bgp_show_instance_or_table_test.h new file mode 100644 index 00000000000..ee7eb051f62 --- /dev/null +++ b/src/bgp/test/bgp_show_instance_or_table_test.h @@ -0,0 +1,1186 @@ +/* + * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. + */ + +#include "base/test/task_test_util.h" +#include "bgp/bgp_config.h" +#include "bgp/bgp_factory.h" +#include "bgp/bgp_peer_membership.h" +#include "bgp/bgp_sandesh.h" +#include "bgp/bgp_session_manager.h" +#include "bgp/bgp_xmpp_channel.h" +#include "bgp/test/bgp_server_test_util.h" +#include "bgp/test/bgp_test_util.h" +#include "bgp/xmpp_message_builder.h" +#include "control-node/control_node.h" +#include "control-node/test/network_agent_mock.h" +#include "ifmap/ifmap_server_parser.h" +#include "ifmap/test/ifmap_test_util.h" +#include "io/test/event_manager_test.h" +#include "schema/bgp_schema_types.h" +#include "schema/vnc_cfg_types.h" +#include "testing/gunit.h" +#include "xmpp/xmpp_factory.h" + +using std::cout; +using std::endl; +using std::string; +using std::vector; + +static const char *config_template = "\ +\ + \ + 192.168.0.1\ + 64512\ +
127.0.0.1
\ + %d\ +
\ +
\ +"; + +// +// Template structure to pass to fixture class template. Needed because +// gtest fixture class template can accept only one template parameter. +// +template +struct TypeDefinition { + typedef T1 ReqT; + typedef T2 ReqIterateT; + typedef T3 RespT; +}; + +// +// Fixture class template - will be instantiated in source test files. +// +template +class BgpShowInstanceOrTableTest : public ::testing::Test { +public: + void ValidateResponse(Sandesh *sandesh, + vector &result, const string &next_batch) { + typename T::RespT *resp = dynamic_cast(sandesh); + TASK_UTIL_EXPECT_TRUE(resp != NULL); + TASK_UTIL_EXPECT_EQ(result.size(), resp->get_instances().size()); + TASK_UTIL_EXPECT_EQ(next_batch, resp->get_next_batch()); + for (size_t i = 0; i < resp->get_instances().size(); ++i) { + TASK_UTIL_EXPECT_EQ(result[i], resp->get_instances()[i].get_name()); + cout << resp->get_instances()[i].log() << endl; + } + validate_done_ = true; + } + +protected: + BgpShowInstanceOrTableTest() + : thread_(&evm_), xmpp_server_(NULL), validate_done_(false) { + } + + bool RequestIsConfig() const { return false; } + bool RequestIsDetail() const { return false; } + void AddInstanceOrTableName(vector *names, const string &name) { + names->push_back(name); + } + + virtual void SetUp() { + IFMapServerParser *parser = IFMapServerParser::GetInstance("schema"); + bgp_schema_ParserInit(parser); + vnc_cfg_ParserInit(parser); + + server_.reset(new BgpServerTest(&evm_, "X")); + server_->session_manager()->Initialize(0); + xmpp_server_ = + new XmppServerTest(&evm_, test::XmppDocumentMock::kControlNodeJID); + xmpp_server_->Initialize(0, false); + LOG(DEBUG, "Created XMPP server at port: " << xmpp_server_->GetPort()); + bcm_.reset(new BgpXmppChannelManager(xmpp_server_, server_.get())); + + sandesh_context_.bgp_server = server_.get(); + sandesh_context_.xmpp_peer_manager = bcm_.get(); + + thread_.Start(); + Configure(); + task_util::WaitForIdle(); + + CreateAgents(); + SubscribeAgents(); + } + + virtual void TearDown() { + ShutdownAgents(); + + xmpp_server_->Shutdown(); + task_util::WaitForIdle(); + server_->Shutdown(); + task_util::WaitForIdle(); + + bcm_.reset(); + TcpServerManager::DeleteServer(xmpp_server_); + xmpp_server_ = NULL; + + DeleteAgents(); + + IFMapCleanUp(); + task_util::WaitForIdle(); + + evm_.Shutdown(); + thread_.Join(); + task_util::WaitForIdle(); + } + + void IFMapCleanUp() { + IFMapServerParser::GetInstance("vnc_cfg")->MetadataClear("vnc_cfg"); + IFMapServerParser::GetInstance("schema")->MetadataClear("schema"); + } + + void Configure() { + char config[4096]; + snprintf(config, sizeof(config), config_template, + server_->session_manager()->GetPort()); + server_->Configure(config); + task_util::WaitForIdle(); + + TASK_UTIL_EXPECT_EQ(64512, server_->autonomous_system()); + TASK_UTIL_EXPECT_EQ(64512, server_->local_autonomous_system()); + + vector instance_names; + for (int idx = 900; idx < 912; ++idx) { + string vn_name = string("vn") + integerToString(idx); + instance_names.push_back(vn_name); + } + NetworkConfig(instance_names); + VerifyNetworkConfig(server_.get(), instance_names); + } + + void NetworkConfig(const vector &instance_names) { + string netconf(bgp_util::NetworkConfigGenerate(instance_names)); + IFMapServerParser *parser = IFMapServerParser::GetInstance("schema"); + parser->Receive( + server_->config_db(), netconf.data(), netconf.length(), 0); + task_util::WaitForIdle(); + } + + void VerifyNetworkConfig(BgpServerTest *server, + const vector &instance_names) { + for (vector::const_iterator iter = instance_names.begin(); + iter != instance_names.end(); ++iter) { + TASK_UTIL_WAIT_NE_NO_MSG( + server->routing_instance_mgr()->GetRoutingInstance(*iter), + NULL, 1000, 10000, "Wait for routing instance.."); + const RoutingInstance *rti = + server->routing_instance_mgr()->GetRoutingInstance(*iter); + TASK_UTIL_WAIT_NE_NO_MSG(rti->virtual_network_index(), + 0, 1000, 10000, "Wait for vn index.."); + } + } + + void CreateAgents() { + if (!RequestIsDetail()) + return; + agent1_.reset(new test::NetworkAgentMock(&evm_, "agent1", + xmpp_server_->GetPort(), "127.0.0.1", "127.0.0.11")); + TASK_UTIL_EXPECT_TRUE(agent1_->IsEstablished()); + agent2_.reset(new test::NetworkAgentMock(&evm_, "agent2", + xmpp_server_->GetPort(), "127.0.0.1", "127.0.0.12")); + TASK_UTIL_EXPECT_TRUE(agent2_->IsEstablished()); + } + + void SubscribeAgents() { + if (!RequestIsDetail()) + return; + for (int idx = 900; idx < 912; ++idx) { + string vn_name = string("vn") + integerToString(idx); + agent1_->Subscribe(vn_name, idx); + agent2_->Subscribe(vn_name, idx); + } + TASK_UTIL_EXPECT_EQ((912 - 900) * 4 * 2, // VNs * Tables per VN * Agents + server_->membership_mgr()->GetMembershipCount()); + task_util::WaitForIdle(); + } + + void ShutdownAgents() { + if (!RequestIsDetail()) + return; + agent1_->SessionDown(); + TASK_UTIL_EXPECT_FALSE(agent1_->IsEstablished()); + agent2_->SessionDown(); + TASK_UTIL_EXPECT_FALSE(agent2_->IsEstablished()); + } + + void DeleteAgents() { + if (!RequestIsDetail()) + return; + agent1_->Delete(); + agent2_->Delete(); + } + + void PauseResumeInstanceDeletion(bool pause) { + if (RequestIsConfig()) + return; + task_util::TaskSchedulerLock lock; + RoutingInstanceMgr *rim = server_->routing_instance_mgr(); + for (RoutingInstanceMgr::name_iterator it1 = rim->name_begin(); + it1 != rim->name_end(); ++it1) { + RoutingInstance *rtinstance = it1->second; + if (pause) { + rtinstance->deleter()->PauseDelete(); + } else { + rtinstance->deleter()->ResumeDelete(); + } + RoutingInstance::RouteTableList tables = rtinstance->GetTables(); + for (RoutingInstance::RouteTableList::iterator it2 = tables.begin(); + it2 != tables.end(); ++it2) { + BgpTable *table = it2->second; + if (pause) { + table->deleter()->PauseDelete(); + } else { + table->deleter()->ResumeDelete(); + } + } + } + } + + void PauseInstanceDeletion() { + PauseResumeInstanceDeletion(true); + } + + void ResumeInstanceDeletion() { + PauseResumeInstanceDeletion(false); + } + + EventManager evm_; + ServerThread thread_; + boost::scoped_ptr server_; + XmppServerTest *xmpp_server_; + boost::scoped_ptr bcm_; + bool validate_done_; + BgpSandeshContext sandesh_context_; + boost::scoped_ptr agent1_; + boost::scoped_ptr agent2_; +}; + +// Declare a type-parameterized test case. +TYPED_TEST_CASE_P(BgpShowInstanceOrTableTest); + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Should return all instances. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, Request1) { + typedef typename TypeParam::ReqT ReqT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 5 +// Should return all instances. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, Request2) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_iter_limit(5); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 13 (number of instances) +// Iteration limit = 1024 (default) +// Should return all instances. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, Request3) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_page_limit(13); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 4 +// Iteration limit = 1024 (default) +// Should return first 4 instances. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, Request4) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_page_limit(4); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + for (int idx = 900; idx < 903; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn903||"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 4 +// Iteration limit = 2 +// Should return first 4 instances. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, Request5) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + for (int idx = 900; idx < 903; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn903||"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "" +// Should return all instances. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch0) { + typedef typename TypeParam::ReqT ReqT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string(""); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "vn" +// Should return all instances with "vn". +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch1) { + typedef typename TypeParam::ReqT ReqT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("vn"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 5 +// Search string = "vn" +// Should return all instances with "vn". +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch2) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_iter_limit(5); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("vn"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 12 (number of matching instances) +// Iteration limit = 1024 (default) +// Search string = "vn" +// Should return all instances with "vn". +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch3) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_page_limit(12); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("vn"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 4 +// Iteration limit = 1024 (default) +// Search string = "vn" +// Should return first 4 instances with "vn". +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch4) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_page_limit(4); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 900; idx < 904; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn904||vn"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("vn"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 4 +// Iteration limit = 2 +// Search string = "vn" +// Should return first 4 instances with "vn". +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch5) { + typedef typename TypeParam::ReqT ReqT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 900; idx < 904; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn904||vn"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("vn"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "xyz" +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch6) { + typedef typename TypeParam::ReqT ReqT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("xyz"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "xyz" +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch7) { + typedef typename TypeParam::ReqT ReqT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("xyz"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "deleted" +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch8) { + typedef typename TypeParam::ReqT ReqT; + if (this->RequestIsConfig()) + return; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("deleted"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "deleted" +// Should return all instances (they are marked deleted) +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch9) { + typedef typename TypeParam::ReqT ReqT; + if (this->RequestIsConfig()) + return; + + this->PauseInstanceDeletion(); + this->server_->Shutdown(false); + task_util::WaitForIdle(); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); + for (int idx = 900; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("deleted"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); + this->ResumeInstanceDeletion(); +} + +// +// Next instance = empty +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "vn907" +// Should return 1 instance. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestWithSearch10) { + typedef typename TypeParam::ReqT ReqT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + this->AddInstanceOrTableName(&names, "vn907"); + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqT *req = new ReqT; + req->set_search_string("vn907"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Should return all instances including and after "vn901" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate1) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 64 (default) +// Iteration limit = 5 +// Should return all instances including and after "vn901" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate2) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_iter_limit(5); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 11 +// Iteration limit = 1024 (default) +// Should return all instances including and after "vn901" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate3) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(11); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 912; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 4 +// Iteration limit = 1024 (default) +// Should return first 4 instances including and after "vn901" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate4) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 905; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn905||"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 4 +// Iteration limit = 2 +// Should return first 4 instances after "vn901" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate5) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 905; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn905||"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = empty +// Page limit = 4 +// Iteration limit = 2 +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate6) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info(""); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = malformed +// Page limit = 4 +// Iteration limit = 2 +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate7) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = malformed +// Page limit = 4 +// Iteration limit = 2 +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate8) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901|"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn919" +// Page limit = 4 +// Iteration limit = 2 +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterate9) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn919||"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 64 (default) +// Iteration limit = 1024 (default) +// Search string = "vn90" +// Should return all instances including and after "vn901" with "vn90" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch1) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 910; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn90"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 64 (default) +// Iteration limit = 4 +// Search string = "vn90" +// Should return all instances including and after "vn901" with "vn90" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch2) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_iter_limit(4); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 910; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn90"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 4 +// Iteration limit = 1024 (default) +// Search string = "vn90" +// Should return first 4 instances including and after "vn901" with "vn90" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch3) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 905; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn905||vn90"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn90"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 9 +// Iteration limit = 1024 (default) +// Search string = "vn90" +// Should return first 9 instances including and after "vn901" with "vn90" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch4) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(9); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 910; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn910||vn90"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn90"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 4 +// Iteration limit = 2 +// Search string = "vn90" +// Should return first 4 instances including and after "vn901" with "vn90" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch5) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 905; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn905||vn90"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn90"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 9 +// Iteration limit = 3 +// Search string = "vn90" +// Should return first 4 instances including and after "vn901" with "vn90" +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch6) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(9); + this->sandesh_context_.set_iter_limit(3); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + for (int idx = 901; idx < 910; ++idx) { + string name = string("vn") + integerToString(idx); + this->AddInstanceOrTableName(&names, name); + } + string next_batch = "vn910||vn90"; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn90"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// +// Next instance = "vn901" +// Page limit = 4 +// Iteration limit = 2 +// Search string = "vn92" +// Should return empty list. +// +TYPED_TEST_P(BgpShowInstanceOrTableTest, RequestIterateWithSearch7) { + typedef typename TypeParam::ReqIterateT ReqIterateT; + + this->sandesh_context_.set_page_limit(4); + this->sandesh_context_.set_iter_limit(2); + Sandesh::set_client_context(&this->sandesh_context_); + vector names; + string next_batch; + Sandesh::set_response_callback(boost::bind( + &BgpShowInstanceOrTableTest::ValidateResponse, this, + _1, names, next_batch)); + this->validate_done_ = false; + ReqIterateT *req = new ReqIterateT; + req->set_iterate_info("vn901||vn92"); + req->HandleRequest(); + req->Release(); + TASK_UTIL_EXPECT_TRUE(this->validate_done_); +} + +// Register all test patterns. +// They will be instantiated from source test files. +REGISTER_TYPED_TEST_CASE_P(BgpShowInstanceOrTableTest, + Request1, + Request2, + Request3, + Request4, + Request5, + RequestWithSearch0, + RequestWithSearch1, + RequestWithSearch2, + RequestWithSearch3, + RequestWithSearch4, + RequestWithSearch5, + RequestWithSearch6, + RequestWithSearch7, + RequestWithSearch8, + RequestWithSearch9, + RequestWithSearch10, + RequestIterate1, + RequestIterate2, + RequestIterate3, + RequestIterate4, + RequestIterate5, + RequestIterate6, + RequestIterate7, + RequestIterate8, + RequestIterate9, + RequestIterateWithSearch1, + RequestIterateWithSearch2, + RequestIterateWithSearch3, + RequestIterateWithSearch4, + RequestIterateWithSearch5, + RequestIterateWithSearch6, + RequestIterateWithSearch7); diff --git a/src/bgp/test/bgp_show_routing_instance_test.cc b/src/bgp/test/bgp_show_routing_instance_test.cc index 74de0a60ef0..819080dea8f 100644 --- a/src/bgp/test/bgp_show_routing_instance_test.cc +++ b/src/bgp/test/bgp_show_routing_instance_test.cc @@ -2,1260 +2,29 @@ * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ -#include "base/test/task_test_util.h" -#include "bgp/bgp_config.h" -#include "bgp/bgp_factory.h" -#include "bgp/bgp_peer_membership.h" -#include "bgp/bgp_sandesh.h" -#include "bgp/bgp_session_manager.h" -#include "bgp/bgp_xmpp_channel.h" -#include "bgp/test/bgp_server_test_util.h" -#include "bgp/test/bgp_test_util.h" -#include "bgp/xmpp_message_builder.h" -#include "control-node/control_node.h" -#include "control-node/test/network_agent_mock.h" -#include "ifmap/ifmap_server_parser.h" -#include "ifmap/test/ifmap_test_util.h" -#include "io/test/event_manager_test.h" -#include "schema/bgp_schema_types.h" -#include "schema/vnc_cfg_types.h" -#include "testing/gunit.h" -#include "xmpp/xmpp_factory.h" +#include "bgp/test/bgp_show_instance_or_table_test.h" -using std::cout; -using std::endl; -using std::string; -using std::vector; - -static const char *config_template = "\ -\ - \ - 192.168.0.1\ - 64512\ -
127.0.0.1
\ - %d\ -
\ -
\ -"; - -// -// Template structure to pass to fixture class template. Needed because -// gtest fixture class template can accept only one template parameter. -// -template -struct TypeDefinition { - typedef T1 ReqT; - typedef T2 ReqIterateT; - typedef T3 RespT; -}; - -// -// List of TypeDefinitions we want to test. -// -typedef ::testing::Types < - TypeDefinition< - ShowRoutingInstanceReq, - ShowRoutingInstanceReqIterate, - ShowRoutingInstanceResp >, - TypeDefinition< - ShowRoutingInstanceSummaryReq, - ShowRoutingInstanceSummaryReqIterate, - ShowRoutingInstanceSummaryResp >, - TypeDefinition< - ShowEvpnTableReq, - ShowEvpnTableReqIterate, - ShowEvpnTableResp >, - TypeDefinition< - ShowEvpnTableSummaryReq, - ShowEvpnTableSummaryReqIterate, - ShowEvpnTableSummaryResp >, - TypeDefinition< - ShowBgpInstanceConfigReq, - ShowBgpInstanceConfigReqIterate, - ShowBgpInstanceConfigResp > > TypeDefinitionList; - -// -// Fixture class template - will be instantiated further below for each entry -// in TypeDefinitionList. -// -template -class BgpShowRoutingInstanceTest : public ::testing::Test { -public: - void ValidateResponse(Sandesh *sandesh, - vector &result, const string &next_batch) { - typename T::RespT *resp = dynamic_cast(sandesh); - TASK_UTIL_EXPECT_TRUE(resp != NULL); - TASK_UTIL_EXPECT_EQ(result.size(), resp->get_instances().size()); - TASK_UTIL_EXPECT_EQ(next_batch, resp->get_next_batch()); - for (size_t i = 0; i < resp->get_instances().size(); ++i) { - TASK_UTIL_EXPECT_EQ(result[i], resp->get_instances()[i].get_name()); - cout << resp->get_instances()[i].log() << endl; - } - validate_done_ = true; - } - -protected: - BgpShowRoutingInstanceTest() - : thread_(&evm_), xmpp_server_(NULL), validate_done_(false) { - } - - bool RequestIsConfig() const { return false; } - bool RequestIsDetail() const { return false; } - void AddInstanceOrTableName(vector *names, const string &name) { - names->push_back(name); - } - - virtual void SetUp() { - IFMapServerParser *parser = IFMapServerParser::GetInstance("schema"); - bgp_schema_ParserInit(parser); - vnc_cfg_ParserInit(parser); - - server_.reset(new BgpServerTest(&evm_, "X")); - server_->session_manager()->Initialize(0); - xmpp_server_ = - new XmppServerTest(&evm_, test::XmppDocumentMock::kControlNodeJID); - xmpp_server_->Initialize(0, false); - LOG(DEBUG, "Created XMPP server at port: " << xmpp_server_->GetPort()); - bcm_.reset(new BgpXmppChannelManager(xmpp_server_, server_.get())); - - sandesh_context_.bgp_server = server_.get(); - sandesh_context_.xmpp_peer_manager = bcm_.get(); - - thread_.Start(); - Configure(); - task_util::WaitForIdle(); - - CreateAgents(); - SubscribeAgents(); - } - - virtual void TearDown() { - ShutdownAgents(); - - xmpp_server_->Shutdown(); - task_util::WaitForIdle(); - server_->Shutdown(); - task_util::WaitForIdle(); - - bcm_.reset(); - TcpServerManager::DeleteServer(xmpp_server_); - xmpp_server_ = NULL; - - DeleteAgents(); - - IFMapCleanUp(); - task_util::WaitForIdle(); - - evm_.Shutdown(); - thread_.Join(); - task_util::WaitForIdle(); - } - - void IFMapCleanUp() { - IFMapServerParser::GetInstance("vnc_cfg")->MetadataClear("vnc_cfg"); - IFMapServerParser::GetInstance("schema")->MetadataClear("schema"); - } - - void Configure() { - char config[4096]; - snprintf(config, sizeof(config), config_template, - server_->session_manager()->GetPort()); - server_->Configure(config); - task_util::WaitForIdle(); - - TASK_UTIL_EXPECT_EQ(64512, server_->autonomous_system()); - TASK_UTIL_EXPECT_EQ(64512, server_->local_autonomous_system()); - - vector instance_names; - for (int idx = 900; idx < 912; ++idx) { - string vn_name = string("vn") + integerToString(idx); - instance_names.push_back(vn_name); - } - NetworkConfig(instance_names); - VerifyNetworkConfig(server_.get(), instance_names); - } - - void NetworkConfig(const vector &instance_names) { - string netconf(bgp_util::NetworkConfigGenerate(instance_names)); - IFMapServerParser *parser = IFMapServerParser::GetInstance("schema"); - parser->Receive( - server_->config_db(), netconf.data(), netconf.length(), 0); - task_util::WaitForIdle(); - } - - void VerifyNetworkConfig(BgpServerTest *server, - const vector &instance_names) { - for (vector::const_iterator iter = instance_names.begin(); - iter != instance_names.end(); ++iter) { - TASK_UTIL_WAIT_NE_NO_MSG( - server->routing_instance_mgr()->GetRoutingInstance(*iter), - NULL, 1000, 10000, "Wait for routing instance.."); - const RoutingInstance *rti = - server->routing_instance_mgr()->GetRoutingInstance(*iter); - TASK_UTIL_WAIT_NE_NO_MSG(rti->virtual_network_index(), - 0, 1000, 10000, "Wait for vn index.."); - } - } - - void CreateAgents() { - if (!RequestIsDetail()) - return; - agent1_.reset(new test::NetworkAgentMock(&evm_, "agent1", - xmpp_server_->GetPort(), "127.0.0.1", "127.0.0.11")); - TASK_UTIL_EXPECT_TRUE(agent1_->IsEstablished()); - agent2_.reset(new test::NetworkAgentMock(&evm_, "agent2", - xmpp_server_->GetPort(), "127.0.0.1", "127.0.0.12")); - TASK_UTIL_EXPECT_TRUE(agent2_->IsEstablished()); - } - - void SubscribeAgents() { - if (!RequestIsDetail()) - return; - for (int idx = 900; idx < 912; ++idx) { - string vn_name = string("vn") + integerToString(idx); - agent1_->Subscribe(vn_name, idx); - agent2_->Subscribe(vn_name, idx); - } - TASK_UTIL_EXPECT_EQ((912 - 900) * 4 * 2, // VNs * Tables per VN * Agents - server_->membership_mgr()->GetMembershipCount()); - task_util::WaitForIdle(); - } - - void ShutdownAgents() { - if (!RequestIsDetail()) - return; - agent1_->SessionDown(); - TASK_UTIL_EXPECT_FALSE(agent1_->IsEstablished()); - agent2_->SessionDown(); - TASK_UTIL_EXPECT_FALSE(agent2_->IsEstablished()); - } - - void DeleteAgents() { - if (!RequestIsDetail()) - return; - agent1_->Delete(); - agent2_->Delete(); - } - - void PauseInstanceDeletion() { - if (RequestIsConfig()) - return; - RoutingInstanceMgr *rim = server_->routing_instance_mgr(); - for (RoutingInstanceMgr::name_iterator it = rim->name_begin(); - it != rim->name_end(); ++it) { - RoutingInstance *rtinstance = it->second; - rtinstance->deleter()->PauseDelete(); - RoutingInstance::RouteTableList tables = rtinstance->GetTables(); - for (RoutingInstance::RouteTableList::iterator it2 = tables.begin(); - it2 != tables.end(); ++it2) { - BgpTable *table = it2->second; - table->deleter()->PauseDelete(); - } - } - } - - void ResumeInstanceDeletion() { - if (RequestIsConfig()) - return; - RoutingInstanceMgr *rim = server_->routing_instance_mgr(); - for (RoutingInstanceMgr::name_iterator it = rim->name_begin(); - it != rim->name_end(); ++it) { - RoutingInstance *rtinstance = it->second; - rtinstance->deleter()->ResumeDelete(); - RoutingInstance::RouteTableList tables = rtinstance->GetTables(); - for (RoutingInstance::RouteTableList::iterator it2 = tables.begin(); - it2 != tables.end(); ++it2) { - BgpTable *table = it2->second; - table->deleter()->ResumeDelete(); - } - } - } - - EventManager evm_; - ServerThread thread_; - boost::scoped_ptr server_; - XmppServerTest *xmpp_server_; - boost::scoped_ptr bcm_; - bool validate_done_; - BgpSandeshContext sandesh_context_; - boost::scoped_ptr agent1_; - boost::scoped_ptr agent2_; -}; - -// Specialization to identify ShowBgpInstanceConfigReq. -template<> -bool BgpShowRoutingInstanceTest >::RequestIsConfig() const { - return true; -} - -// Specialization to identify ShowRoutingInstanceReq. -template<> -bool BgpShowRoutingInstanceTest >::RequestIsDetail() const { - return true; -} - -// Common routine ShowEvpnTableReq and ShowEvpnTableSummaryReq. -static void AddEvpnTableName(vector *names, const string &name) { - string table_name; - if (name == BgpConfigManager::kMasterInstance) { - table_name = "bgp.evpn.0"; - } else { - table_name = name + ".evpn.0"; - } - names->push_back(table_name); -} + ShowRoutingInstanceResp> RegularReq; -// Specialization to identify ShowEvpnTableReq. -template<> -void BgpShowRoutingInstanceTest >::AddInstanceOrTableName(vector *names, - const string &name) { - AddEvpnTableName(names, name); -} - -// Specialization to identify ShowEvpnTableSummaryReq. -template<> -void BgpShowRoutingInstanceTest >::AddInstanceOrTableName(vector *names, - const string &name) { - AddEvpnTableName(names, name); -} +typedef TypeDefinition< + ShowRoutingInstanceSummaryReq, + ShowRoutingInstanceSummaryReqIterate, + ShowRoutingInstanceSummaryResp> SummaryReq; -// Specialization to identify ShowEvpnTableReq. +// Specialization of RequestIsDetail for regular request. template<> -void BgpShowRoutingInstanceTest >::ValidateResponse( - Sandesh *sandesh, vector &result, const string &next_batch) { - ShowEvpnTableResp *resp = - dynamic_cast(sandesh); - TASK_UTIL_EXPECT_TRUE(resp != NULL); - TASK_UTIL_EXPECT_EQ(result.size(), resp->get_tables().size()); - TASK_UTIL_EXPECT_EQ(next_batch, resp->get_next_batch()); - for (size_t i = 0; i < resp->get_tables().size(); ++i) { - TASK_UTIL_EXPECT_EQ(result[i], resp->get_tables()[i].get_name()); - cout << resp->get_tables()[i].log() << endl; - } - validate_done_ = true; -} - -// Specialization to identify ShowEvpnTableSummaryReq. -template<> -void BgpShowRoutingInstanceTest >::ValidateResponse(Sandesh *sandesh, - vector &result, const string &next_batch) { - ShowEvpnTableSummaryResp *resp = - dynamic_cast(sandesh); - TASK_UTIL_EXPECT_TRUE(resp != NULL); - TASK_UTIL_EXPECT_EQ(result.size(), resp->get_tables().size()); - TASK_UTIL_EXPECT_EQ(next_batch, resp->get_next_batch()); - for (size_t i = 0; i < resp->get_tables().size(); ++i) { - TASK_UTIL_EXPECT_EQ(result[i], resp->get_tables()[i].get_name()); - cout << resp->get_tables()[i].log() << endl; - } - validate_done_ = true; -} - -// -// Instantiate fixture class template for each entry in TypeDefinitionList. -// -TYPED_TEST_CASE(BgpShowRoutingInstanceTest, TypeDefinitionList); - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Should return all instances. -// -TYPED_TEST(BgpShowRoutingInstanceTest, Request1) { - typedef typename TypeParam::ReqT ReqT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 5 -// Should return all instances. -// -TYPED_TEST(BgpShowRoutingInstanceTest, Request2) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_iter_limit(5); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 13 (number of instances) -// Iteration limit = 1024 (default) -// Should return all instances. -// -TYPED_TEST(BgpShowRoutingInstanceTest, Request3) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_page_limit(13); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 4 -// Iteration limit = 1024 (default) -// Should return first 4 instances. -// -TYPED_TEST(BgpShowRoutingInstanceTest, Request4) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_page_limit(4); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - for (int idx = 900; idx < 903; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn903||"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 4 -// Iteration limit = 2 -// Should return first 4 instances. -// -TYPED_TEST(BgpShowRoutingInstanceTest, Request5) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - for (int idx = 900; idx < 903; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn903||"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "" -// Should return all instances. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch0) { - typedef typename TypeParam::ReqT ReqT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string(""); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "vn" -// Should return all instances with "vn". -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch1) { - typedef typename TypeParam::ReqT ReqT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("vn"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 5 -// Search string = "vn" -// Should return all instances with "vn". -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch2) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_iter_limit(5); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("vn"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 12 (number of matching instances) -// Iteration limit = 1024 (default) -// Search string = "vn" -// Should return all instances with "vn". -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch3) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_page_limit(12); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("vn"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 4 -// Iteration limit = 1024 (default) -// Search string = "vn" -// Should return first 4 instances with "vn". -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch4) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_page_limit(4); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 900; idx < 904; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn904||vn"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("vn"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 4 -// Iteration limit = 2 -// Search string = "vn" -// Should return first 4 instances with "vn". -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch5) { - typedef typename TypeParam::ReqT ReqT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 900; idx < 904; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn904||vn"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("vn"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "xyz" -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch6) { - typedef typename TypeParam::ReqT ReqT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("xyz"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "xyz" -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch7) { - typedef typename TypeParam::ReqT ReqT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("xyz"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "deleted" -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch8) { - typedef typename TypeParam::ReqT ReqT; - if (this->RequestIsConfig()) - return; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("deleted"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "deleted" -// Should return all instances (they are marked deleted) -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch9) { - typedef typename TypeParam::ReqT ReqT; - if (this->RequestIsConfig()) - return; - - this->PauseInstanceDeletion(); - this->server_->Shutdown(false); - task_util::WaitForIdle(); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, BgpConfigManager::kMasterInstance); - for (int idx = 900; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("deleted"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); - this->ResumeInstanceDeletion(); -} - -// -// Next instance = empty -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "vn907" -// Should return 1 instance. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestWithSearch10) { - typedef typename TypeParam::ReqT ReqT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - this->AddInstanceOrTableName(&names, "vn907"); - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqT *req = new ReqT; - req->set_search_string("vn907"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Should return all instances including and after "vn901" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate1) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 64 (default) -// Iteration limit = 5 -// Should return all instances including and after "vn901" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate2) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_iter_limit(5); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 11 -// Iteration limit = 1024 (default) -// Should return all instances including and after "vn901" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate3) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(11); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 912; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 4 -// Iteration limit = 1024 (default) -// Should return first 4 instances including and after "vn901" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate4) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 905; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn905||"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 4 -// Iteration limit = 2 -// Should return first 4 instances after "vn901" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate5) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 905; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn905||"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = empty -// Page limit = 4 -// Iteration limit = 2 -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate6) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info(""); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = malformed -// Page limit = 4 -// Iteration limit = 2 -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate7) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = malformed -// Page limit = 4 -// Iteration limit = 2 -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate8) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901|"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn919" -// Page limit = 4 -// Iteration limit = 2 -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterate9) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn919||"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 64 (default) -// Iteration limit = 1024 (default) -// Search string = "vn90" -// Should return all instances including and after "vn901" with "vn90" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch1) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 910; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn90"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 64 (default) -// Iteration limit = 4 -// Search string = "vn90" -// Should return all instances including and after "vn901" with "vn90" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch2) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_iter_limit(4); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 910; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn90"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 4 -// Iteration limit = 1024 (default) -// Search string = "vn90" -// Should return first 4 instances including and after "vn901" with "vn90" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch3) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 905; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn905||vn90"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn90"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 9 -// Iteration limit = 1024 (default) -// Search string = "vn90" -// Should return first 9 instances including and after "vn901" with "vn90" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch4) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(9); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 910; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn910||vn90"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn90"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 4 -// Iteration limit = 2 -// Search string = "vn90" -// Should return first 4 instances including and after "vn901" with "vn90" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch5) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 905; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn905||vn90"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn90"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} - -// -// Next instance = "vn901" -// Page limit = 9 -// Iteration limit = 3 -// Search string = "vn90" -// Should return first 4 instances including and after "vn901" with "vn90" -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch6) { - typedef typename TypeParam::ReqIterateT ReqIterateT; - - this->sandesh_context_.set_page_limit(9); - this->sandesh_context_.set_iter_limit(3); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - for (int idx = 901; idx < 910; ++idx) { - string name = string("vn") + integerToString(idx); - this->AddInstanceOrTableName(&names, name); - } - string next_batch = "vn910||vn90"; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn90"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); +bool BgpShowInstanceOrTableTest::RequestIsDetail() const { + return true; } -// -// Next instance = "vn901" -// Page limit = 4 -// Iteration limit = 2 -// Search string = "vn92" -// Should return empty list. -// -TYPED_TEST(BgpShowRoutingInstanceTest, RequestIterateWithSearch7) { - typedef typename TypeParam::ReqIterateT ReqIterateT; +// Instantiate all test patterns for ShowRoutingInstanceReq. +INSTANTIATE_TYPED_TEST_CASE_P(Regular, BgpShowInstanceOrTableTest, RegularReq); - this->sandesh_context_.set_page_limit(4); - this->sandesh_context_.set_iter_limit(2); - Sandesh::set_client_context(&this->sandesh_context_); - vector names; - string next_batch; - Sandesh::set_response_callback(boost::bind( - &BgpShowRoutingInstanceTest::ValidateResponse, this, - _1, names, next_batch)); - this->validate_done_ = false; - ReqIterateT *req = new ReqIterateT; - req->set_iterate_info("vn901||vn92"); - req->HandleRequest(); - req->Release(); - TASK_UTIL_EXPECT_TRUE(this->validate_done_); -} +// Instantiate all test patterns for ShowRoutingInstanceSummaryReq. +INSTANTIATE_TYPED_TEST_CASE_P(Summary, BgpShowInstanceOrTableTest, SummaryReq); class TestEnvironment : public ::testing::Environment { virtual ~TestEnvironment() { }