From 1550065bd7227349be93132889951fb2481daf03 Mon Sep 17 00:00:00 2001 From: Naveen N Date: Tue, 19 May 2015 18:31:50 +0530 Subject: [PATCH] Set static preference field only if local preference field is initialized In case of service instance, VMI would have VMI_property field set, but the local preference value would not be assigned in such cases also agent was not running mastership algorithm for active path selection based on traffic.Set static preference only if local preference is greater than 0, such that if AAP address is assigned to service interface it works fine. Test case for same. Closes-bug:#1435689 Change-Id: If642ae574306cc6339ef03cb6783acb720092ac7 --- src/vnsw/agent/oper/test/test_aap.cc | 18 ++++++++++++++++++ src/vnsw/agent/oper/vm_interface.cc | 12 +++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/vnsw/agent/oper/test/test_aap.cc b/src/vnsw/agent/oper/test/test_aap.cc index f621370b883..ec7f80c9792 100644 --- a/src/vnsw/agent/oper/test/test_aap.cc +++ b/src/vnsw/agent/oper/test/test_aap.cc @@ -528,6 +528,24 @@ TEST_F(TestAap, StaticMachine_11) { EXPECT_TRUE(path->path_preference().static_preference() == false); } +//Verify that static preference is not populated +//when preference value is set to 0 +TEST_F(TestAap, StateMachine_12) { + AddStaticPreference("intf1", 1, 0); + Ip4Address ip = Ip4Address::from_string("1.1.1.1"); + EXPECT_TRUE(RouteFind("vrf1", ip, 32)); + + InetUnicastRouteEntry *rt = + RouteGet("vrf1", ip, 32); + const AgentPath *path = rt->GetActivePath(); + EXPECT_TRUE(path->path_preference().sequence() == 0); + EXPECT_TRUE(path->path_preference().preference() == PathPreference::LOW); + EXPECT_TRUE(path->path_preference().ecmp() == false); + EXPECT_TRUE(path->path_preference().wait_for_traffic() == true); + EXPECT_TRUE(path->path_preference().static_preference() == false); +} + + int main(int argc, char *argv[]) { GETUSERARGS(); client = TestInit(init_file, ksync_init); diff --git a/src/vnsw/agent/oper/vm_interface.cc b/src/vnsw/agent/oper/vm_interface.cc index 9b35c571b04..18dbf008509 100644 --- a/src/vnsw/agent/oper/vm_interface.cc +++ b/src/vnsw/agent/oper/vm_interface.cc @@ -634,9 +634,15 @@ static void BuildAttributes(Agent *agent, IFMapNode *node, //Extract the local preference if (cfg->IsPropertySet(VirtualMachineInterface::PROPERTIES)) { autogen::VirtualMachineInterfacePropertiesType prop = cfg->properties(); - data->local_preference_ = VmInterface::LOW; - if (prop.local_preference == VmInterface::HIGH) { - data->local_preference_ = VmInterface::HIGH; + //Service instance also would have VirtualMachineInterface + //properties field set, pick up local preference + //value only when it has been initialized to proper + //value, if its 0, ignore the local preference + if (prop.local_preference) { + data->local_preference_ = VmInterface::LOW; + if (prop.local_preference == VmInterface::HIGH) { + data->local_preference_ = VmInterface::HIGH; + } } }