OpenSDN source code
sandesh_client.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // sandesh_client.h
7 //
8 // Sandesh Analytics Database Client
9 //
10 
11 #ifndef __SANDESH_CLIENT_H__
12 #define __SANDESH_CLIENT_H__
13 
14 #include <boost/asio.hpp>
15 #include <boost/statechart/state_machine.hpp>
16 #include <boost/asio/ip/tcp.hpp>
17 #include <boost/scoped_ptr.hpp>
18 #include <boost/ptr_container/ptr_map.hpp>
19 #include <boost/tuple/tuple.hpp>
20 
21 #include <io/tcp_server.h>
22 #include <io/ssl_server.h>
23 #include <io/ssl_session.h>
24 #include <base/queue_task.h>
25 #include <base/timer.h>
26 #include <sandesh/stats_client.h>
27 #include <sandesh/sandesh_session.h>
28 #include "sandesh_client_sm.h"
29 #include "sandesh.h"
30 
31 class SandeshClient;
32 class Sandesh;
33 class SandeshUVE;
34 class SandeshHeader;
35 
36 bool DoCloseSMSession(uint64_t now_usec, uint64_t last_close_usec,
37  uint64_t last_close_interval_usec, int *close_interval_msec);
38 
40 public:
41  static const int kInitialSMSessionCloseIntervalMSec = 10 * 1000;
42  static const int kMaxSMSessionCloseIntervalMSec = 60 * 1000;
43 
44  SandeshClient(EventManager *evm, const std::vector<Endpoint> &collectors,
45  const SandeshConfig &config,
46  bool periodicuve = false);
47 
48  virtual ~SandeshClient();
49 
50  void Initiate();
51  void Shutdown();
52 
57 
58  void InitializeSMSession(int connects);
61  }
62  bool CloseSMSession();
63  bool ReceiveMsg(const std::string& msg,
64  const SandeshHeader &header, const std::string &sandesh_name,
65  const uint32_t header_offset);
66  void SendUVE(int count,
67  const std::string & stateName, const std::string & server,
68  const Endpoint & server_ip, const std::vector<Endpoint> & collector_eps);
69 
70  bool SendSandesh(Sandesh *snh);
71 
72  bool SendSandeshUVE(Sandesh *snh_uve);
73 
75  return sm_->state();
76  }
77 
78  bool IsSession() {
79  if (sm_->session()) return true;
80  else return false;
81  }
82 
83  SandeshSession * session() const {
84  return sm_->session();
85  }
86 
88  return sm_.get();
89  }
90 
92  return stats_client_.get();
93  }
94 
95  void SetDscpValue(uint8_t value);
96  uint8_t dscp_value() const { return dscp_value_; }
97 
101  std::vector<Sandesh::QueueWaterMarkInfo> &scwm_info) const;
102  void ReConfigCollectors(const std::vector<std::string>&);
103 
106  }
107  uint64_t session_close_time_usec() const {
109  }
110 
111  friend class CollectorInfoRequest;
112 protected:
113  virtual SslSession *AllocSession(SslSocket *socket);
114  bool CloseSMSessionInternal();
115 
116 private:
117  static const int kSMTaskInstance = 0;
118  static const std::string kSMTask;
120  static const std::string kSessionWriterTask;
121  static const std::string kSessionReaderTask;
122  static const std::vector<Sandesh::QueueWaterMarkInfo> kSessionWaterMarkInfo;
123 
129  uint8_t dscp_value_;
130  std::vector<Endpoint> collectors_;
131  std::string stats_collector_;
132  boost::scoped_ptr<SandeshClientSM> sm_;
133  boost::scoped_ptr<StatsClient> stats_client_;
134  std::vector<Sandesh::QueueWaterMarkInfo> session_wm_info_;
135  static bool task_policy_set_;
138 
139  bool ReceiveCtrlMsg(const std::string &msg,
140  const SandeshHeader &header, const std::string &sandesh_name,
141  const uint32_t header_offset);
142 
144 };
145 
146 #endif // __SANDESH_CLIENT_H__
void InitializeSMSession(int connects)
int session_close_interval_msec() const
virtual SandeshSession * CreateSMSession(SslSession::EventObserver eocb, SandeshReceiveMsgCb rmcb, TcpServer::Endpoint ep)
SandeshSession * session() const
std::vector< Sandesh::QueueWaterMarkInfo > session_wm_info_
void ReConfigCollectors(const std::vector< std::string > &)
std::vector< Endpoint > collectors_
static const std::string kSessionReaderTask
uint64_t session_close_time_usec_
void DeleteSMSession(SandeshSession *session)
void GetSessionWaterMarkInfo(std::vector< Sandesh::QueueWaterMarkInfo > &scwm_info) const
bool ReceiveMsg(const std::string &msg, const SandeshHeader &header, const std::string &sandesh_name, const uint32_t header_offset)
friend class CollectorInfoRequest
boost::scoped_ptr< StatsClient > stats_client_
int session_task_instance_
virtual ~SandeshClient()
static bool task_policy_set_
void ResetSessionWaterMarkInfo()
static const int kInitialSMSessionCloseIntervalMSec
void SetDscpValue(uint8_t value)
bool CloseSMSessionInternal()
bool SendSandeshUVE(Sandesh *snh_uve)
uint64_t session_close_time_usec() const
void SendUVE(int count, const std::string &stateName, const std::string &server, const Endpoint &server_ip, const std::vector< Endpoint > &collector_eps)
uint8_t dscp_value() const
SandeshClientSM::State state()
StatsClient * stats_client() const
std::string stats_collector_
uint8_t dscp_value_
static const int kMaxSMSessionCloseIntervalMSec
static const int kSMTaskInstance
int session_writer_task_id_
bool SendSandesh(Sandesh *snh)
int session_close_interval_msec_
static const int kSessionTaskInstance
bool ReceiveCtrlMsg(const std::string &msg, const SandeshHeader &header, const std::string &sandesh_name, const uint32_t header_offset)
static const std::vector< Sandesh::QueueWaterMarkInfo > kSessionWaterMarkInfo
static const std::string kSessionWriterTask
int session_reader_task_id_
static const std::string kSMTask
DISALLOW_COPY_AND_ASSIGN(SandeshClient)
boost::scoped_ptr< SandeshClientSM > sm_
SandeshClient(EventManager *evm, const std::vector< Endpoint > &collectors, const SandeshConfig &config, bool periodicuve=false)
void SetSessionWaterMarkInfo(Sandesh::QueueWaterMarkInfo &scwm)
SandeshClientSM * state_machine() const
virtual SslSession * AllocSession(SslSocket *socket)
boost::tuple< size_t, SandeshLevel::type, bool, bool > QueueWaterMarkInfo
Definition: cpp/sandesh.h:149
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
Definition: ssl_server.h:16
static const int kTaskInstanceAny
Specifies value for wildcard (any or *) task data ID.
Definition: task.h:104
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp_server.h:30
virtual void DeleteSession(TcpSession *session)
Definition: tcp_server.cc:199
boost::function< void(TcpSession *, Event)> EventObserver
Definition: tcp_session.h:59
static EventManager evm
bool DoCloseSMSession(uint64_t now_usec, uint64_t last_close_usec, uint64_t last_close_interval_usec, int *close_interval_msec)
boost::function< bool(const std::string &, SandeshSession *)> SandeshReceiveMsgCb