LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/sandesh/library/cpp - sandesh_client.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 10 15 66.7 %
Date: 2026-11-09 02:10:49 Functions: 4 7 57.1 %
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_client.h
       8             : //
       9             : // Sandesh Analytics Database Client
      10             : //
      11             : 
      12             : #ifndef __SANDESH_CLIENT_H__
      13             : #define __SANDESH_CLIENT_H__
      14             : 
      15             : #include <boost/asio.hpp>
      16             : #include <boost/statechart/state_machine.hpp>
      17             : #include <boost/asio/ip/tcp.hpp>
      18             : #include <boost/scoped_ptr.hpp>
      19             : #include <boost/ptr_container/ptr_map.hpp>
      20             : #include <boost/tuple/tuple.hpp>
      21             : 
      22             : #include <io/tcp_server.h>
      23             : #include <io/ssl_server.h>
      24             : #include <io/ssl_session.h>
      25             : #include <base/queue_task.h>
      26             : #include <base/timer.h>
      27             : #include <sandesh/stats_client.h>
      28             : #include <sandesh/sandesh_session.h>
      29             : #include "sandesh_client_sm.h"
      30             : #include "sandesh.h"
      31             : 
      32             : class SandeshClient;
      33             : class Sandesh;
      34             : class SandeshUVE;
      35             : class SandeshHeader;
      36             : 
      37             : bool DoCloseSMSession(uint64_t now_usec, uint64_t last_close_usec,
      38             :     uint64_t last_close_interval_usec, int *close_interval_msec);
      39             : 
      40             : class SandeshClient : public SslServer, public SandeshClientSM::Mgr {
      41             : public:
      42             :     static const int kInitialSMSessionCloseIntervalMSec = 10 * 1000;
      43             :     static const int kMaxSMSessionCloseIntervalMSec = 60 * 1000;
      44             : 
      45             :     SandeshClient(EventManager *evm, const std::vector<Endpoint> &collectors,
      46             :              const SandeshConfig &config,
      47             :              bool periodicuve = false);
      48             : 
      49             :     virtual ~SandeshClient();
      50             : 
      51             :     void Initiate();
      52             :     void Shutdown();
      53             : 
      54             :     virtual SandeshSession *CreateSMSession(
      55             :             SslSession::EventObserver eocb,
      56             :             SandeshReceiveMsgCb rmcb,
      57             :             TcpServer::Endpoint ep);
      58             : 
      59             :     void InitializeSMSession(int connects);
      60         105 :     void DeleteSMSession(SandeshSession * session) {
      61         105 :         DeleteSession(session);
      62         105 :     }
      63             :     bool CloseSMSession();
      64             :     bool ReceiveMsg(const std::string& msg,
      65             :         const SandeshHeader &header, const std::string &sandesh_name,
      66             :         const uint32_t header_offset);
      67             :     void SendUVE(int count,
      68             :         const std::string & stateName, const std::string & server,
      69             :         const Endpoint & server_ip, const std::vector<Endpoint> & collector_eps);
      70             : 
      71             :     bool SendSandesh(Sandesh *snh);
      72             : 
      73             :     bool SendSandeshUVE(Sandesh *snh_uve);
      74             : 
      75             :     SandeshClientSM::State state() {
      76             :         return sm_->state();
      77             :     }
      78             : 
      79         170 :     bool IsSession() {
      80         170 :         if (sm_->session()) return true;
      81          83 :         else return false;
      82             :     }
      83             : 
      84       13889 :     SandeshSession * session() const {
      85       13889 :         return sm_->session();
      86             :     }
      87             : 
      88             :     SandeshClientSM* state_machine() const {
      89             :         return sm_.get();
      90             :     }
      91             : 
      92         105 :     StatsClient* stats_client() const {
      93         105 :         return stats_client_.get();
      94             :     }
      95             : 
      96             :     void SetDscpValue(uint8_t value);
      97           0 :     uint8_t dscp_value() const { return dscp_value_; }
      98             : 
      99             :     void SetSessionWaterMarkInfo(Sandesh::QueueWaterMarkInfo &scwm);
     100             :     void ResetSessionWaterMarkInfo();
     101             :     void GetSessionWaterMarkInfo(
     102             :         std::vector<Sandesh::QueueWaterMarkInfo> &scwm_info) const;
     103             :     void ReConfigCollectors(const std::vector<std::string>&);
     104             : 
     105           0 :     int session_close_interval_msec() const {
     106           0 :         return session_close_interval_msec_;
     107             :     }
     108           0 :     uint64_t session_close_time_usec() const {
     109           0 :         return session_close_time_usec_;
     110             :     }
     111             : 
     112             :     friend class CollectorInfoRequest;
     113             : protected:
     114             :     virtual SslSession *AllocSession(SslSocket *socket);
     115             :     bool CloseSMSessionInternal();
     116             : 
     117             : private:
     118             :     static const int kSMTaskInstance = 0;
     119             :     static const std::string kSMTask;
     120             :     static const int kSessionTaskInstance = Task::kTaskInstanceAny;
     121             :     static const std::string kSessionWriterTask;
     122             :     static const std::string kSessionReaderTask;
     123             :     static const std::vector<Sandesh::QueueWaterMarkInfo> kSessionWaterMarkInfo;
     124             : 
     125             :     int sm_task_instance_;
     126             :     int sm_task_id_;
     127             :     int session_task_instance_;
     128             :     int session_writer_task_id_;
     129             :     int session_reader_task_id_;
     130             :     uint8_t dscp_value_;
     131             :     std::vector<Endpoint> collectors_;
     132             :     std::string stats_collector_;
     133             :     boost::scoped_ptr<SandeshClientSM> sm_;
     134             :     boost::scoped_ptr<StatsClient> stats_client_;
     135             :     std::vector<Sandesh::QueueWaterMarkInfo> session_wm_info_;
     136             :     static bool task_policy_set_;
     137             :     int session_close_interval_msec_;
     138             :     uint64_t session_close_time_usec_;
     139             : 
     140             :     bool ReceiveCtrlMsg(const std::string &msg,
     141             :         const SandeshHeader &header, const std::string &sandesh_name,
     142             :         const uint32_t header_offset);
     143             : 
     144             :     DISALLOW_COPY_AND_ASSIGN(SandeshClient);
     145             : };
     146             : 
     147             : #endif // __SANDESH_CLIENT_H__

Generated by: LCOV version 1.14