LCOV - code coverage report
Current view: top level - vnsw/agent/cmn - agent_stats.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 3 118 2.5 %
Date: 2026-11-09 02:10:49 Functions: 1 6 16.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include <string>
       7             : #include <vector>
       8             : #include <base/logging.h>
       9             : 
      10             : #include <vnc_cfg_types.h>
      11             : #include <cmn/agent_cmn.h>
      12             : #include <xmpp/xmpp_channel.h>
      13             : #include <controller/controller_peer.h>
      14             : 
      15             : #include <cmn/agent_stats.h>
      16             : #include <cmn/stats_types.h>
      17             : #include <uve/agent_uve_base.h>
      18             : #include <vrouter/flow_stats/flow_stats_collector.h>
      19             : 
      20             : AgentStats *AgentStats::singleton_;
      21             : 
      22           0 : void AgentStats::Reset() {
      23           0 :     sandesh_reconnects_ = sandesh_in_msgs_ = sandesh_out_msgs_ = 0;
      24           0 :     sandesh_http_sessions_ = nh_count_ = pkt_exceptions_ = 0;
      25           0 :     pkt_invalid_agent_hdr_ = pkt_invalid_interface_ = 0;
      26           0 :     pkt_no_handler_ = pkt_dropped_ = 0;
      27           0 :     pkt_invalid_mpls_hdr_ = pkt_invalid_ip_pkt_ = pkt_drop_due_to_disable_tnl_ = 0;
      28           0 :     pkt_invalid_frm_tor_ = pkt_drop_due_to_decode_error_ = pkt_drop_due_to_invalid_ethertype_ = 0;
      29           0 :     pkt_drop_due_to_flow_trap_ = 0;
      30           0 :     flow_created_ = pkt_fragments_dropped_ = hold_flow_count_ = 0;
      31           0 :     flow_aged_ = flow_drop_due_to_max_limit_ = 0;
      32           0 :     flow_drop_due_to_linklocal_limit_ = ipc_in_msgs_ = 0;
      33           0 :     ipc_out_msgs_ = in_tpkts_ = in_bytes_ = out_tpkts_ = 0;
      34           0 :     out_bytes_ = 0;
      35           0 : }
      36             : 
      37           0 : void AgentStatsReq::HandleRequest() const {
      38           0 :     Agent *agent = Agent::GetInstance();
      39           0 :     AgentStats *stats = agent->stats();
      40           0 :     IpcStatsResp *ipc = new IpcStatsResp();
      41             : 
      42           0 :     ipc->set_ipc_in_msgs(stats->ipc_in_msgs());
      43           0 :     ipc->set_ipc_out_msgs(stats->ipc_out_msgs());
      44           0 :     ipc->set_context(context());
      45           0 :     ipc->set_more(true);
      46           0 :     ipc->Response();
      47             : 
      48             :     /* If Pkt module is not set (for tor-agents for example), no need to send
      49             :      * PktTrapStatsResp and FlowStatsResp */
      50           0 :     if (agent->pkt()) {
      51           0 :         PktTrapStatsResp *pkt = new PktTrapStatsResp();
      52           0 :         pkt->set_exceptions(stats->pkt_exceptions());
      53           0 :         pkt->set_invalid_agent_hdr(stats->pkt_invalid_agent_hdr());
      54           0 :         pkt->set_invalid_interface(stats->pkt_invalid_interface());
      55           0 :         pkt->set_no_handler(stats->pkt_no_handler());
      56           0 :         pkt->set_pkt_dropped(stats->pkt_dropped());
      57           0 :         pkt->set_pkt_fragments_dropped(stats->pkt_fragments_dropped());
      58           0 :         pkt->set_pkt_invalid_mpls_hdr(stats->pkt_invalid_mpls_hdr());
      59           0 :         pkt->set_pkt_invalid_ip_pkt(stats->pkt_invalid_ip_pkt());
      60           0 :         pkt->set_pkt_drop_due_to_disable_tnl(stats->pkt_drop_due_to_disable_tnl());
      61           0 :         pkt->set_pkt_invalid_frm_tor(stats->pkt_invalid_frm_tor());
      62           0 :         pkt->set_pkt_drop_due_to_decode_error(stats->pkt_drop_due_to_decode_error());
      63           0 :         pkt->set_pkt_drop_due_to_invalid_ethertype(stats->pkt_drop_due_to_invalid_ethertype());
      64           0 :         pkt->set_pkt_drop_due_to_flow_trap(stats->pkt_drop_due_to_flow_trap());
      65           0 :         pkt->set_context(context());
      66           0 :         pkt->set_more(true);
      67           0 :         pkt->Response();
      68             : 
      69           0 :         FlowStatsResp *flow = new FlowStatsResp();
      70           0 :         flow->set_flow_active(stats->FlowCount());
      71           0 :         flow->set_flow_created(stats->flow_created());
      72           0 :         flow->set_flow_aged(stats->flow_aged());
      73           0 :         flow->set_flow_drop_due_to_max_limit(
      74             :                 stats->flow_drop_due_to_max_limit());
      75           0 :         flow->set_flow_drop_due_to_linklocal_limit(
      76             :                 stats->flow_drop_due_to_linklocal_limit());
      77           0 :         flow->set_flow_max_system_flows(agent->flow_table_size());
      78           0 :         flow->set_flow_max_vm_flows(agent->max_vm_flows());
      79           0 :         flow->set_context(context());
      80           0 :         flow->set_more(true);
      81           0 :         flow->Response();
      82             :     }
      83             : 
      84           0 :     XmppStatsResp *xmpp_resp = new XmppStatsResp();
      85           0 :     vector<XmppStatsInfo> list;
      86           0 :     for (int count = 0; count < MAX_XMPP_SERVERS; count++) {
      87           0 :         XmppStatsInfo peer;
      88           0 :         if (!agent->controller_ifmap_xmpp_server(count).empty()) {
      89           0 :             peer.set_ip(agent->controller_ifmap_xmpp_server(count));
      90           0 :             AgentXmppChannel *ch = agent->controller_xmpp_channel(count);
      91           0 :             if (ch == NULL) {
      92           0 :                 continue;
      93             :             }
      94           0 :             XmppChannel *xc = ch->GetXmppChannel();
      95           0 :             if (xc == NULL) {
      96           0 :                 continue;
      97             :             }
      98           0 :             peer.set_reconnect(stats->xmpp_reconnects(count));
      99           0 :             peer.set_in_msgs(stats->xmpp_in_msgs(count));
     100           0 :             peer.set_out_msgs(stats->xmpp_out_msgs(count));
     101           0 :             peer.set_config_in_msgs(stats->xmpp_config_in_msgs(count));
     102           0 :             list.push_back(peer);
     103             :         }
     104           0 :     }
     105           0 :     xmpp_resp->set_xmpp_list(list);
     106           0 :     xmpp_resp->set_context(context());
     107           0 :     xmpp_resp->set_more(true);
     108           0 :     xmpp_resp->Response();
     109             : 
     110           0 :     SandeshStatsResp *sandesh = new SandeshStatsResp();
     111           0 :     sandesh->set_sandesh_in_msgs(stats->sandesh_in_msgs());
     112           0 :     sandesh->set_sandesh_out_msgs(stats->sandesh_out_msgs());
     113           0 :     sandesh->set_sandesh_http_sessions(stats->sandesh_http_sessions());
     114           0 :     sandesh->set_sandesh_reconnects(stats->sandesh_reconnects());
     115           0 :     sandesh->set_context(context());
     116           0 :     sandesh->set_more(true);
     117           0 :     sandesh->Response();
     118             : 
     119           0 :     SessionEndpointExportStatsResp *srsp = new SessionEndpointExportStatsResp();
     120           0 :     srsp->set_record_export_count(agent->flow_stats_manager()->
     121             :                                   session_sample_exports());
     122           0 :     srsp->set_msg_export_count(agent->flow_stats_manager()->
     123             :                                session_msg_exports());
     124           0 :     srsp->set_session_export_disable_drops(agent->flow_stats_manager()->
     125             :                                            session_export_disable_drops());
     126           0 :     srsp->set_session_export_sampling_drops(agent->flow_stats_manager()->
     127           0 :                                             session_export_sampling_drops());
     128           0 :     srsp->set_session_exports(agent->flow_stats_manager()->session_exports());
     129           0 :     srsp->set_session_export_drops(agent->flow_stats_manager()->
     130           0 :                                    session_export_drops());
     131           0 :     srsp->set_session_global_slo_logging_drops(agent->flow_stats_manager()->
     132             :                                             session_global_slo_logging_drops());
     133           0 :     srsp->set_session_slo_logging_drops(agent->flow_stats_manager()->
     134             :                                             session_slo_logging_drops());
     135           0 :     srsp->set_context(context());
     136           0 :     srsp->set_more(false);
     137           0 :     srsp->Response();
     138           0 : }
     139             : 
     140           0 : void AgentStats::UpdateFlowMinMaxStats(uint64_t total_flows,
     141             :                                        FlowCounters &stat) const {
     142           0 :     uint64_t count = total_flows - stat.prev_flow_count;
     143           0 :     if ((stat.max_flows_per_second == kInvalidFlowCount) ||
     144           0 :         (count > stat.max_flows_per_second)) {
     145           0 :         stat.max_flows_per_second = count;
     146             :     }
     147           0 :     if ((stat.min_flows_per_second == kInvalidFlowCount) ||
     148           0 :         (count < stat.min_flows_per_second)) {
     149           0 :         stat.min_flows_per_second = count;
     150             :     }
     151           0 :     stat.prev_flow_count = total_flows;
     152           0 : }
     153             : 
     154           0 : void AgentStats::ResetFlowMinMaxStats(FlowCounters &stat) const {
     155           0 :     stat.max_flows_per_second = kInvalidFlowCount;
     156           0 :     stat.min_flows_per_second = kInvalidFlowCount;
     157           0 : }
     158             : 
     159           2 : void AgentStats::RegisterFlowCountFn(FlowCountFn cb) {
     160           2 :     flow_count_fn_ = cb;
     161           2 : }
     162             : 
     163           0 : uint32_t AgentStats::FlowCount() const {
     164           0 :     if (flow_count_fn_.empty())
     165           0 :         return 0;
     166           0 :     return flow_count_fn_();
     167             : }

Generated by: LCOV version 1.14