Skip to content

Commit

Permalink
Use BGP port number in BGP router config
Browse files Browse the repository at this point in the history
made changes to use bgp port number in BGP router configuration, this
port number is sused as dest port for nat flow towards control node.

Change-Id: Ib48d8cdda26d0a99fd9e88a5d79859fd2660f5a6
Closes-Bug: #1751394
  • Loading branch information
Sangarshan committed Mar 27, 2018
1 parent 48cb8ba commit e5d8a5a
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 45 deletions.
21 changes: 14 additions & 7 deletions src/vnsw/agent/oper/bgp_as_service.cc
Expand Up @@ -269,6 +269,7 @@ void BgpAsAService::BuildBgpAsAServiceInfo(IFMapNode *bgp_as_a_service_node,
temp_bgp_as_a_service_entry_list.insert(
BgpAsAServiceEntry(peer_ip,
bgp_router->parameters().source_port,
bgp_router->parameters().port,
health_check_configured,
health_check_uuid,
bgp_as_a_service->bgpaas_shared(),
Expand All @@ -294,6 +295,7 @@ void BgpAsAService::BuildBgpAsAServiceInfo(IFMapNode *bgp_as_a_service_node,
}
if (source_port) {
new_list.insert(BgpAsAServiceEntry(peer_ip, source_port,
bgp_router->parameters().port,
health_check_configured,
health_check_uuid,
bgp_as_a_service->bgpaas_shared(),
Expand Down Expand Up @@ -513,7 +515,7 @@ uint32_t BgpAsAService::AddBgpVmiServicePortIndex(const uint32_t source_port,
bool BgpAsAService::GetBgpRouterServiceDestination(
const VmInterface *vm_intf, const IpAddress &source_ip,
const IpAddress &dest, IpAddress *nat_server,
uint32_t *sport) const {
uint32_t *sport, uint32_t *dport) const {
const VnEntry *vn = vm_intf->vn();
if (vn == NULL) return false;

Expand Down Expand Up @@ -542,6 +544,7 @@ bool BgpAsAService::GetBgpRouterServiceDestination(
return false;
}
*sport = it->source_port_;
*dport = it->dest_port_;
return true;
}
if (dest == dns) {
Expand All @@ -558,6 +561,7 @@ bool BgpAsAService::GetBgpRouterServiceDestination(
return false;
}
*sport = it->source_port_;
*dport = it->dest_port_;
return true;
}
it++;
Expand Down Expand Up @@ -621,6 +625,7 @@ void BgpAsAService::UpdateBgpAsAServiceSessionInfo() {
if (list_iter->source_port_ != source_port) {
BgpAsAServiceEntry temp(list_iter->local_peer_ip_,
source_port,
list_iter->dest_port_,
list_iter->health_check_configured_,
list_iter->health_check_uuid_,
list_iter->is_shared_,
Expand Down Expand Up @@ -650,11 +655,11 @@ void BgpAsAService::UpdateBgpAsAServiceSessionInfo() {
////////////////////////////////////////////////////////////////////////////
BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry() :
VmInterface::ListEntry(), installed_(false),
local_peer_ip_(), source_port_(0), health_check_configured_(false),
health_check_uuid_(), new_health_check_add_(false),
old_health_check_delete_(false), old_health_check_uuid_(),
hc_delay_usecs_(0), hc_timeout_usecs_(0), hc_retries_(0),
is_shared_(false) {
local_peer_ip_(), source_port_(0), dest_port_(0),
health_check_configured_(false), health_check_uuid_(),
new_health_check_add_(false),old_health_check_delete_(false),
old_health_check_uuid_(),hc_delay_usecs_(0),
hc_timeout_usecs_(0), hc_retries_(0), is_shared_(false) {
}

BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry
Expand All @@ -663,6 +668,7 @@ BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry
installed_(rhs.installed_),
local_peer_ip_(rhs.local_peer_ip_),
source_port_(rhs.source_port_),
dest_port_(rhs.dest_port_),
health_check_configured_(rhs.health_check_configured_),
health_check_uuid_(rhs.health_check_uuid_),
new_health_check_add_(rhs.new_health_check_add_),
Expand All @@ -675,14 +681,15 @@ BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry
}

BgpAsAService::BgpAsAServiceEntry::BgpAsAServiceEntry
(const IpAddress &local_peer_ip, uint32_t source_port,
(const IpAddress &local_peer_ip, uint32_t source_port, uint32_t dest_port,
bool health_check_configured, const boost::uuids::uuid &health_check_uuid,
bool is_shared, uint64_t hc_delay_usecs, uint64_t hc_timeout_usecs,
uint32_t hc_retries) :
VmInterface::ListEntry(),
installed_(false),
local_peer_ip_(local_peer_ip),
source_port_(source_port),
dest_port_(dest_port),
health_check_configured_(health_check_configured),
health_check_uuid_(health_check_uuid),
new_health_check_add_(health_check_configured),
Expand Down
4 changes: 3 additions & 1 deletion src/vnsw/agent/oper/bgp_as_service.h
Expand Up @@ -77,6 +77,7 @@ class BgpAsAService {
BgpAsAServiceEntry(const BgpAsAServiceEntry &rhs);
BgpAsAServiceEntry(const IpAddress &local_peer_ip,
uint32_t source_port,
uint32_t dest_port,
bool health_check_configured,
const boost::uuids::uuid &health_check_uuid,
bool is_shared,
Expand All @@ -92,6 +93,7 @@ class BgpAsAService {
bool installed_;
IpAddress local_peer_ip_;
uint32_t source_port_;
uint32_t dest_port_;
mutable bool health_check_configured_;
mutable boost::uuids::uuid health_check_uuid_;
// the following three are used to invoke add / delete of health check
Expand Down Expand Up @@ -138,7 +140,7 @@ class BgpAsAService {
const IpAddress &source,
const IpAddress &dest,
IpAddress *nat_server,
uint32_t *sport) const;
uint32_t *sport, uint32_t *dport) const;
bool GetBgpHealthCheck(const VmInterface *vm_intf,
boost::uuids::uuid *health_check_uuid) const;
size_t AllocateBgpVmiServicePortIndex(const uint32_t sport,
Expand Down
9 changes: 6 additions & 3 deletions src/vnsw/agent/pkt/flow_entry.cc
Expand Up @@ -299,7 +299,8 @@ void FlowData::Reset() {
rpf_vrf = VrfEntry::kInvalidIndex;
disable_validation = false;
vm_cfg_name = "";
bgp_as_a_service_port = 0;
bgp_as_a_service_sport = 0;
bgp_as_a_service_dport = 0;
acl_assigned_vrf_index_ = VrfEntry::kInvalidIndex;
qos_config_idx = AgentQosConfigTable::kInvalidIndex;
ttl = 0;
Expand Down Expand Up @@ -591,10 +592,12 @@ bool FlowEntry::InitFlowCmn(const PktFlowInfo *info, const PktControlInfo *ctrl,
}
if (info->bgp_router_service_flow) {
set_flags(FlowEntry::BgpRouterService);
data_.bgp_as_a_service_port = info->nat_sport;
data_.bgp_as_a_service_sport = info->nat_sport;
data_.bgp_as_a_service_dport = info->nat_dport;
} else {
reset_flags(FlowEntry::BgpRouterService);
data_.bgp_as_a_service_port = 0;
data_.bgp_as_a_service_sport = 0;
data_.bgp_as_a_service_dport = 0;
}

if (info->alias_ip_flow) {
Expand Down
12 changes: 9 additions & 3 deletions src/vnsw/agent/pkt/flow_entry.h
Expand Up @@ -307,7 +307,8 @@ struct FlowData {
uint32_t mirror_vrf;
uint32_t dest_vrf;
uint32_t component_nh_idx;
uint32_t bgp_as_a_service_port;
uint32_t bgp_as_a_service_sport;
uint32_t bgp_as_a_service_dport;
boost::uuids::uuid bgp_health_check_uuid;
uint32_t ttl;
// In case of policy on fabric, the forwarding happens in
Expand Down Expand Up @@ -633,9 +634,14 @@ class FlowEntry {
const NextHop *src_ip_nh() const { return data_.src_ip_nh.get(); }
const NextHop *rpf_nh() const { return data_.rpf_nh.get(); }
uint32_t GetEcmpIndex() const { return data_.component_nh_idx; }
const uint32_t bgp_as_a_service_port() const {
const uint32_t bgp_as_a_service_sport() const {
if (is_flags_set(FlowEntry::BgpRouterService))
return data_.bgp_as_a_service_port;
return data_.bgp_as_a_service_sport;
return 0;
}
const uint32_t bgp_as_a_service_dport() const {
if (is_flags_set(FlowEntry::BgpRouterService))
return data_.bgp_as_a_service_dport;
return 0;
}
const MatchPolicy &match_p() const { return data_.match_p; }
Expand Down
4 changes: 2 additions & 2 deletions src/vnsw/agent/pkt/flow_mgmt.cc
Expand Up @@ -406,12 +406,12 @@ void BgpAsAServiceFlowMgmtTree::ExtractKeys(FlowEntry *flow,
return;
const VmInterface *vm_intf =
dynamic_cast<const VmInterface *>(flow->intf_entry());
if (!vm_intf || (flow->bgp_as_a_service_port() == 0))
if (!vm_intf || (flow->bgp_as_a_service_sport() == 0))
return;

BgpAsAServiceFlowMgmtKey *key =
new BgpAsAServiceFlowMgmtKey(vm_intf->GetUuid(),
flow->bgp_as_a_service_port(),
flow->bgp_as_a_service_sport(),
index_, NULL, NULL);
AddFlowMgmtKey(tree, key);
}
Expand Down
5 changes: 3 additions & 2 deletions src/vnsw/agent/pkt/pkt_flow_info.cc
Expand Up @@ -715,6 +715,7 @@ void PktFlowInfo::BgpRouterServiceFromVm(const PktInfo *pkt, PktControlInfo *in,

const VnEntry *vn = static_cast<const VnEntry *>(vm_port->vn());
uint32_t sport = 0;
uint32_t dport = 0;
IpAddress nat_server = IpAddress();

if (vn == NULL) {
Expand All @@ -728,7 +729,7 @@ void PktFlowInfo::BgpRouterServiceFromVm(const PktInfo *pkt, PktControlInfo *in,
pkt->ip_saddr.to_v4(),
pkt->ip_daddr.to_v4(),
&nat_server,
&sport) == false) {
&sport, &dport) == false) {
return;
}

Expand All @@ -740,7 +741,7 @@ void PktFlowInfo::BgpRouterServiceFromVm(const PktInfo *pkt, PktControlInfo *in,
nat_ip_saddr = agent->router_id();
nat_ip_daddr = nat_server;
nat_sport = sport;
nat_dport = pkt->dport;
nat_dport = dport;
if ((nat_ip_daddr == agent->router_id()) &&
(nat_ip_daddr == nat_ip_saddr)) {
boost::system::error_code ec;
Expand Down
53 changes: 34 additions & 19 deletions src/vnsw/agent/pkt/test/test_bgp_service.cc
Expand Up @@ -79,22 +79,22 @@ class BgpServiceTest : public ::testing::Test {
AddIPAM("vn5", &ipam_info[4], 1);
AddIPAM("vn6", &ipam_info[5], 1);
client->WaitForIdle();
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1",
SendBgpServiceConfig("1.1.1.10", 50000, 179, 1, "vnet1",
"vrf1", "bgpaas-client",
false, true);
SendBgpServiceConfig("2.2.2.20", 50000, 2, "vnet2",
SendBgpServiceConfig("2.2.2.20", 50000, 179, 2, "vnet2",
"vrf2", "bgpaas-client",
false, true);
SendBgpServiceConfig("3.3.3.30", 50000, 3, "vnet3",
SendBgpServiceConfig("3.3.3.30", 50000, 500, 3, "vnet3",
"vrf3", "bgpaas-client",
false, true);
SendBgpServiceConfig("4.4.4.40", 50001, 4, "vnet4",
SendBgpServiceConfig("4.4.4.40", 50001, 179, 4, "vnet4",
"vrf4", "bgpaas-client",
false, true);
SendBgpServiceConfig("5.5.5.50", 50001, 5, "vnet5",
SendBgpServiceConfig("5.5.5.50", 50001, 179, 5, "vnet5",
"vrf5", "bgpaas-client",
false, true);
SendBgpServiceConfig("6.6.6.60", 50001, 6, "vnet6",
SendBgpServiceConfig("6.6.6.60", 50001, 179, 6, "vnet6",
"vrf6", "bgpaas-client",
false, true);
client->WaitForIdle();
Expand All @@ -106,22 +106,22 @@ class BgpServiceTest : public ::testing::Test {
client->WaitForIdle();
EXPECT_EQ(0U, flow_proto_->FlowCount());
client->WaitForIdle();
SendBgpServiceConfig("1.1.1.10", 50000, 1, "vnet1",
SendBgpServiceConfig("1.1.1.10", 50000, 179, 1, "vnet1",
"vrf1", "bgpaas-server",
true, true);
SendBgpServiceConfig("2.2.2.20", 50000, 2, "vnet2",
SendBgpServiceConfig("2.2.2.20", 50000, 179, 2, "vnet2",
"vrf2", "bgpaas-server",
true, true);
SendBgpServiceConfig("3.3.3.30", 50000, 3, "vnet3",
SendBgpServiceConfig("3.3.3.30", 50000, 500, 3, "vnet3",
"vrf3", "bgpaas-client",
true, true);
SendBgpServiceConfig("4.4.4.40", 50001, 4, "vnet4",
SendBgpServiceConfig("4.4.4.40", 50001, 179, 4, "vnet4",
"vrf4", "bgpaas-server",
true, true);
SendBgpServiceConfig("5.5.5.50", 50001, 5, "vnet5",
SendBgpServiceConfig("5.5.5.50", 50001, 179, 5, "vnet5",
"vrf5", "bgpaas-server",
true, true);
SendBgpServiceConfig("6.6.6.60", 50001, 6, "vnet6",
SendBgpServiceConfig("6.6.6.60", 50001, 179, 6, "vnet6",
"vrf6", "bgpaas-client",
true, true);
DelIPAM("vn1");
Expand All @@ -139,7 +139,6 @@ class BgpServiceTest : public ::testing::Test {
Agent *agent_;
FlowProto *flow_proto_;
};

//TTL 1
TEST_F(BgpServiceTest, Test_ttl_1) {
AddAap("vnet1", 1, Ip4Address::from_string("10.10.10.10"), "00:00:01:01:01:01");
Expand All @@ -154,7 +153,7 @@ TEST_F(BgpServiceTest, Test_ttl_1) {
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe->bgp_as_a_service_port() == 50000);
EXPECT_TRUE(fe->bgp_as_a_service_sport() == 50000);
EXPECT_TRUE(fe->data().ttl == BGP_SERVICE_TTL_FWD_FLOW);
EXPECT_TRUE(fe->reverse_flow_entry()->data().ttl ==
BGP_SERVICE_TTL_REV_FLOW);
Expand Down Expand Up @@ -249,7 +248,7 @@ TEST_F(BgpServiceTest, Test_2) {
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe->bgp_as_a_service_port() == 50000);
EXPECT_TRUE(fe->bgp_as_a_service_sport() == 50000);

//Explicitly call deleteall on bgp service tree.
//agent_->pkt()->flow_mgmt_manager()->ControllerNotify(0);
Expand All @@ -274,7 +273,7 @@ TEST_F(BgpServiceTest, Test_3) {
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe->bgp_as_a_service_port() == 50000);
EXPECT_TRUE(fe->bgp_as_a_service_sport() == 50000);
client->WaitForIdle();
}

Expand Down Expand Up @@ -309,7 +308,7 @@ TEST_F(BgpServiceTest, Test_4) {
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe->bgp_as_a_service_port() == 50000);
EXPECT_TRUE(fe->bgp_as_a_service_sport() == 50000);
client->WaitForIdle();
}

Expand Down Expand Up @@ -347,7 +346,7 @@ TEST_F(BgpServiceTest, Test_5) {
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe->bgp_as_a_service_port() == 50500);
EXPECT_TRUE(fe->bgp_as_a_service_sport() == 50500);

//Delete
DelLink("virtual-machine-interface", "vnet1",
Expand Down Expand Up @@ -386,7 +385,23 @@ TEST_F(BgpServiceTest, Test_6) {
EXPECT_TRUE(fe2 != NULL);
EXPECT_TRUE(fe2->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe2->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe2->bgp_as_a_service_port() == 54002);
EXPECT_TRUE(fe2->bgp_as_a_service_sport() == 54002);
client->WaitForIdle();
}
//Test to verify dest port for nat flow
TEST_F(BgpServiceTest, Test_7) {
AddAap("vnet3", 3, Ip4Address::from_string("30.30.30.30"), "00:00:03:03:03:03");
client->WaitForIdle();

TxTcpPacket(VmInterfaceGet(3)->id(), "30.30.30.30", "3.3.3.3", 10000, 179,
false);
client->WaitForIdle();
FlowEntry *fe = FlowGet(VmInterfaceGet(3)->flow_key_nh()->id(),
"30.30.30.30", "3.3.3.3", 6, 10000, 179);
EXPECT_TRUE(fe != NULL);
EXPECT_TRUE(fe->reverse_flow_entry() != NULL);
EXPECT_TRUE(fe->is_flags_set(FlowEntry::BgpRouterService));
EXPECT_TRUE(fe->bgp_as_a_service_dport() == 500);
client->WaitForIdle();
}
int main(int argc, char *argv[]) {
Expand Down
16 changes: 8 additions & 8 deletions src/vnsw/agent/test/test_bgp_service_configuration.cc
Expand Up @@ -59,15 +59,15 @@ TEST_F(BgpCfgTest, Test_1) {
uint32_t bgp_service_count =
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);
SendBgpServiceConfig("1.1.1.10", 50000, 179, 1, "vnet1", "vrf1",
"bgpaas-client", 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, false);
SendBgpServiceConfig("1.1.1.10", 50000, 179, 1, "vnet1", "vrf1",
"bgpaas-client", true, false);
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
bgp_service_count =
Expand All @@ -91,15 +91,15 @@ TEST_F(BgpCfgTest, Test_2) {
uint32_t bgp_service_count =
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);
SendBgpServiceConfig("1.1.1.10", 50000, 179, 1, "vnet1", "vrf1",
"bgpaas-server", 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, false);
SendBgpServiceConfig("1.1.1.10", 50000, 179, 1, "vnet1", "vrf1",
"bgpaas-server", true, false);
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
bgp_service_count =
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/test/test_cmn_util.h
Expand Up @@ -654,6 +654,7 @@ void AddStaticPreference(std::string intf_name, int intf_id, uint32_t value);
bool VnMatch(VnListType &vn_list, std::string &vn);
void SendBgpServiceConfig(const std::string &ip,
uint32_t source_port,
uint32_t dest_port,
uint32_t id,
const std::string &vmi_name,
const std::string &vrf_name,
Expand Down

0 comments on commit e5d8a5a

Please sign in to comment.