From a82a822b730516b89ab6f0ac8c2b3d2a5fa87bdb Mon Sep 17 00:00:00 2001 From: Ananth Suryanarayana Date: Wed, 11 May 2016 19:06:08 -0700 Subject: [PATCH] Update BGP and XMPP UVEs o Add UVEs for BgpTables (total, primary, secondary and infeasible path counts) o Add total_path_count and primary_path_count to bgp and xmpp peer UVEs o Send UVEs periodically off a new bgp::Uve task. This runs mutually exclusively with (only) bgp::Config task o Convert all counters in IPeerDebygStats to tbb::atomic, as they can now be changed and read at the same from different threads o Cleanup stats collection in control-node/main.c by moving code into respective modules BgpServer, BgpXmppChannelManager and IFMapServer TODO: Integrate UVEs (selectively) with KPIs Change-Id: Ia53e766956bb2590d417a1f4ce71e5df570cf040 Partial-Bug: #1576437 --- src/analytics/viz.sandesh | 15 + src/bgp/SConscript | 12 + src/bgp/bgp_path.cc | 2 +- src/bgp/bgp_peer.cc | 9 +- src/bgp/bgp_peer.h | 12 +- src/bgp/bgp_server.cc | 198 ++++++++++- src/bgp/bgp_server.h | 4 + src/bgp/bgp_table.cc | 4 +- src/bgp/bgp_table.h | 3 + src/bgp/bgp_table.sandesh | 20 ++ src/bgp/bgp_xmpp_channel.cc | 120 +++++-- src/bgp/bgp_xmpp_channel.h | 5 + src/bgp/daemon/SConscript | 1 + src/bgp/ermvpn/SConscript | 2 + src/bgp/ermvpn/test/SConscript | 3 +- src/bgp/evpn/test/SConscript | 3 +- src/bgp/inet/SConscript | 2 + src/bgp/inet/test/SConscript | 3 +- src/bgp/inet6/SConscript | 2 + src/bgp/inet6/test/SConscript | 3 +- src/bgp/inet6vpn/SConscript | 2 + src/bgp/inet6vpn/test/SConscript | 1 + src/bgp/ipeer.h | 102 +++--- src/bgp/l3vpn/SConscript | 2 + src/bgp/l3vpn/test/SConscript | 1 + src/bgp/l3vpn/test/inetvpn_table_test.cc | 8 +- src/bgp/peer_info.sandesh | 6 + src/bgp/peer_stats.cc | 82 +++++ src/bgp/peer_stats.h | 28 ++ src/bgp/routing-instance/SConscript | 2 + src/bgp/routing-instance/static_route.cc | 4 +- src/bgp/routing-policy/SConscript | 2 + src/bgp/rtarget/test/SConscript | 13 +- src/bgp/table_info.sandesh | 12 + src/bgp/test/SConscript | 1 + src/bgp/test/bgp_evpn_manager_test.cc | 10 +- src/bgp/test/bgp_ip_test.cc | 8 +- src/bgp/test/bgp_multicast_test.cc | 8 +- src/bgp/test/bgp_route_test.cc | 8 +- src/bgp/test/bgp_table_export_test.cc | 8 +- src/bgp/test/path_resolver_test.cc | 8 +- src/bgp/test/ribout_attributes_test.cc | 8 +- src/bgp/test/route_aggregator_test.cc | 8 +- .../test/routepath_replicator_random_test.cc | 8 +- src/bgp/test/routepath_replicator_test.cc | 8 +- src/bgp/test/routing_policy_test.cc | 8 +- src/bgp/test/service_chain_test.cc | 8 +- src/bgp/test/static_route_test.cc | 12 +- src/control-node/SConscript | 1 + src/control-node/control_node.cc | 1 + src/control-node/main.cc | 323 ++---------------- src/dns/SConscript | 2 +- src/ifmap/SConscript | 4 + src/ifmap/client/SConscript | 2 + src/ifmap/client/ifmap_manager.cc | 8 +- src/ifmap/client/ifmap_manager.h | 2 +- src/ifmap/client/test/SConscript | 8 +- src/ifmap/ifmap_server.cc | 27 +- src/ifmap/ifmap_server.h | 9 +- src/ifmap/test/SConscript | 4 +- src/ksync/test/SConscript | 8 +- src/vnsw/agent/SConscript | 1 + src/xmpp/test/SConscript | 2 +- src/xmpp/xmpp_connection.h | 33 +- 64 files changed, 731 insertions(+), 503 deletions(-) create mode 100644 src/bgp/bgp_table.sandesh create mode 100644 src/bgp/peer_stats.cc create mode 100644 src/bgp/peer_stats.h create mode 100644 src/bgp/table_info.sandesh diff --git a/src/analytics/viz.sandesh b/src/analytics/viz.sandesh index 69f4b0348bc..b2e4b56403f 100644 --- a/src/analytics/viz.sandesh +++ b/src/analytics/viz.sandesh @@ -391,6 +391,7 @@ const map UVE_MAP = { "vrouter" : VROUTER_TABLE, "control-node" : BGP_ROUTER_TABLE, "bgp-peer" : BGP_PEER_TABLE, + "routing-instance" : ROUTING_INSTANCE_TABLE, "xmpp-peer" : XMPP_PEER_INFO_TABLE, "analytics-node" : COLLECTOR_INFO_TABLE, "database-node" : DATABASE_INFO_TABLE, @@ -2052,6 +2053,20 @@ const list _STAT_TABLES = [ { 'name' : 'phy_if_band.out_bandwidth_usage', 'datatype' : 'int', 'index' : false } ] }, + { + 'display_name' : 'Routung Instance Information', + 'stat_type' : 'RoutingInstanceStatsData', + 'stat_attr' : 'table_stats', + 'obj_table' : ROUTING_INSTANCE_TABLE, + 'attributes': [ + { 'name' : 'table_stats.address_family', 'datatype' : 'string', 'index' : true}, + { 'name' : 'table_stats.prefixes', 'datatype' : 'int', 'index' : false}, + { 'name' : 'table_stats.primary_paths', 'datatype' : 'int', 'index' : false}, + { 'name' : 'table_stats.secondary_paths', 'datatype' : 'int', 'index' : false}, + { 'name' : 'table_stats.infeasible_paths', 'datatype' : 'int', 'index' : false}, + { 'name' : 'table_stats.total_paths', 'datatype' : 'int', 'index' : false}, + ] + }, #ifdef BROADVIEW_RECEIVER_SUPPORT { diff --git a/src/bgp/SConscript b/src/bgp/SConscript index bceba778099..6397d833c1a 100644 --- a/src/bgp/SConscript +++ b/src/bgp/SConscript @@ -18,17 +18,28 @@ SandeshGenFiles += env.SandeshGenOnlyCpp('bgp_peer_internal.sandesh') SandeshGenFiles += env.SandeshGenCpp('bgp_log.sandesh') SandeshGenFiles += env.SandeshGenCpp('virtual_network.sandesh') SandeshGenFiles += env.SandeshGenCpp('vrouter.sandesh') +SandeshGenFiles += env.SandeshGenCpp('bgp_table.sandesh') SandeshGenSrcs = env.ExtractCpp(SandeshGenFiles) env.Append(CPPPATH = env['TOP']) env.Append(CPPPATH = [env['TOP'] + '/bgp']) env.Append(CPPPATH = [env['TOP'] + '/io']) env.Append(CPPPATH = [env['TOP'] + '/db']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) SandeshPeerFiles = env.SandeshGenCpp('peer_info.sandesh') SandeshPeerGenSrcs = env.ExtractCpp(SandeshPeerFiles) libpeer_sandesh = env.Library('peer_sandesh', SandeshPeerGenSrcs); +SandeshTableFiles = env.SandeshGenCpp('table_info.sandesh') +SandeshTableGenSrcs = env.ExtractCpp(SandeshTableFiles) +libtable_sandesh = env.Library('table_sandesh', SandeshTableGenSrcs); + +SandeshTableFiles = env.SandeshGenCpp('sandesh_info.sandesh') +SandeshTableGenSrcs = env.ExtractCpp(SandeshTableFiles) +libsandesh_sandesh = env.Library('sandesh_sandesh', SandeshTableGenSrcs); + libbgp = env.Library('bgp', SandeshGenSrcs + ['bgp_aspath.cc', @@ -75,6 +86,7 @@ libbgp = env.Library('bgp', 'bgp_update_queue.cc', 'community.cc', 'message_builder.cc', + 'peer_stats.cc', 'scheduling_group.cc', 'state_machine.cc', ]) diff --git a/src/bgp/bgp_path.cc b/src/bgp/bgp_path.cc index e4548623a03..a0ae18cb2ee 100644 --- a/src/bgp/bgp_path.cc +++ b/src/bgp/bgp_path.cc @@ -140,7 +140,7 @@ bool BgpPath::PathSameNeighborAs(const BgpPath &rhs) const { void BgpPath::UpdatePeerRefCount(int count) const { if (!peer_) return; - peer_->UpdateRefCount(count); + peer_->UpdateTotalPathCount(count); if (source_ != BGP_XMPP || IsReplicated()) return; peer_->UpdatePrimaryPathCount(count); diff --git a/src/bgp/bgp_peer.cc b/src/bgp/bgp_peer.cc index dc52352b89b..00879a6480f 100644 --- a/src/bgp/bgp_peer.cc +++ b/src/bgp/bgp_peer.cc @@ -280,6 +280,11 @@ class BgpPeer::PeerStats : public IPeerDebugStats { virtual void GetRxErrorStats(RxErrorStats *stats) const { } + virtual void GetRxRouteStats(RxRouteStats *stats) const { + stats->total_path_count = peer_->GetTotalPathCount(); + stats->primary_path_count = peer_->GetPrimaryPathCount(); + } + private: friend class BgpPeer; @@ -496,7 +501,7 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, peer_basename_ = peer_name_; } - refcount_ = 0; + total_path_count_ = 0; primary_path_count_ = 0; ProcessEndpointConfig(config); @@ -522,7 +527,7 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, } BgpPeer::~BgpPeer() { - assert(GetRefCount() == 0); + assert(GetTotalPathCount() == 0); STLDeleteValues(&family_attributes_list_); ClearListenSocketAuthKey(); BgpPeerInfoData peer_info; diff --git a/src/bgp/bgp_peer.h b/src/bgp/bgp_peer.h index f6445799c48..0f3296881f6 100644 --- a/src/bgp/bgp_peer.h +++ b/src/bgp/bgp_peer.h @@ -270,14 +270,14 @@ class BgpPeer : public IPeer { bool ResumeClose(); void MembershipRequestCallback(IPeer *ipeer, BgpTable *table); - virtual void UpdateRefCount(int count) const { refcount_ += count; } - virtual tbb::atomic GetRefCount() const { return refcount_; } + virtual void UpdateTotalPathCount(int count) const { + total_path_count_ += count; + } + virtual int GetTotalPathCount() const { return total_path_count_; } virtual void UpdatePrimaryPathCount(int count) const { primary_path_count_ += count; } - virtual int GetPrimaryPathCount() const { - return primary_path_count_; - } + virtual int GetPrimaryPathCount() const { return primary_path_count_; } void RegisterToVpnTables(); @@ -447,7 +447,7 @@ class BgpPeer : public IPeer { boost::scoped_ptr peer_stats_; boost::scoped_ptr deleter_; LifetimeRef instance_delete_ref_; - mutable tbb::atomic refcount_; + mutable tbb::atomic total_path_count_; mutable tbb::atomic primary_path_count_; uint64_t flap_count_; uint64_t last_flap_; diff --git a/src/bgp/bgp_server.cc b/src/bgp/bgp_server.cc index 003a857fc02..41fd1571112 100644 --- a/src/bgp/bgp_server.cc +++ b/src/bgp/bgp_server.cc @@ -16,6 +16,8 @@ #include "bgp/bgp_peer.h" #include "bgp/bgp_peer_membership.h" #include "bgp/bgp_session_manager.h" +#include "bgp/bgp_table_types.h" +#include "bgp/peer_stats.h" #include "bgp/scheduling_group.h" #include "bgp/routing-instance/iservice_chain_mgr.h" #include "bgp/routing-instance/istatic_route_mgr.h" @@ -25,6 +27,9 @@ #include "bgp/routing-instance/rtarget_group_mgr.h" #include "bgp/routing-policy/routing_policy.h" +#include "sandesh/sandesh.h" +#include "control-node/sandesh/control_node_types.h" + using boost::system::error_code; using boost::tie; using process::ConnectionState; @@ -705,7 +710,7 @@ void BgpServer::NotifyAllStaticRoutes() { } uint32_t BgpServer::GetStaticRouteCount() const { - CHECK_CONCURRENCY("bgp::Config"); + CHECK_CONCURRENCY("bgp::Uve"); uint32_t count = 0; for (StaticRouteMgrList::iterator it = srt_manager_list_.begin(); it != srt_manager_list_.end(); ++it) { @@ -716,7 +721,7 @@ uint32_t BgpServer::GetStaticRouteCount() const { } uint32_t BgpServer::GetDownStaticRouteCount() const { - CHECK_CONCURRENCY("bgp::Config"); + CHECK_CONCURRENCY("bgp::Uve"); uint32_t count = 0; for (StaticRouteMgrList::iterator it = srt_manager_list_.begin(); it != srt_manager_list_.end(); ++it) { @@ -725,3 +730,192 @@ uint32_t BgpServer::GetDownStaticRouteCount() const { } return count; } + +uint32_t BgpServer::SendTableStatsUve(bool first) const { + uint32_t out_q_depth = 0; + for (RoutingInstanceMgr::RoutingInstanceIterator rit = inst_mgr_->begin(); + rit != inst_mgr_->end(); ++rit) { + RoutingInstanceStatsData instance_info; + RoutingInstance::RouteTableList const rt_list = rit->GetTables(); + std::vector tables_stats; + + for (RoutingInstance::RouteTableList::const_iterator it = + rt_list.begin(); it != rt_list.end(); ++it) { + BgpTable *table = it->second; + + size_t markers; + out_q_depth += table->GetPendingRiboutsCount(&markers); + string family = Address::FamilyToString(table->family()); + + bool changed = false; + if (first || table->stats()->get_address_family() != family) { + changed = true; + table->stats()->set_address_family(family); + } + + if (first || table->stats()->get_prefixes() != table->Size()) { + changed = true; + table->stats()->set_prefixes(table->Size()); + } + + if (first || table->stats()->get_primary_paths() != + table->GetPrimaryPathCount()) { + changed = true; + table->stats()->set_primary_paths(table->GetPrimaryPathCount()); + } + + if (first || table->stats()->get_secondary_paths() != + table->GetSecondaryPathCount()) { + changed = true; + table->stats()->set_secondary_paths( + table->GetSecondaryPathCount()); + } + + uint64_t total_paths = table->stats()->get_primary_paths() + + table->stats()->get_secondary_paths() + + table->stats()->get_infeasible_paths(); + if (first || table->stats()->get_total_paths() != total_paths) { + changed = true; + table->stats()->set_total_paths(total_paths); + } + + if (changed) { + tables_stats.push_back(*table->stats()); + + // Reset changed flags in the uve structure. + memset(&(table->stats()->__isset), 0, + sizeof(table->stats()->__isset)); + } + } + + // Set the key and send out the uve. + if (!tables_stats.empty()) { + instance_info.set_name(rit->name()); + instance_info.set_table_stats(tables_stats); + RoutingInstanceStats::Send(instance_info); + } + } + + return out_q_depth; +} + +void BgpServer::FillPeerStats(const BgpPeer *peer) const { + PeerStatsInfo stats; + PeerStats::FillPeerDebugStats(peer->peer_stats(), &stats); + + BgpPeerInfoData peer_info; + peer_info.set_name(peer->ToUVEKey()); + peer_info.set_peer_stats_info(stats); + BGPPeerInfo::Send(peer_info); +} + +bool BgpServer::CollectStats(BgpRouterState *state, bool first) const { + CHECK_CONCURRENCY("bgp::Uve"); + + VisitBgpPeers(boost::bind(&BgpServer::FillPeerStats, this, _1)); + bool change = false; + uint32_t is_admin_down = admin_down(); + if (first || is_admin_down != state->get_admin_down()) { + state->set_admin_down(is_admin_down); + change = true; + } + + string router_id = bgp_identifier_string(); + if (first || router_id != state->get_router_id()) { + state->set_router_id(router_id); + change = true; + } + + uint32_t local_asn = local_autonomous_system(); + if (first || local_asn != state->get_local_asn()) { + state->set_local_asn(local_asn); + change = true; + } + + uint32_t global_asn = autonomous_system(); + if (first || global_asn != state->get_global_asn()) { + state->set_global_asn(global_asn); + change = true; + } + + uint32_t num_bgp = num_bgp_peer(); + if (first || num_bgp != state->get_num_bgp_peer()) { + state->set_num_bgp_peer(num_bgp); + change = true; + } + + uint32_t num_up_bgp_peer = NumUpPeer(); + if (first || num_up_bgp_peer != state->get_num_up_bgp_peer()) { + state->set_num_up_bgp_peer(num_up_bgp_peer); + change = true; + } + + uint32_t deleting_bgp_peer = num_deleting_bgp_peer(); + if (first || deleting_bgp_peer != state->get_num_deleting_bgp_peer()) { + state->set_num_deleting_bgp_peer(deleting_bgp_peer); + change = true; + } + + uint32_t num_bgpaas = num_bgpaas_peer(); + if (first || num_bgpaas != state->get_num_bgpaas_peer()) { + state->set_num_bgpaas_peer(num_bgpaas); + change = true; + } + + uint32_t num_up_bgpaas_peer = NumUpBgpaasPeer(); + if (first || num_up_bgpaas_peer != state->get_num_up_bgpaas_peer()) { + state->set_num_up_bgpaas_peer(num_up_bgpaas_peer); + change = true; + } + + uint32_t deleting_bgpaas_peer = num_deleting_bgpaas_peer(); + if (first || deleting_bgpaas_peer != + state->get_num_deleting_bgpaas_peer()) { + state->set_num_deleting_bgpaas_peer(deleting_bgpaas_peer); + change = true; + } + + uint32_t num_ri = num_routing_instance(); + if (first || num_ri != state->get_num_routing_instance()) { + state->set_num_routing_instance(num_ri); + change = true; + } + + uint32_t num_deleted_ri = num_deleted_routing_instance(); + if (first || num_deleted_ri != state->get_num_deleted_routing_instance()) { + state->set_num_deleted_routing_instance(num_deleted_ri); + change = true; + } + + uint32_t service_chains = num_service_chains(); + if (first || service_chains != state->get_num_service_chains()) { + state->set_num_service_chains(service_chains); + change = true; + } + + uint32_t down_service_chains = num_down_service_chains(); + if (first || down_service_chains != state->get_num_down_service_chains()) { + state->set_num_down_service_chains(down_service_chains); + change = true; + } + + uint32_t static_routes = num_static_routes(); + if (first || static_routes != state->get_num_static_routes()) { + state->set_num_static_routes(static_routes); + change = true; + } + + uint32_t down_static_routes = num_down_static_routes(); + if (first || down_static_routes != state->get_num_down_static_routes()) { + state->set_num_down_static_routes(down_static_routes); + change = true; + } + + uint32_t out_load = SendTableStatsUve(first); + if (first || out_load != state->get_output_queue_depth()) { + state->set_output_queue_depth(out_load); + change = true; + } + + return change; +} diff --git a/src/bgp/bgp_server.h b/src/bgp/bgp_server.h index cd82ee0873c..41a589ffa0d 100644 --- a/src/bgp/bgp_server.h +++ b/src/bgp/bgp_server.h @@ -28,6 +28,7 @@ class BgpConfigManager; class BgpMembershipManager; class BgpOListDB; class BgpPeer; +class BgpRouterState; class BgpSessionManager; class ClusterListDB; class CommunityDB; @@ -242,6 +243,7 @@ class BgpServer { void NotifyAllStaticRoutes(); uint32_t GetStaticRouteCount() const; uint32_t GetDownStaticRouteCount() const; + bool CollectStats(BgpRouterState *state, bool first) const; private: class ConfigUpdater; @@ -255,6 +257,8 @@ class BgpServer { typedef std::map EndpointToBgpPeerList; void RoutingInstanceMgrDeletionComplete(RoutingInstanceMgr *mgr); + uint32_t SendTableStatsUve(bool first) const; + void FillPeerStats(const BgpPeer *peer) const; // base config variables tbb::spin_rw_mutex rw_mutex_; diff --git a/src/bgp/bgp_table.cc b/src/bgp/bgp_table.cc index 5c30bc64461..ed749e73c7b 100644 --- a/src/bgp/bgp_table.cc +++ b/src/bgp/bgp_table.cc @@ -17,6 +17,7 @@ #include "bgp/bgp_ribout_updates.h" #include "bgp/bgp_route.h" #include "bgp/bgp_server.h" +#include "bgp/bgp_table_types.h" #include "bgp/bgp_update_queue.h" #include "bgp/routing-instance/iroute_aggregator.h" #include "bgp/routing-instance/path_resolver.h" @@ -60,6 +61,7 @@ BgpTable::BgpTable(DB *db, const string &name) : RouteTable(db, name), rtinstance_(NULL), path_resolver_(NULL), + stats_(new BgpTableStats()), instance_delete_ref_(this, NULL) { primary_path_count_ = 0; secondary_path_count_ = 0; @@ -745,7 +747,7 @@ void BgpTable::DestroyPathResolver() { } size_t BgpTable::GetPendingRiboutsCount(size_t *markers) const { - CHECK_CONCURRENCY("bgp::ShowCommand", "bgp::Config"); + CHECK_CONCURRENCY("bgp::ShowCommand", "bgp::Config", "bgp::Uve"); size_t count = 0; *markers = 0; diff --git a/src/bgp/bgp_table.h b/src/bgp/bgp_table.h index b020f894e92..4819126ab5f 100644 --- a/src/bgp/bgp_table.h +++ b/src/bgp/bgp_table.h @@ -17,6 +17,7 @@ #include "route/table.h" class BgpServer; +class BgpTableStats; class BgpRoute; class BgpPath; class IPeer; @@ -148,6 +149,7 @@ class BgpTable : public RouteTable { // Check whether the route is contributing route to aggregate route bool IsContributingRoute(const BgpRoute *route) const; + BgpTableStats *stats() { return stats_.get(); } bool InputCommon(DBTablePartBase *root, BgpRoute *rt, BgpPath *path, const IPeer *peer, DBRequest *req, @@ -172,6 +174,7 @@ class BgpTable : public RouteTable { RoutingInstance *rtinstance_; PathResolver *path_resolver_; RibOutMap ribout_map_; + boost::scoped_ptr stats_; boost::scoped_ptr deleter_; LifetimeRef instance_delete_ref_; diff --git a/src/bgp/bgp_table.sandesh b/src/bgp/bgp_table.sandesh new file mode 100644 index 00000000000..a0e163ece0a --- /dev/null +++ b/src/bgp/bgp_table.sandesh @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + +include "bgp/table_info.sandesh" + +struct RoutingInstanceStatsData { + 1: string name (key="ObjectRoutingInstance"); + 2: optional bool deleted + 3: optional list table_stats (tags=".address_family"); +} + +/** + * @description: RoutingInstance related statistics + * @severity: DEBUG + * @cause: Normal operation + */ +uve sandesh RoutingInstanceStats { + 1: RoutingInstanceStatsData data; +} diff --git a/src/bgp/bgp_xmpp_channel.cc b/src/bgp/bgp_xmpp_channel.cc index 29ff968c4b1..f301cf2b5a7 100644 --- a/src/bgp/bgp_xmpp_channel.cc +++ b/src/bgp/bgp_xmpp_channel.cc @@ -22,10 +22,12 @@ #include "bgp/extended-community/mac_mobility.h" #include "bgp/ermvpn/ermvpn_table.h" #include "bgp/evpn/evpn_table.h" +#include "bgp/peer_stats.h" #include "bgp/rtarget/rtarget_table.h" #include "bgp/scheduling_group.h" #include "bgp/security_group/security_group.h" #include "bgp/tunnel_encap/tunnel_encap.h" +#include "control-node/sandesh/control_node_types.h" #include "net/community_type.h" #include "schema/xmpp_multicast_types.h" #include "schema/xmpp_enet_types.h" @@ -247,7 +249,7 @@ class BgpXmppChannel::PeerClose : public IPeerClose { class BgpXmppChannel::PeerStats : public IPeerDebugStats { public: explicit PeerStats(BgpXmppChannel *peer) - : peer_(peer) { + : parent_(peer) { } // Used when peer flaps. @@ -257,16 +259,16 @@ class BgpXmppChannel::PeerStats : public IPeerDebugStats { // Printable name virtual string ToString() const { - return peer_->ToString(); + return parent_->ToString(); } // Previous State of the peer virtual string last_state() const { - return (peer_->channel_->LastStateName()); + return (parent_->channel_->LastStateName()); } // Last state change occurred at virtual string last_state_change_at() const { - return (peer_->channel_->LastStateChangeAt()); + return (parent_->channel_->LastStateChangeAt()); } // Last error on this peer @@ -276,47 +278,47 @@ class BgpXmppChannel::PeerStats : public IPeerDebugStats { // Last Event on this peer virtual string last_event() const { - return (peer_->channel_->LastEvent()); + return (parent_->channel_->LastEvent()); } // When was the Last virtual string last_flap() const { - return (peer_->channel_->LastFlap()); + return (parent_->channel_->LastFlap()); } // Total number of flaps virtual uint64_t num_flaps() const { - return (peer_->channel_->FlapCount()); + return (parent_->channel_->FlapCount()); } virtual void GetRxProtoStats(ProtoStats *stats) const { - stats->open = peer_->channel_->rx_open(); - stats->close = peer_->channel_->rx_close(); - stats->keepalive = peer_->channel_->rx_keepalive(); - stats->update = peer_->channel_->rx_update(); + stats->open = parent_->channel_->rx_open(); + stats->close = parent_->channel_->rx_close(); + stats->keepalive = parent_->channel_->rx_keepalive(); + stats->update = parent_->channel_->rx_update(); } virtual void GetTxProtoStats(ProtoStats *stats) const { - stats->open = peer_->channel_->tx_open(); - stats->close = peer_->channel_->tx_close(); - stats->keepalive = peer_->channel_->tx_keepalive(); - stats->update = peer_->channel_->tx_update(); + stats->open = parent_->channel_->tx_open(); + stats->close = parent_->channel_->tx_close(); + stats->keepalive = parent_->channel_->tx_keepalive(); + stats->update = parent_->channel_->tx_update(); } virtual void GetRxRouteUpdateStats(UpdateStats *stats) const { - stats->total = peer_->stats_[RX].rt_updates; - stats->reach = peer_->stats_[RX].reach; - stats->unreach = peer_->stats_[RX].unreach; + stats->total = parent_->stats_[RX].rt_updates; + stats->reach = parent_->stats_[RX].reach; + stats->unreach = parent_->stats_[RX].unreach; } virtual void GetTxRouteUpdateStats(UpdateStats *stats) const { - stats->total = peer_->stats_[TX].rt_updates; - stats->reach = peer_->stats_[TX].reach; - stats->unreach = peer_->stats_[TX].unreach; + stats->total = parent_->stats_[TX].rt_updates; + stats->reach = parent_->stats_[TX].reach; + stats->unreach = parent_->stats_[TX].unreach; } virtual void GetRxSocketStats(IPeerDebugStats::SocketStats *stats) const { - const XmppSession *session = peer_->GetSession(); + const XmppSession *session = parent_->GetSession(); if (session) { io::SocketStats socket_stats(session->GetSocketStats()); stats->calls = socket_stats.read_calls; @@ -325,7 +327,7 @@ class BgpXmppChannel::PeerStats : public IPeerDebugStats { } virtual void GetTxSocketStats(IPeerDebugStats::SocketStats *stats) const { - const XmppSession *session = peer_->GetSession(); + const XmppSession *session = parent_->GetSession(); if (session) { io::SocketStats socket_stats(session->GetSocketStats()); stats->calls = socket_stats.write_calls; @@ -337,7 +339,7 @@ class BgpXmppChannel::PeerStats : public IPeerDebugStats { } virtual void GetRxErrorStats(RxErrorStats *stats) const { - const BgpXmppChannel::ErrorStats &err_stats = peer_->error_stats(); + const BgpXmppChannel::ErrorStats &err_stats = parent_->error_stats(); stats->inet6_bad_xml_token_count = err_stats.get_inet6_rx_bad_xml_token_count(); stats->inet6_bad_prefix_count = @@ -348,16 +350,21 @@ class BgpXmppChannel::PeerStats : public IPeerDebugStats { err_stats.get_inet6_rx_bad_afi_safi_count(); } + virtual void GetRxRouteStats(RxRouteStats *stats) const { + stats->total_path_count = parent_->Peer()->GetTotalPathCount(); + stats->primary_path_count = parent_->Peer()->GetPrimaryPathCount(); + } + virtual void UpdateTxUnreachRoute(uint64_t count) { - peer_->stats_[TX].unreach += count; + parent_->stats_[TX].unreach += count; } virtual void UpdateTxReachRoute(uint64_t count) { - peer_->stats_[TX].reach += count; + parent_->stats_[TX].reach += count; } private: - BgpXmppChannel *peer_; + BgpXmppChannel *parent_; }; class BgpXmppChannel::XmppPeer : public IPeer { @@ -368,12 +375,12 @@ class BgpXmppChannel::XmppPeer : public IPeer { is_closed_(false), send_ready_(true), closed_at_(0) { - refcount_ = 0; + total_path_count_ = 0; primary_path_count_ = 0; } virtual ~XmppPeer() { - assert(GetRefCount() == 0); + assert(GetTotalPathCount() == 0); } virtual bool SendUpdate(const uint8_t *msg, size_t msgsize); @@ -436,8 +443,12 @@ class BgpXmppChannel::XmppPeer : public IPeer { return 0; } - virtual void UpdateRefCount(int count) const { refcount_ += count; } - virtual tbb::atomic GetRefCount() const { return refcount_; } + virtual void UpdateTotalPathCount(int count) const { + total_path_count_ += count; + } + virtual int GetTotalPathCount() const { + return total_path_count_; + } virtual void UpdatePrimaryPathCount(int count) const { primary_path_count_ += count; } @@ -461,7 +472,7 @@ class BgpXmppChannel::XmppPeer : public IPeer { BgpServer *server_; BgpXmppChannel *parent_; - mutable tbb::atomic refcount_; + mutable tbb::atomic total_path_count_; mutable tbb::atomic primary_path_count_; bool is_closed_; bool send_ready_; @@ -2455,6 +2466,14 @@ void BgpXmppChannelManager::VisitChannels(BgpXmppChannelManager::VisitorFn fn) { } } +void BgpXmppChannelManager::VisitChannels(BgpXmppChannelManager::VisitorFn fn) + const { + tbb::mutex::scoped_lock lock(mutex_); + BOOST_FOREACH(const XmppChannelMap::value_type &i, channel_map_) { + fn(i.second); + } +} + BgpXmppChannel *BgpXmppChannelManager::FindChannel(string client) { BOOST_FOREACH(XmppChannelMap::value_type &i, channel_map_) { if (i.second->ToString() == client) { @@ -2545,6 +2564,43 @@ void BgpXmppChannelManager::XmppHandleChannelEvent(XmppChannel *channel, } } +void BgpXmppChannelManager::FillPeerStats(const BgpXmppChannel *channel) const { + PeerStatsInfo stats; + PeerStats::FillPeerDebugStats(channel->Peer()->peer_stats(), &stats); + + XmppPeerInfoData peer_info; + peer_info.set_name(channel->Peer()->ToUVEKey()); + peer_info.set_peer_stats_info(stats); + XMPPPeerInfo::Send(peer_info); +} + +bool BgpXmppChannelManager::CollectStats(BgpRouterState *state, bool first) + const { + CHECK_CONCURRENCY("bgp::Uve"); + + VisitChannels(boost::bind(&BgpXmppChannelManager::FillPeerStats, this, _1)); + bool change = false; + uint32_t num_xmpp = count(); + if (first || num_xmpp != state->get_num_xmpp_peer()) { + state->set_num_xmpp_peer(num_xmpp); + change = true; + } + + uint32_t num_up_xmpp = NumUpPeer(); + if (first || num_up_xmpp != state->get_num_up_xmpp_peer()) { + state->set_num_up_xmpp_peer(num_up_xmpp); + change = true; + } + + uint32_t num_deleting_xmpp = deleting_count(); + if (first || num_deleting_xmpp != state->get_num_deleting_xmpp_peer()) { + state->set_num_deleting_xmpp_peer(num_deleting_xmpp); + change = true; + } + + return change; +} + void BgpXmppChannel::Close() { vrf_membership_request_map_.clear(); STLDeleteElements(&defer_q_); diff --git a/src/bgp/bgp_xmpp_channel.h b/src/bgp/bgp_xmpp_channel.h index 832d7f77398..a1f43384a01 100644 --- a/src/bgp/bgp_xmpp_channel.h +++ b/src/bgp/bgp_xmpp_channel.h @@ -26,6 +26,7 @@ namespace pugi { class xml_node; } +class BgpRouterState; class BgpServer; struct DBRequest; class IPeer; @@ -284,6 +285,7 @@ class BgpXmppChannelManager { } void VisitChannels(BgpXmppChannelManager::VisitorFn); + void VisitChannels(BgpXmppChannelManager::VisitorFn) const; BgpXmppChannel *FindChannel(const XmppChannel *channel); BgpXmppChannel *FindChannel(std::string client); void RemoveChannel(XmppChannel *channel); @@ -321,6 +323,7 @@ class BgpXmppChannelManager { uint64_t get_subscription_gen_id() { return subscription_gen_id_.fetch_and_increment(); } + bool CollectStats(BgpRouterState *state, bool first) const; protected: virtual BgpXmppChannel *CreateChannel(XmppChannel *channel); @@ -329,6 +332,8 @@ class BgpXmppChannelManager { friend class BgpXmppChannelManagerMock; friend class BgpXmppUnitTest; + void FillPeerStats(const BgpXmppChannel *channel) const; + XmppServer *xmpp_server_; BgpServer *bgp_server_; WorkQueue queue_; diff --git a/src/bgp/daemon/SConscript b/src/bgp/daemon/SConscript index 213738e93e1..db9540ee679 100644 --- a/src/bgp/daemon/SConscript +++ b/src/bgp/daemon/SConscript @@ -15,6 +15,7 @@ libs = [ 'tunnel_encap', 'origin_vn', 'peer_sandesh', + 'table_sandesh', 'route', 'net', 'db', diff --git a/src/bgp/ermvpn/SConscript b/src/bgp/ermvpn/SConscript index 9fbb95dc402..d7f64cb1033 100644 --- a/src/bgp/ermvpn/SConscript +++ b/src/bgp/ermvpn/SConscript @@ -8,6 +8,8 @@ Import('BuildEnv') env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) libbgp_ermvpn = env.Library('bgp_ermvpn', ['ermvpn_route.cc', 'ermvpn_table.cc']) diff --git a/src/bgp/ermvpn/test/SConscript b/src/bgp/ermvpn/test/SConscript index 2e81cb6e1f6..006a6484b53 100644 --- a/src/bgp/ermvpn/test/SConscript +++ b/src/bgp/ermvpn/test/SConscript @@ -43,9 +43,10 @@ env.Prepend(LIBS = [ 'task_test', 'bgptest', 'bgp', - 'bgp_ifmap_config', + 'bgp_ifmap_config', 'extended_community', 'peer_sandesh', + 'table_sandesh', 'control_node', 'origin_vn', 'routing_instance', diff --git a/src/bgp/evpn/test/SConscript b/src/bgp/evpn/test/SConscript index 3bf77c8516e..df3fd9689b5 100644 --- a/src/bgp/evpn/test/SConscript +++ b/src/bgp/evpn/test/SConscript @@ -43,11 +43,12 @@ env.Prepend(LIBS = [ 'task_test', 'bgptest', 'bgp', - 'bgp_ifmap_config', + 'bgp_ifmap_config', 'bgp_test_factory', 'control_node', 'extended_community', 'peer_sandesh', + 'table_sandesh', 'origin_vn', 'routing_instance', 'routing_policy', diff --git a/src/bgp/inet/SConscript b/src/bgp/inet/SConscript index e18627039df..6f16d64c70d 100644 --- a/src/bgp/inet/SConscript +++ b/src/bgp/inet/SConscript @@ -8,6 +8,8 @@ Import('BuildEnv') env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) libbgp_inet = env.Library('bgp_inet', ['inet_route.cc', diff --git a/src/bgp/inet/test/SConscript b/src/bgp/inet/test/SConscript index f59edfc26ed..0bbcd9f465e 100644 --- a/src/bgp/inet/test/SConscript +++ b/src/bgp/inet/test/SConscript @@ -45,8 +45,9 @@ env.Prepend(LIBS = [ 'task_test', 'bgptest', 'bgp', - 'bgp_ifmap_config', + 'bgp_ifmap_config', 'peer_sandesh', + 'table_sandesh', 'control_node', 'origin_vn', 'routing_instance', diff --git a/src/bgp/inet6/SConscript b/src/bgp/inet6/SConscript index 4446ff44722..241db696559 100644 --- a/src/bgp/inet6/SConscript +++ b/src/bgp/inet6/SConscript @@ -8,6 +8,8 @@ Import('BuildEnv') env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) libbgp_inet6 = env.Library('bgp_inet6', [ diff --git a/src/bgp/inet6/test/SConscript b/src/bgp/inet6/test/SConscript index 445b447d27b..2d2555c1447 100644 --- a/src/bgp/inet6/test/SConscript +++ b/src/bgp/inet6/test/SConscript @@ -45,8 +45,9 @@ env.Prepend(LIBS = [ 'task_test', 'bgptest', 'bgp', - 'bgp_ifmap_config', + 'bgp_ifmap_config', 'peer_sandesh', + 'table_sandesh', 'control_node', 'origin_vn', 'routing_instance', diff --git a/src/bgp/inet6vpn/SConscript b/src/bgp/inet6vpn/SConscript index c3c104b7acc..24ba14aa065 100644 --- a/src/bgp/inet6vpn/SConscript +++ b/src/bgp/inet6vpn/SConscript @@ -8,6 +8,8 @@ Import('BuildEnv') env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) libbgp_inet6vpn = env.Library('bgp_inet6vpn', [ diff --git a/src/bgp/inet6vpn/test/SConscript b/src/bgp/inet6vpn/test/SConscript index da113ea79ed..7b89bb45ef8 100644 --- a/src/bgp/inet6vpn/test/SConscript +++ b/src/bgp/inet6vpn/test/SConscript @@ -46,6 +46,7 @@ env.Prepend(LIBS = [ 'bgp', 'bgp_ifmap_config', 'peer_sandesh', + 'table_sandesh', 'control_node', 'origin_vn', 'routing_instance', diff --git a/src/bgp/ipeer.h b/src/bgp/ipeer.h index 3314d3f3406..4cd26359833 100644 --- a/src/bgp/ipeer.h +++ b/src/bgp/ipeer.h @@ -30,60 +30,83 @@ class IPeerUpdate { class IPeerDebugStats { public: struct ProtoStats { - ProtoStats() : total(0), open(0), keepalive(0), notification(0), - update(0), close(0) { + ProtoStats() { + total = 0; + open = 0; + keepalive = 0; + notification = 0; + update = 0; + close = 0; } - uint64_t total; - uint64_t open; - uint64_t keepalive; - uint64_t notification; - uint64_t update; - uint64_t close; + tbb::atomic total; + tbb::atomic open; + tbb::atomic keepalive; + tbb::atomic notification; + tbb::atomic update; + tbb::atomic close; }; struct ErrorStats { - ErrorStats() - : connect_error(0), - connect_timer(0), - hold_timer(0), - open_error(0), - update_error(0) { + ErrorStats() { + connect_error = 0; + connect_timer = 0; + hold_timer = 0; + open_error = 0; + update_error = 0; } - uint64_t connect_error; - uint64_t connect_timer; - uint64_t hold_timer; - uint64_t open_error; - uint64_t update_error; + tbb::atomic connect_error; + tbb::atomic connect_timer; + tbb::atomic hold_timer; + tbb::atomic open_error; + tbb::atomic update_error; }; struct RxErrorStats { - RxErrorStats() : inet6_bad_xml_token_count(0), - inet6_bad_prefix_count(0), inet6_bad_nexthop_count(0), - inet6_bad_afi_safi_count(0) { + RxErrorStats() { + inet6_bad_xml_token_count = 0; + inet6_bad_prefix_count = 0; + inet6_bad_nexthop_count = 0; + inet6_bad_afi_safi_count = 0; } - uint64_t inet6_bad_xml_token_count; - uint64_t inet6_bad_prefix_count; - uint64_t inet6_bad_nexthop_count; - uint64_t inet6_bad_afi_safi_count; + tbb::atomic inet6_bad_xml_token_count; + tbb::atomic inet6_bad_prefix_count; + tbb::atomic inet6_bad_nexthop_count; + tbb::atomic inet6_bad_afi_safi_count; + }; + + struct RxRouteStats { + RxRouteStats() { + total_path_count = 0; + primary_path_count = 0; + } + tbb::atomic total_path_count; + tbb::atomic primary_path_count; }; struct UpdateStats { - UpdateStats() : end_of_rib(0), total(0), reach(0), unreach(0) { + UpdateStats() { + end_of_rib = 0; + total = 0; + reach = 0; + unreach = 0; } - uint64_t end_of_rib; - uint64_t total; - uint64_t reach; - uint64_t unreach; + tbb::atomic end_of_rib; + tbb::atomic total; + tbb::atomic reach; + tbb::atomic unreach; }; struct SocketStats { - SocketStats() : calls(0), bytes(0), blocked_count(0), - blocked_duration_usecs(0) { + SocketStats() { + calls = 0; + bytes = 0; + blocked_count = 0; + blocked_duration_usecs = 0; } - uint64_t calls; - uint64_t bytes; - uint64_t blocked_count; - uint64_t blocked_duration_usecs; + tbb::atomic calls; + tbb::atomic bytes; + tbb::atomic blocked_count; + tbb::atomic blocked_duration_usecs; }; virtual ~IPeerDebugStats() { } @@ -109,6 +132,7 @@ class IPeerDebugStats { virtual void GetRxRouteUpdateStats(UpdateStats *stats) const = 0; virtual void GetRxSocketStats(SocketStats *stats) const = 0; virtual void GetRxErrorStats(RxErrorStats *stats) const = 0; + virtual void GetRxRouteStats(RxRouteStats *stats) const = 0; virtual void GetTxProtoStats(ProtoStats *stats) const = 0; virtual void GetTxRouteUpdateStats(UpdateStats *stats) const = 0; @@ -167,8 +191,8 @@ class IPeer : public IPeerUpdate { virtual BgpProto::BgpPeerType PeerType() const = 0; virtual uint32_t bgp_identifier() const = 0; virtual const std::string GetStateName() const = 0; - virtual void UpdateRefCount(int count) const = 0; - virtual tbb::atomic GetRefCount() const = 0; + virtual void UpdateTotalPathCount(int count) const = 0; + virtual int GetTotalPathCount() const = 0; virtual void UpdatePrimaryPathCount(int count) const = 0; virtual int GetPrimaryPathCount() const = 0; virtual void MembershipCallback(BgpTable *table) { } diff --git a/src/bgp/l3vpn/SConscript b/src/bgp/l3vpn/SConscript index bae696dc060..3a1fabe801e 100644 --- a/src/bgp/l3vpn/SConscript +++ b/src/bgp/l3vpn/SConscript @@ -8,6 +8,8 @@ Import('BuildEnv') env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) libbgp_l3vpn = env.Library('bgp_l3vpn', ['inetvpn_address.cc', diff --git a/src/bgp/l3vpn/test/SConscript b/src/bgp/l3vpn/test/SConscript index a055b99fc08..9737eb8289b 100644 --- a/src/bgp/l3vpn/test/SConscript +++ b/src/bgp/l3vpn/test/SConscript @@ -49,6 +49,7 @@ env.Prepend(LIBS = [ 'bgp_ifmap_config', 'extended_community', 'peer_sandesh', + 'table_sandesh', 'control_node', 'origin_vn', 'routing_instance', diff --git a/src/bgp/l3vpn/test/inetvpn_table_test.cc b/src/bgp/l3vpn/test/inetvpn_table_test.cc index 867f3ea5623..3f8a89e48e9 100644 --- a/src/bgp/l3vpn/test/inetvpn_table_test.cc +++ b/src/bgp/l3vpn/test/inetvpn_table_test.cc @@ -27,12 +27,8 @@ class BgpPeerMock : public IPeer { BgpProto::BgpPeerType PeerType() const { return BgpProto::IBGP; } virtual uint32_t bgp_identifier() const { return 0; } virtual const std::string GetStateName() const { return "UNKNOWN"; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/peer_info.sandesh b/src/bgp/peer_info.sandesh index 1098469a28d..31b05e2daf7 100644 --- a/src/bgp/peer_info.sandesh +++ b/src/bgp/peer_info.sandesh @@ -54,6 +54,11 @@ struct PeerFlapInfo { 2: optional u64 flap_time; } +struct PeerRxRouteStats { + 1: optional u64 total_path_count; + 2: optional u64 primary_path_count; +} + struct PeerStatsInfo { 1: optional PeerProtoStats rx_proto_stats; 2: optional PeerProtoStats tx_proto_stats; @@ -62,4 +67,5 @@ struct PeerStatsInfo { 5: optional PeerSocketStats rx_socket_stats; 6: optional PeerSocketStats tx_socket_stats; 7: optional PeerRxErrorStats rx_error_stats; + 8: optional PeerRxRouteStats rx_route_stats; } diff --git a/src/bgp/peer_stats.cc b/src/bgp/peer_stats.cc new file mode 100644 index 00000000000..5715c8b7b7f --- /dev/null +++ b/src/bgp/peer_stats.cc @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + +#include "bgp/peer_stats.h" + +void PeerStats::FillProtoStats(const IPeerDebugStats::ProtoStats &stats, + PeerProtoStats *proto_stats) { + proto_stats->open = stats.open; + proto_stats->keepalive = stats.keepalive; + proto_stats->close = stats.close; + proto_stats->update = stats.update; + proto_stats->notification = stats.notification; + proto_stats->total = stats.open + stats.keepalive + stats.close + + stats.update + stats.notification; +} + +void PeerStats::FillRouteUpdateStats(const IPeerDebugStats::UpdateStats &stats, + PeerUpdateStats *rt_stats) { + rt_stats->total = stats.total; + rt_stats->reach = stats.reach; + rt_stats->unreach = stats.unreach; +} + +void PeerStats::FillRxErrorStats(const IPeerDebugStats::RxErrorStats &src, + PeerRxErrorStats *dest) { + dest->inet6_error_stats.bad_inet6_xml_token_count = + src.inet6_bad_xml_token_count; + dest->inet6_error_stats.bad_inet6_prefix_count = + src.inet6_bad_prefix_count; + dest->inet6_error_stats.bad_inet6_nexthop_count = + src.inet6_bad_nexthop_count; + dest->inet6_error_stats.bad_inet6_afi_safi_count = + src.inet6_bad_afi_safi_count; +} + +void PeerStats::FillRxRouteStats(const IPeerDebugStats::RxRouteStats &src, + PeerRxRouteStats *dest) { + dest->total_path_count = src.total_path_count; + dest->primary_path_count = src.primary_path_count; +} + +void PeerStats::FillPeerDebugStats(const IPeerDebugStats *peer_state, + PeerStatsInfo *stats) { + PeerProtoStats proto_stats_tx; + PeerProtoStats proto_stats_rx; + PeerUpdateStats rt_stats_rx; + PeerUpdateStats rt_stats_tx; + PeerRxErrorStats dest_error_stats_rx; + PeerRxRouteStats dest_route_stats_rx; + + IPeerDebugStats::ProtoStats stats_rx; + peer_state->GetRxProtoStats(&stats_rx); + FillProtoStats(stats_rx, &proto_stats_rx); + + IPeerDebugStats::ProtoStats stats_tx; + peer_state->GetTxProtoStats(&stats_tx); + FillProtoStats(stats_tx, &proto_stats_tx); + + IPeerDebugStats::UpdateStats update_stats_rx; + peer_state->GetRxRouteUpdateStats(&update_stats_rx); + FillRouteUpdateStats(update_stats_rx, &rt_stats_rx); + + IPeerDebugStats::UpdateStats update_stats_tx; + peer_state->GetTxRouteUpdateStats(&update_stats_tx); + FillRouteUpdateStats(update_stats_tx, &rt_stats_tx); + + IPeerDebugStats::RxErrorStats src_error_stats_rx; + peer_state->GetRxErrorStats(&src_error_stats_rx); + FillRxErrorStats(src_error_stats_rx, &dest_error_stats_rx); + + IPeerDebugStats::RxRouteStats src_route_stats_rx; + peer_state->GetRxRouteStats(&src_route_stats_rx); + FillRxRouteStats(src_route_stats_rx, &dest_route_stats_rx); + + stats->set_rx_proto_stats(proto_stats_rx); + stats->set_tx_proto_stats(proto_stats_tx); + stats->set_rx_update_stats(rt_stats_rx); + stats->set_tx_update_stats(rt_stats_tx); + stats->set_rx_error_stats(dest_error_stats_rx); + stats->set_rx_route_stats(dest_route_stats_rx); +} diff --git a/src/bgp/peer_stats.h b/src/bgp/peer_stats.h new file mode 100644 index 00000000000..0da306ff696 --- /dev/null +++ b/src/bgp/peer_stats.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + +#ifndef SRC_BGP_PEER_STATS_H_ +#define SRC_BGP_PEER_STATS_H_ + +#include "sandesh/sandesh.h" +#include "bgp/bgp_peer_types.h" +#include "bgp/ipeer.h" + +class PeerStats { +public: + static void FillPeerDebugStats(const IPeerDebugStats *peer_state, + PeerStatsInfo *stats); + +private: + static void FillProtoStats(const IPeerDebugStats::ProtoStats &stats, + PeerProtoStats *proto_stats); + static void FillRouteUpdateStats(const IPeerDebugStats::UpdateStats &stats, + PeerUpdateStats *rt_stats); + static void FillRxErrorStats(const IPeerDebugStats::RxErrorStats &src, + PeerRxErrorStats *dest); + static void FillRxRouteStats(const IPeerDebugStats::RxRouteStats &src, + PeerRxRouteStats *dest); +}; + +#endif // SRC_BGP_PEER_STATS_H_ diff --git a/src/bgp/routing-instance/SConscript b/src/bgp/routing-instance/SConscript index 8794f26e236..c3b6ba8aaa7 100644 --- a/src/bgp/routing-instance/SConscript +++ b/src/bgp/routing-instance/SConscript @@ -11,6 +11,8 @@ env.Append(CPPPATH = env['TOP']) env.Append(CPPPATH = [env['TOP'] + '/bgp']) env.Append(CPPPATH = [env['TOP'] + '/db']) env.Append(CPPPATH = [env['TOP'] + '/io']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) # Generate the source files SandeshGenFiles = env.SandeshGenCpp('routing_instance_analytics.sandesh') diff --git a/src/bgp/routing-instance/static_route.cc b/src/bgp/routing-instance/static_route.cc index 16564da7575..fcd7c451d5f 100644 --- a/src/bgp/routing-instance/static_route.cc +++ b/src/bgp/routing-instance/static_route.cc @@ -911,13 +911,13 @@ void StaticRouteMgr::EnableUnregisterTrigger() { template uint32_t StaticRouteMgr::GetRouteCount() const { - CHECK_CONCURRENCY("bgp::Config"); + CHECK_CONCURRENCY("bgp::Uve"); return static_route_map_.size(); } template uint32_t StaticRouteMgr::GetDownRouteCount() const { - CHECK_CONCURRENCY("bgp::Config"); + CHECK_CONCURRENCY("bgp::Uve"); uint32_t count = 0; for (typename StaticRouteMap::const_iterator it = static_route_map_.begin(); it != static_route_map_.end(); ++it) { diff --git a/src/bgp/routing-policy/SConscript b/src/bgp/routing-policy/SConscript index 27bcbee69c2..5d31d86f450 100644 --- a/src/bgp/routing-policy/SConscript +++ b/src/bgp/routing-policy/SConscript @@ -11,6 +11,8 @@ env.Append(CPPPATH = env['TOP']) env.Append(CPPPATH = [env['TOP'] + '/bgp']) env.Append(CPPPATH = [env['TOP'] + '/db']) env.Append(CPPPATH = [env['TOP'] + '/io']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) # Generate the source files SandeshGenFiles = env.SandeshGenCpp('routing_policy.sandesh') diff --git a/src/bgp/rtarget/test/SConscript b/src/bgp/rtarget/test/SConscript index af3907c9296..fd5e7425b25 100644 --- a/src/bgp/rtarget/test/SConscript +++ b/src/bgp/rtarget/test/SConscript @@ -31,14 +31,13 @@ env.Append(LIBPATH = [env['TOP'] + '/base', env['TOP'] + '/base/test', env['TOP'] + '/schema', env['TOP'] + '/xmpp', env['TOP'] + '/xml']) env.Prepend(LIBS = ['control_test', 'bgptest', 'bgp', 'peer_sandesh', - 'bgp_test_factory', - 'bgp_schema', 'control_node', 'dbtest', - 'ifmap_vnc', 'task_test', + 'table_sandesh', 'bgp_test_factory', 'bgp_schema', + 'control_node', 'dbtest', 'ifmap_vnc', 'task_test', 'ifmap_test_util', 'ifmap_test_util_server', - 'ifmap_server', 'ifmap_common', - 'ifmapio', 'ds', 'pugixml', 'httpc', 'curl', - 'crypto', 'ssl', 'sandesh', 'http', 'http_parser', - 'db', 'sandeshvns', 'io', 'process_info', 'base', 'gunit']) + 'ifmap_server', 'ifmap_common', 'ifmapio', 'ds', + 'pugixml', 'httpc', 'curl', 'crypto', 'ssl', 'sandesh', + 'http', 'http_parser', 'db', 'sandeshvns', 'io', + 'process_info', 'base', 'gunit']) env.Append(LIBS = ['bgp_ermvpn', 'bgp_evpn']) env.Append(LIBS = ['bgp_inet', 'bgp_l3vpn']) diff --git a/src/bgp/table_info.sandesh b/src/bgp/table_info.sandesh new file mode 100644 index 00000000000..a3ab2f0996b --- /dev/null +++ b/src/bgp/table_info.sandesh @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + +struct BgpTableStats { + 1: optional string address_family; + 2: optional u64 prefixes; + 3: optional u64 primary_paths; + 4: optional u64 secondary_paths; + 5: optional u64 infeasible_paths; + 6: optional u64 total_paths; +} diff --git a/src/bgp/test/SConscript b/src/bgp/test/SConscript index 2c2cb6c7c32..6b50feb1546 100644 --- a/src/bgp/test/SConscript +++ b/src/bgp/test/SConscript @@ -67,6 +67,7 @@ env.Prepend(LIBS = ['control_test', 'bgp_ifmap_config', 'bgp_xmpp', 'peer_sandesh', + 'table_sandesh', 'bgp_schema', 'control_node', 'dbtest', 'ifmap_vnc', 'task_test', 'ifmap_test_util', 'ifmap_test_util_server', diff --git a/src/bgp/test/bgp_evpn_manager_test.cc b/src/bgp/test/bgp_evpn_manager_test.cc index 8f131b29329..3336fc76a29 100644 --- a/src/bgp/test/bgp_evpn_manager_test.cc +++ b/src/bgp/test/bgp_evpn_manager_test.cc @@ -31,7 +31,7 @@ class PeerMock : public IPeer { } virtual ~PeerMock() { } - virtual void UpdateRefCount(int count) const { } + virtual void UpdateTotalPathCount(int count) const { } int index() { return index_; } @@ -112,12 +112,8 @@ class PeerMock : public IPeer { virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/bgp_ip_test.cc b/src/bgp/test/bgp_ip_test.cc index f22fd77b913..6f39b979127 100644 --- a/src/bgp/test/bgp_ip_test.cc +++ b/src/bgp/test/bgp_ip_test.cc @@ -43,12 +43,8 @@ class PeerMock : public IPeer { return htonl(address_.to_ulong()); } virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/bgp_multicast_test.cc b/src/bgp/test/bgp_multicast_test.cc index b8c7a932508..82c53b8a452 100644 --- a/src/bgp/test/bgp_multicast_test.cc +++ b/src/bgp/test/bgp_multicast_test.cc @@ -79,12 +79,8 @@ class XmppPeerMock : public IPeer { virtual uint32_t bgp_identifier() const { return address_.to_ulong(); } virtual const std::string GetStateName() const { return ""; } virtual bool SendUpdate(const uint8_t *msg, size_t msgsize) { return true; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/bgp_route_test.cc b/src/bgp/test/bgp_route_test.cc index 8bdb01cb18f..ce286c45924 100644 --- a/src/bgp/test/bgp_route_test.cc +++ b/src/bgp/test/bgp_route_test.cc @@ -41,12 +41,8 @@ class PeerMock : public IPeer { virtual const string GetStateName() const { return "Established"; } BgpProto::BgpPeerType PeerType() const { return peer_type_; } virtual uint32_t bgp_identifier() const { return address_.to_ulong(); } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/bgp_table_export_test.cc b/src/bgp/test/bgp_table_export_test.cc index 70c0d783c8b..6dc06fb0105 100644 --- a/src/bgp/test/bgp_table_export_test.cc +++ b/src/bgp/test/bgp_table_export_test.cc @@ -81,12 +81,8 @@ class BgpTestPeer : public IPeer { } virtual uint32_t bgp_identifier() const { return 0; } virtual const string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/path_resolver_test.cc b/src/bgp/test/path_resolver_test.cc index a9639d3a983..bb9b9746b1b 100644 --- a/src/bgp/test/path_resolver_test.cc +++ b/src/bgp/test/path_resolver_test.cc @@ -59,12 +59,8 @@ class PeerMock : public IPeer { return htonl(address_.to_ulong()); } virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/ribout_attributes_test.cc b/src/bgp/test/ribout_attributes_test.cc index 7d6d6a8fd3c..2fc353876b5 100644 --- a/src/bgp/test/ribout_attributes_test.cc +++ b/src/bgp/test/ribout_attributes_test.cc @@ -26,12 +26,8 @@ class BgpPeerMock : public IPeer { BgpProto::BgpPeerType PeerType() const { return BgpProto::IBGP; } virtual uint32_t bgp_identifier() const { return 0; } virtual const std::string GetStateName() const { return "UNKNOWN"; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/route_aggregator_test.cc b/src/bgp/test/route_aggregator_test.cc index 25d1891fd99..412a189c11c 100644 --- a/src/bgp/test/route_aggregator_test.cc +++ b/src/bgp/test/route_aggregator_test.cc @@ -90,12 +90,8 @@ class BgpPeerMock : public IPeer { virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/routepath_replicator_random_test.cc b/src/bgp/test/routepath_replicator_random_test.cc index b440984398f..cfec2f468e5 100644 --- a/src/bgp/test/routepath_replicator_random_test.cc +++ b/src/bgp/test/routepath_replicator_random_test.cc @@ -98,12 +98,8 @@ class BgpPeerMock : public IPeer { virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/routepath_replicator_test.cc b/src/bgp/test/routepath_replicator_test.cc index 04dc6b38cb5..6966a0ab6a1 100644 --- a/src/bgp/test/routepath_replicator_test.cc +++ b/src/bgp/test/routepath_replicator_test.cc @@ -67,12 +67,8 @@ class BgpPeerMock : public IPeer { virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/routing_policy_test.cc b/src/bgp/test/routing_policy_test.cc index 65dbf9115e7..cc0d0e6af67 100644 --- a/src/bgp/test/routing_policy_test.cc +++ b/src/bgp/test/routing_policy_test.cc @@ -92,12 +92,8 @@ class BgpPeerMock : public IPeer { virtual const std::string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/service_chain_test.cc b/src/bgp/test/service_chain_test.cc index 15a391829f0..025fd68d67a 100644 --- a/src/bgp/test/service_chain_test.cc +++ b/src/bgp/test/service_chain_test.cc @@ -99,12 +99,8 @@ class BgpPeerMock : public IPeer { virtual const string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } diff --git a/src/bgp/test/static_route_test.cc b/src/bgp/test/static_route_test.cc index d908915d52b..7bb04e376d3 100644 --- a/src/bgp/test/static_route_test.cc +++ b/src/bgp/test/static_route_test.cc @@ -95,12 +95,8 @@ class BgpPeerMock : public IPeer { virtual const string GetStateName() const { return ""; } - virtual void UpdateRefCount(int count) const { } - virtual tbb::atomic GetRefCount() const { - tbb::atomic count; - count = 0; - return count; - } + virtual void UpdateTotalPathCount(int count) const { } + virtual int GetTotalPathCount() const { return 0; } virtual void UpdatePrimaryPathCount(int count) const { } virtual int GetPrimaryPathCount() const { return 0; } @@ -772,12 +768,12 @@ class StaticRouteTest : public ::testing::Test { } void VerifyStaticRouteCount(uint32_t count) { - ConcurrencyScope scope("bgp::Config"); + ConcurrencyScope scope("bgp::Uve"); TASK_UTIL_EXPECT_EQ(count, bgp_server_->num_static_routes()); } void VerifyDownStaticRouteCount(uint32_t count) { - ConcurrencyScope scope("bgp::Config"); + ConcurrencyScope scope("bgp::Uve"); TASK_UTIL_EXPECT_EQ(count, bgp_server_->num_down_static_routes()); } diff --git a/src/control-node/SConscript b/src/control-node/SConscript index b9d8eb20e95..fda65cad3de 100644 --- a/src/control-node/SConscript +++ b/src/control-node/SConscript @@ -74,6 +74,7 @@ env.Prepend(LIBS=['bgp', 'xmpp_enet', 'control_node', 'peer_sandesh', + 'table_sandesh', 'origin_vn', 'routing_instance', 'routing_policy', diff --git a/src/control-node/control_node.cc b/src/control-node/control_node.cc index ddadfc51049..b78e08ea3c2 100644 --- a/src/control-node/control_node.cc +++ b/src/control-node/control_node.cc @@ -42,6 +42,7 @@ void ControlNode::SetDefaultSchedulingPolicy() { (TaskExclusion(scheduler->GetTaskId("bgp::ShowCommand"))) (TaskExclusion(scheduler->GetTaskId("bgp::SendReadyTask"))) (TaskExclusion(scheduler->GetTaskId("bgp::StaticRoute"))) + (TaskExclusion(scheduler->GetTaskId("bgp::Uve"))) (TaskExclusion(scheduler->GetTaskId("bgp::RouteAggregation"))) (TaskExclusion(scheduler->GetTaskId("bgp::ResolverPath"))) (TaskExclusion(scheduler->GetTaskId("bgp::ResolverNexthop"))); diff --git a/src/control-node/main.cc b/src/control-node/main.cc index 7025245f638..b2f6092f561 100644 --- a/src/control-node/main.cc +++ b/src/control-node/main.cc @@ -173,315 +173,68 @@ static void ShutdownServers( WaitForIdle(); } -bool ControlNodeInfoLogTimer(TaskTrigger *node_info_trigger) { +static bool ControlNodeInfoLogTimer(TaskTrigger *node_info_trigger) { node_info_trigger->Set(); // Periodic timer. Restart return true; } -bool ControlNodeVersion(string &build_info_str) { - return MiscUtils::GetBuildInfo(MiscUtils::ControlNode, BuildInfo, - build_info_str); -} - -static void FillProtoStats(const IPeerDebugStats::ProtoStats &stats, - PeerProtoStats *proto_stats) { - proto_stats->open = stats.open; - proto_stats->keepalive = stats.keepalive; - proto_stats->close = stats.close; - proto_stats->update = stats.update; - proto_stats->notification = stats.notification; - proto_stats->total = stats.open + stats.keepalive + stats.close + - stats.update + stats.notification; -} - -static void FillRouteUpdateStats(const IPeerDebugStats::UpdateStats &stats, - PeerUpdateStats *rt_stats) { - rt_stats->total = stats.total; - rt_stats->reach = stats.reach; - rt_stats->unreach = stats.unreach; -} - -static void FillRxErrorStats(const IPeerDebugStats::RxErrorStats &src, - PeerRxErrorStats *dest) { - dest->inet6_error_stats.bad_inet6_xml_token_count = - src.inet6_bad_xml_token_count; - dest->inet6_error_stats.bad_inet6_prefix_count = - src.inet6_bad_prefix_count; - dest->inet6_error_stats.bad_inet6_nexthop_count = - src.inet6_bad_nexthop_count; - dest->inet6_error_stats.bad_inet6_afi_safi_count = - src.inet6_bad_afi_safi_count; -} - -static void FillPeerDebugStats(const IPeerDebugStats *peer_state, - PeerStatsInfo *stats) { - PeerProtoStats proto_stats_tx; - PeerProtoStats proto_stats_rx; - PeerUpdateStats rt_stats_rx; - PeerUpdateStats rt_stats_tx; - PeerRxErrorStats dest_error_stats_rx; - - IPeerDebugStats::ProtoStats stats_rx; - peer_state->GetRxProtoStats(&stats_rx); - FillProtoStats(stats_rx, &proto_stats_rx); - - IPeerDebugStats::ProtoStats stats_tx; - peer_state->GetTxProtoStats(&stats_tx); - FillProtoStats(stats_tx, &proto_stats_tx); - - IPeerDebugStats::UpdateStats update_stats_rx; - peer_state->GetRxRouteUpdateStats(&update_stats_rx); - FillRouteUpdateStats(update_stats_rx, &rt_stats_rx); - - IPeerDebugStats::UpdateStats update_stats_tx; - peer_state->GetTxRouteUpdateStats(&update_stats_tx); - FillRouteUpdateStats(update_stats_tx, &rt_stats_tx); - - IPeerDebugStats::RxErrorStats src_error_stats_rx; - peer_state->GetRxErrorStats(&src_error_stats_rx); - FillRxErrorStats(src_error_stats_rx, &dest_error_stats_rx); - - stats->set_rx_proto_stats(proto_stats_rx); - stats->set_tx_proto_stats(proto_stats_tx); - stats->set_rx_update_stats(rt_stats_rx); - stats->set_tx_update_stats(rt_stats_tx); - stats->set_rx_error_stats(dest_error_stats_rx); -} - -void FillXmppPeerStats(BgpServer *server, BgpXmppChannel *channel) { - PeerStatsInfo stats; - FillPeerDebugStats(channel->Peer()->peer_stats(), &stats); - - XmppPeerInfoData peer_info; - peer_info.set_name(channel->Peer()->ToUVEKey()); - peer_info.set_peer_stats_info(stats); - XMPPPeerInfo::Send(peer_info); -} - -void FillBgpPeerStats(BgpServer *server, BgpPeer *peer) { - PeerStatsInfo stats; - FillPeerDebugStats(peer->peer_stats(), &stats); - - BgpPeerInfoData peer_info; - peer_info.set_name(peer->ToUVEKey()); - peer_info.set_peer_stats_info(stats); - BGPPeerInfo::Send(peer_info); -} - -void LogControlNodePeerStats(BgpServer *server, - BgpXmppChannelManager *xmpp_channel_mgr) { - xmpp_channel_mgr->VisitChannels(boost::bind(FillXmppPeerStats, - server, _1)); - server->VisitBgpPeers(boost::bind(FillBgpPeerStats, server, _1)); -} - -bool ControlNodeInfoLogger(BgpServer *server, - BgpXmppChannelManager *xmpp_channel_mgr, - IFMapServer *ifmap_server, - uint64_t start_time, - Timer *node_info_log_timer) { - LogControlNodePeerStats(server, xmpp_channel_mgr); - - BgpRouterState state; - static BgpRouterState prev_state; - static bool first = true, build_info_set = false; - bool change = false; - +static bool ControlNodeInfoLogger(BgpServer *server, + BgpXmppChannelManager *xmpp_channel_mgr, + IFMapServer *ifmap_server, + Timer *node_info_log_timer) { + // Send CPU usage Information. CpuLoadInfo cpu_load_info; CpuLoadData::FillCpuInfo(cpu_load_info, false); - state.set_name(server->localname()); - - uint32_t admin_down = server->admin_down(); - if (admin_down != prev_state.get_admin_down() || first) { - state.set_admin_down(admin_down); - prev_state.set_admin_down(admin_down); - change = true; - } - - string router_id = server->bgp_identifier_string(); - if (router_id != prev_state.get_router_id() || first) { - state.set_router_id(router_id); - prev_state.set_router_id(router_id); - change = true; - } - - uint32_t local_asn = server->local_autonomous_system(); - if (local_asn != prev_state.get_local_asn() || first) { - state.set_local_asn(local_asn); - prev_state.set_local_asn(local_asn); - change = true; - } - - uint32_t global_asn = server->autonomous_system(); - if (global_asn != prev_state.get_global_asn() || first) { - state.set_global_asn(global_asn); - prev_state.set_global_asn(global_asn); - change = true; - } - - if (first) { - state.set_uptime(start_time); - vector ip_list; - ip_list.push_back(ControlNode::GetSelfIp()); - state.set_bgp_router_ip_list(ip_list); - vector list; - MiscUtils::GetCoreFileList(ControlNode::GetProgramName(), list); - if (list.size()) { - state.set_core_files_list(list); - } - } - if (!build_info_set) { - string build_info; - build_info_set = ControlNodeVersion(build_info); - if (build_info != prev_state.get_build_info()) { - state.set_build_info(build_info); - prev_state.set_build_info(build_info); - change = true; - } - } - SendCpuInfoStat(server->localname(), - cpu_load_info); + cpu_load_info); - uint32_t num_xmpp = xmpp_channel_mgr->count(); - if (num_xmpp != prev_state.get_num_xmpp_peer() || first) { - state.set_num_xmpp_peer(num_xmpp); - prev_state.set_num_xmpp_peer(num_xmpp); - change = true; - } - - uint32_t num_up_xmpp = xmpp_channel_mgr->NumUpPeer(); - if (num_up_xmpp != prev_state.get_num_up_xmpp_peer() || first) { - state.set_num_up_xmpp_peer(num_up_xmpp); - prev_state.set_num_up_xmpp_peer(num_up_xmpp); - change = true; - } - - uint32_t num_deleting_xmpp = xmpp_channel_mgr->deleting_count(); - if (num_deleting_xmpp != prev_state.get_num_deleting_xmpp_peer() || first) { - state.set_num_deleting_xmpp_peer(num_deleting_xmpp); - prev_state.set_num_deleting_xmpp_peer(num_deleting_xmpp); - change = true; - } - - uint32_t num_bgp = server->num_bgp_peer(); - if (num_bgp != prev_state.get_num_bgp_peer() || first) { - state.set_num_bgp_peer(num_bgp); - prev_state.set_num_bgp_peer(num_bgp); - change = true; - } - - uint32_t num_up_bgp_peer = server->NumUpPeer(); - if (num_up_bgp_peer != prev_state.get_num_up_bgp_peer() || first) { - state.set_num_up_bgp_peer(num_up_bgp_peer); - prev_state.set_num_up_bgp_peer(num_up_bgp_peer); - change = true; - } - - uint32_t num_deleting_bgp_peer = server->num_deleting_bgp_peer(); - if (num_deleting_bgp_peer != prev_state.get_num_deleting_bgp_peer() || - first) { - state.set_num_deleting_bgp_peer(num_deleting_bgp_peer); - prev_state.set_num_deleting_bgp_peer(num_deleting_bgp_peer); - 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_deleting_bgpaas_peer = server->num_deleting_bgpaas_peer(); - if (num_deleting_bgpaas_peer != prev_state.get_num_deleting_bgpaas_peer() || - first) { - state.set_num_deleting_bgpaas_peer(num_deleting_bgpaas_peer); - prev_state.set_num_deleting_bgpaas_peer(num_deleting_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); - prev_state.set_num_routing_instance(num_ri); - change = true; - } + static bool first = true; + static BgpRouterState state; + bool change = false; - uint32_t num_deleted_ri = server->num_deleted_routing_instance(); - if (num_deleted_ri != prev_state.get_num_deleted_routing_instance() || - first) { - state.set_num_deleted_routing_instance(num_deleted_ri); - prev_state.set_num_deleted_routing_instance(num_deleted_ri); - change = true; - } + state.set_name(server->localname()); - uint32_t num_service_chains = server->num_service_chains(); - if (num_service_chains != prev_state.get_num_service_chains() || - first) { - state.set_num_service_chains(num_service_chains); - prev_state.set_num_service_chains(num_service_chains); + // Send self information. + uint64_t start_time = UTCTimestampUsec(); + if (first || start_time != state.get_uptime()) { + state.set_uptime(start_time); change = true; } - uint32_t num_down_service_chains = server->num_down_service_chains(); - if (num_down_service_chains != prev_state.get_num_down_service_chains() || - first) { - state.set_num_down_service_chains(num_down_service_chains); - prev_state.set_num_down_service_chains(num_down_service_chains); + vector ip_list; + ip_list.push_back(ControlNode::GetSelfIp()); + if (first || state.get_bgp_router_ip_list() != ip_list) { + state.set_bgp_router_ip_list(ip_list); change = true; } - uint32_t num_static_routes = server->num_static_routes(); - if (num_static_routes != prev_state.get_num_static_routes() || - first) { - state.set_num_static_routes(num_static_routes); - prev_state.set_num_static_routes(num_static_routes); + vector list; + MiscUtils::GetCoreFileList(ControlNode::GetProgramName(), list); + if (first || state.get_core_files_list() != list) { + state.set_core_files_list(list); change = true; } - uint32_t num_down_static_routes = server->num_down_static_routes(); - if (num_down_static_routes != prev_state.get_num_down_static_routes() || - first) { - state.set_num_down_static_routes(num_down_static_routes); - prev_state.set_num_down_static_routes(num_down_static_routes); + // Send Build information. + string build_info; + MiscUtils::GetBuildInfo(MiscUtils::ControlNode, BuildInfo, build_info); + if (first || build_info != state.get_build_info()) { + state.set_build_info(build_info); change = true; } - IFMapPeerServerInfoUI peer_server_info; - ifmap_server->get_ifmap_manager()->GetPeerServerInfo(peer_server_info); - if (peer_server_info != prev_state.get_ifmap_info() || first) { - state.set_ifmap_info(peer_server_info); - prev_state.set_ifmap_info(peer_server_info); - change = true; - } + change |= server->CollectStats(&state, first); + change |= xmpp_channel_mgr->CollectStats(&state, first); + change |= ifmap_server->CollectStats(&state, first); - IFMapServerInfoUI server_info; - ifmap_server->GetUIInfo(&server_info); - if (server_info != prev_state.get_ifmap_server_info() || first) { - state.set_ifmap_server_info(server_info); - prev_state.set_ifmap_server_info(server_info); - change = true; - } + if (change) { + BGPRouterInfo::Send(state); - uint32_t out_load = server->get_output_queue_depth(); - if (out_load != prev_state.get_output_queue_depth() || first) { - state.set_output_queue_depth(out_load); - prev_state.set_output_queue_depth(out_load); - change = true; + // Reset changed flags in the uve structure. + memset(&state.__isset, 0, sizeof(state.__isset)); } - if (change) - BGPRouterInfo::Send(state); - first = false; return true; } @@ -773,7 +526,6 @@ int main(int argc, char *argv[]) { ifmap_manager->InitializeDiscovery(ds_client, options.ifmap_server_url()); CpuLoadData::Init(); - uint64_t start_time = UTCTimestampUsec(); std::auto_ptr node_info_log_timer( TimerManager::CreateTimer( @@ -783,9 +535,8 @@ int main(int argc, char *argv[]) { new TaskTrigger( boost::bind(&ControlNodeInfoLogger, bgp_server.get(), bgp_peer_manager.get(), - &ifmap_server, - start_time, node_info_log_timer.get()), - TaskScheduler::GetInstance()->GetTaskId("bgp::Config"), 0)); + &ifmap_server, node_info_log_timer.get()), + TaskScheduler::GetInstance()->GetTaskId("bgp::Uve"), 0)); // Start periodic timer to send BGPRouterInfo UVE. node_info_log_timer->Start( diff --git a/src/dns/SConscript b/src/dns/SConscript index 9ed7908e4d3..293bcbccade 100644 --- a/src/dns/SConscript +++ b/src/dns/SConscript @@ -21,7 +21,7 @@ env.Prepend(CPPPATH = env['TOP'] + '/discovery/client') env.Prepend(CPPPATH = env['TOP'] + '/http/client') env.Prepend(LIBS=['ifmap_vnc', 'ifmap_server', 'ifmap_common', 'net', 'ifmapio', - 'xmpp', 'ds', 'sandeshvns', 'sandesh', 'peer_sandesh', + 'xmpp', 'ds', 'sandeshvns', 'sandesh', 'peer_sandesh', 'table_sandesh', 'httpc', 'http', 'http_parser', 'curl', 'process_info', 'db', 'io', 'base', 'xml', 'pugixml', 'libxml2', 'boost_regex', 'boost_chrono', 'boost_program_options', diff --git a/src/ifmap/SConscript b/src/ifmap/SConscript index e2c3777362b..dae1496e5e6 100644 --- a/src/ifmap/SConscript +++ b/src/ifmap/SConscript @@ -9,10 +9,14 @@ env = BuildEnv.Clone() env.CppDisableExceptions() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) env.Append(CPPPATH = env['TOP'] + '/discovery/client') env.Prepend(LIBS=['ds', 'sandesh', 'http', 'http_parser', 'curl', 'io', 'base']) except_env = BuildEnv.Clone() +except_env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +except_env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) except_env.CppEnableExceptions() except_env.Append(CPPPATH = env['TOP']) diff --git a/src/ifmap/client/SConscript b/src/ifmap/client/SConscript index 0f9610c4891..75cd309cb1f 100644 --- a/src/ifmap/client/SConscript +++ b/src/ifmap/client/SConscript @@ -7,6 +7,8 @@ Import('BuildEnv') env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) +env.Append(CPPPATH = [env['TOP'] + '/ifmap']) +env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) env.Prepend(LIBS=['io', 'base']) except_env = BuildEnv.Clone() diff --git a/src/ifmap/client/ifmap_manager.cc b/src/ifmap/client/ifmap_manager.cc index deeb27ff322..bf01cd4dbfb 100644 --- a/src/ifmap/client/ifmap_manager.cc +++ b/src/ifmap/client/ifmap_manager.cc @@ -57,10 +57,10 @@ bool IFMapManager::GetEndOfRibComputed() const { return channel_->end_of_rib_computed(); } -void IFMapManager::GetPeerServerInfo(IFMapPeerServerInfoUI &server_info) { - server_info.set_url(get_host_port()); - server_info.set_connection_status(channel_->get_connection_status()); - server_info.set_connection_status_change_at( +void IFMapManager::GetPeerServerInfo(IFMapPeerServerInfoUI *server_info) { + server_info->set_url(get_host_port()); + server_info->set_connection_status(channel_->get_connection_status()); + server_info->set_connection_status_change_at( channel_->get_connection_status_change_at()); } diff --git a/src/ifmap/client/ifmap_manager.h b/src/ifmap/client/ifmap_manager.h index 20d4c9287f9..1fb7fdbcf57 100644 --- a/src/ifmap/client/ifmap_manager.h +++ b/src/ifmap/client/ifmap_manager.h @@ -48,7 +48,7 @@ class IFMapManager { std::string get_url(); uint64_t GetChannelSequenceNumber(); bool GetEndOfRibComputed() const; - void GetPeerServerInfo(IFMapPeerServerInfoUI &server_info); + void GetPeerServerInfo(IFMapPeerServerInfoUI *server_info); void RetrieveStaticHostPort(const std::string& url); void GetAllDSPeerInfo(IFMapDSPeerInfo *ds_peer_info); bool get_init_done(); diff --git a/src/ifmap/client/test/SConscript b/src/ifmap/client/test/SConscript index 5dfdbb9f6a3..6a780599210 100644 --- a/src/ifmap/client/test/SConscript +++ b/src/ifmap/client/test/SConscript @@ -33,10 +33,10 @@ env.Install(env['TOP_LIB'], libboostssltest) env.Prepend(LIBS = [ 'boostssl', 'ifmapio', 'ifmap_server', 'ds', 'xmpp', 'peer_sandesh', - 'sandesh', 'http', 'http_parser', 'httpc', 'curl', - 'sandeshvns', 'process_info', 'io', 'ifmap_common', 'ifmap_vnc', - 'pugixml', 'xml', 'task_test', 'db', 'curl', 'base', - 'gunit', 'crypto', 'ssl', 'boost_regex' + 'table_sandesh', 'sandesh', 'http', 'http_parser', 'httpc', + 'curl', 'sandeshvns', 'process_info', 'io', 'ifmap_common', + 'ifmap_vnc', 'pugixml', 'xml', 'task_test', 'db', 'curl', + 'base', 'gunit', 'crypto', 'ssl', 'boost_regex' ]) if sys.platform != 'darwin': diff --git a/src/ifmap/ifmap_server.cc b/src/ifmap/ifmap_server.cc index 0ae7b1a80f1..42be1b8a9d1 100644 --- a/src/ifmap/ifmap_server.cc +++ b/src/ifmap/ifmap_server.cc @@ -32,6 +32,9 @@ #include "ifmap/ifmap_uuid_mapper.h" #include "schema/vnc_cfg_types.h" +#include "sandesh/sandesh.h" +#include "control-node/sandesh/control_node_types.h" + using std::make_pair; class IFMapServer::IFMapStaleEntriesCleaner : public Task { @@ -514,6 +517,28 @@ void IFMapServer::FillClientHistory(IFMapServerClientHistoryList *out_list, out_list->set_print_count(out_list->clients.size()); } -void IFMapServer::GetUIInfo(IFMapServerInfoUI *server_info) { +void IFMapServer::GetUIInfo(IFMapServerInfoUI *server_info) const { server_info->set_num_peer_clients(GetClientMapSize()); } + +bool IFMapServer::CollectStats(BgpRouterState *state, bool first) const { + CHECK_CONCURRENCY("bgp::Uve"); + + IFMapPeerServerInfoUI peer_server_info; + bool change = false; + + get_ifmap_manager()->GetPeerServerInfo(&peer_server_info); + if (first || peer_server_info != state->get_ifmap_info()) { + state->set_ifmap_info(peer_server_info); + change = true; + } + + IFMapServerInfoUI server_info; + GetUIInfo(&server_info); + if (first || server_info != state->get_ifmap_server_info()) { + state->set_ifmap_server_info(server_info); + change = true; + } + + return change; +} diff --git a/src/ifmap/ifmap_server.h b/src/ifmap/ifmap_server.h index 2b840fb68ad..11b8b5fd182 100644 --- a/src/ifmap/ifmap_server.h +++ b/src/ifmap/ifmap_server.h @@ -18,6 +18,7 @@ #include "base/queue_task.h" #include "ifmap/client/ifmap_manager.h" +class BgpRouterState; class DB; class DBGraph; class DBGraphEdge; @@ -88,9 +89,8 @@ class IFMapServer { void set_ifmap_manager(IFMapManager *manager) { ifmap_manager_ = manager; } - IFMapManager *get_ifmap_manager() { - return ifmap_manager_; - } + IFMapManager *get_ifmap_manager() { return ifmap_manager_; } + IFMapManager *get_ifmap_manager() const { return ifmap_manager_; } virtual uint64_t get_ifmap_channel_sequence_number() { return ifmap_manager_->GetChannelSequenceNumber(); } @@ -121,9 +121,10 @@ class IFMapServer { const std::string &search_string); const CmSz_t GetClientMapSize() const { return client_map_.size(); } const CmSz_t GetIndexMapSize() const { return index_map_.size(); } - void GetUIInfo(IFMapServerInfoUI *server_info); + void GetUIInfo(IFMapServerInfoUI *server_info) const; bool ClientNameToIndex(const std::string &id, int *index); bool ProcessStaleEntriesTimeout(); + bool CollectStats(BgpRouterState *state, bool first) const; private: friend class IFMapServerTest; diff --git a/src/ifmap/test/SConscript b/src/ifmap/test/SConscript index 7aad7ee49c4..3372c029d21 100644 --- a/src/ifmap/test/SConscript +++ b/src/ifmap/test/SConscript @@ -21,8 +21,8 @@ env.Append(LIBPATH = env['TOP'] + '/discovery/client') env.Append(LIBPATH = env['TOP'] + '/http/client') env.Prepend(LIBS = ['ifmap_server', 'ifmapio', 'ds', 'xmpp', 'peer_sandesh', - 'sandesh', 'http', 'http_parser', 'httpc', 'curl', - 'sandeshvns', 'process_info', 'io', 'control_node', + 'table_sandesh', 'sandesh', 'http', 'http_parser', 'httpc', + 'curl', 'sandeshvns', 'process_info', 'io', 'control_node', 'ifmap_common', 'pugixml', 'xml', 'db', 'base', 'gunit', 'crypto', 'ssl', 'boost_regex', 'boost_chrono', 'boost_program_options']) diff --git a/src/ksync/test/SConscript b/src/ksync/test/SConscript index df94b678167..f2a4345da2c 100644 --- a/src/ksync/test/SConscript +++ b/src/ksync/test/SConscript @@ -18,12 +18,12 @@ env.Prepend(CPPPATH = '#/third_party/thrift-0.8.0/lib/cpp/src/') env.Prepend(CPPPATH = env['TOP'] + '/discovery/client') env.Prepend(CPPPATH = env['TOP'] + '/http/client') -env.Prepend(LIBS=['thrift','xmpp', 'peer_sandesh', 'xmpp_unicast', - 'xmpp_multicast', 'ds', 'services', +env.Prepend(LIBS=['thrift','xmpp', 'peer_sandesh', 'table_sandesh', + 'xmpp_unicast', 'xmpp_multicast', 'ds', 'services', 'xml', 'pugixml', 'route', - 'bgp_schema', 'ifmap_vnc', 'ifmap_agent', 'ifmap_common', + 'bgp_schema', 'ifmap_vnc', 'ifmap_agent', 'ifmap_common', 'sandeshflow', 'sandesh', 'httpc', 'http', 'http_parser', 'curl', - 'process_info', 'db', 'base', 'task_test', 'io', 'sandeshvns', 'net', + 'process_info', 'db', 'base', 'task_test', 'io', 'sandeshvns', 'net', 'gunit', 'boost_regex', 'boost_filesystem', 'cpuinfo', 'pugixml']) diff --git a/src/vnsw/agent/SConscript b/src/vnsw/agent/SConscript index fc7834b8f9e..2af68634736 100644 --- a/src/vnsw/agent/SConscript +++ b/src/vnsw/agent/SConscript @@ -107,6 +107,7 @@ env.Append(LIBPATH = MapBuildDir([ env.Prepend(LIBS = [ 'xmpp', 'peer_sandesh', + 'table_sandesh', 'xmpp_multicast', 'xmpp_enet', 'xmpp_unicast', diff --git a/src/xmpp/test/SConscript b/src/xmpp/test/SConscript index 4916b15a638..921711e6561 100644 --- a/src/xmpp/test/SConscript +++ b/src/xmpp/test/SConscript @@ -27,7 +27,7 @@ libxmpptest = env.Library('xmpptest', env.Prepend(LIBS = ['task_test', 'gunit', 'xmpp', 'xml', 'pugixml', 'sandesh', 'http', 'http_parser', 'curl', 'process_info', 'io', 'ssl', 'crypto', 'sandeshvns', 'base', 'peer_sandesh', - 'boost_regex', 'xmpptest', 'control_node']) + 'table_sandesh', 'boost_regex', 'xmpptest', 'control_node']) if sys.platform != 'darwin': env.Append(LIBS = ['rt']) diff --git a/src/xmpp/xmpp_connection.h b/src/xmpp/xmpp_connection.h index 02d509f8bfe..39c07e0c1cb 100644 --- a/src/xmpp/xmpp_connection.h +++ b/src/xmpp/xmpp_connection.h @@ -7,6 +7,7 @@ #include #include +#include #include #include "base/timer.h" @@ -29,23 +30,31 @@ class XmppSession; class XmppConnection { public: struct ProtoStats { - ProtoStats() : open(0), close(0), keepalive(0), update(0) { + ProtoStats() { + open = 0; + close = 0; + keepalive = 0; + update = 0; } - uint32_t open; - uint32_t close; - uint32_t keepalive; - uint32_t update; + tbb::atomic open; + tbb::atomic close; + tbb::atomic keepalive; + tbb::atomic update; }; struct ErrorStats { - ErrorStats() : connect_error(0), session_close(0), open_fail(0), - stream_feature_fail(0), handshake_fail(0) { + ErrorStats() { + connect_error = 0; + session_close = 0; + open_fail = 0; + stream_feature_fail = 0; + handshake_fail = 0; } - uint32_t connect_error; - uint32_t session_close; - uint32_t open_fail; - uint32_t stream_feature_fail; - uint32_t handshake_fail; + tbb::atomic connect_error; + tbb::atomic session_close; + tbb::atomic open_fail; + tbb::atomic stream_feature_fail; + tbb::atomic handshake_fail; }; XmppConnection(TcpServer *server, const XmppChannelConfig *config);