FD.io VPP  v21.01.1
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_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:538
const char *const string
Definition: cJSON.h:172
virtual void read()
read stats for registered objects from stat_segment and set those stats to respective objects ...
Definition: stat_reader.cpp:58
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
uint64_t packets
Definition: types.hpp:398
u8 data[128]
Definition: ipsec_types.api:90
uint64_t bytes
Definition: types.hpp:399
virtual int connect()
connection to stat object
Definition: stat_reader.cpp:34
counter_t packets
packet counter
Definition: counter_types.h:28
int vec_len(void *vec)
Get vector length of VPP style vector.
void disconnect()
Disconnect to stat segment.
A representation of a stat client in VPP.
Definition: stat_client.hpp:32
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
~stat_reader()
Destructor.
Definition: stat_reader.cpp:31
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
string name[64]
Definition: ip.api:44
int connect()
Connect to stat segment.
const stat_data_vec_t & dump()
dump all the stats for given pattern
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:40
u8 count
Definition: dhcp.api:208