LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/sandesh/library/cpp - sandesh_req.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 10 153 6.5 %
Date: 2026-08-03 02:19:58 Functions: 1 15 6.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : //
       6             : // sandesh_req.cc
       7             : //
       8             : // File to handle all sandesh requests..
       9             : //
      10             : 
      11             : #include <sandesh/sandesh_types.h>
      12             : #include <sandesh/sandesh.h>
      13             : #include <sandesh/sandesh_uve_types.h>
      14             : 
      15             : #include "sandesh_statistics.h"
      16             : #include "sandesh_client.h"
      17             : #include "sandesh_connection.h"
      18             : 
      19             : using boost::asio::ip::address;
      20             : 
      21             : int PullSandeshGenStatsReq = 0;
      22             : 
      23           0 : void SandeshMessageStatsReq::HandleRequest() const {
      24           0 :     SandeshMessageStatsResp *resp(new SandeshMessageStatsResp);
      25           0 :     std::vector<SandeshMessageTypeStats> mtype_stats;
      26           0 :     SandeshMessageStats magg_stats;
      27           0 :     GetMsgStats(&mtype_stats, &magg_stats);
      28           0 :     SandeshGeneratorStats sandesh_stats;
      29           0 :     sandesh_stats.set_type_stats(mtype_stats);
      30           0 :     sandesh_stats.set_aggregate_stats(magg_stats);
      31           0 :     SandeshClient *client(Sandesh::client());
      32           0 :     if (client) {
      33           0 :         resp->set_session_close_interval_msec(
      34           0 :             client->session_close_interval_msec());
      35           0 :         resp->set_session_close_timestamp(client->session_close_time_usec());
      36           0 :         SandeshSession *ssession(client->session());
      37           0 :         if (ssession) {
      38           0 :             SandeshQueueStats qstats;
      39           0 :             qstats.set_enqueues(ssession->send_queue()->NumEnqueues());
      40           0 :             qstats.set_count(ssession->send_queue()->Length());
      41           0 :             qstats.set_max_count(ssession->send_queue()->max_queue_len());
      42           0 :             resp->set_send_queue_stats(qstats);
      43           0 :             resp->set_sending_level(LevelToString(ssession->SendingLevel()));
      44           0 :         }
      45             :     }
      46           0 :     resp->set_stats(sandesh_stats);
      47           0 :     resp->set_context(context());
      48           0 :     resp->Response();
      49           0 : }
      50             : 
      51           0 : static void SendSandeshLoggingParams(const std::string &context) {
      52           0 :     SandeshLoggingParams *slogger(new SandeshLoggingParams());
      53           0 :     slogger->set_enable(Sandesh::IsLocalLoggingEnabled());
      54           0 :     std::string category = Sandesh::LoggingCategory();
      55           0 :     if (category.empty()) {
      56           0 :         category = "*";
      57             :     }
      58           0 :     slogger->set_category(category);
      59           0 :     slogger->set_log_level(Sandesh::LevelToString(Sandesh::LoggingLevel()));
      60           0 :     slogger->set_trace_print(Sandesh::IsTracePrintEnabled());
      61           0 :     slogger->set_enable_flow_log(Sandesh::IsFlowLoggingEnabled());
      62           0 :     slogger->set_context(context);
      63           0 :     slogger->Response();
      64           0 : }
      65             : 
      66           0 : void SandeshLoggingParamsSet::HandleRequest() const {
      67             :     // Set the logging parameters
      68           0 :     if (__isset.log_level) {
      69           0 :         Sandesh::SetLoggingLevel(get_log_level());
      70             :     }
      71           0 :     if (__isset.category) {
      72           0 :         std::string category = get_category();
      73           0 :         if (category == "*") {
      74           0 :             category = "";
      75             :         }
      76           0 :         Sandesh::SetLoggingCategory(category);
      77           0 :     }
      78           0 :     if (__isset.enable) {
      79           0 :         Sandesh::SetLocalLogging(get_enable());
      80             :     }
      81           0 :     if (__isset.trace_print) {
      82           0 :         Sandesh::SetTracePrint(get_trace_print());
      83             :     }
      84           0 :     if (__isset.enable_flow_log) {
      85           0 :         Sandesh::SetFlowLogging(get_enable_flow_log());
      86             :     }
      87             :     // Send response
      88           0 :     SendSandeshLoggingParams(context());
      89           0 : }
      90             : 
      91           0 : void SandeshLoggingParamsStatus::HandleRequest() const {
      92             :     // Send response
      93           0 :     SendSandeshLoggingParams(context());
      94           0 : }
      95             : 
      96           0 : static void SendSandeshSendingParams(const std::string &context) {
      97           0 :     SandeshSendingParams *ssparams(new SandeshSendingParams());
      98           0 :     ssparams->set_system_logs_rate_limit(Sandesh::get_send_rate_limit());
      99           0 :     ssparams->set_disable_object_logs(Sandesh::IsSendingObjectLogsDisabled());
     100           0 :     ssparams->set_disable_all_logs(Sandesh::IsSendingAllMessagesDisabled());
     101           0 :     ssparams->set_disable_flows(Sandesh::IsSendingFlowsDisabled());
     102           0 :     SandeshClient *client = Sandesh::client();
     103           0 :     if (client && client->IsSession()) {
     104           0 :         SandeshSession *sess = client->session();
     105           0 :         ssparams->set_dscp(sess->GetDscpValue());
     106             :     }
     107           0 :     ssparams->set_context(context);
     108           0 :     ssparams->Response();
     109           0 : }
     110             : 
     111           0 : void SandeshSendingParamsSet::HandleRequest() const {
     112           0 :     if (__isset.system_logs_rate_limit) {
     113           0 :         Sandesh::set_send_rate_limit(system_logs_rate_limit);
     114             :     }
     115           0 :     if (__isset.disable_object_logs) {
     116           0 :         Sandesh::DisableSendingObjectLogs(disable_object_logs);
     117             :     }
     118           0 :     if (__isset.disable_all_logs) {
     119           0 :         Sandesh::DisableSendingAllMessages(disable_all_logs);
     120             :     }
     121           0 :     if (__isset.disable_flows) {
     122           0 :         Sandesh::DisableSendingFlows(disable_flows);
     123             :     }
     124             :     // Send response
     125           0 :     SendSandeshSendingParams(context());
     126           0 : }
     127             : 
     128           0 : void SandeshSendingParamsStatus::HandleRequest() const {
     129             :     // Send response
     130           0 :     SendSandeshSendingParams(context());
     131           0 : }
     132             : 
     133           0 : static void SendSandeshSendQueueResponse(std::string context) {
     134           0 :     SandeshSendQueueResponse *ssqr(new SandeshSendQueueResponse);
     135           0 :     ssqr->set_enable(Sandesh::IsSendQueueEnabled());
     136           0 :     ssqr->set_context(context);
     137           0 :     ssqr->Response();
     138           0 : }
     139             : 
     140           0 : void SandeshSendQueueSet::HandleRequest() const {
     141           0 :     if (__isset.enable) {
     142           0 :         Sandesh::SetSendQueue(get_enable());
     143             :     }
     144             :     // Send response
     145           0 :     SendSandeshSendQueueResponse(context());
     146           0 : }
     147             : 
     148           0 : void SandeshSendQueueStatus::HandleRequest() const {
     149             :     // Send response
     150           0 :     SendSandeshSendQueueResponse(context());
     151           0 : }
     152             : 
     153           6 : void CollectorInfoRequest::HandleRequest() const {
     154           6 :     CollectorInfoResponse *resp (new CollectorInfoResponse());
     155           6 :     SandeshClient *client = Sandesh::client();
     156           6 :     if (client) {
     157           6 :         resp->set_ip(client->sm_->server().address().to_string());
     158           6 :         resp->set_port(client->sm_->server().port());
     159           6 :         resp->set_status(client->sm_->StateName());
     160             :     }
     161           6 :     resp->set_context(context());
     162           6 :     resp->Response();
     163           6 : }
     164             : 
     165           0 : static void SendSandeshSendQueueParamsResponse(const std::string &context) {
     166           0 :     std::vector<Sandesh::QueueWaterMarkInfo> scwm_info;
     167           0 :     std::vector<SandeshSendQueueParams> ssp_info;
     168           0 :     SandeshClient *client(Sandesh::client());
     169           0 :     if (client) {
     170           0 :         client->GetSessionWaterMarkInfo(scwm_info);
     171           0 :         for (size_t i = 0; i < scwm_info.size(); i++) {
     172           0 :             Sandesh::QueueWaterMarkInfo &scwm(scwm_info[i]);
     173           0 :             SandeshSendQueueParams ssp;
     174           0 :             ssp.set_queue_count(boost::get<0>(scwm));
     175           0 :             SandeshLevel::type level(boost::get<1>(scwm));
     176           0 :             ssp.set_sending_level(Sandesh::LevelToString(level));
     177           0 :             ssp.set_high(boost::get<2>(scwm));
     178           0 :             ssp_info.push_back(ssp);
     179           0 :         }
     180             :     }
     181           0 :     SandeshSendQueueParamsResponse *sspr(new SandeshSendQueueParamsResponse);
     182           0 :     sspr->set_context(context);
     183           0 :     sspr->set_info(ssp_info);
     184           0 :     sspr->Response();
     185           0 : }
     186             : 
     187           0 : void SandeshSendQueueParamsSet::HandleRequest() const {
     188           0 :     if (!(__isset.high && __isset.queue_count &&  __isset.sending_level)) {
     189             :         // Send response
     190           0 :         SendSandeshSendQueueParamsResponse(context());
     191           0 :         return;
     192             :     }
     193           0 :     SandeshClient *client(Sandesh::client());
     194           0 :     if (client) {
     195           0 :         size_t qcount(get_queue_count());
     196           0 :         bool high(get_high());
     197           0 :         std::string slevel(get_sending_level());
     198           0 :         SandeshLevel::type level(Sandesh::StringToLevel(slevel));
     199           0 :         Sandesh::QueueWaterMarkInfo scwm(qcount, level, high);
     200           0 :         client->SetSessionWaterMarkInfo(scwm);
     201           0 :     }
     202             :     // Send response
     203           0 :     SendSandeshSendQueueParamsResponse(context());
     204             : }
     205             : 
     206           0 : void SandeshSendQueueParamsReset::HandleRequest() const {
     207           0 :     SandeshClient *client(Sandesh::client());
     208           0 :     if (client) {
     209           0 :         client->ResetSessionWaterMarkInfo();
     210             :     }
     211             :     // Send response
     212           0 :     SendSandeshSendQueueParamsResponse(context());
     213           0 : }
     214             : 
     215           0 : void SandeshSendQueueParamsStatus::HandleRequest() const {
     216             :     // Send response
     217           0 :     SendSandeshSendQueueParamsResponse(context());
     218           0 : }

Generated by: LCOV version 1.14