Skip to content

Commit

Permalink
Use IANA codepoints for Tunnel Encapsulation types
Browse files Browse the repository at this point in the history
Highlights:

- No changes to vRouter agent code
- Changes are backward compatible with older vRouter agents and CNs
- Xmpp encapsulation string for udp translated to 2 communities
- Xmpp encapsulation string for vxlan translated to 2 communities
- IANA and pre-standard communites for udp translated to 1 xmpp string
- IANA and pre-standard communites for vxlan translated to 1 xmpp string

Change-Id: I5d64282f81409a0805c2f5d97818b5a7649636bd
Closes-Bug: 1373559
  • Loading branch information
Nischal Sheth committed Oct 21, 2014
1 parent 7f0a011 commit db5f612
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 85 deletions.
92 changes: 68 additions & 24 deletions src/bgp/bgp_xmpp_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,16 @@ void BgpXmppChannel::ProcessMcastItem(std::string vrf_name,
item.entry.next_hops.next_hop[0].tunnel_encapsulation_list.end();
it++) {
TunnelEncap tun_encap(*it);
if (tun_encap.tunnel_encap() != TunnelEncapType::UNSPEC) {
no_valid_tunnel_encap = false;
ext.communities.push_back(tun_encap.GetExtCommunityValue());
}
if (tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
no_valid_tunnel_encap = false;
ext.communities.push_back(tun_encap.GetExtCommunityValue());

string alt_encap_string = *it + "-contrail";
TunnelEncap alt_tun_encap(alt_encap_string);
if (alt_tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
ext.communities.push_back(alt_tun_encap.GetExtCommunityValue());
}

// If all of the tunnel encaps published by the agent is invalid,
Expand Down Expand Up @@ -1049,13 +1055,26 @@ void BgpXmppChannel::ProcessItem(string vrf_name,
item.entry.next_hops.next_hop[i].tunnel_encapsulation_list.end();
it++) {
TunnelEncap tun_encap(*it);
if (tun_encap.tunnel_encap() != TunnelEncapType::UNSPEC) {
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(tun_encap.GetExtCommunity());
if (tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(
tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
tun_encap.GetExtCommunity());

string alt_encap_string = *it + "-contrail";
TunnelEncap alt_tun_encap(alt_encap_string);
if (alt_tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
if (i == 0) {
ext.communities.push_back(
alt_tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
alt_tun_encap.GetExtCommunity());
}

// If all of the tunnel encaps published by the agent are
Expand Down Expand Up @@ -1289,15 +1308,26 @@ void BgpXmppChannel::ProcessInet6Item(string vrf_name,
tunnel_encapsulation_list.end();
++it) {
TunnelEncap tun_encap(*it);
if (tun_encap.tunnel_encap() != TunnelEncapType::UNSPEC) {
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(
tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
tun_encap.GetExtCommunity());
if (tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(
tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
tun_encap.GetExtCommunity());

string alt_encap_string = *it + "-contrail";
TunnelEncap alt_tun_encap(alt_encap_string);
if (alt_tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
if (i == 0) {
ext.communities.push_back(
alt_tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
alt_tun_encap.GetExtCommunity());
}

// If all of the tunnel encaps published by the agent are
Expand Down Expand Up @@ -1549,14 +1579,28 @@ void BgpXmppChannel::ProcessEnetItem(string vrf_name,
item.entry.next_hops.next_hop[i].tunnel_encapsulation_list.end();
it++) {
TunnelEncap tun_encap(*it);
if (tun_encap.tunnel_encap() != TunnelEncapType::UNSPEC) {
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(tun_encap.GetExtCommunity());
if (tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(
tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
tun_encap.GetExtCommunity());

string alt_encap_string = *it + "-contrail";
TunnelEncap alt_tun_encap(alt_encap_string);
if (alt_tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
if (i == 0) {
ext.communities.push_back(
alt_tun_encap.GetExtCommunityValue());
}
nexthop.tunnel_encapsulations_.push_back(
alt_tun_encap.GetExtCommunity());
}

//
// If all of the tunnel encaps published by the agent is invalid,
// mark the path as infeasible
Expand Down
8 changes: 5 additions & 3 deletions src/bgp/community.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ std::vector<std::string> ExtCommunity::GetTunnelEncap() const {
if (!ExtCommunity::is_tunnel_encap(*iter))
continue;
TunnelEncap encap(*iter);
TunnelEncapType::Encap id = encap.tunnel_encap();
if (id == TunnelEncapType::UNSPEC)
if (encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
encap_list.push_back(TunnelEncapType::TunnelEncapToString(id));
encap_list.push_back(encap.ToXmppString());
}

std::sort(encap_list.begin(), encap_list.end());
std::vector<std::string>::iterator encap_iter =
std::unique(encap_list.begin(), encap_list.end());
encap_list.erase(encap_iter, encap_list.end());
return encap_list;
}

Expand Down
67 changes: 64 additions & 3 deletions src/bgp/test/bgp_xmpp_inetvpn_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,35 @@ class BgpXmppInetvpn2ControlNodeTest : public ::testing::Test {
bs_y_->Configure(config);
}

bool CheckEncap(autogen::TunnelEncapsulationListType &rt_encap,
const string &encap) {
if (rt_encap.tunnel_encapsulation.size() != 1)
return false;
return (rt_encap.tunnel_encapsulation[0] == encap);
}

bool CheckRoute(test::NetworkAgentMockPtr agent, string net,
string prefix, string nexthop, int local_pref) {
string prefix, string nexthop, int local_pref, const string &encap) {
const autogen::ItemType *rt = agent->RouteLookup(net, prefix);
if (!rt)
return false;
if (rt->entry.next_hops.next_hop[0].address != nexthop)
return false;
if (rt->entry.local_preference != local_pref)
return false;

autogen::TunnelEncapsulationListType rt_encap =
rt->entry.next_hops.next_hop[0].tunnel_encapsulation_list;
if (!encap.empty() && !CheckEncap(rt_encap, encap))
return false;
return true;
}

void VerifyRouteExists(test::NetworkAgentMockPtr agent, string net,
string prefix, string nexthop, int local_pref) {
string prefix, string nexthop, int local_pref,
const string &encap = string()) {
TASK_UTIL_EXPECT_TRUE(
CheckRoute(agent, net, prefix, nexthop, local_pref));
CheckRoute(agent, net, prefix, nexthop, local_pref, encap));
}

void VerifyRouteNoExists(test::NetworkAgentMockPtr agent, string net,
Expand Down Expand Up @@ -316,6 +329,54 @@ TEST_F(BgpXmppInetvpn2ControlNodeTest, RouteFlap) {
agent_b_->SessionDown();
}

TEST_F(BgpXmppInetvpn2ControlNodeTest, TunnelEncap) {
Configure();
task_util::WaitForIdle();

// Create XMPP Agent A connected to XMPP server X.
agent_a_.reset(
new test::NetworkAgentMock(&evm_, "agent-a", xs_x_->GetPort(),
"127.0.0.1", "127.0.0.1"));
TASK_UTIL_EXPECT_TRUE(agent_a_->IsEstablished());

// Create XMPP Agent B connected to XMPP server Y.
agent_b_.reset(
new test::NetworkAgentMock(&evm_, "agent-b", xs_y_->GetPort(),
"127.0.0.2", "127.0.0.2"));
TASK_UTIL_EXPECT_TRUE(agent_b_->IsEstablished());

// Register to blue instance
agent_a_->Subscribe("blue", 1);
agent_b_->Subscribe("blue", 1);

// Add route from agent A.
stringstream route_a;
route_a << "10.1.1.1/32";
test::NextHops next_hops;
test::NextHop next_hop("192.168.1.1", 0, "udp");
next_hops.push_back(next_hop);
agent_a_->AddRoute("blue", route_a.str(), next_hops, 100);
task_util::WaitForIdle();

// Verify that route showed up on agents A and B.
VerifyRouteExists(
agent_a_, "blue", route_a.str(), "192.168.1.1", 100, "udp");
VerifyRouteExists(
agent_b_, "blue", route_a.str(), "192.168.1.1", 100, "udp");

// Delete route from agent A.
agent_a_->DeleteRoute("blue", route_a.str());
task_util::WaitForIdle();

// Verify that route is deleted at agents A and B.
VerifyRouteNoExists(agent_a_, "blue", route_a.str());
VerifyRouteNoExists(agent_b_, "blue", route_a.str());

// Close the sessions.
agent_a_->SessionDown();
agent_b_->SessionDown();
}

class TestEnvironment : public ::testing::Environment {
virtual ~TestEnvironment() { }
virtual void SetUp() {
Expand Down
3 changes: 1 addition & 2 deletions src/bgp/test/service_chain_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,7 @@ class ServiceChainTest : public ::testing::Test {
if (!ExtCommunity::is_tunnel_encap(comm))
continue;
TunnelEncap encap(comm);

list.insert(TunnelEncapType::TunnelEncapToString(encap.tunnel_encap()));
list.insert(encap.ToXmppString());
}
return list;
}
Expand Down
3 changes: 1 addition & 2 deletions src/bgp/test/static_route_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class StaticRouteTest : public ::testing::Test {
if (!ExtCommunity::is_tunnel_encap(comm))
continue;
TunnelEncap encap(comm);

list.insert(TunnelEncapType::TunnelEncapToString(encap.tunnel_encap()));
list.insert(encap.ToXmppString());
}
return list;
}
Expand Down
3 changes: 1 addition & 2 deletions src/bgp/test/svc_static_route_intergration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ class ServiceChainTest : public ::testing::Test {
if (!ExtCommunity::is_tunnel_encap(comm))
continue;
TunnelEncap encap(comm);
list.insert(TunnelEncapType::TunnelEncapToString(
encap.tunnel_encap()));
list.insert(encap.ToXmppString());
}
return list;
}
Expand Down

0 comments on commit db5f612

Please sign in to comment.