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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/stat_reader.hpp"
17 #include "vom/interface.hpp"
21 stat_reader::stat_indexes_t stat_reader::m_stat_itf_indexes;
23 stat_reader::stat_reader()
27 stat_reader::stat_reader(stat_client sc)
31 stat_reader::~stat_reader() {}
34 stat_reader::connect()
36 return m_client.connect();
40 stat_reader::disconnect()
42 m_client.disconnect();
46 stat_reader::registers(const interface& intf)
48 m_stat_itf_indexes.insert(intf.handle_i().value());
52 stat_reader::unregisters(const interface& intf)
54 m_stat_itf_indexes.erase(intf.handle_i().value());
60 std::set<std::shared_ptr<interface>> itfs_w_stats;
61 const stat_client::stat_data_vec_t& sd = m_client.dump();
63 for (auto& sde : sd) {
66 if (sde.name().empty())
71 if (name.find("/if") != std::string::npos)
75 case STAT_DIR_TYPE_ERROR_INDEX:
76 case STAT_DIR_TYPE_SCALAR_INDEX:
77 case STAT_DIR_TYPE_NAME_VECTOR:
78 case STAT_DIR_TYPE_ILLEGAL:
79 case STAT_DIR_TYPE_EMPTY:
82 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE: {
85 data = sde.get_stat_segment_simple_counter_data();
87 for (auto& i : m_stat_itf_indexes) {
90 for (int k = 0; k < m_client.vec_len(data); k++) {
91 count.packets += data[k][i];
94 std::shared_ptr<interface> itf = interface::find(i);
96 itf->set(count, name);
97 itfs_w_stats.insert(itf);
103 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED: {
104 vlib_counter_t** data;
106 data = sde.get_stat_segment_combined_counter_data();
108 for (auto& i : m_stat_itf_indexes) {
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;
116 std::shared_ptr<interface> itf = interface::find(i);
118 itf->set(count, name);
119 itfs_w_stats.insert(itf);
126 for (auto itf : itfs_w_stats) {
127 itf->publish_stats();
134 * fd.io coding-style-patch-verification: ON
137 * eval: (c-set-style "mozilla")