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()
28 stat_reader::stat_reader(stat_client sc)
33 stat_reader::~stat_reader()
38 stat_reader::connect()
40 return m_client.connect();
44 stat_reader::disconnect()
46 m_client.disconnect();
50 stat_reader::registers(const interface& intf)
52 m_stat_itf_indexes.insert(intf.handle_i().value());
56 stat_reader::unregisters(const interface& intf)
58 m_stat_itf_indexes.erase(intf.handle_i().value());
64 std::set<std::shared_ptr<interface>> itfs_w_stats;
65 const stat_client::stat_data_vec_t& sd = m_client.dump();
67 for (auto& sde : sd) {
70 if (sde.name().empty())
75 if (name.find("/if") != std::string::npos)
79 case STAT_DIR_TYPE_ERROR_INDEX:
80 case STAT_DIR_TYPE_SCALAR_INDEX:
81 case STAT_DIR_TYPE_NAME_VECTOR:
82 case STAT_DIR_TYPE_ILLEGAL:
85 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE: {
88 data = sde.get_stat_segment_simple_counter_data();
90 for (auto& i : m_stat_itf_indexes) {
93 for (int k = 0; k < m_client.vec_len(data); k++) {
94 count.packets += data[k][i];
97 std::shared_ptr<interface> itf = interface::find(i);
99 itf->set(count, name);
100 itfs_w_stats.insert(itf);
106 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED: {
107 vlib_counter_t** data;
109 data = sde.get_stat_segment_combined_counter_data();
111 for (auto& i : m_stat_itf_indexes) {
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;
119 std::shared_ptr<interface> itf = interface::find(i);
121 itf->set(count, name);
122 itfs_w_stats.insert(itf);
129 for (auto itf : itfs_w_stats) {
130 itf->publish_stats();
137 * fd.io coding-style-patch-verification: ON
140 * eval: (c-set-style "mozilla")