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  */
4 
5 #include <db/db.h>
6 #include <cmn/agent_cmn.h>
7 
9 #include <oper/interface.h>
10 #include <oper/mirror_table.h>
11 
12 #include "vr_genetlink.h"
13 #include "vr_interface.h"
14 #include "vr_types.h"
15 #include "nl_util.h"
16 
17 #include <uve/stats_collector.h>
19 #include <uve/vn_uve_table.h>
20 #include <uve/vm_uve_table.h>
22 #include <init/agent_param.h>
26 #include <uve/agent_uve.h>
27 #include <vrouter/stats_collector/agent_stats_interval_types.h>
28 
30  (boost::asio::io_context &io, Agent* agent)
31  : StatsCollector(TaskScheduler::GetInstance()->
32  GetTaskId("Agent::StatsCollector"),
34  io, agent->params()->agent_stats_interval(),
35  "Agent Stats collector"),
36  agent_(agent) {
40  InitDone();
41 }
42 
44 }
45 
47  vr_interface_req encoder;
48 
49  encoder.set_h_op(sandesh_op::DUMP);
50  encoder.set_vifr_context(0);
51  encoder.set_vifr_marker(intf_stats_sandesh_ctx_.get()->marker_id());
52  /* Always fetch per-interface Drop-stats along with other stats */
53  encoder.set_vifr_flags(VIF_FLAG_GET_DROP_STATS);
55 }
56 
58  vr_vrf_stats_req encoder;
59 
60  encoder.set_h_op(sandesh_op::DUMP);
61  encoder.set_vsr_rid(0);
62  encoder.set_vsr_family(AF_INET);
63  encoder.set_vsr_marker(vrf_stats_sandesh_ctx_.get()->marker_id());
64  SendRequest(encoder, VrfStatsType);
65 }
66 
68  vr_drop_stats_req encoder;
69 
70  encoder.set_h_op(sandesh_op::GET);
71  encoder.set_vds_rid(0);
72  encoder.set_vds_core(0);
73  SendRequest(encoder, DropStatsType);
74 }
75 
78  return true;
79  int encode_len;
80  int error;
81  uint8_t *buf = (uint8_t *)malloc(KSYNC_DEFAULT_MSG_SIZE);
82 
83  encode_len = encoder.WriteBinary(buf, KSYNC_DEFAULT_MSG_SIZE, &error);
84  SendAsync((char*)buf, encode_len, type);
85 
86  return true;
87 }
88 
90  StatsType type, uint32_t seq) {
91  switch (type) {
92  case InterfaceStatsType:
93  return (new InterfaceStatsIoContext(buf_len, buf, seq,
96  break;
97  case VrfStatsType:
98  return (new VrfStatsIoContext(buf_len, buf, seq,
101  break;
102  case DropStatsType:
103  return (new DropStatsIoContext(buf_len, buf, seq,
106  break;
107  default:
108  return NULL;
109  }
110 }
111 
112 void AgentStatsCollector::SendAsync(char* buf, uint32_t buf_len,
113  StatsType type) {
114  KSyncSock *sock = KSyncSock::Get(0);
115  uint32_t seq = sock->AllocSeqNo(IoContext::IOC_UVE, 0);
116 
117  IoContext *ioc = AllocateIoContext(buf, buf_len, type, seq);
118  if (ioc) {
119  sock->GenericSend(ioc);
120  }
121 }
122 
127  return true;
128 }
129 
132 }
133 
134 void SetAgentStatsInterval_InSeconds::HandleRequest() const {
135  SandeshResponse *resp;
137  if (!col) {
138  resp = new AgentStatsCfgResp();
139  } else if (get_interval() > 0) {
140  col->set_expiry_time(get_interval() * 1000);
141  resp = new AgentStatsCfgResp();
142  } else {
143  resp = new AgentStatsCfgErrResp();
144  }
145 
146  resp->set_context(context());
147  resp->Response();
148  return;
149 }
150 
151 void GetAgentStatsInterval::HandleRequest() const {
152  AgentStatsIntervalResp_InSeconds *resp =
153  new AgentStatsIntervalResp_InSeconds();
155  if (col) {
156  resp->set_agent_stats_interval((col->expiry_time())/1000);
157  }
158  resp->set_context(context());
159  resp->Response();
160  return;
161 }
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:360
AgentParam * params() const
Definition: agent.h:1226
AgentStatsCollector * stats_collector() const
Definition: agent.cc:920
static Agent * GetInstance()
Definition: agent.h:438
void GenericSend(IoContext *ctx)
Definition: ksync_sock.cc:451
uint32_t AllocSeqNo(IoContext::Type type)
Definition: ksync_sock.cc:299
static KSyncSock * Get(DBTablePartBase *partition)
Definition: ksync_sock.cc:340
virtual void Response()
Definition: cpp/sandesh.h:502
virtual int32_t WriteBinary(u_int8_t *buf, u_int32_t buf_len, int *error)
Definition: sandesh.cc:571
void set_context(std::string context)
Definition: cpp/sandesh.h:310
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:178
#define KSYNC_DEFAULT_MSG_SIZE
Definition: ksync_sock.h:27
uint8_t type
Definition: load_balance.h:2
Definition: io_utils.cc:11