Skip to content

Commit

Permalink
Keep separate counts for regular and bgpaas peers
Browse files Browse the repository at this point in the history
Change-Id: Iec0f67c503a51d3c0c37f23c98a01e76af422fb3
Closes-Bug: 1551050
  • Loading branch information
Nischal Sheth committed Apr 25, 2016
1 parent b1e91c8 commit 2abb247
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 11 deletions.
28 changes: 26 additions & 2 deletions src/bgp/bgp_peer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ class BgpPeer::PeerClose : public IPeerClose {
// attempt to bring up session with the neighbor
//
virtual bool CloseComplete(bool from_timer, bool gr_cancelled) {
peer_->server()->decrement_closing_count();
if (peer_->router_type() == "bgpaas-client") {
peer_->server()->decrement_closing_bgpaas_count();
} else {
peer_->server()->decrement_closing_count();
}
if (!peer_->IsDeleted()) {

//
Expand Down Expand Up @@ -108,7 +112,11 @@ class BgpPeer::PeerClose : public IPeerClose {
void Close() {
if (!is_closed_ && !manager_->IsCloseInProgress()) {
manager_->Close();
peer_->server()->increment_closing_count();
if (peer_->router_type() == "bgpaas-client") {
peer_->server()->increment_closing_bgpaas_count();
} else {
peer_->server()->increment_closing_count();
}
}
}

Expand Down Expand Up @@ -434,6 +442,22 @@ void BgpPeer::Initialize() {
state_machine_->Initialize();
}

void BgpPeer::NotifyEstablished(bool established) {
if (established) {
if (router_type_ == "bgpaas-client") {
server_->IncrementUpBgpaasPeerCount();
} else {
server_->IncrementUpPeerCount();
}
} else {
if (router_type_ == "bgpaas-client") {
server_->DecrementUpBgpaasPeerCount();
} else {
server_->DecrementUpPeerCount();
}
}
}

void BgpPeer::BindLocalEndpoint(BgpSession *session) {
}

Expand Down
2 changes: 2 additions & 0 deletions src/bgp/bgp_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class BgpPeer : public IPeer {
LifetimeActor *deleter();
void Initialize();

void NotifyEstablished(bool established);

void increment_flap_count();
void reset_flap_count();
uint64_t flap_count() const { return flap_count_; };
Expand Down
21 changes: 21 additions & 0 deletions src/bgp/bgp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,18 @@ BgpServer::BgpServer(EventManager *evm)
BgpObjectFactory::Create<IServiceChainMgr, Address::INET6>(this)),
config_mgr_(BgpObjectFactory::Create<BgpConfigManager>(this)),
updater_(new ConfigUpdater(this)) {
bgp_count_ = 0;
num_up_peer_ = 0;
closing_count_ = 0;
bgpaas_count_ = 0;
num_up_bgpaas_peer_ = 0;
closing_bgpaas_count_ = 0;
message_build_error_ = 0;
}

BgpServer::~BgpServer() {
assert(closing_count_ == 0);
assert(closing_bgpaas_count_ == 0);
assert(srt_manager_list_.empty());
}

Expand Down Expand Up @@ -357,6 +362,13 @@ bool BgpServer::HasSelfConfiguration() const {

int BgpServer::RegisterPeer(BgpPeer *peer) {
CHECK_CONCURRENCY("bgp::Config");

if (peer->router_type() == "bgpaas-client") {
bgpaas_count_++;
} else {
bgp_count_++;
}

BgpPeerList::iterator loc;
bool result;
tie(loc, result) = peer_list_.insert(make_pair(peer->peer_name(), peer));
Expand All @@ -374,6 +386,15 @@ int BgpServer::RegisterPeer(BgpPeer *peer) {

void BgpServer::UnregisterPeer(BgpPeer *peer) {
CHECK_CONCURRENCY("bgp::Config");

if (peer->router_type() == "bgpaas-client") {
assert(bgpaas_count_);
bgpaas_count_--;
} else {
assert(bgp_count_);
bgp_count_--;
}

BgpPeerList::iterator loc = peer_list_.find(peer->peer_name());
assert(loc != peer_list_.end());
peer_list_.erase(loc);
Expand Down
28 changes: 23 additions & 5 deletions src/bgp/bgp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,31 +170,45 @@ class BgpServer {
// Status
uint32_t num_routing_instance() const;
uint32_t num_deleted_routing_instance() const;
uint32_t num_bgp_peer() const {
return (peer_bmap_.size() - peer_bmap_.count());
}

uint32_t num_bgp_peer() const { return bgp_count_; }
uint32_t num_closing_bgp_peer() const { return closing_count_; }
void increment_closing_count() { closing_count_++; }
void decrement_closing_count() { closing_count_--; }

uint32_t num_bgpaas_peer() const { return bgpaas_count_; }
uint32_t num_closing_bgpaas_peer() const { return closing_bgpaas_count_; }
void increment_closing_bgpaas_count() { closing_bgpaas_count_++; }
void decrement_closing_bgpaas_count() { closing_bgpaas_count_--; }

uint32_t get_output_queue_depth() const;

uint32_t num_service_chains() const;
uint32_t num_down_service_chains() const;
uint32_t num_static_routes() const;
uint32_t num_down_static_routes() const;

void IncUpPeerCount() {
void IncrementUpPeerCount() {
num_up_peer_++;
}
void DecUpPeerCount() {
void DecrementUpPeerCount() {
assert(num_up_peer_);
num_up_peer_--;
}
uint32_t NumUpPeer() const {
return num_up_peer_;
}
void IncrementUpBgpaasPeerCount() {
num_up_bgpaas_peer_++;
}
void DecrementUpBgpaasPeerCount() {
assert(num_up_bgpaas_peer_);
num_up_bgpaas_peer_--;
}
uint32_t NumUpBgpaasPeer() const {
return num_up_bgpaas_peer_;
}

LifetimeActor *deleter();
boost::asio::io_service *ioservice();

Expand Down Expand Up @@ -247,8 +261,12 @@ class BgpServer {

DB db_;
boost::dynamic_bitset<> peer_bmap_;
tbb::atomic<uint32_t> bgp_count_;
tbb::atomic<uint32_t> num_up_peer_;
tbb::atomic<uint32_t> closing_count_;
tbb::atomic<uint32_t> bgpaas_count_;
tbb::atomic<uint32_t> num_up_bgpaas_peer_;
tbb::atomic<uint32_t> closing_bgpaas_count_;
BgpPeerList peer_list_;
EndpointToBgpPeerList endpoint_peer_list_;

Expand Down
4 changes: 2 additions & 2 deletions src/bgp/state_machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ struct Established : sc::state<Established, StateMachine> {
explicit Established(my_context ctx) : my_base(ctx) {
StateMachine *state_machine = &context<StateMachine>();
BgpPeer *peer = state_machine->peer();
peer->server()->IncUpPeerCount();
peer->NotifyEstablished(true);
state_machine->connect_attempts_clear();
state_machine->StartHoldTimer();
state_machine->set_state(StateMachine::ESTABLISHED);
Expand All @@ -1037,7 +1037,7 @@ struct Established : sc::state<Established, StateMachine> {
~Established() {
StateMachine *state_machine = &context<StateMachine>();
BgpPeer *peer = state_machine->peer();
peer->server()->DecUpPeerCount();
peer->NotifyEstablished(false);
state_machine->CancelHoldTimer();
}

Expand Down
22 changes: 20 additions & 2 deletions src/bgp/test/bgp_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors1) {
server_.routing_instance_mgr()->GetRoutingInstance("test");
TASK_UTIL_ASSERT_TRUE(rti != NULL);
TASK_UTIL_EXPECT_EQ(2, rti->peer_manager()->size());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(2, server_.num_bgpaas_peer());

TASK_UTIL_EXPECT_TRUE(
rti->peer_manager()->PeerLookup("test:vm1:0") != NULL);
Expand Down Expand Up @@ -375,6 +377,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors1) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, rti->peer_manager()->size());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());
}

TEST_F(BgpConfigTest, BGPaaSNeighbors2) {
Expand All @@ -387,6 +391,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors2) {
server_.routing_instance_mgr()->GetRoutingInstance("test");
TASK_UTIL_ASSERT_TRUE(rti != NULL);
TASK_UTIL_EXPECT_EQ(2, rti->peer_manager()->size());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(2, server_.num_bgpaas_peer());

TASK_UTIL_EXPECT_TRUE(
rti->peer_manager()->PeerLookup("test:vm1:0") != NULL);
Expand Down Expand Up @@ -421,6 +427,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors2) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, rti->peer_manager()->size());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());
}

TEST_F(BgpConfigTest, BGPaaSNeighbors3) {
Expand All @@ -433,6 +441,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors3) {
server_.routing_instance_mgr()->GetRoutingInstance("test");
TASK_UTIL_ASSERT_TRUE(rti != NULL);
TASK_UTIL_EXPECT_EQ(2, rti->peer_manager()->size());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(2, server_.num_bgpaas_peer());

// Verify that the port is set for test:vm1.
TASK_UTIL_EXPECT_TRUE(
Expand Down Expand Up @@ -488,6 +498,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors3) {
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, rti->peer_manager()->size());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());
}

//
Expand Down Expand Up @@ -521,6 +533,7 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors4) {
task_util::WaitForIdle();

TASK_UTIL_EXPECT_EQ(1, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());

// Remove peering between local and remote.
router1 = master_instance + ":" + string("local");
Expand All @@ -537,6 +550,7 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors4) {
task_util::WaitForIdle();

TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());

// Cleanup.
boost::replace_all(content, "<config>", "<delete>");
Expand Down Expand Up @@ -575,7 +589,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors5) {
new autogen::BgpPeeringAttributes());
task_util::WaitForIdle();

TASK_UTIL_EXPECT_EQ(1, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(1, server_.num_bgpaas_peer());

// Remove peering between server and client.
router1 = test_instance + ":" + string("server");
Expand All @@ -592,6 +607,7 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors5) {
task_util::WaitForIdle();

TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());

// Cleanup.
boost::replace_all(content, "<config>", "<delete>");
Expand Down Expand Up @@ -629,7 +645,8 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors6) {
new autogen::BgpPeeringAttributes());
task_util::WaitForIdle();

TASK_UTIL_EXPECT_EQ(1, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(1, server_.num_bgpaas_peer());

// Remove peering between server and client in same instance.
router1 = string("test1") + ":" + string("server");
Expand All @@ -646,6 +663,7 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors6) {
task_util::WaitForIdle();

TASK_UTIL_EXPECT_EQ(0, server_.num_bgp_peer());
TASK_UTIL_EXPECT_EQ(0, server_.num_bgpaas_peer());

// Cleanup.
boost::replace_all(content, "<config>", "<delete>");
Expand Down
22 changes: 22 additions & 0 deletions src/control-node/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,28 @@ bool ControlNodeInfoLogger(BgpServer *server,
change = true;
}

uint32_t num_bgpaas = server->num_bgpaas_peer();
if (num_bgpaas != prev_state.get_num_bgpaas_peer() || first) {
state.set_num_bgpaas_peer(num_bgpaas);
prev_state.set_num_bgpaas_peer(num_bgpaas);
change = true;
}

uint32_t num_up_bgpaas_peer = server->NumUpBgpaasPeer();
if (num_up_bgpaas_peer != prev_state.get_num_up_bgpaas_peer() || first) {
state.set_num_up_bgpaas_peer(num_up_bgpaas_peer);
prev_state.set_num_up_bgpaas_peer(num_up_bgpaas_peer);
change = true;
}

uint32_t num_closing_bgpaas_peer = server->num_closing_bgpaas_peer();
if (num_closing_bgpaas_peer != prev_state.get_num_closing_bgpaas_peer() ||
first) {
state.set_num_closing_bgpaas_peer(num_closing_bgpaas_peer);
prev_state.set_num_closing_bgpaas_peer(num_closing_bgpaas_peer);
change = true;
}

uint32_t num_ri = server->num_routing_instance();
if (num_ri != prev_state.get_num_routing_instance() || first) {
state.set_num_routing_instance(num_ri);
Expand Down
3 changes: 3 additions & 0 deletions src/control-node/sandesh/control_node.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ struct BgpRouterState {
8: optional u32 num_bgp_peer;
9: optional u32 num_up_bgp_peer;
20: optional u32 num_closing_bgp_peer;
31: optional u32 num_bgpaas_peer;
32: optional u32 num_up_bgpaas_peer;
33: optional u32 num_closing_bgpaas_peer;
10: optional u32 num_xmpp_peer;
11: optional u32 num_up_xmpp_peer;
21: optional u32 num_closing_xmpp_peer;
Expand Down

0 comments on commit 2abb247

Please sign in to comment.