OpenSDN source code
agent_stats_collector.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <db/db.h>
7 #include <cmn/agent_cmn.h>
8 
10 #include <oper/interface.h>
11 #include <oper/mirror_table.h>
12 
13 #include "vr_genetlink.h"
14 #include "vr_interface.h"
15 #include "vr_types.h"
16 #include "nl_util.h"
17 
18 #include <uve/stats_collector.h>
20 #include <uve/vn_uve_table.h>
21 #include <uve/vm_uve_table.h>
23 #include <init/agent_param.h>
27 #include <uve/agent_uve.h>
28 #include <vrouter/stats_collector/agent_stats_interval_types.h>
29 
31  (boost::asio::io_context &io, Agent* agent)
32  : StatsCollector(TaskScheduler::GetInstance()->
33  GetTaskId("Agent::StatsCollector"),
35  io, agent->params()->agent_stats_interval(),
36  "Agent Stats collector"),
37  agent_(agent) {
41  InitDone();
42 }
43 
45 }
46 
48  vr_interface_req encoder;
49 
50  encoder.set_h_op(sandesh_op::DUMP);
51  encoder.set_vifr_context(0);
52  encoder.set_vifr_marker(intf_stats_sandesh_ctx_.get()->marker_id());
53  /* Always fetch per-interface Drop-stats along with other stats */
54  encoder.set_vifr_flags(VIF_FLAG_GET_DROP_STATS);
56 }
57 
59  vr_vrf_stats_req encoder;
60 
61  encoder.set_h_op(sandesh_op::DUMP);
62  encoder.set_vsr_rid(0);
63  encoder.set_vsr_family(AF_INET);
64  encoder.set_vsr_marker(vrf_stats_sandesh_ctx_.get()->marker_id());
65  SendRequest(encoder, VrfStatsType);
66 }
67 
69  vr_drop_stats_req encoder;
70 
71  encoder.set_h_op(sandesh_op::GET);
72  encoder.set_vds_rid(0);
73  encoder.set_vds_core(0);
74  SendRequest(encoder, DropStatsType);
75 }
76 
79  return true;
80  int encode_len;
81  int error;
82  uint8_t *buf = (uint8_t *)malloc(KSYNC_DEFAULT_MSG_SIZE);
83 
84  encode_len = encoder.WriteBinary(buf, KSYNC_DEFAULT_MSG_SIZE, &error);
85  SendAsync((char*)buf, encode_len, type);
86 
87  return true;
88 }
89 
91  StatsType type, uint32_t seq) {
92  switch (type) {
93  case InterfaceStatsType:
94  return (new InterfaceStatsIoContext(buf_len, buf, seq,
97  break;
98  case VrfStatsType:
99  return (new VrfStatsIoContext(buf_len, buf, seq,
102  break;
103  case DropStatsType:
104  return (new DropStatsIoContext(buf_len, buf, seq,
107  break;
108  default:
109  return NULL;
110  }
111 }
112 
113 void AgentStatsCollector::SendAsync(char* buf, uint32_t buf_len,
114  StatsType type) {
115  KSyncSock *sock = KSyncSock::Get(0);
116  uint32_t seq = sock->AllocSeqNo(IoContext::IOC_UVE, 0);
117 
118  IoContext *ioc = AllocateIoContext(buf, buf_len, type, seq);
119  if (ioc) {
120  sock->GenericSend(ioc);
121  }
122 }
123 
128  return true;
129 }
130 
133 }
134 
135 void SetAgentStatsInterval_InSeconds::HandleRequest() const {
136  SandeshResponse *resp;
138  if (!col) {
139  resp = new AgentStatsCfgResp();
140  } else if (get_interval() > 0) {
141  col->set_expiry_time(get_interval() * 1000);
142  resp = new AgentStatsCfgResp();
143  } else {
144  resp = new AgentStatsCfgErrResp();
145  }
146 
147  resp->set_context(context());
148  resp->Response();
149  return;
150 }
151 
152 void GetAgentStatsInterval::HandleRequest() const {
153  AgentStatsIntervalResp_InSeconds *resp =
154  new AgentStatsIntervalResp_InSeconds();
156  if (col) {
157  resp->set_agent_stats_interval((col->expiry_time())/1000);
158  }
159  resp->set_context(context());
160  resp->Response();
161  return;
162 }
bool cat_is_dpdk_mocked() const
Definition: agent_param.h:570
virtual IoContext * AllocateIoContext(char *buf, uint32_t buf_len, StatsType type, uint32_t seq)
void SendAsync(char *buf, uint32_t buf_len, StatsType type)
boost::scoped_ptr< AgentStatsSandeshContext > drop_stats_sandesh_ctx_
boost::scoped_ptr< AgentStatsSandeshContext > vrf_stats_sandesh_ctx_
boost::scoped_ptr< AgentStatsSandeshContext > intf_stats_sandesh_ctx_
bool SendRequest(Sandesh &encoder, StatsType type)
Definition: agent.h:361
AgentParam * params() const
Definition: agent.h:1227
AgentStatsCollector * stats_collector() const
Definition: agent.cc:921
static Agent * GetInstance()
Definition: agent.h:439
void GenericSend(IoContext *ctx)
Definition: ksync_sock.cc:457
uint32_t AllocSeqNo(IoContext::Type type)
Definition: ksync_sock.cc:305
static KSyncSock * Get(DBTablePartBase *partition)
Definition: ksync_sock.cc:346
virtual void Response()
Definition: cpp/sandesh.h:505
virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:573
void set_context(std::string context)
Definition: cpp/sandesh.h:313
void set_expiry_time(int time)
int expiry_time() const
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
#define KSYNC_DEFAULT_MSG_SIZE
Definition: ksync_sock.h:28
uint8_t type
Definition: load_balance.h:2
Definition: io_utils.cc:12