Skip to content

Commit

Permalink
Merge "Support Link local service running on loopback address." into …
Browse files Browse the repository at this point in the history
…R2.20
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jul 31, 2015
2 parents cc7e7b2 + 1d03508 commit 4d0a49f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/vnsw/agent/oper/global_vrouter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <oper/global_vrouter.h>

const std::string GlobalVrouter::kMetadataService = "metadata";
const Ip4Address GlobalVrouter::kLoopBackIp = Ip4Address(0x7f000001);

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -113,6 +114,9 @@ class GlobalVrouter::FabricDnsResolver {
if (it != address_map_.end() && it->second.size()) {
int index = rand() % it->second.size();
*address = it->second[index];
if (*address == kLoopBackIp) {
*address = global_vrouter_->oper_db()->agent()->router_id();
}
return true;
}
return false;
Expand Down Expand Up @@ -455,6 +459,9 @@ bool GlobalVrouter::FindLinkLocalService(const std::string &service_name,
// if there are multiple addresses, return one of them
int index = rand() % it->second.ipfabric_service_ip.size();
*fabric_ip = it->second.ipfabric_service_ip[index];
if (*fabric_ip == kLoopBackIp) {
*fabric_ip = oper_->agent()->router_id();
}
return true;
} else if (!it->second.ipfabric_dns_service_name.empty()) {
return fabric_dns_resolver_->Resolve(
Expand Down Expand Up @@ -508,6 +515,9 @@ bool GlobalVrouter::FindLinkLocalService(const Ip4Address &service_ip,
if (it->second.ipfabric_service_ip.size()) {
int index = rand() % it->second.ipfabric_service_ip.size();
*fabric_ip = it->second.ipfabric_service_ip[index];
if (*fabric_ip == kLoopBackIp) {
*fabric_ip = oper_->agent()->router_id();
}
return true;
} else if (!it->second.ipfabric_dns_service_name.empty()) {
return fabric_dns_resolver_->Resolve(
Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/oper/global_vrouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct LinkLocalDBState : DBState {
class GlobalVrouter {
public:
static const std::string kMetadataService;
static const Ip4Address kLoopBackIp;

struct LinkLocalServiceKey {
Ip4Address linklocal_service_ip;
Expand Down Expand Up @@ -85,6 +86,7 @@ class GlobalVrouter {
bool IsLinkLocalAddressInUse(const Ip4Address &ip) const;

uint64_t PendingFabricDnsRequests() const;

private:
class FabricDnsResolver;
class LinkLocalRouteManager;
Expand Down
45 changes: 45 additions & 0 deletions src/vnsw/agent/pkt/test/test_pkt_flow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,51 @@ TEST_F(FlowTest, LinkLocalFlow_1) {
client->WaitForIdle();
}

// Linklocal flow with fabric-ip as loopback IP
TEST_F(FlowTest, LinkLocalFlow_loopback_1) {
Ip4Address rid = Ip4Address::from_string(vhost_ip_addr);
Agent::GetInstance()->set_router_id(rid);
Agent::GetInstance()->set_compute_node_ip(rid);
std::string mdata_ip = flow0->mdata_ip_addr().to_string();
std::string fabric_ip("127.0.0.1");
std::vector<std::string> fabric_ip_list;
fabric_ip_list.push_back(fabric_ip);
TestLinkLocalService service = { "test_service", linklocal_ip, linklocal_port,
"", fabric_ip_list, fabric_port };
AddLinkLocalConfig(&service, 1);
client->WaitForIdle();

TestFlow nat_flow[] = {
{
TestFlowPkt(Address::INET, vm1_ip, linklocal_ip, IPPROTO_TCP, 3000,
linklocal_port, "vrf5", flow0->id(), 1),
{
new VerifyNat(vhost_ip_addr, mdata_ip, IPPROTO_TCP, fabric_port,
3000)
}
}
};

CreateFlow(nat_flow, 1);
client->WaitForIdle();
EXPECT_EQ(2U, Agent::GetInstance()->pkt()->flow_table()->Size());

EXPECT_TRUE(FlowGet(0, vhost_ip_addr, mdata_ip.c_str(), IPPROTO_TCP,
fabric_port, 3000,
vhost->flow_key_nh()->id()));
EXPECT_TRUE(FlowGet(VrfGet("vrf5")->vrf_id(), vm1_ip, linklocal_ip,
IPPROTO_TCP, 3000, linklocal_port,
GetFlowKeyNH(input[0].intf_id)));

//Delete forward flow and expect both flows to be deleted
DeleteFlow(nat_flow, 1);
client->WaitForIdle();
EXPECT_TRUE(FlowTableWait(0));

DelLinkLocalConfig();
client->WaitForIdle();
}

TEST_F(FlowTest, LinkLocalFlow_Fail1) {
Agent::GetInstance()->set_router_id(Ip4Address::from_string(vhost_ip_addr));
std::string fabric_ip("1.2.3.4");
Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/services/test/metadata_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class MetadataTest : public ::testing::Test {
done_(0), itf_count_(0), data_size_(0) {
rid_ = Agent::GetInstance()->interface_table()->Register(
boost::bind(&MetadataTest::ItfUpdate, this, _2));
Agent::GetInstance()->set_router_id(Ip4Address::from_string("127.0.0.1"));
Agent::GetInstance()->set_compute_node_ip(Ip4Address::from_string("127.0.0.1"));
}

~MetadataTest() {
Expand Down

0 comments on commit 4d0a49f

Please sign in to comment.