FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
stat_reader.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "vom/stat_reader.hpp"
17 #include "vom/interface.hpp"
18 
19 namespace VOM {
20 
21 stat_reader::stat_indexes_t stat_reader::m_stat_itf_indexes;
22 
24  : m_client()
25 {
26 }
27 
29  : m_client(sc)
30 {
31 }
32 
34 {
35 }
36 
37 int
39 {
40  return m_client.connect();
41 }
42 
43 void
45 {
46  m_client.disconnect();
47 }
48 
49 void
50 stat_reader::registers(const interface& intf)
51 {
52  m_stat_itf_indexes.insert(intf.handle_i().value());
53 }
54 
55 void
56 stat_reader::unregisters(const interface& intf)
57 {
58  m_stat_itf_indexes.erase(intf.handle_i().value());
59 }
60 
61 void
63 {
64  std::set<std::shared_ptr<interface>> itfs_w_stats;
65  const stat_client::stat_data_vec_t& sd = m_client.dump();
66 
67  for (auto& sde : sd) {
68  std::string name;
69 
70  if (sde.name().empty())
71  continue;
72 
73  name = sde.name();
74 
75  if (name.find("/if") != std::string::npos)
76  name.erase(0, 4);
77 
78  switch (sde.type()) {
82  break;
83 
85  uint64_t** data;
86 
87  data = sde.get_stat_segment_simple_counter_data();
88 
89  for (auto& i : m_stat_itf_indexes) {
91 
92  for (int k = 0; k < m_client.vec_len(data); k++) {
93  count.packets += data[k][i];
94  }
95 
96  std::shared_ptr<interface> itf = interface::find(i);
97  if (itf) {
98  itf->set(count, name);
99  itfs_w_stats.insert(itf);
100  }
101  }
102  break;
103  }
104 
106  vlib_counter_t** data;
107 
108  data = sde.get_stat_segment_combined_counter_data();
109 
110  for (auto& i : m_stat_itf_indexes) {
112 
113  for (int k = 0; k < m_client.vec_len(data); k++) {
114  count.packets += data[k][i].packets;
115  count.bytes += data[k][i].bytes;
116  }
117 
118  std::shared_ptr<interface> itf = interface::find(i);
119  if (itf) {
120  itf->set(count, name);
121  itfs_w_stats.insert(itf);
122  }
123  }
124  break;
125  }
126  }
127  }
128  for (auto itf : itfs_w_stats) {
129  itf->publish_stats();
130  }
131 }
132 
133 } // namespace VOM
134 
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "mozilla")
140  * End:
141  */
stat_reader()
Default Constructor.
Definition: stat_reader.cpp:23
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:527
virtual void read()
read stats for registered objects from stat_segment and set those stats to respective objects ...
Definition: stat_reader.cpp:62
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
int i
uint64_t packets
Definition: types.hpp:398
uint64_t bytes
Definition: types.hpp:399
virtual int connect()
connection to stat object
Definition: stat_reader.cpp:38
counter_t packets
packet counter
Definition: counter_types.h:28
int vec_len(void *vec)
Get vector length of VPP style vector.
u8 name[64]
Definition: memclnt.api:152
void disconnect()
Disconnect to stat segment.
A representation of a stat client in VPP.
Definition: stat_client.hpp:32
~stat_reader()
Destructor.
Definition: stat_reader.cpp:33
std::vector< stat_data_t > stat_data_vec_t
vector of stat_data_t
Definition: stat_client.hpp:89
A representation of an interface in VPP.
Definition: interface.hpp:41
int connect()
Connect to stat segment.
const stat_data_vec_t & dump()
dump all the stats for given pattern
size_t count
Definition: vapi.c:47
counter_t bytes
byte counter
Definition: counter_types.h:29
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
virtual void disconnect()
disconnect to stat object
Definition: stat_reader.cpp:44