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