Skip to content

Commit

Permalink
Use default ri/vrf for fip processing by looking at is_default proper…
Browse files Browse the repository at this point in the history
…ty of ri.

Add UT for same .

Change-Id: I443916b9c3ff31d21b818d1ec1c8686b4f3736ae
Closes-Bug: #1380750
  • Loading branch information
krharsh committed Aug 20, 2015
1 parent 4093db7 commit 5b1e9ca
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/vnsw/agent/oper/vm_interface.cc
Expand Up @@ -35,6 +35,7 @@
#include <oper/inet_unicast_route.h>
#include <oper/physical_device_vn.h>

#include <bgp_schema_types.h>
#include <vnc_cfg_types.h>
#include <oper/agent_sandesh.h>
#include <oper/sg.h>
Expand Down Expand Up @@ -213,12 +214,8 @@ static void BuildFloatingIpList(Agent *agent, VmInterfaceConfigData *data,
continue;
}
// Checking whether it is default vrf of not
size_t found = vn_node->name().find_last_of(':');
std::string vrf_name = "";
if (found != string::npos) {
vrf_name = vn_node->name() + vn_node->name().substr(found);
}
if (vrf_node->name().compare(vrf_name) != 0) {
RoutingInstance *ri = static_cast<RoutingInstance *>(vrf_node->GetObject());
if(!(ri->is_default())) {
continue;
}
FloatingIp *fip = static_cast<FloatingIp *>(node->GetObject());
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/test/test_cmn_util.h
Expand Up @@ -209,7 +209,7 @@ void AsioRun();
void AsioStop();
void AddVm(const char *name, int id);
void DelVm(const char *name);
void AddVrf(const char *name, int id = 0);
void AddVrf(const char *name, int id = 0, bool default_ri = true);
void DelVrf(const char *name);
void ModifyForwardingModeVn(const string &name, int id, const string &fw_mode);
void AddL2L3Vn(const char *name, int id);
Expand Down
71 changes: 71 additions & 0 deletions src/vnsw/agent/test/test_fip_cfg.cc
Expand Up @@ -282,6 +282,77 @@ TEST_F(CfgTest, FloatingIp_1) {
EXPECT_FALSE(VmFind(1));
}

TEST_F(CfgTest, FloatingIpDefaultVrf) {
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
};

CreateVmportEnv(input, 1);
client->WaitForIdle();

AddVn("default-project:vn2", 2);
client->WaitForIdle();

AddVrf("default-project:vn2:vn2");
AddLink("virtual-network", "default-project:vn2", "routing-instance", "default-project:vn2:vn2");
AddVrf("vrf2", 0, false);
client->WaitForIdle();

AddLink("virtual-network", "default-project:vn2", "routing-instance", "vrf2");
client->WaitForIdle();

// Create floating-ip on vn2
AddFloatingIpPool("fip-pool1", 1);
AddFloatingIp("fip1", 1, "2.2.2.100");
AddLink("floating-ip-pool", "fip-pool1", "virtual-network",
"default-project:vn2");
AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
AddLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1");
client->WaitForIdle();
client->Reset();

EXPECT_TRUE(VmPortActive(input, 0));
EXPECT_TRUE(VmPortFloatingIpCount(1, 1));
EXPECT_TRUE(RouteFind("vrf1", Ip4Address::from_string("1.1.1.1"), 32));
EXPECT_TRUE(RouteFind("default-project:vn2:vn2",
Ip4Address::from_string("2.2.2.100"), 32));
EXPECT_FALSE(RouteFind("vrf2",
Ip4Address::from_string("2.2.2.100"), 32));

// Cleanup
LOG(DEBUG, "Doing cleanup");

// Delete links
DelLink("virtual-machine-interface", "vnet1", "floating-ip", "fip1");
DelLink("floating-ip-pool", "fip-pool1", "virtual-network",
"default-project:vn2:vn2");
DelLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
client->WaitForIdle();

EXPECT_FALSE(RouteFind("default-project:vn2:vn2",
Ip4Address::from_string("2.2.2.100"), 32));

DelFloatingIp("fip1");
DelFloatingIpPool("fip-pool1");

// Delete virtual-machine-interface to vrf link attribute
DelLink("virtual-network", "default-project:vn2", "routing-instance",
"default-project:vn2:vn2");
DelLink("virtual-network", "default-project:vn2", "routing-instance",
"vrf2");

client->WaitForIdle();

DelVn("default-project:vn2");
DelVrf("default-project:vn2:vn2");
DelVrf("vrf2");
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
EXPECT_FALSE(VrfFind("vrf2"));
EXPECT_FALSE(VrfFind("default-project:vn2:vn2"));
EXPECT_FALSE(VnFind(2));
}

// Create Nova intf first
// Intf config without FIP
// Add FIP later
Expand Down
12 changes: 10 additions & 2 deletions src/vnsw/agent/test/test_util.cc
Expand Up @@ -1540,8 +1540,16 @@ void DelVm(const char *name) {
DelNode("virtual-machine", name);
}

void AddVrf(const char *name, int id) {
AddNode("routing-instance", name, id);
void AddVrf(const char *name, int id, bool default_ri) {
std::stringstream str;
str << " <routing-instance-is-default>" << default_ri << "</routing-instance-is-default>" << endl;
char buff[10240];
int len = 0;
AddXmlHdr(buff, len);
AddNodeString(buff, len, "routing-instance", name, id, str.str().c_str());
AddXmlTail(buff, len);
ApplyXmlString(buff);
return;
}

void DelVrf(const char *name) {
Expand Down

0 comments on commit 5b1e9ca

Please sign in to comment.