Skip to content

Commit

Permalink
Support single-active BGPaaS object attached to multiple VMIs
Browse files Browse the repository at this point in the history
 - New flag "bgpaas-shared" is added in the schema to indicate
   the given bgp-aas session is shared or not.
 - To support this flag in vrouter-agent,
   1. If this flag is true, then local index will be allocated for
      each VMI for the given source port.
   2. If the flag is false, then the session will continue to use
      original source port which is given by the controller.

Change-Id: I860f5a2319c2787f35aa0170ddbe2e896dd1efd9
Closes-Bug: #1649707
  • Loading branch information
srinivn committed Aug 28, 2017
1 parent 910711f commit d9d629d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/vnsw/agent/oper/agent.sandesh
Expand Up @@ -2870,6 +2870,8 @@ struct BgpAsAServiceSandeshList {
2: i32 vm_nat_source_port;
/** Uuid of vmi for bgp as a service */
3: string vmi_uuid (link="ItfReq");
/** Sharing flag to indicate the session is shared or not */
4: bool is_shared;
}

/**
Expand Down
42 changes: 29 additions & 13 deletions src/vnsw/agent/oper/bgp_as_service.cc
Expand Up @@ -169,7 +169,8 @@ void BgpAsAService::BuildBgpAsAServiceInfo(IFMapNode *bgp_as_a_service_node,
BgpAsAServiceEntryList temp_bgp_as_a_service_entry_list;
temp_bgp_as_a_service_entry_list.insert(
BgpAsAServiceEntry(peer_ip,
bgp_router->parameters().source_port));
bgp_router->parameters().source_port,
bgp_as_a_service->bgpaas_shared()));
/*
* if it is same session then retain original source port
*/
Expand All @@ -179,13 +180,18 @@ void BgpAsAService::BuildBgpAsAServiceInfo(IFMapNode *bgp_as_a_service_node,
}
}
if (!source_port) {
source_port = AddBgpVmiServicePortIndex(
bgp_router->parameters().source_port,
vm_uuid);
if (bgp_as_a_service->bgpaas_shared()) {
source_port = AddBgpVmiServicePortIndex(
bgp_router->parameters().source_port,
vm_uuid);
} else {
source_port = bgp_router->parameters().source_port;
}
}
if (source_port) {
new_list.insert(BgpAsAServiceEntry(peer_ip,
source_port));
source_port,
bgp_as_a_service->bgpaas_shared()));
}
}
}
Expand Down Expand Up @@ -231,7 +237,9 @@ void BgpAsAService::ProcessConfig(const std::string &vrf_name,
BgpAsAServiceEntryListIterator prev = deleted_list_iter++;
if (prev->del_pending_) {
service_delete_cb_(vm_uuid, prev->source_port_);
FreeBgpVmiServicePortIndex(prev->source_port_);
if (prev->is_shared_) {
FreeBgpVmiServicePortIndex(prev->source_port_);
}
old_bgp_as_a_service_entry_list_iter->second->list_.erase(prev);
}
}
Expand All @@ -251,7 +259,9 @@ void BgpAsAService::DeleteVmInterface(const boost::uuids::uuid &vm_uuid) {
BgpAsAServiceEntryListIterator list_iter = list.begin();
while (list_iter != list.end()) {
service_delete_cb_(vm_uuid, (*list_iter).source_port_);
FreeBgpVmiServicePortIndex((*list_iter).source_port_);
if ((*list_iter).is_shared_) {
FreeBgpVmiServicePortIndex((*list_iter).source_port_);
}
list_iter++;
}
delete iter->second;
Expand Down Expand Up @@ -405,21 +415,23 @@ bool BgpAsAService::GetBgpRouterServiceDestination(const VmInterface *vm_intf,
////////////////////////////////////////////////////////////////////////////
BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry() :
VmInterface::ListEntry(),
local_peer_ip_(), source_port_(0) {
local_peer_ip_(), source_port_(0), is_shared_(false) {
}

BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry
(const BgpAsAService::BgpAsAServiceEntry &rhs) :
VmInterface::ListEntry(rhs.installed_, rhs.del_pending_),
local_peer_ip_(rhs.local_peer_ip_),
source_port_(rhs.source_port_) {
local_peer_ip_(rhs.local_peer_ip_),
source_port_(rhs.source_port_), is_shared_(rhs.is_shared_) {
}

BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry(const IpAddress &local_peer_ip,
uint32_t source_port) :
uint32_t source_port,
bool is_shared) :
VmInterface::ListEntry(),
local_peer_ip_(local_peer_ip),
source_port_(source_port) {
source_port_(source_port),
is_shared_(is_shared) {
}

BgpAsAService::BgpAsAServiceEntry::~BgpAsAServiceEntry() {
Expand All @@ -428,7 +440,8 @@ BgpAsAService::BgpAsAServiceEntry::~BgpAsAServiceEntry() {
bool BgpAsAService::BgpAsAServiceEntry::operator ==
(const BgpAsAServiceEntry &rhs) const {
return ((source_port_ == rhs.source_port_) &&
(local_peer_ip_ == rhs.local_peer_ip_));
(local_peer_ip_ == rhs.local_peer_ip_) &&
(is_shared_ == rhs.is_shared_));
}

bool BgpAsAService::BgpAsAServiceEntry::operator()
Expand All @@ -440,7 +453,9 @@ bool BgpAsAService::BgpAsAServiceEntry::IsLess
(const BgpAsAServiceEntry *rhs) const {
if (source_port_ != rhs->source_port_)
return source_port_ < rhs->source_port_;
if (local_peer_ip_ != rhs->local_peer_ip_)
return local_peer_ip_ < rhs->local_peer_ip_;
return is_shared_ < rhs->is_shared_;
}

void BgpAsAServiceSandeshReq::HandleRequest() const {
Expand All @@ -462,6 +477,7 @@ void BgpAsAServiceSandeshReq::HandleRequest() const {
entry.set_vm_bgp_peer_ip((*it).local_peer_ip_.to_string());
entry.set_vm_nat_source_port((*it).source_port_);
entry.set_vmi_uuid(UuidToString(map_it->first));
entry.set_is_shared((*it).is_shared_);
bgpaas_map.push_back(entry);
it++;
}
Expand Down
4 changes: 3 additions & 1 deletion src/vnsw/agent/oper/bgp_as_service.h
Expand Up @@ -73,7 +73,8 @@ class BgpAsAService {
BgpAsAServiceEntry();
BgpAsAServiceEntry(const BgpAsAServiceEntry &rhs);
BgpAsAServiceEntry(const IpAddress &local_peer_ip,
uint32_t source_port);
uint32_t source_port,
bool is_shared);
~BgpAsAServiceEntry();
bool operator == (const BgpAsAServiceEntry &rhs) const;
bool operator() (const BgpAsAServiceEntry &lhs,
Expand All @@ -82,6 +83,7 @@ class BgpAsAService {

IpAddress local_peer_ip_;
uint32_t source_port_;
bool is_shared_;
};
typedef std::set<BgpAsAServiceEntry, BgpAsAServiceEntry> BgpAsAServiceEntryList;
typedef BgpAsAServiceEntryList::iterator BgpAsAServiceEntryListIterator;
Expand Down
24 changes: 12 additions & 12 deletions src/vnsw/agent/pkt/test/test_bgp_service.cc
Expand Up @@ -80,22 +80,22 @@ class BgpServiceTest : public ::testing::Test {
client->WaitForIdle();
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1",
"vrf1", "bgpaas-client",
false);
false, true);
SendBgpServiceConfig("2.2.2.20", 50000, 2, "vnet2",
"vrf2", "bgpaas-client",
false);
false, true);
SendBgpServiceConfig("3.3.3.30", 50000, 3, "vnet3",
"vrf3", "bgpaas-client",
false);
false, true);
SendBgpServiceConfig("4.4.4.40", 50001, 4, "vnet4",
"vrf4", "bgpaas-client",
false);
false, true);
SendBgpServiceConfig("5.5.5.50", 50001, 5, "vnet5",
"vrf5", "bgpaas-client",
false);
false, true);
SendBgpServiceConfig("6.6.6.60", 50001, 6, "vnet6",
"vrf6", "bgpaas-client",
false);
false, true);
client->WaitForIdle();
}

Expand All @@ -106,22 +106,22 @@ class BgpServiceTest : public ::testing::Test {
client->WaitForIdle();
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1",
"vrf1", "bgpaas-server",
true);
true, true);
SendBgpServiceConfig("2.2.2.20", 50000, 2, "vnet2",
"vrf2", "bgpaas-server",
true);
true, true);
SendBgpServiceConfig("3.3.3.30", 50000, 3, "vnet3",
"vrf3", "bgpaas-client",
true);
true, true);
SendBgpServiceConfig("4.4.4.40", 50001, 4, "vnet4",
"vrf4", "bgpaas-server",
true);
true, true);
SendBgpServiceConfig("5.5.5.50", 50001, 5, "vnet5",
"vrf5", "bgpaas-server",
true);
true, true);
SendBgpServiceConfig("6.6.6.60", 50001, 6, "vnet6",
"vrf6", "bgpaas-client",
true);
true, true);
DelIPAM("vn1");
DelIPAM("vn2");
DelIPAM("vn3");
Expand Down
8 changes: 4 additions & 4 deletions src/vnsw/agent/test/test_bgp_service_configuration.cc
Expand Up @@ -60,14 +60,14 @@ TEST_F(BgpCfgTest, Test_1) {
agent_->oper_db()->bgp_as_a_service()->bgp_as_a_service_map().size();
EXPECT_TRUE(bgp_service_count == 0);
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1", "vrf1", "bgpaas-client",
false);
false, false);
bgp_service_count =
agent_->oper_db()->bgp_as_a_service()->bgp_as_a_service_map().size();
EXPECT_TRUE(bgp_service_count == 1);

//Delete
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1", "vrf1", "bgpaas-client",
true);
true, false);
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
bgp_service_count =
Expand All @@ -92,14 +92,14 @@ TEST_F(BgpCfgTest, Test_2) {
agent_->oper_db()->bgp_as_a_service()->bgp_as_a_service_map().size();
EXPECT_TRUE(bgp_service_count == 0);
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1", "vrf1", "bgpaas-server",
false);
false, false);
bgp_service_count =
agent_->oper_db()->bgp_as_a_service()->bgp_as_a_service_map().size();
EXPECT_TRUE(bgp_service_count == 0);

//Delete
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1", "vrf1", "bgpaas-server",
true);
true, false);
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
bgp_service_count =
Expand Down
10 changes: 2 additions & 8 deletions src/vnsw/agent/test/test_cmn_util.h
Expand Up @@ -626,19 +626,13 @@ void SendBgpServiceConfig(const std::string &ip,
const std::string &vmi_name,
const std::string &vrf_name,
const std::string &bgp_router_type,
bool deleted);
bool deleted,
bool is_shared);
void AddAddressVrfAssignAcl(const char *intf_name, int intf_id,
const char *sip, const char *dip, int proto,
int sport_start, int sport_end, int dport_start,
int dport_end, const char *vrf, const char *ignore_acl,
const char *svc_intf_type = NULL);
void SendBgpServiceConfig(const std::string &ip,
uint32_t source_port,
uint32_t id,
const std::string &vmi_name,
const std::string &vrf_name,
const std::string &bgp_router_type,
bool deleted);
bool QosConfigFind(uint32_t id);
const AgentQosConfig* QosConfigGetByIndex(uint32_t id);
const AgentQosConfig* QosConfigGet(uint32_t id);
Expand Down
6 changes: 4 additions & 2 deletions src/vnsw/agent/test/test_util.cc
Expand Up @@ -4329,7 +4329,8 @@ void SendBgpServiceConfig(const std::string &ip,
const std::string &vmi_name,
const std::string &vrf_name,
const std::string &bgp_router_type,
bool deleted) {
bool deleted,
bool is_shared) {
std::stringstream bgp_router_name;
bgp_router_name << "bgp-router-" << source_port << "-" << ip;

Expand All @@ -4342,7 +4343,8 @@ void SendBgpServiceConfig(const std::string &ip,

std::stringstream str1;
//Agent does not pick IP from bgpaas-ip-address. So dont populate.
str1 << "<bgpaas-ip-address></bgpaas-ip-address>" << endl;
str1 << "<bgpaas-ip-address></bgpaas-ip-address>"
"<bgpaas-shared>" << is_shared << "</bgpaas-shared>" << endl;

if (deleted) {
DelLink("bgp-router", bgp_router_name.str().c_str(),
Expand Down

0 comments on commit d9d629d

Please sign in to comment.