From 3ccd103208ab52f7689aae2a658d06d60cce74a9 Mon Sep 17 00:00:00 2001 From: Nischal Sheth Date: Mon, 8 Feb 2016 12:25:17 -0800 Subject: [PATCH] Trigger pending chain resolution on routing instance change (and add) Recent change to treat a service chain as pending if the dest routing instance doesn't have a VN index causes problems if the instance does not have an index when it's created. Also fix issue in service_chain_test that causes occasional failures. Check if DBEnry returned by DBTable::Find is NULL before dynamic_cast. Change-Id: I971443345699a7909e5247967916ddff0818f78a Related-bug: 1500698 --- src/bgp/routing-instance/service_chaining.cc | 3 ++- src/bgp/test/service_chain_test.cc | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bgp/routing-instance/service_chaining.cc b/src/bgp/routing-instance/service_chaining.cc index 0d525b6def7..09c4b5952a3 100644 --- a/src/bgp/routing-instance/service_chaining.cc +++ b/src/bgp/routing-instance/service_chaining.cc @@ -1096,7 +1096,8 @@ bool ServiceChainMgr::ResolvePendingServiceChain() { template void ServiceChainMgr::RoutingInstanceCallback(string name, int op) { - if (op == RoutingInstanceMgr::INSTANCE_ADD) StartResolve(); + if (op != RoutingInstanceMgr::INSTANCE_DELETE) + StartResolve(); } template diff --git a/src/bgp/test/service_chain_test.cc b/src/bgp/test/service_chain_test.cc index f007966f8fb..9473871398b 100644 --- a/src/bgp/test/service_chain_test.cc +++ b/src/bgp/test/service_chain_test.cc @@ -600,8 +600,7 @@ class ServiceChainTest : public ::testing::Test { return table->Size(); } - BgpRoute *RouteLookup(const string &instance_name, - const string &prefix) { + BgpRoute *RouteLookup(const string &instance_name, const string &prefix) { BgpTable *bgp_table = GetTable(instance_name); TableT *table = dynamic_cast(bgp_table); EXPECT_TRUE(table != NULL); @@ -612,12 +611,14 @@ class ServiceChainTest : public ::testing::Test { PrefixT nlri = PrefixT::FromString(prefix, &error); EXPECT_FALSE(error); typename TableT::RequestKey key(nlri, NULL); - BgpRoute *rt = dynamic_cast(table->Find(&key)); - return rt; + DBEntry *db_entry = table->Find(&key); + if (db_entry == NULL) { + return NULL; + } + return dynamic_cast(db_entry); } - BgpRoute *VerifyRouteExists(const string &instance, - const string &prefix) { + BgpRoute *VerifyRouteExists(const string &instance, const string &prefix) { TASK_UTIL_EXPECT_TRUE(RouteLookup(instance, prefix) != NULL); BgpRoute *rt = RouteLookup(instance, prefix); if (rt == NULL) { @@ -627,13 +628,11 @@ class ServiceChainTest : public ::testing::Test { return rt; } - void VerifyRouteNoExists(const string &instance, - const string &prefix) { + void VerifyRouteNoExists(const string &instance, const string &prefix) { TASK_UTIL_EXPECT_TRUE(RouteLookup(instance, prefix) == NULL); } - void VerifyRouteIsDeleted(const string &instance, - const string &prefix) { + void VerifyRouteIsDeleted(const string &instance, const string &prefix) { TASK_UTIL_EXPECT_TRUE(RouteLookup(instance, prefix) != NULL); BgpRoute *rt = RouteLookup(instance, prefix); TASK_UTIL_EXPECT_TRUE(rt->IsDeleted());