Skip to content

Commit

Permalink
Merge "* Set service vlan IP ecmp mode and tracking ip based on servi…
Browse files Browse the repository at this point in the history
…ce IP"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jun 3, 2016
2 parents 9f25523 + 18f6501 commit d09b6b5
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/vnsw/agent/oper/agent.sandesh
Expand Up @@ -339,6 +339,7 @@ struct PathPreferenceSandeshData {
2: i32 preference;
3: bool ecmp;
4: bool wait_for_traffic;
5: optional string dependent_ip;
}

/**
Expand Down Expand Up @@ -1019,6 +1020,7 @@ traceobject sandesh PathPreferenceTrace {
4: i32 sequence;
5: string state;
6: i32 retry_timeout;
7: string dependent_ip;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/vnsw/agent/oper/agent_path.cc
Expand Up @@ -960,6 +960,7 @@ bool PathPreferenceData::AddChangePath(Agent *agent, AgentPath *path,
}

path_preference_.set_ecmp(path->path_preference().ecmp());
path_preference_.set_dependent_ip(path->path_preference().dependent_ip());
if (path &&
path->path_preference() != path_preference_) {
path->set_path_preference(path_preference_);
Expand Down Expand Up @@ -1219,6 +1220,10 @@ void AgentPath::SetSandeshData(PathSandeshData &pdata) const {
path_preference_data.set_ecmp(path_preference_.ecmp());
path_preference_data.set_wait_for_traffic(
path_preference_.wait_for_traffic());
if (path_preference_.dependent_ip().is_unspecified() == false) {
path_preference_data.set_dependent_ip(
path_preference_.dependent_ip().to_string());
}
pdata.set_path_preference_data(path_preference_data);
pdata.set_active_label(GetActiveLabel());
if (peer()->GetType() == Peer::MAC_VM_BINDING_PEER) {
Expand Down
10 changes: 9 additions & 1 deletion src/vnsw/agent/oper/path_preference.cc
Expand Up @@ -416,8 +416,14 @@ void PathPreferenceSM::Process() {
}

void PathPreferenceSM::Log(std::string state) {
std::string dependent_ip_str = "";
if (is_dependent_rt()) {
dependent_ip_str = dependent_ip().to_string();
}

PATH_PREFERENCE_TRACE(rt_->vrf()->GetName(), rt_->GetAddressString(),
preference(), sequence(), state, timeout());
preference(), sequence(), state, timeout(),
dependent_ip_str);
}

void PathPreferenceSM::EnqueuePathChange() {
Expand Down Expand Up @@ -767,6 +773,8 @@ void PathPreferenceState::Process() {
path_preference_sm->set_dependent_rt(NULL);
}
path_preference_sm->set_is_dependent_rt(dependent_rt);
path_preference_sm->set_dependent_ip(
path->path_preference().dependent_ip());

path_preference_sm->set_seen(true);
path_preference_sm->Process();
Expand Down
8 changes: 8 additions & 0 deletions src/vnsw/agent/oper/path_preference.h
Expand Up @@ -88,6 +88,14 @@ class PathPreferenceSM:
is_dependent_rt_ = dependent_path;
}

void set_dependent_ip(const IpAddress &ip) {
path_preference_.set_dependent_ip(ip);
}

IpAddress dependent_ip() {
return path_preference_.dependent_ip();
}

bool seen() { return seen_; }
uint32_t max_sequence() const { return max_sequence_;}
void Process();
Expand Down
56 changes: 55 additions & 1 deletion src/vnsw/agent/oper/test/test_aap.cc
Expand Up @@ -46,7 +46,7 @@ void RouterIdDepInit(Agent *agent) {
}

struct PortInfo input[] = {
{"intf1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
{"intf1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1, "fd10::2"},
};

class TestAap : public ::testing::Test {
Expand Down Expand Up @@ -1133,6 +1133,60 @@ TEST_F(TestAap, StateMachine_19) {
client->WaitForIdle();
}

TEST_F(TestAap, StateMachine_20) {
Ip4Address ip = Ip4Address::from_string("1.1.1.1");

AddVmPortVrf("ser1", "11.1.1.253", 1);
AddLink("virtual-machine-interface-routing-instance", "ser1",
"routing-instance", "vrf1");
AddLink("virtual-machine-interface-routing-instance", "ser1",
"virtual-machine-interface", "intf1");
client->WaitForIdle();

Ip4Address service_vlan_rt = Ip4Address::from_string("11.1.1.253");
VmInterface *vm_intf = VmInterfaceGet(1);
InetUnicastRouteEntry *rt =
RouteGet("vrf1", service_vlan_rt, 32);
const AgentPath *path = rt->FindPath(vm_intf->peer());
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);

Agent::GetInstance()->oper_db()->route_preference_module()->
EnqueueTrafficSeen(ip, 32, vm_intf->id(), vm_intf->vrf()->vrf_id(),
MacAddress::FromString(vm_intf->vm_mac()));
client->WaitForIdle();
EXPECT_TRUE(path->path_preference().sequence() == 0);
EXPECT_TRUE(path->path_preference().preference() == PathPreference::HIGH);
EXPECT_TRUE(path->path_preference().ecmp() == false);
EXPECT_TRUE(path->path_preference().wait_for_traffic() == false);

AddServiceInstanceIp("instaneip100", 100, "2.2.2.2", false);
AddLink("virtual-machine-interface", "intf1", "instance-ip", "instaneip100");
client->WaitForIdle();
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);

AddServiceInstanceIp("instaneip100", 100, "2.2.2.2", true);
client->WaitForIdle();
EXPECT_TRUE(path->path_preference().sequence() == 0);
EXPECT_TRUE(path->path_preference().preference() == PathPreference::HIGH);
EXPECT_TRUE(path->path_preference().ecmp() == true);
EXPECT_TRUE(path->path_preference().wait_for_traffic() == false);

Ip6Address ip6 = Ip6Address::from_string("ffd2::11");
Agent::GetInstance()->oper_db()->route_preference_module()->
EnqueueTrafficSeen(ip6, 128, vm_intf->id(), vm_intf->vrf()->vrf_id(),
MacAddress::FromString(vm_intf->vm_mac()));
client->WaitForIdle();
EXPECT_TRUE(path->path_preference().sequence() == 0);
EXPECT_TRUE(path->path_preference().preference() == PathPreference::HIGH);
EXPECT_TRUE(path->path_preference().ecmp() == true);
EXPECT_TRUE(path->path_preference().wait_for_traffic() == false);
}

int main(int argc, char *argv[]) {
GETUSERARGS();
Expand Down
93 changes: 93 additions & 0 deletions src/vnsw/agent/oper/test/test_intf.cc
Expand Up @@ -1717,6 +1717,11 @@ TEST_F(IntfTest, VmPortServiceVlanDelete_1) {
Ip4Address service_ip = Ip4Address::from_string("2.2.2.100");
EXPECT_TRUE(RouteFind("vrf2", service_ip, 32));
EXPECT_TRUE(VmPortServiceVlanCount(1, 1));
InetUnicastRouteEntry *rt = RouteGet("vrf2", service_ip, 32);
if (rt) {
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));
}
DoInterfaceSandesh("");
client->WaitForIdle();

Expand Down Expand Up @@ -1771,6 +1776,12 @@ TEST_F(IntfTest, VmPortServiceVlanDelete_2) {
Ip4Address service_ip = Ip4Address::from_string("2.2.2.100");
EXPECT_TRUE(RouteFind("vrf2", service_ip, 32));
EXPECT_TRUE(VmPortServiceVlanCount(1, 1));
InetUnicastRouteEntry *rt = RouteGet("vrf2", service_ip, 32);
if (rt) {
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));
}

DoInterfaceSandesh("");
client->WaitForIdle();

Expand Down Expand Up @@ -1811,6 +1822,13 @@ TEST_F(IntfTest, VmPortServiceVlanDelete_2) {
client->WaitForIdle();
EXPECT_TRUE(RouteFind("vrf2", service_ip, 32));
EXPECT_TRUE(VmPortServiceVlanCount(1, 1));

rt = RouteGet("vrf2", service_ip, 32);
if (rt) {
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));
}

DoInterfaceSandesh("");
client->WaitForIdle();

Expand Down Expand Up @@ -1867,6 +1885,11 @@ TEST_F(IntfTest, VmPortServiceVlanAdd_1) {
EXPECT_TRUE(VmPortActive(input, 0));
service_ip = Ip4Address::from_string("2.2.2.100");
EXPECT_TRUE(RouteFind("vrf2", service_ip, 32));
InetUnicastRouteEntry *rt = RouteGet("vrf2", service_ip, 32);
if (rt) {
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));
}

//Delete config for vnet1, forcing interface to deactivate
//verify that route and service vlan map gets cleaned up
Expand Down Expand Up @@ -1913,6 +1936,11 @@ TEST_F(IntfTest, VmPortServiceVlanAdd_2) {
client->WaitForIdle();
Ip4Address service_ip = Ip4Address::from_string("2.2.2.100");
EXPECT_TRUE(RouteFind("vrf2", service_ip, 32));
InetUnicastRouteEntry *rt = RouteGet("vrf2", service_ip, 32);
if (rt) {
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));
}

//Delete the interface, all service vlan routes should be deleted
//and interface should be released
Expand Down Expand Up @@ -2081,6 +2109,71 @@ TEST_F(IntfTest, VmPortServiceVlanVrfDelete_1) {
EXPECT_FALSE(VrfFind("vrf2"));
}

TEST_F(IntfTest, VmPortServiceVlanServiceIp_1) {
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.10", "00:00:00:01:01:01", 1, 1},
};

client->Reset();
CreateVmportEnv(input, 1);
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(input, 0));
Ip4Address service_ip = Ip4Address::from_string("2.2.2.100");

AddVn("vn2", 2);
AddVrf("vrf2", 2);
AddLink("virtual-network", "vn2", "routing-instance", "vrf2");
//Add service vlan for vnet1
client->WaitForIdle();
AddVmPortVrf("vmvrf1", "2.2.2.100", 10);
AddLink("virtual-machine-interface-routing-instance", "vmvrf1",
"routing-instance", "vrf2");
AddLink("virtual-machine-interface-routing-instance", "vmvrf1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();

InetUnicastRouteEntry *rt = RouteGet("vrf2", service_ip, 32);
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));

AddServiceInstanceIp("serviceip1", 100, "1.1.1.100", false);
AddLink("virtual-machine-interface", "vnet1", "instance-ip", "serviceip1");
client->WaitForIdle();

EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.100"));
EXPECT_TRUE(rt->GetActivePath()->path_preference().ecmp() == false);

AddServiceInstanceIp("serviceip1", 100, "1.1.1.100", true);
client->WaitForIdle();
EXPECT_TRUE(rt->GetActivePath()->path_preference().ecmp() == true);

DelLink("virtual-machine-interface", "vnet1", "instance-ip", "serviceip1");
client->WaitForIdle();
EXPECT_TRUE(rt->GetActivePath()->path_preference().dependent_ip() ==
Ip4Address::from_string("1.1.1.10"));
EXPECT_TRUE(rt->GetActivePath()->path_preference().ecmp() == false);

DelNode("instance-ip", "serviceip1");
//Clean up
DelLink("virtual-machine-interface-routing-instance", "vmvrf1",
"routing-instance", "vrf2");
DelLink("virtual-machine-interface-routing-instance", "vmvrf1",
"virtual-machine-interface", "vnet1");
DelLink("virtual-network", "vn2", "routing-instance", "vrf2");
DelLink("virtual-network", "vn1", "virtual-machine-interface",
input[0].name);
DelVmPortVrf("vmvrf1");
DelVrf("vrf2");
DelVn("vn2");
client->WaitForIdle();
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
EXPECT_FALSE(VrfFind("vrf1"));
EXPECT_FALSE(VrfFind("vrf2"));
}


//Add and delete static route
TEST_F(IntfTest, IntfStaticRoute) {
struct PortInfo input[] = {
Expand Down

0 comments on commit d09b6b5

Please sign in to comment.