FD.io VPP  v21.10.1-2-g0a485f517
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 
28  : m_client(sc)
29 {}
30 
32 
33 int
35 {
36  return m_client.connect();
37 }
38 
39 void
41 {
42  m_client.disconnect();
43 }
44 
45 void
46 stat_reader::registers(const interface& intf)
47 {
48  m_stat_itf_indexes.insert(intf.handle_i().value());
49 }
50 
51 void
52 stat_reader::unregisters(const interface& intf)
53 {
54  m_stat_itf_indexes.erase(intf.handle_i().value());
55 }
56 
57 void
59 {
60  std::set<std::shared_ptr<interface>> itfs_w_stats;
61  const stat_client::stat_data_vec_t& sd = m_client.dump();
62 
63  for (auto& sde : sd) {
65 
66  if (sde.name().empty())
67  continue;
68 
69  name = sde.name();
70 
71  if (name.find("/if") != std::string::npos)
72  name.erase(0, 4);
73 
74  switch (sde.type()) {
80  break;
81 
83  uint64_t** data;
84 
85  data = sde.get_stat_segment_simple_counter_data();
86 
87  for (auto& i : m_stat_itf_indexes) {
89 
90  for (int k = 0; k < m_client.vec_len(data); k++) {
91  count.packets += data[k][i];
92  }
93 
94  std::shared_ptr<interface> itf = interface::find(i);
95  if (itf) {
96  itf->set(count, name);
97  itfs_w_stats.insert(itf);
98  }
99  }
100  break;
101  }
102 
105 
106  data = sde.get_stat_segment_combined_counter_data();
107 
108  for (auto& i : m_stat_itf_indexes) {
110 
111  for (int k = 0; k < m_client.vec_len(data); k++) {
112  count.packets += data[k][i].packets;
113  count.bytes += data[k][i].bytes;
114  }
115 
116  std::shared_ptr<interface> itf = interface::find(i);
117  if (itf) {
118  itf->set(count, name);
119  itfs_w_stats.insert(itf);
120  }
121  }
122  break;
123  }
124  }
125  }
126  for (auto itf : itfs_w_stats) {
127  itf->publish_stats();
128  }
129 }
130 
131 } // namespace VOM
132 
133 /*
134  * fd.io coding-style-patch-verification: OFF
135  *
136  * Local Variables:
137  * eval: (c-set-style "mozilla")
138  * End:
139  */
STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED
@ STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED
Definition: stat_segment_shared.h:24
VOM::stat_client::connect
int connect()
Connect to stat segment.
Definition: stat_client.cpp:137
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
name
string name[64]
Definition: fib.api:25
STAT_DIR_TYPE_NAME_VECTOR
@ STAT_DIR_TYPE_NAME_VECTOR
Definition: stat_segment_shared.h:26
VOM::handle_t::value
uint32_t value() const
get the value of the handle
Definition: types.cpp:93
VOM::stat_reader::connect
virtual int connect()
connection to stat object
Definition: stat_reader.cpp:34
STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE
@ STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE
Definition: stat_segment_shared.h:23
STAT_DIR_TYPE_EMPTY
@ STAT_DIR_TYPE_EMPTY
Definition: stat_segment_shared.h:27
count
u8 count
Definition: dhcp.api:208
VOM::stat_client::disconnect
void disconnect()
Disconnect to stat segment.
Definition: stat_client.cpp:147
VOM::stat_reader::read
virtual void read()
read stats for registered objects from stat_segment and set those stats to respective objects
Definition: stat_reader.cpp:58
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
VOM::stat_client::vec_len
int vec_len(void *vec)
Get vector length of VPP style vector.
Definition: stat_client.cpp:155
VOM::stat_reader::~stat_reader
~stat_reader()
Destructor.
Definition: stat_reader.cpp:31
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::counter_t
Definition: types.hpp:386
data
u8 data[128]
Definition: ipsec_types.api:95
VOM::stat_client::stat_data_vec_t
std::vector< stat_data_t > stat_data_vec_t
vector of stat_data_t
Definition: stat_client.hpp:89
STAT_DIR_TYPE_SCALAR_INDEX
@ STAT_DIR_TYPE_SCALAR_INDEX
Definition: stat_segment_shared.h:22
VOM::stat_reader::stat_reader
stat_reader()
Default Constructor.
Definition: stat_reader.cpp:23
VOM::stat_client
A representation of a stat client in VPP.
Definition: stat_client.hpp:32
interface.hpp
VOM::stat_client::dump
const stat_data_vec_t & dump()
dump all the stats for given pattern
Definition: stat_client.cpp:178
STAT_DIR_TYPE_ILLEGAL
@ STAT_DIR_TYPE_ILLEGAL
Definition: stat_segment_shared.h:21
i
int i
Definition: flowhash_template.h:376
VOM::stat_reader::disconnect
virtual void disconnect()
disconnect to stat object
Definition: stat_reader.cpp:40
STAT_DIR_TYPE_ERROR_INDEX
@ STAT_DIR_TYPE_ERROR_INDEX
Definition: stat_segment_shared.h:25
VOM::interface::find
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:538
string
const char *const string
Definition: cJSON.h:172
stat_reader.hpp