From eaf400371a4a8d32a388c9638304361ca927c0ac Mon Sep 17 00:00:00 2001 From: Prakash M Bailkeri Date: Tue, 12 May 2015 15:54:19 +0530 Subject: [PATCH] static route introspect crash StaticRoute constructor doesn't initialize the nexthop_route_ pointer. Due to this introspect access uninitialized memory if vrouter agent has not yet published the nexthop route Fix: Fix the constructor to initialize the pointer Also added UT cases for HTTP introspect function Change-Id: I405e974f63b48ea494caf03980eb68e3d958aa73 Closes-bug: #1454191 --- src/bgp/routing-instance/static_route.cc | 2 +- src/bgp/test/static_route_test.cc | 74 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/bgp/routing-instance/static_route.cc b/src/bgp/routing-instance/static_route.cc index 31fbf346b3e..f777b9278a2 100644 --- a/src/bgp/routing-instance/static_route.cc +++ b/src/bgp/routing-instance/static_route.cc @@ -203,7 +203,7 @@ StaticRoute::StaticRoute(RoutingInstance *rtinst, const Ip4Prefix &static_route, const vector &rtargets, IpAddress nexthop) : routing_instance_(rtinst), static_route_prefix_(static_route), - nexthop_(nexthop), unregistered_(false) { + nexthop_(nexthop), nexthop_route_(NULL), unregistered_(false) { for (vector::const_iterator it = rtargets.begin(); it != rtargets.end(); it++) { error_code ec; diff --git a/src/bgp/test/static_route_test.cc b/src/bgp/test/static_route_test.cc index b51affe5942..8b4457dc5aa 100644 --- a/src/bgp/test/static_route_test.cc +++ b/src/bgp/test/static_route_test.cc @@ -1338,6 +1338,80 @@ TEST_F(StaticRouteTest, EntryAfterStop) { "Wait for Static route in blue.."); } +// Sandesh introspect test +// Verify http introspect output +// 1. After creating the config and before nexthop route is published +// 2. After creating the config and after nexthop route is published +// 3. After updating the config(nexthop) and before new nexthop route is published +// 4. After updating the config(nexthop) and after new nexthop route is published +TEST_F(StaticRouteTest, SandeshTest) { + vector instance_names = list_of("blue")("nat")("red")("green"); + multimap connections; + NetworkConfig(instance_names, connections); + task_util::WaitForIdle(); + + std::auto_ptr params = + GetStaticRouteConfig("controller/src/bgp/testdata/static_route_1.xml"); + + ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "routing-instance", + "nat", "static-route-entries", params.release(), 0); + task_util::WaitForIdle(); + + // Check for Static route + TASK_UTIL_WAIT_EQ_NO_MSG(InetRouteLookup("blue", "192.168.1.0/24"), + NULL, 1000, 10000, + "Wait for Static route in blue.."); + + VerifyStaticRouteSandesh("nat"); + + // Add Nexthop Route + AddInetRoute(NULL, "nat", "192.168.1.254/32", 100, "2.3.4.5"); + task_util::WaitForIdle(); + + // Check for Static route + TASK_UTIL_WAIT_NE_NO_MSG(InetRouteLookup("nat", "192.168.1.0/24"), + NULL, 1000, 10000, + "Wait for Static route in nat instance.."); + + // Check for Static route + TASK_UTIL_WAIT_NE_NO_MSG(InetRouteLookup("blue", "192.168.1.0/24"), + NULL, 1000, 10000, + "Wait for Static route in blue.."); + + VerifyStaticRouteSandesh("nat"); + // Delete nexthop route + DeleteInetRoute(NULL, "nat", "192.168.1.254/32"); + task_util::WaitForIdle(); + + + params = GetStaticRouteConfig("controller/src/bgp/testdata/static_route_4.xml"); + + ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "routing-instance", + "nat", "static-route-entries", params.release(), 0); + task_util::WaitForIdle(); + + // Check for Static route + TASK_UTIL_WAIT_EQ_NO_MSG(InetRouteLookup("blue", "192.168.1.0/24"), + NULL, 1000, 10000, + "Wait for Static route in blue.."); + + VerifyStaticRouteSandesh("nat"); + + // Add Nexthop Route + AddInetRoute(NULL, "nat", "192.168.1.1/32", 100, "5.4.3.2"); + task_util::WaitForIdle(); + + // Check for Static route + TASK_UTIL_WAIT_NE_NO_MSG(InetRouteLookup("blue", "192.168.1.0/24"), + NULL, 1000, 10000, + "Wait for Static route in blue.."); + + VerifyStaticRouteSandesh("nat"); + // Delete nexthop route + DeleteInetRoute(NULL, "nat", "192.168.1.1/32"); + task_util::WaitForIdle(); +} + class TestEnvironment : public ::testing::Environment { virtual ~TestEnvironment() { } };