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