Skip to content

Commit

Permalink
Merge "Update Path of static-route with correct label on VMI’s label …
Browse files Browse the repository at this point in the history
…change." into R3.1
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jul 22, 2016
2 parents df2ebb6 + 3a0c933 commit 44d1f55
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/vnsw/agent/oper/inet_unicast_route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ bool InetUnicastRouteEntry::UpdateComponentNH(Agent *agent,
}
//Build ComponentNHKey for new path
DBEntryBase::KeyPtr key = path->ComputeNextHop(agent)->GetDBRequestKey();
NextHopKey *nh_key = static_cast<NextHopKey *>(key.release());
NextHopKey *nh_key = static_cast<NextHopKey *>(key.get());
nh_key->SetPolicy(false);

ComponentNHKeyList component_nh_key_list;
Expand Down
95 changes: 78 additions & 17 deletions src/vnsw/agent/oper/test/test_intf_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#define vm1_ip "11.1.1.1"
#define vm2_ip "11.1.1.2"

IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.10"},
};

void RouterIdDepInit(Agent *agent) {
}

Expand Down Expand Up @@ -187,15 +183,6 @@ class PolicyTest : public ::testing::Test {
flow_proto_ = agent_->pkt()->get_flow_proto();
}

void SetUp() {
AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
}
void TearDown() {
WAIT_FOR(1000, 1000, agent_->vrf_table()->Size() == 1);
DelIPAM("vn1");
client->WaitForIdle();
}
void SetPolicyDisabledStatus(struct PortInfo *input, bool status) {
ostringstream str;

Expand Down Expand Up @@ -694,13 +681,22 @@ TEST_F(PolicyTest, IntfPolicyDisable_Flow) {
EXPECT_EQ(0U, flow_proto_->FlowCount());
}

//When policy is enabled/disabled on VMI, label of VMI changes. When a VMI is
//part of ECMP and its policy-status is changed, verify that the label of the
//VMI in CompositeNH is updated correctly.
TEST_F(PolicyTest, EcmpNH_1) {
//Create mutliple VM interface with same IP
struct PortInfo input1[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
{"vnet2", 2, "1.1.1.1", "00:00:00:02:02:01", 1, 2},
{"vnet2", 2, "1.1.1.1", "00:00:00:02:02:01", 1, 2}
};

IpamInfo ipam_info[] = {
{"1.1.1.0", 24, "1.1.1.10"},
};

AddIPAM("vn1", ipam_info, 1);
client->WaitForIdle();
CreateVmportWithEcmp(input1, 2, 1);
client->WaitForIdle();

Expand Down Expand Up @@ -742,7 +738,7 @@ TEST_F(PolicyTest, EcmpNH_1) {
SetPolicyDisabledStatus(&input1[0], true);
client->WaitForIdle();

//Verify that policy status of interfaces
//Verify that policy status of interface
WAIT_FOR(100, 1000, ((VmPortPolicyEnabled(input1, 0)) == false));

//Verify that vnet1's label has changed after disabling policy on it.
Expand All @@ -756,16 +752,81 @@ TEST_F(PolicyTest, EcmpNH_1) {
EXPECT_TRUE(label1 != comp_nh->Get(0)->label());
EXPECT_TRUE(comp_nh->Get(0)->label() == intf1->label());


DeleteVmportEnv(input1, 2, true, 1);
DeleteVmportEnv(input1, 2, 1, 1, NULL, NULL, true, false);
client->WaitForIdle();

DelIPAM("vn1");
client->WaitForIdle(3);

WAIT_FOR(100, 1000, (VrfFind("vrf1") == false));
EXPECT_FALSE(RouteFind("vrf1", ip, 32));

//Expect MPLS label to be not present
EXPECT_FALSE(FindMplsLabel(MplsLabel::VPORT_NH, mpls_label));
}

//When policy is enabled/disabled on VMI, label of VMI changes. When a VMI
//has static_route associated with it and its policy-status changes verify that
//the label of the static-route's path is updated accordingly.
TEST_F(PolicyTest, IntfStaticRoute) {
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.10", "00:00:00:01:01:01", 1, 1}
};

client->Reset();
CreateVmportEnv(input, 1, 1);
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(input, 0));
const VmInterface *intf1 = VmInterfaceGet(input[0].intf_id);
EXPECT_TRUE(intf1 != NULL);

//Add a static route
struct TestIp4Prefix static_route[] = {
{ Ip4Address::from_string("2.1.1.10"), 32}
};

AddInterfaceRouteTable("static_route", 1, static_route, 1);
AddLink("virtual-machine-interface", "vnet1",
"interface-route-table", "static_route");
client->WaitForIdle();

InetUnicastRouteEntry *rt = RouteGet("vrf1", static_route[0].addr_,
static_route[0].plen_);
EXPECT_TRUE(rt != NULL);
const AgentPath *path = rt->GetActivePath();
EXPECT_TRUE(path != NULL);
EXPECT_TRUE(path->label() == intf1->label());
uint32_t vmi_label = intf1->label();

WAIT_FOR(100, 1000, ((VmPortPolicyEnabled(input, 0)) == true));

//Disable policy on vnet1 VMI
SetPolicyDisabledStatus(&input[0], true);
client->WaitForIdle();

//Verify that policy status of interface
WAIT_FOR(100, 1000, ((VmPortPolicyEnabled(input, 0)) == false));

//Verify that vnet1's label has changed after disabling policy on it.
EXPECT_TRUE(vmi_label != intf1->label());

//Verify that label of static_route's path is updated with new label of VMI
EXPECT_TRUE(path->label() == intf1->label());

//Delete the link between interface and route table
DelLink("virtual-machine-interface", "vnet1",
"interface-route-table", "static_route");
client->WaitForIdle();
EXPECT_FALSE(RouteFind("vrf1", static_route[0].addr_,
static_route[0].plen_));

DelNode("interface-route-table", "static_route");
client->WaitForIdle();
DeleteVmportEnv(input, 1, true, 1);
client->WaitForIdle();
WAIT_FOR(100, 1000, (VrfFind("vrf1") == false));
}

int main(int argc, char **argv) {
GETUSERARGS();

Expand Down
5 changes: 1 addition & 4 deletions src/vnsw/agent/oper/vm_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4484,10 +4484,7 @@ void VmInterface::StaticRoute::Activate(VmInterface *interface,
vrf_ = interface->vrf()->GetName();
}

if (installed_ == true && policy_change) {
InetUnicastAgentRouteTable::ReEvaluatePaths(interface->agent(),
vrf_, addr_, plen_);
} else if (installed_ == false || force_update) {
if (installed_ == false || force_update || policy_change) {
Ip4Address gw_ip(0);
if (gw_.is_v4() && addr_.is_v4() && gw_.to_v4() != gw_ip) {
SecurityGroupList sg_id_list;
Expand Down

0 comments on commit 44d1f55

Please sign in to comment.