diff --git a/src/bgp/SConscript b/src/bgp/SConscript index af5d87a92cd..26fa5087bc5 100644 --- a/src/bgp/SConscript +++ b/src/bgp/SConscript @@ -27,6 +27,7 @@ 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']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) SandeshPeerFiles = env.SandeshGenCpp('peer_info.sandesh') SandeshPeerGenSrcs = env.ExtractCpp(SandeshPeerFiles) diff --git a/src/bgp/bgp_peer.cc b/src/bgp/bgp_peer.cc index 7f2008eb9d2..0be1cf7fa3f 100644 --- a/src/bgp/bgp_peer.cc +++ b/src/bgp/bgp_peer.cc @@ -654,6 +654,12 @@ BgpPeer::~BgpPeer() { peer_info.set_name(ToUVEKey()); peer_info.set_deleted(true); BGPPeerInfoSend(peer_info); + + PeerStatsData peer_stats_data; + peer_stats_data.set_name(ToUVEKey()); + peer_stats_data.set_deleted(true); + PeerStatsUve::Send(peer_stats_data, "ObjectBgpPeer"); + BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL, BGP_PEER_DIR_NA, "Deleted"); } @@ -2571,6 +2577,11 @@ void BgpPeer::increment_flap_count() { flap_info.set_flap_time(last_flap_); peer_info.set_flap_info(flap_info); BGPPeerInfoSend(peer_info); + + PeerFlapData peer_flap_data; + peer_flap_data.set_name(ToUVEKey()); + peer_flap_data.set_flap_info(flap_info); + PeerFlap::Send(peer_flap_data, "ObjectBgpPeer"); } void BgpPeer::reset_flap_count() { @@ -2582,4 +2593,9 @@ void BgpPeer::reset_flap_count() { PeerFlapInfo flap_info; peer_info.set_flap_info(flap_info); BGPPeerInfoSend(peer_info); + + PeerFlapData peer_flap_data; + peer_flap_data.set_name(ToUVEKey()); + peer_flap_data.set_flap_info(flap_info); + PeerFlap::Send(peer_flap_data, "ObjectBgpPeer"); } diff --git a/src/bgp/bgp_server.cc b/src/bgp/bgp_server.cc index 998361ca1fc..92630b2b44d 100644 --- a/src/bgp/bgp_server.cc +++ b/src/bgp/bgp_server.cc @@ -813,6 +813,11 @@ void BgpServer::FillPeerStats(const BgpPeer *peer) const { peer_info.set_name(peer->ToUVEKey()); peer_info.set_peer_stats_info(stats); BGPPeerInfo::Send(peer_info); + + PeerStatsData peer_stats_data; + peer_stats_data.set_name(peer->ToUVEKey()); + PeerStats::FillPeerUpdateStats(peer->peer_stats(), &peer_stats_data); + PeerStatsUve::Send(peer_stats_data, "ObjectBgpPeer"); } bool BgpServer::CollectStats(BgpRouterState *state, bool first) const { diff --git a/src/bgp/bgp_xmpp_channel.cc b/src/bgp/bgp_xmpp_channel.cc index 52eb72c0374..90cff1b4d4b 100644 --- a/src/bgp/bgp_xmpp_channel.cc +++ b/src/bgp/bgp_xmpp_channel.cc @@ -419,10 +419,16 @@ class BgpXmppChannel::XmppPeer : public IPeer { virtual ~XmppPeer() { assert(GetTotalPathCount() == 0); + XmppPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_deleted(true); parent_->XMPPPeerInfoSend(peer_info); + + PeerStatsData peer_stats_data; + peer_stats_data.set_name(ToUVEKey()); + peer_stats_data.set_deleted(true); + PeerStatsUve::Send(peer_stats_data, "ObjectXmppPeerInfo"); } virtual bool MembershipPathCallback(DBTablePartBase *tpart, BgpRoute *rt, @@ -2818,7 +2824,7 @@ void BgpXmppChannelManager::XmppHandleChannelEvent(XmppChannel *channel, } } -void BgpXmppChannelManager::FillPeerStats(const BgpXmppChannel *channel) const { +void BgpXmppChannelManager::FillPeerInfo(const BgpXmppChannel *channel) const { PeerStatsInfo stats; PeerStats::FillPeerDebugStats(channel->Peer()->peer_stats(), &stats); @@ -2826,13 +2832,36 @@ void BgpXmppChannelManager::FillPeerStats(const BgpXmppChannel *channel) const { peer_info.set_name(channel->Peer()->ToUVEKey()); peer_info.set_peer_stats_info(stats); XMPPPeerInfo::Send(peer_info); + + PeerStatsData peer_stats_data; + peer_stats_data.set_name(channel->Peer()->ToUVEKey()); + PeerStats::FillPeerUpdateStats(channel->Peer()->peer_stats(), + &peer_stats_data); + PeerStatsUve::Send(peer_stats_data, "ObjectXmppPeerInfo"); +} + +void BgpXmppChannelManager::FillPeerStats(const XmppConnectionEndpoint *endp) + const { + if (!endp) + return; + + PeerFlapInfo flap_info; + flap_info.set_flap_count(endp->flap_count()); + flap_info.set_flap_time(endp->last_flap()); + + PeerFlapData peer_flap_data; + peer_flap_data.set_name(endp->client()); + peer_flap_data.set_flap_info(flap_info); + PeerFlap::Send(peer_flap_data, "ObjectXmppPeerInfo"); } bool BgpXmppChannelManager::CollectStats(BgpRouterState *state, bool first) const { CHECK_CONCURRENCY("bgp::Uve"); - VisitChannels(boost::bind(&BgpXmppChannelManager::FillPeerStats, this, _1)); + VisitChannels(boost::bind(&BgpXmppChannelManager::FillPeerInfo, this, _1)); + xmpp_server_->VisitEndpoints( + boost::bind(&BgpXmppChannelManager::FillPeerStats, this, _1)); bool change = false; uint32_t num_xmpp = count(); if (first || num_xmpp != state->get_num_xmpp_peer()) { diff --git a/src/bgp/bgp_xmpp_channel.h b/src/bgp/bgp_xmpp_channel.h index 01b602ef322..8bac39e4991 100644 --- a/src/bgp/bgp_xmpp_channel.h +++ b/src/bgp/bgp_xmpp_channel.h @@ -38,6 +38,7 @@ class BgpXmppChannelManager; class BgpXmppChannelManagerMock; class Timer; class XmppConfigUpdater; +class XmppConnectionEndpoint; class XmppPeerInfoData; class XmppSession; @@ -361,7 +362,8 @@ class BgpXmppChannelManager { friend class BgpXmppChannelManagerMock; friend class BgpXmppUnitTest; - void FillPeerStats(const BgpXmppChannel *channel) const; + void FillPeerInfo(const BgpXmppChannel *channel) const; + void FillPeerStats(const XmppConnectionEndpoint *endp) const; XmppServer *xmpp_server_; BgpServer *bgp_server_; diff --git a/src/bgp/ermvpn/SConscript b/src/bgp/ermvpn/SConscript index d7f64cb1033..d064f819d8f 100644 --- a/src/bgp/ermvpn/SConscript +++ b/src/bgp/ermvpn/SConscript @@ -10,6 +10,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = env['TOP']) env.Append(CPPPATH = [env['TOP'] + '/ifmap']) env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) 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 006a6484b53..40cd3683f65 100644 --- a/src/bgp/ermvpn/test/SConscript +++ b/src/bgp/ermvpn/test/SConscript @@ -10,6 +10,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [env['TOP'], env['TOP'] + '/db', env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common', ]) env.Append(LIBPATH = env['TOP'] + '/base') diff --git a/src/bgp/evpn/test/SConscript b/src/bgp/evpn/test/SConscript index df3fd9689b5..b348c49910d 100644 --- a/src/bgp/evpn/test/SConscript +++ b/src/bgp/evpn/test/SConscript @@ -38,6 +38,7 @@ env.Append(LIBPATH = env['TOP'] + '/route') env.Append(LIBPATH = env['TOP'] + '/xmpp') env.Append(LIBPATH = env['TOP'] + '/xml') env.Append(LIBPATH = env['TOP'] + '/schema') +env.Append(CPPPATH = env['TOP'] + '/tools/sandesh/library/common') env.Prepend(LIBS = [ 'task_test', diff --git a/src/bgp/extended-community/SConscript b/src/bgp/extended-community/SConscript index 3f38cddf8e1..f94a2e69cc8 100644 --- a/src/bgp/extended-community/SConscript +++ b/src/bgp/extended-community/SConscript @@ -10,6 +10,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [ env['TOP'] ]) env.Append(CPPPATH = [ env['TOP'] + '/db']) env.Append(CPPPATH = [ env['TOP'] + '/io']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) libextended_community = env.Library('extended_community', ['default_gateway.cc', diff --git a/src/bgp/extended-community/test/SConscript b/src/bgp/extended-community/test/SConscript index 72a86067952..6577101c2b1 100644 --- a/src/bgp/extended-community/test/SConscript +++ b/src/bgp/extended-community/test/SConscript @@ -10,6 +10,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [ env['TOP'] ]) env.Append(CPPPATH = [ env['TOP'] + '/db' ]) env.Append(CPPPATH = [ env['TOP'] + '/io' ]) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) env.Append(LIBPATH = env['TOP'] + '/bgp/extended-community') env.Append(LIBPATH = env['TOP'] + '/net') diff --git a/src/bgp/inet/test/SConscript b/src/bgp/inet/test/SConscript index 0bbcd9f465e..deb1f874d33 100644 --- a/src/bgp/inet/test/SConscript +++ b/src/bgp/inet/test/SConscript @@ -12,6 +12,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [env['TOP'], env['TOP'] + '/db', env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common', ]) env.Append(LIBPATH = env['TOP'] + '/base') diff --git a/src/bgp/inet6/test/SConscript b/src/bgp/inet6/test/SConscript index 2d2555c1447..3eae35b1510 100644 --- a/src/bgp/inet6/test/SConscript +++ b/src/bgp/inet6/test/SConscript @@ -12,6 +12,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [env['TOP'], env['TOP'] + '/db', env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common', ]) env.Append(LIBPATH = env['TOP'] + '/base') diff --git a/src/bgp/inet6vpn/test/SConscript b/src/bgp/inet6vpn/test/SConscript index 7b89bb45ef8..cea88dfc808 100644 --- a/src/bgp/inet6vpn/test/SConscript +++ b/src/bgp/inet6vpn/test/SConscript @@ -10,6 +10,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [env['TOP'], env['TOP'] + '/db', env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common', ]) env.Append(LIBPATH = env['TOP'] + '/base') diff --git a/src/bgp/l3vpn/test/SConscript b/src/bgp/l3vpn/test/SConscript index 9737eb8289b..a6c29e1bbe2 100644 --- a/src/bgp/l3vpn/test/SConscript +++ b/src/bgp/l3vpn/test/SConscript @@ -12,6 +12,7 @@ env = BuildEnv.Clone() env.Append(CPPPATH = [env['TOP'], env['TOP'] + '/db', env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common', ]) env.Append(LIBPATH = env['TOP'] + '/base') diff --git a/src/bgp/peer_info.sandesh b/src/bgp/peer_info.sandesh index 31b05e2daf7..6d80bd3eed8 100644 --- a/src/bgp/peer_info.sandesh +++ b/src/bgp/peer_info.sandesh @@ -1,6 +1,7 @@ /* * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. */ +include "sandesh/library/common/derived_stats_results.sandesh" struct PeerProtoStats { 1: u64 total; @@ -69,3 +70,42 @@ struct PeerStatsInfo { 7: optional PeerRxErrorStats rx_error_stats; 8: optional PeerRxRouteStats rx_route_stats; } + +struct PeerStatsData { + 1: string name (key=""); + 2: optional bool deleted; + 3: optional PeerUpdateStats rx_update_stats(metric="agg",tags=""); + 4: optional PeerUpdateStats tx_update_stats(metric="agg",tags=""); + 5: optional derived_stats_results.AnomalyResult rx_update_stats_ewm (stats="rx_update_stats.total:DSAnomaly:EWM:0.2"); + 6: optional derived_stats_results.AnomalyResult tx_update_stats_ewm (stats="tx_update_stats.total:DSAnomaly:EWM:0.2"); +} + +uve sandesh PeerStatsUve { + 1: PeerStatsData data; +} + +typedef u64 flap_u64 + +struct flap_u64_P_ { + 1: optional flap_u64 value; + 2: optional flap_u64 staging; +} + +struct PeerFlapData { + 1: string name (key=""); // Control-node-ip:Agent-ip + 2: optional bool deleted; + 3: optional PeerFlapInfo flap_info (metric="agg"); + 4: optional flap_u64_P_ flap_10m + (stats="1-flap_info.flap_count:DSSum:"); + 5: optional flap_u64_P_ flap_1h + (stats="6-flap_info.flap_count:DSSum:",hidden="yes"); +} (period="600") + +/** + * @description: Peer specific information + * @severity: DEBUG + * @cause: Normal operation + */ +uve sandesh PeerFlap { + 1: PeerFlapData data; +} diff --git a/src/bgp/peer_stats.cc b/src/bgp/peer_stats.cc index 5715c8b7b7f..997fb0ceb6b 100644 --- a/src/bgp/peer_stats.cc +++ b/src/bgp/peer_stats.cc @@ -40,7 +40,30 @@ void PeerStats::FillRxRouteStats(const IPeerDebugStats::RxRouteStats &src, dest->primary_path_count = src.primary_path_count; } -void PeerStats::FillPeerDebugStats(const IPeerDebugStats *peer_state, +void PeerStats::FillPeerUpdateStats(const IPeerDebugStats *peer_stats, + PeerUpdateStats *rt_stats_rx, + PeerUpdateStats *rt_stats_tx) { + + IPeerDebugStats::UpdateStats update_stats_rx; + peer_stats->GetRxRouteUpdateStats(&update_stats_rx); + FillRouteUpdateStats(update_stats_rx, rt_stats_rx); + + IPeerDebugStats::UpdateStats update_stats_tx; + peer_stats->GetTxRouteUpdateStats(&update_stats_tx); + FillRouteUpdateStats(update_stats_tx, rt_stats_tx); +} + +void PeerStats::FillPeerUpdateStats(const IPeerDebugStats *peer_stats, + PeerStatsData *peer_stats_data) { + PeerUpdateStats stats_rx; + PeerUpdateStats stats_tx; + + FillPeerUpdateStats(peer_stats, &stats_rx, &stats_tx); + peer_stats_data->set_rx_update_stats(stats_rx); + peer_stats_data->set_tx_update_stats(stats_tx); +} + +void PeerStats::FillPeerDebugStats(const IPeerDebugStats *peer_stats, PeerStatsInfo *stats) { PeerProtoStats proto_stats_tx; PeerProtoStats proto_stats_rx; @@ -50,27 +73,21 @@ void PeerStats::FillPeerDebugStats(const IPeerDebugStats *peer_state, PeerRxRouteStats dest_route_stats_rx; IPeerDebugStats::ProtoStats stats_rx; - peer_state->GetRxProtoStats(&stats_rx); + peer_stats->GetRxProtoStats(&stats_rx); FillProtoStats(stats_rx, &proto_stats_rx); IPeerDebugStats::ProtoStats stats_tx; - peer_state->GetTxProtoStats(&stats_tx); + peer_stats->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); + FillPeerUpdateStats(peer_stats, &rt_stats_rx, &rt_stats_tx); IPeerDebugStats::RxErrorStats src_error_stats_rx; - peer_state->GetRxErrorStats(&src_error_stats_rx); + peer_stats->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); + peer_stats->GetRxRouteStats(&src_route_stats_rx); FillRxRouteStats(src_route_stats_rx, &dest_route_stats_rx); stats->set_rx_proto_stats(proto_stats_rx); diff --git a/src/bgp/peer_stats.h b/src/bgp/peer_stats.h index 0da306ff696..e5af2e0bde2 100644 --- a/src/bgp/peer_stats.h +++ b/src/bgp/peer_stats.h @@ -11,8 +11,10 @@ class PeerStats { public: - static void FillPeerDebugStats(const IPeerDebugStats *peer_state, + static void FillPeerDebugStats(const IPeerDebugStats *peer_stats, PeerStatsInfo *stats); + static void FillPeerUpdateStats(const IPeerDebugStats *peer_stats, + PeerStatsData *peer_stats_data); private: static void FillProtoStats(const IPeerDebugStats::ProtoStats &stats, @@ -23,6 +25,9 @@ class PeerStats { PeerRxErrorStats *dest); static void FillRxRouteStats(const IPeerDebugStats::RxRouteStats &src, PeerRxRouteStats *dest); + static void FillPeerUpdateStats(const IPeerDebugStats *peer_stats, + PeerUpdateStats *rt_stats_rx, + PeerUpdateStats *rt_stats_tx); }; #endif // SRC_BGP_PEER_STATS_H_ diff --git a/src/bgp/routing-instance/SConscript b/src/bgp/routing-instance/SConscript index c3b6ba8aaa7..1a4b265c1f9 100644 --- a/src/bgp/routing-instance/SConscript +++ b/src/bgp/routing-instance/SConscript @@ -13,6 +13,7 @@ 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']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) # Generate the source files SandeshGenFiles = env.SandeshGenCpp('routing_instance_analytics.sandesh') diff --git a/src/bgp/routing-policy/SConscript b/src/bgp/routing-policy/SConscript index 5d31d86f450..4278a81c021 100644 --- a/src/bgp/routing-policy/SConscript +++ b/src/bgp/routing-policy/SConscript @@ -13,6 +13,7 @@ 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']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) # Generate the source files SandeshGenFiles = env.SandeshGenCpp('routing_policy.sandesh') diff --git a/src/bgp/test/SConscript b/src/bgp/test/SConscript index a809c2a9c37..6ee3ed5b28a 100644 --- a/src/bgp/test/SConscript +++ b/src/bgp/test/SConscript @@ -14,6 +14,7 @@ env.Append(CPPPATH = [env['TOP'], env['TOP'] + '/bgp', env['TOP'] + '/db', env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common', env['TOP'] + '/xmpp' ]) env.Append(LIBPATH = ['#/' + Dir('..').path, diff --git a/src/control-node/SConscript b/src/control-node/SConscript index 2c1da1a0a83..32a1d2b3b11 100644 --- a/src/control-node/SConscript +++ b/src/control-node/SConscript @@ -17,6 +17,7 @@ env.Append(CPPPATH = [env['TOP'] + '/base/sandesh']) env.Append(CPPPATH = [env['TOP'] + '/db']) env.Append(CPPPATH = [env['TOP'] + '/ifmap']) env.Append(CPPPATH = [env['TOP'] + '/bgp']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) ControlNodeSandeshGenFiles = env.SandeshGenCpp('sandesh/control_node.sandesh') ControlNodeSandeshGenSrcs = env.ExtractCpp(ControlNodeSandeshGenFiles) diff --git a/src/control-node/test/SConscript b/src/control-node/test/SConscript index eff2625e6f7..aab576e503c 100644 --- a/src/control-node/test/SConscript +++ b/src/control-node/test/SConscript @@ -9,7 +9,8 @@ import sys env = BuildEnv.Clone() env.Prepend(CPPPATH = [env['TOP'], env['TOP'] + '/db', - env['TOP'] + '/io' + env['TOP'] + '/io', + env['TOP'] + '/tools/sandesh/library/common' ]) libcontrol_test = env.Library('control_test', diff --git a/src/xmpp/SConscript b/src/xmpp/SConscript index c3ed0ccd1ba..cccac7f3f41 100644 --- a/src/xmpp/SConscript +++ b/src/xmpp/SConscript @@ -63,6 +63,7 @@ xmpp_include = '#/' + Dir('.').path env.Append(CPPPATH=xmpp_include) env.Append(CPPPATH = [env['TOP'] + '/bgp']) env.Append(CPPPATH = [env['TOP'] + '/io']) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) xmppd = env.Program(target = 'xmppd', source = ['main.cc']) diff --git a/src/xmpp/test/SConscript b/src/xmpp/test/SConscript index 632f8a56a69..740f2c4c35d 100644 --- a/src/xmpp/test/SConscript +++ b/src/xmpp/test/SConscript @@ -8,6 +8,7 @@ Import('BuildEnv') import sys env = BuildEnv.Clone() env.Append(CPPPATH = [env['TOP']]) +env.Append(CPPPATH = [env['TOP'] + '/tools/sandesh/library/common']) env.Append(LIBPATH = ['#/' + Dir('..').path, '../../base', @@ -28,7 +29,8 @@ 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', - 'table_sandesh', 'boost_regex', 'xmpptest', 'control_node']) + 'table_sandesh', 'boost_regex', 'xmpptest', 'control_node', + 'sandesh']) if sys.platform != 'darwin': env.Append(LIBS = ['rt']) diff --git a/src/xmpp/xmpp_connection.cc b/src/xmpp/xmpp_connection.cc index e0d8c879c2a..6cf47c59192 100644 --- a/src/xmpp/xmpp_connection.cc +++ b/src/xmpp/xmpp_connection.cc @@ -774,6 +774,11 @@ void XmppServerConnection::increment_flap_count() { flap_info.set_flap_time(conn_endpoint->last_flap()); peer_info.set_flap_info(flap_info); XMPPPeerInfoSend(peer_info); + + PeerFlapData peer_flap_data; + peer_flap_data.set_name(ToUVEKey()); + peer_flap_data.set_flap_info(flap_info); + PeerFlap::Send(peer_flap_data, "ObjectXmppPeerInfo"); } const std::string XmppServerConnection::last_flap_at() const { @@ -931,7 +936,11 @@ uint64_t XmppConnectionEndpoint::last_flap() const { return last_flap_; } -const std::string XmppConnectionEndpoint::last_flap_at() const { +std::string XmppConnectionEndpoint::client() const { + return client_; +} + +std::string XmppConnectionEndpoint::last_flap_at() const { return last_flap_ ? integerToString(UTCUsecToPTime(last_flap_)) : ""; } diff --git a/src/xmpp/xmpp_connection.h b/src/xmpp/xmpp_connection.h index dcb72934d94..c60e34c468a 100644 --- a/src/xmpp/xmpp_connection.h +++ b/src/xmpp/xmpp_connection.h @@ -347,7 +347,8 @@ class XmppConnectionEndpoint { uint32_t flap_count() const; void increment_flap_count(); uint64_t last_flap() const; - const std::string last_flap_at() const; + std::string last_flap_at() const; + std::string client() const; XmppConnection *connection(); const XmppConnection *connection() const; void set_connection(XmppConnection *connection); diff --git a/src/xmpp/xmpp_server.cc b/src/xmpp/xmpp_server.cc index 6af6c67b550..638d958b071 100644 --- a/src/xmpp/xmpp_server.cc +++ b/src/xmpp/xmpp_server.cc @@ -537,8 +537,16 @@ void XmppServer::RemoveDeletedConnection(XmppServerConnection *connection) { ReleaseConnectionEndpoint(connection); } +void XmppServer::VisitEndpoints(VisitorFn fn) const { + tbb::mutex::scoped_lock lock(endpoint_map_mutex_); + BOOST_FOREACH(const ConnectionEndpointMap::value_type &i, + connection_endpoint_map_) { + fn(i.second); + } +} + XmppConnectionEndpoint *XmppServer::FindConnectionEndpoint( - const string &endpoint_name) { + const string &endpoint_name) const { tbb::mutex::scoped_lock lock(endpoint_map_mutex_); ConnectionEndpointMap::const_iterator loc = connection_endpoint_map_.find(endpoint_name); diff --git a/src/xmpp/xmpp_server.h b/src/xmpp/xmpp_server.h index 15d1e8c52fa..3e47d90c803 100644 --- a/src/xmpp/xmpp_server.h +++ b/src/xmpp/xmpp_server.h @@ -31,6 +31,7 @@ class XmppServerConnection; class XmppServer : public XmppConnectionManager { public: typedef boost::asio::ip::tcp::endpoint Endpoint; + typedef boost::function VisitorFn; XmppServer(EventManager *evm, const std::string &server_addr, const XmppChannelConfig *config); @@ -70,9 +71,10 @@ class XmppServer : public XmppConnectionManager { const std::string &ServerAddr() const { return server_addr_; } size_t ConnectionCount() const; + void VisitEndpoints(VisitorFn fn) const; XmppConnectionEndpoint *FindConnectionEndpoint( - const std::string &endpoint_name); + const std::string &endpoint_name) const; XmppConnectionEndpoint *LocateConnectionEndpoint( XmppServerConnection *connection, bool &created); void ReleaseConnectionEndpoint(XmppServerConnection *connection); @@ -113,7 +115,7 @@ class XmppServer : public XmppConnectionManager { ConnectionSet deleted_connection_set_; size_t max_connections_; - tbb::mutex endpoint_map_mutex_; + mutable tbb::mutex endpoint_map_mutex_; ConnectionEndpointMap connection_endpoint_map_; tbb::mutex deletion_mutex_;