FD.io VPP  v20.01-48-g3e0dafb74
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()) {
83  break;
84 
86  uint64_t** data;
87 
88  data = sde.get_stat_segment_simple_counter_data();
89 
90  for (auto& i : m_stat_itf_indexes) {
92 
93  for (int k = 0; k < m_client.vec_len(data); k++) {
94  count.packets += data[k][i];
95  }
96 
97  std::shared_ptr<interface> itf = interface::find(i);
98  if (itf) {
99  itf->set(count, name);
100  itfs_w_stats.insert(itf);
101  }
102  }
103  break;
104  }
105 
108 
109  data = sde.get_stat_segment_combined_counter_data();
110 
111  for (auto& i : m_stat_itf_indexes) {
113 
114  for (int k = 0; k < m_client.vec_len(data); k++) {
115  count.packets += data[k][i].packets;
116  count.bytes += data[k][i].bytes;
117  }
118 
119  std::shared_ptr<interface> itf = interface::find(i);
120  if (itf) {
121  itf->set(count, name);
122  itfs_w_stats.insert(itf);
123  }
124  }
125  break;
126  }
127  }
128  }
129  for (auto itf : itfs_w_stats) {
130  itf->publish_stats();
131  }
132 }
133 
134 } // namespace VOM
135 
136 /*
137  * fd.io coding-style-patch-verification: ON
138  *
139  * Local Variables:
140  * eval: (c-set-style "mozilla")
141  * End:
142  */
u8 count
Definition: dhcp.api:208
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
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.
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
string name[64]
Definition: ip.api:44
u8 data[128]
Definition: ipsec_types.api:87
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:44