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 stat_client::stat_data_vec_t sd = m_client.dump();
65 for (auto& sde : sd) {
68 if (sde.name().empty())
74 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
75 case STAT_DIR_TYPE_ERROR_INDEX:
76 case STAT_DIR_TYPE_SCALAR_INDEX:
79 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
80 if (name.find("/if") != std::string::npos)
82 for (auto& i : m_stat_itf_indexes) {
83 counter_t count = {.packets = 0, .bytes = 0 };
84 for (int k = 0; k < m_client.vec_len(
85 sde.get_stat_segment_combined_counter_data());
88 sde.get_stat_segment_combined_counter_data()[k][i].packets;
90 sde.get_stat_segment_combined_counter_data()[k][i].bytes;
92 std::shared_ptr<interface> itf = interface::find(i);
94 itf->set(count, name);
102 for (auto& i : m_stat_itf_indexes) {
103 std::shared_ptr<interface> itf = interface::find(i);
105 itf->publish_stats();
112 * fd.io coding-style-patch-verification: ON
115 * eval: (c-set-style "mozilla")