Skip to content

Commit

Permalink
Update agent to receive the VN info as part of nexthops in unicast XMPP.
Browse files Browse the repository at this point in the history
Change VN info in path to a list. Make the rest of the code in line with this.
Check the ACLs to get the matched VN for a flow.

Change-Id: I4587ce712f1ab7a7ca41ea41a1a96c03a6ab3f73
closes-bug: 1534160
  • Loading branch information
haripk committed Jan 18, 2016
1 parent 840a9ea commit c72b546
Show file tree
Hide file tree
Showing 56 changed files with 645 additions and 372 deletions.
1 change: 1 addition & 0 deletions src/vnsw/agent/cmn/agent.cc
Expand Up @@ -41,6 +41,7 @@
#include <cmn/agent_factory.h>

const std::string Agent::null_string_ = "";
const std::set<std::string> Agent::null_string_list_;
const std::string Agent::fabric_vn_name_ =
"default-domain:default-project:ip-fabric";
std::string Agent::fabric_vrf_name_ =
Expand Down
8 changes: 6 additions & 2 deletions src/vnsw/agent/cmn/agent.h
Expand Up @@ -135,6 +135,8 @@ void intrusive_ptr_add_ref(const HealthCheckService* p);
typedef std::vector<int> SecurityGroupList;
typedef std::vector<std::string> CommunityList;

typedef std::set<std::string> VnListType;

class AgentDBTable;
class InterfaceTable;
class HealthCheckTable;
Expand Down Expand Up @@ -271,9 +273,10 @@ class Agent {
void Shutdown() { }

static Agent *GetInstance() {return singleton_;}
static const std::string &NullString() {return null_string_;};
static const std::string &NullString() {return null_string_;}
static const std::set<std::string> &NullStringList() {return null_string_list_;}
static const MacAddress &vrrp_mac() {return vrrp_mac_;}
static const std::string &BcastMac() {return bcast_mac_;};
static const std::string &BcastMac() {return bcast_mac_;}
static const std::string &xmpp_dns_server_prefix() {
return xmpp_dns_server_connection_name_prefix_;
}
Expand Down Expand Up @@ -1166,6 +1169,7 @@ class Agent {
static const std::string config_file_;
static const std::string log_file_;
static const std::string null_string_;
static const std::set<std::string> null_string_list_;
static std::string fabric_vrf_name_;
static const std::string fabric_vn_name_;
static const std::string link_local_vrf_name_;
Expand Down
10 changes: 7 additions & 3 deletions src/vnsw/agent/controller/controller_export.cc
Expand Up @@ -20,7 +20,7 @@

RouteExport::State::State() :
DBState(), exported_(false), fabric_multicast_exported_(false),
force_chg_(false), label_(MplsTable::kInvalidLabel), vn_(""), sg_list_(),
force_chg_(false), label_(MplsTable::kInvalidLabel), vn_(), sg_list_(),
tunnel_type_(TunnelType::INVALID), path_preference_(),
destination_(), source_() {
}
Expand Down Expand Up @@ -171,19 +171,23 @@ void RouteExport::UnicastNotify(AgentXmppChannel *bgp_xmpp_peer,

if (path) {
if (state->Changed(route, path)) {
VnListType vn_list;
vn_list.insert(state->vn_);
state->Update(route, path);
state->exported_ =
AgentXmppChannel::ControllerSendRouteAdd(bgp_xmpp_peer,
static_cast<AgentRoute * >(route),
path->NexthopIp(table->agent()), state->vn_,
path->NexthopIp(table->agent()), vn_list,
state->label_, path->GetTunnelBmap(),
&path->sg_list(), &path->communities(),
type, state->path_preference_);
}
} else {
if (state->exported_ == true) {
VnListType vn_list;
vn_list.insert(state->vn_);
AgentXmppChannel::ControllerSendRouteDelete(bgp_xmpp_peer,
static_cast<AgentRoute *>(route), state->vn_,
static_cast<AgentRoute *>(route), vn_list,
(state->tunnel_type_ == TunnelType::VXLAN ?
state->label_ : 0),
TunnelType::AllType(), NULL, NULL,
Expand Down
93 changes: 62 additions & 31 deletions src/vnsw/agent/controller/controller_peer.cc
Expand Up @@ -605,7 +605,8 @@ void AgentXmppChannel::ReceiveV4V6Update(XmlPugi *pugi) {
}

void AgentXmppChannel::AddEcmpRoute(string vrf_name, IpAddress prefix_addr,
uint32_t prefix_len, ItemType *item) {
uint32_t prefix_len, ItemType *item,
const VnListType &vn_list) {
PathPreference::Preference preference = PathPreference::LOW;
TunnelType::TypeBmap encap = TunnelType::MplsType(); //default
if (item->entry.local_preference == PathPreference::HIGH) {
Expand Down Expand Up @@ -645,7 +646,7 @@ void AgentXmppChannel::AddEcmpRoute(string vrf_name, IpAddress prefix_addr,
BgpPeer *bgp_peer = bgp_peer_id();
ClonedLocalPath *data =
new ClonedLocalPath(unicast_sequence_number(), this,
label, item->entry.virtual_network,
label, vn_list,
item->entry.security_group_list.security_group);
rt_table->AddClonedLocalPathReq(bgp_peer, vrf_name,
prefix_addr, prefix_len,
Expand Down Expand Up @@ -687,8 +688,7 @@ void AgentXmppChannel::AddEcmpRoute(string vrf_name, IpAddress prefix_addr,
nh_req.data.reset(new CompositeNHData());
ControllerEcmpRoute *data =
new ControllerEcmpRoute(bgp_peer_id(), prefix_addr, prefix_len,
item->entry.virtual_network, -1,
false, vrf_name,
vn_list, -1, false, vrf_name,
item->entry.security_group_list.security_group,
rp, encap, nh_req);

Expand Down Expand Up @@ -822,6 +822,8 @@ void AgentXmppChannel::AddEvpnRoute(const std::string &vrf_name,
if (agent_->router_id() != nh_ip.to_v4()) {
CONTROLLER_INFO_TRACE(Trace, GetBgpPeerName(), nexthop_addr,
"add remote evpn route");
VnListType vn_list;
vn_list.insert(item->entry.virtual_network);
// for number of nexthops more than 1, carry flag ecmp suppressed
// to indicate the same to all modules, till we handle L2 ecmp
ControllerVmRoute *data =
Expand All @@ -830,7 +832,7 @@ void AgentXmppChannel::AddEvpnRoute(const std::string &vrf_name,
agent_->router_id(),
vrf_name, nh_ip.to_v4(),
encap, label,
item->entry.virtual_network,
vn_list,
item->entry.security_group_list.security_group,
path_preference,
(item->entry.next_hops.next_hop.size() > 1));
Expand Down Expand Up @@ -898,12 +900,13 @@ void AgentXmppChannel::AddEvpnRoute(const std::string &vrf_name,
SecurityGroupList sg_list = item->entry.security_group_list.security_group;
VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, intf_nh->GetIfUuid(), "");
ControllerLocalVmRoute *local_vm_route = NULL;
VnListType vn_list;
vn_list.insert(item->entry.virtual_network);
if (encap == TunnelType::VxlanType()) {
local_vm_route =
new ControllerLocalVmRoute(intf_key,
MplsTable::kInvalidLabel,
label, false,
item->entry.virtual_network,
label, false, vn_list,
InterfaceNHFlags::BRIDGE,
sg_list, path_preference,
unicast_sequence_number(),
Expand All @@ -913,8 +916,7 @@ void AgentXmppChannel::AddEvpnRoute(const std::string &vrf_name,
new ControllerLocalVmRoute(intf_key,
label,
VxLanTable::kInvalidvxlan_id,
false,
item->entry.virtual_network,
false, vn_list,
InterfaceNHFlags::BRIDGE,
sg_list, path_preference,
unicast_sequence_number(),
Expand All @@ -926,7 +928,8 @@ void AgentXmppChannel::AddEvpnRoute(const std::string &vrf_name,
}

void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
uint32_t prefix_len, ItemType *item) {
uint32_t prefix_len, ItemType *item,
const VnListType &vn_list) {
InetUnicastAgentRouteTable *rt_table = PrefixToRouteTable(vrf_name,
prefix_addr);

Expand All @@ -953,17 +956,20 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
}
PathPreference path_preference(item->entry.sequence_number, preference,
false, false);
std::string vn_string;
for (VnListType::const_iterator vnit = vn_list.begin();
vnit != vn_list.end(); ++vnit) {
vn_string += *vnit + " ";
}
CONTROLLER_INFO_TRACE(RouteImport, GetBgpPeerName(), vrf_name,
prefix_addr.to_string(), prefix_len,
addr.to_v4().to_string(), label,
item->entry.virtual_network);
addr.to_v4().to_string(), label, vn_string);

if (agent_->router_id() != addr.to_v4()) {
ControllerVmRoute *data =
ControllerVmRoute::MakeControllerVmRoute(bgp_peer_id(),
agent_->fabric_vrf_name(), agent_->router_id(),
vrf_name, addr.to_v4(), encap, label,
item->entry.virtual_network ,
vrf_name, addr.to_v4(), encap, label, vn_list,
item->entry.security_group_list.security_group,
path_preference, false);
rt_table->AddRemoteVmRouteReq(bgp_peer_id(), vrf_name, prefix_addr,
Expand All @@ -988,8 +994,8 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
if (interface->type() == Interface::VM_INTERFACE) {
ControllerLocalVmRoute *local_vm_route =
new ControllerLocalVmRoute(intf_key, label,
VxLanTable::kInvalidvxlan_id, false,
item->entry.virtual_network,
VxLanTable::kInvalidvxlan_id,
false, vn_list,
InterfaceNHFlags::INET4,
item->entry.security_group_list.security_group,
path_preference,
Expand All @@ -1009,7 +1015,7 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
ControllerInetInterfaceRoute *inet_interface_route =
new ControllerInetInterfaceRoute(intf_key, label,
TunnelType::GREType(),
item->entry.virtual_network,
vn_list,
unicast_sequence_number(),
this);
rt_table->AddInetInterfaceRouteReq(bgp_peer, vrf_name,
Expand All @@ -1032,7 +1038,7 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
BgpPeer *bgp_peer = bgp_peer_id();
ControllerVlanNhRoute *data =
new ControllerVlanNhRoute(intf_key, vlan_nh->GetVlanTag(),
label, item->entry.virtual_network,
label, vn_list,
item->entry.security_group_list.security_group,
path_preference,
unicast_sequence_number(),
Expand All @@ -1042,7 +1048,7 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
break;
}
case NextHop::COMPOSITE: {
AddEcmpRoute(vrf_name, prefix_addr, prefix_len, item);
AddEcmpRoute(vrf_name, prefix_addr, prefix_len, item, vn_list);
break;
}
case NextHop::VRF: {
Expand All @@ -1058,7 +1064,7 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
BgpPeer *bgp_peer = bgp_peer_id();
ClonedLocalPath *data =
new ClonedLocalPath(unicast_sequence_number(), this,
label, item->entry.virtual_network,
label, vn_list,
item->entry.security_group_list.security_group);
rt_table->AddClonedLocalPathReq(bgp_peer, vrf_name,
prefix_addr.to_v4(),
Expand All @@ -1073,12 +1079,31 @@ void AgentXmppChannel::AddRemoteRoute(string vrf_name, IpAddress prefix_addr,
}
}

bool AgentXmppChannel::IsEcmp(const std::vector<autogen::NextHopType> &nexthops) {
std::string address = nexthops[0].address;
for (uint32_t index = 1; index < nexthops.size(); index++) {
if (nexthops[index].address != address)
return true;
}

return false;
}

void AgentXmppChannel::GetVnList(const std::vector<autogen::NextHopType> &nexthops,
VnListType *vn_list) {
for (uint32_t index = 0; index < nexthops.size(); index++) {
vn_list->insert(nexthops[index].virtual_network);
}
}

void AgentXmppChannel::AddRoute(string vrf_name, IpAddress prefix_addr,
uint32_t prefix_len, ItemType *item) {
if (item->entry.next_hops.next_hop.size() > 1) {
AddEcmpRoute(vrf_name, prefix_addr, prefix_len, item);
VnListType vn_list;
GetVnList(item->entry.next_hops.next_hop, &vn_list);
if (IsEcmp(item->entry.next_hops.next_hop)) {
AddEcmpRoute(vrf_name, prefix_addr, prefix_len, item, vn_list);
} else {
AddRemoteRoute(vrf_name, prefix_addr, prefix_len, item);
AddRemoteRoute(vrf_name, prefix_addr, prefix_len, item, vn_list);
}
}

Expand Down Expand Up @@ -1726,7 +1751,7 @@ bool AgentXmppChannel::ControllerSendSubscribe(AgentXmppChannel *peer,
}

bool AgentXmppChannel::ControllerSendV4V6UnicastRouteCommon(AgentRoute *route,
const std::string &vn,
const VnListType &vn_list,
const SecurityGroupList *sg_list,
const CommunityList *communities,
uint32_t mpls_label,
Expand Down Expand Up @@ -1766,7 +1791,11 @@ bool AgentXmppChannel::ControllerSendV4V6UnicastRouteCommon(AgentRoute *route,
if (bmap & TunnelType::UDPType()) {
nh.tunnel_encapsulation_list.tunnel_encapsulation.push_back("udp");
}
item.entry.next_hops.next_hop.push_back(nh);
for (VnListType::const_iterator vnit = vn_list.begin();
vnit != vn_list.end(); ++vnit) {
nh.virtual_network = *vnit;
item.entry.next_hops.next_hop.push_back(nh);
}

if (sg_list && sg_list->size()) {
item.entry.security_group_list.security_group = *sg_list;
Expand All @@ -1777,7 +1806,6 @@ bool AgentXmppChannel::ControllerSendV4V6UnicastRouteCommon(AgentRoute *route,
}

item.entry.version = 1; //TODO
item.entry.virtual_network = vn;

//Set sequence number and preference of route
item.entry.sequence_number = path_preference.sequence();
Expand Down Expand Up @@ -2378,7 +2406,7 @@ bool AgentXmppChannel::ControllerSendEvpnRouteDelete(AgentXmppChannel *peer,
bool AgentXmppChannel::ControllerSendRouteAdd(AgentXmppChannel *peer,
AgentRoute *route,
const Ip4Address *nexthop_ip,
std::string vn,
const VnListType &vn_list,
uint32_t label,
TunnelType::TypeBmap bmap,
const SecurityGroupList *sg_list,
Expand All @@ -2397,12 +2425,13 @@ bool AgentXmppChannel::ControllerSendRouteAdd(AgentXmppChannel *peer,
bool ret = false;
if (((type == Agent::INET4_UNICAST) || (type == Agent::INET6_UNICAST)) &&
(peer->agent()->simulate_evpn_tor() == false)) {
ret = peer->ControllerSendV4V6UnicastRouteCommon(route, vn,
ret = peer->ControllerSendV4V6UnicastRouteCommon(route, vn_list,
sg_list, communities, label,
bmap, path_preference, true,
type);
}
if (type == Agent::EVPN) {
std::string vn = *vn_list.begin();
ret = peer->ControllerSendEvpnRouteCommon(route, nexthop_ip, vn,
sg_list, communities, label,
bmap, "", "",
Expand All @@ -2413,7 +2442,7 @@ bool AgentXmppChannel::ControllerSendRouteAdd(AgentXmppChannel *peer,

bool AgentXmppChannel::ControllerSendRouteDelete(AgentXmppChannel *peer,
AgentRoute *route,
std::string vn,
const VnListType &vn_list,
uint32_t label,
TunnelType::TypeBmap bmap,
const SecurityGroupList *sg_list,
Expand All @@ -2432,7 +2461,7 @@ bool AgentXmppChannel::ControllerSendRouteDelete(AgentXmppChannel *peer,
bool ret = false;
if (((type == Agent::INET4_UNICAST) || (type == Agent::INET6_UNICAST)) &&
(peer->agent()->simulate_evpn_tor() == false)) {
ret = peer->ControllerSendV4V6UnicastRouteCommon(route, vn,
ret = peer->ControllerSendV4V6UnicastRouteCommon(route, vn_list,
sg_list, communities,
label,
bmap,
Expand All @@ -2442,7 +2471,9 @@ bool AgentXmppChannel::ControllerSendRouteDelete(AgentXmppChannel *peer,
}
if (type == Agent::EVPN) {
Ip4Address nh_ip(0);
ret = peer->ControllerSendEvpnRouteCommon(route, &nh_ip, vn, NULL, NULL,
ret = peer->ControllerSendEvpnRouteCommon(route, &nh_ip,
*vn_list.begin(),
NULL, NULL,
label, bmap, "", "",
path_preference, false);
}
Expand Down

0 comments on commit c72b546

Please sign in to comment.