OpenSDN source code
agent_stats_sandesh_context.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 <net/if.h>
7 
8 #include <uve/agent_uve_stats.h>
11 #include <cmn/agent_stats.h>
12 #include <oper/vrf.h>
13 #include <vrouter_types.h>
14 
16  : agent_(agent), marker_id_(kInvalidIndex), check_marker_(check) {
17  AgentUveStats *uve = static_cast<AgentUveStats *>(agent_->uve());
18  stats_ = uve->stats_manager();
19 }
20 
22 }
23 
25  return (response_code_ & VR_MESSAGE_DUMP_INCOMPLETE);
26 }
27 
29  int code = r->get_resp_code();
30 
31  set_response_code(code);
32  if (code > 0) {
33  /* Positive value indicates the number of records returned in the
34  * response from Kernel. Kernel response includes vr_response along
35  * with actual response.
36  */
37  return 0;
38  }
39 
40  if (code < 0) {
41  LOG(ERROR, "Error in reading Statistics from vrouter: " <<
43  return -code;
44  }
45 
46  return 0;
47 }
48 
50  const {
52  if (intf == NULL) {
53  return NULL;
54  }
55 
56  return stats_->GetInterfaceStats(intf);
57 }
58 
59 void AgentStatsSandeshContext::IfMsgHandler(vr_interface_req *req) {
60  set_marker_id(req->get_vifr_idx());
62  (marker_id());
63  if (intf == NULL) {
64  return;
65  }
66 
68 
69  if (!stats) {
70  return;
71  }
72  if (intf->type() == Interface::VM_INTERFACE) {
73  agent_->stats()->incr_in_pkts(req->get_vifr_ipackets() -
74  stats->in_pkts);
75  agent_->stats()->incr_in_bytes(req->get_vifr_ibytes() -
76  stats->in_bytes);
77  agent_->stats()->incr_out_pkts(req->get_vifr_opackets() -
78  stats->out_pkts);
79  agent_->stats()->incr_out_bytes(req->get_vifr_obytes() -
80  stats->out_bytes);
81  }
82 
83  stats->drop_stats_received = false;
84  stats->UpdateStats(req->get_vifr_ibytes(), req->get_vifr_ipackets(),
85  req->get_vifr_obytes(), req->get_vifr_opackets());
86  stats->speed = req->get_vifr_speed();
87  stats->duplexity = req->get_vifr_duplex();
88 }
89 
90 void AgentStatsSandeshContext::VrfStatsMsgHandler(vr_vrf_stats_req *req) {
91  set_marker_id(req->get_vsr_vrf());
92  bool vrf_present = true;
93  const VrfEntry *vrf = agent_->vrf_table()->
94  FindVrfFromId(req->get_vsr_vrf());
95  if (vrf == NULL) {
96  if (req->get_vsr_vrf() != stats_->GetNamelessVrfId()) {
97  vrf_present = false;
98  } else {
99  return;
100  }
101  }
102 
103  StatsManager::VrfStats *stats = stats_->GetVrfStats(req->get_vsr_vrf());
104  if (!stats) {
105  LOG(DEBUG, "Vrf not present in stats tree <" << req->get_vsr_vrf()
106  << ">");
107  return;
108  }
109  if (!vrf_present) {
110  stats->prev_discards = req->get_vsr_discards();
111  stats->prev_resolves = req->get_vsr_resolves();
112  stats->prev_receives = req->get_vsr_receives();
113  stats->prev_udp_tunnels = req->get_vsr_udp_tunnels();
114  stats->prev_udp_mpls_tunnels = req->get_vsr_udp_mpls_tunnels();
115  stats->prev_gre_mpls_tunnels = req->get_vsr_gre_mpls_tunnels();
116  stats->prev_ecmp_composites = req->get_vsr_ecmp_composites();
117  stats->prev_l2_mcast_composites = req->get_vsr_l2_mcast_composites();
118  stats->prev_fabric_composites = req->get_vsr_fabric_composites();
119  stats->prev_encaps = req->get_vsr_encaps();
120  stats->prev_l2_encaps = req->get_vsr_l2_encaps();
121 
122  stats->prev_gros = req->get_vsr_gros();
123  stats->prev_diags = req->get_vsr_diags();
124  stats->prev_encap_composites = req->get_vsr_encap_composites();
125  stats->prev_evpn_composites = req->get_vsr_evpn_composites();
126  stats->prev_vrf_translates = req->get_vsr_vrf_translates();
127  stats->prev_vxlan_tunnels = req->get_vsr_vxlan_tunnels();
128  stats->prev_arp_virtual_proxy = req->get_vsr_arp_virtual_proxy();
129  stats->prev_arp_virtual_stitch = req->get_vsr_arp_virtual_stitch();
130  stats->prev_arp_virtual_flood = req->get_vsr_arp_virtual_flood();
131  stats->prev_arp_physical_stitch = req->get_vsr_arp_physical_stitch();
132  stats->prev_arp_tor_proxy = req->get_vsr_arp_tor_proxy();
133  stats->prev_arp_physical_flood = req->get_vsr_arp_physical_flood();
134  stats->prev_l2_receives = req->get_vsr_l2_receives();
135  stats->prev_uuc_floods = req->get_vsr_uuc_floods();
136  } else {
137  stats->discards = req->get_vsr_discards() - stats->prev_discards;
138  stats->resolves = req->get_vsr_resolves() - stats->prev_resolves;
139  stats->receives = req->get_vsr_receives() - stats->prev_receives;
140  stats->udp_tunnels = req->get_vsr_udp_tunnels() -
141  stats->prev_udp_tunnels;
142  stats->gre_mpls_tunnels = req->get_vsr_gre_mpls_tunnels() -
143  stats->prev_gre_mpls_tunnels;
144  stats->udp_mpls_tunnels = req->get_vsr_udp_mpls_tunnels() -
145  stats->prev_udp_mpls_tunnels;
146  stats->encaps = req->get_vsr_encaps() - stats->prev_encaps;
147  stats->l2_encaps = req->get_vsr_l2_encaps() - stats->prev_l2_encaps;
148  stats->ecmp_composites = req->get_vsr_ecmp_composites() -
149  stats->prev_ecmp_composites;
150  stats->l2_mcast_composites = req->get_vsr_l2_mcast_composites() -
152  stats->fabric_composites = req->get_vsr_fabric_composites() -
153  stats->prev_fabric_composites;
154 
155  stats->gros = req->get_vsr_gros() - stats->prev_gros;
156  stats->diags = req->get_vsr_diags() - stats->prev_diags;
157  stats->encap_composites = req->get_vsr_encap_composites() -
158  stats->prev_encap_composites;
159  stats->evpn_composites = req->get_vsr_evpn_composites() -
160  stats->prev_evpn_composites;
161  stats->vrf_translates = req->get_vsr_vrf_translates() -
162  stats->prev_vrf_translates;
163  stats->vxlan_tunnels = req->get_vsr_vxlan_tunnels() -
164  stats->prev_vxlan_tunnels;
165  stats->arp_virtual_proxy = req->get_vsr_arp_virtual_proxy() -
166  stats->prev_arp_virtual_proxy;
167  stats->arp_virtual_stitch = req->get_vsr_arp_virtual_stitch() -
169  stats->arp_virtual_flood = req->get_vsr_arp_virtual_flood() -
170  stats->prev_arp_virtual_flood;
171  stats->arp_physical_stitch = req->get_vsr_arp_physical_stitch() -
173  stats->arp_tor_proxy = req->get_vsr_arp_tor_proxy() -
174  stats->prev_arp_tor_proxy;
175  stats->arp_physical_flood = req->get_vsr_arp_physical_flood() -
177  stats->l2_receives = req->get_vsr_l2_receives() -
178  stats->prev_l2_receives;
179  stats->uuc_floods = req->get_vsr_uuc_floods() -
180  stats->prev_uuc_floods;
181  /* Update the last read values from Kernel in the following fields.
182  * This will be used to update prev_* fields on receiving vrf delete
183  * notification
184  */
185  if (req->get_vsr_vrf() != stats_->GetNamelessVrfId()) {
186  stats->k_discards = req->get_vsr_discards();
187  stats->k_resolves = req->get_vsr_resolves();
188  stats->k_receives = req->get_vsr_receives();
189  stats->k_udp_tunnels = req->get_vsr_udp_tunnels();
190  stats->k_gre_mpls_tunnels = req->get_vsr_gre_mpls_tunnels();
191  stats->k_udp_mpls_tunnels = req->get_vsr_udp_mpls_tunnels();
192  stats->k_l2_mcast_composites = req->get_vsr_l2_mcast_composites();
193  stats->k_ecmp_composites = req->get_vsr_ecmp_composites();
194  stats->k_fabric_composites = req->get_vsr_fabric_composites();
195  stats->k_encaps = req->get_vsr_encaps();
196  stats->k_l2_encaps = req->get_vsr_l2_encaps();
197  stats->k_gros = req->get_vsr_gros();
198  stats->k_diags = req->get_vsr_diags();
199  stats->k_encap_composites = req->get_vsr_encap_composites();
200  stats->k_evpn_composites = req->get_vsr_evpn_composites();
201  stats->k_vrf_translates = req->get_vsr_vrf_translates();
202  stats->k_vxlan_tunnels = req->get_vsr_vxlan_tunnels();
203  stats->k_arp_virtual_proxy = req->get_vsr_arp_virtual_proxy();
204  stats->k_arp_virtual_stitch = req->get_vsr_arp_virtual_stitch();
205  stats->k_arp_virtual_flood = req->get_vsr_arp_virtual_flood();
206  stats->k_arp_physical_stitch = req->get_vsr_arp_physical_stitch();
207  stats->k_arp_tor_proxy = req->get_vsr_arp_tor_proxy();
208  stats->k_arp_physical_flood = req->get_vsr_arp_physical_flood();
209  stats->k_l2_receives = req->get_vsr_l2_receives();
210  stats->k_uuc_floods = req->get_vsr_uuc_floods();
211  }
212  }
213 }
214 
215 void AgentStatsSandeshContext::DropStatsMsgHandler(vr_drop_stats_req *req) {
216  /* vr_drop_stats_req msg can be received by agent in response to two
217  * possible requests :-
218  * 1. Interface request
219  * 2. Drop stats request
220  * The request is identified here using the check_marker_ field of sandesh
221  * context.
222  */
223  if (!check_marker()) {
224  stats_->set_drop_stats(*req);
225  return;
226  }
228  return;
229  }
231 
232  if (!stats) {
233  return;
234  }
235  stats->drop_stats = *req;
236  stats->drop_stats_received = true;
237 }
virtual void IfMsgHandler(vr_interface_req *req)
virtual void DropStatsMsgHandler(vr_drop_stats_req *req)
StatsManager::InterfaceStats * IdToStats(int id) const
AgentStatsSandeshContext(Agent *agent, bool check_marker)
virtual int VrResponseMsgHandler(vr_response *r)
virtual void VrfStatsMsgHandler(vr_vrf_stats_req *req)
void incr_out_pkts(uint64_t count)
Definition: agent_stats.h:180
void incr_in_pkts(uint64_t count)
Definition: agent_stats.h:174
void incr_in_bytes(uint64_t count)
Definition: agent_stats.h:177
void incr_out_bytes(uint64_t count)
Definition: agent_stats.h:183
StatsManager * stats_manager() const
Definition: agent.h:361
VrfTable * vrf_table() const
Definition: agent.h:488
AgentUveBase * uve() const
Definition: agent.cc:913
AgentStats * stats() const
Definition: agent.cc:885
static InterfaceTable * GetInstance()
Definition: interface.h:449
const Interface * FindInterface(size_t index) const
Definition: interface.cc:323
@ VM_INTERFACE
Definition: interface.h:38
Type type() const
Definition: interface.h:115
static std::string VrouterErrorToString(uint32_t error)
InterfaceStats * GetInterfaceStats(const Interface *intf)
VrfStats * GetVrfStats(int vrf_id)
void set_drop_stats(const vr_drop_stats_req &req)
int GetNamelessVrfId()
Definition: vrf.h:90
#define LOG(_Level, _Msg)
Definition: logging.h:35
vr_drop_stats_req drop_stats
Definition: stats_manager.h:61
void UpdateStats(uint64_t in_b, uint64_t in_p, uint64_t out_b, uint64_t out_p)
uint64_t prev_l2_mcast_composites
Definition: stats_manager.h:99
uint64_t prev_arp_physical_flood
uint64_t prev_gre_mpls_tunnels
Definition: stats_manager.h:97
uint64_t prev_arp_physical_stitch
uint64_t prev_arp_virtual_stitch
uint64_t prev_udp_mpls_tunnels
Definition: stats_manager.h:96