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

Generated by: LCOV version 1.14