diff options
Diffstat (limited to 'extras/vom/vom/stat_reader.cpp')
-rw-r--r-- | extras/vom/vom/stat_reader.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/extras/vom/vom/stat_reader.cpp b/extras/vom/vom/stat_reader.cpp new file mode 100644 index 00000000000..4b054aba5af --- /dev/null +++ b/extras/vom/vom/stat_reader.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "vom/stat_reader.hpp" +#include "vom/interface.hpp" + +namespace VOM { + +stat_reader::stat_indexes_t stat_reader::m_stat_itf_indexes; + +stat_reader::stat_reader() + : m_client() +{ +} + +stat_reader::stat_reader(stat_client sc) + : m_client(sc) +{ +} + +stat_reader::~stat_reader() +{ +} + +int +stat_reader::connect() +{ + return m_client.connect(); +} + +void +stat_reader::disconnect() +{ + m_client.disconnect(); +} + +void +stat_reader::registers(const interface& intf) +{ + m_stat_itf_indexes.insert(intf.handle().value()); +} + +void +stat_reader::unregisters(const interface& intf) +{ + m_stat_itf_indexes.erase(intf.handle().value()); +} + +void +stat_reader::read() +{ + stat_client::stat_data_vec_t sd = m_client.dump(); + for (auto& sde : sd) { + std::string name; + + if (sde.name().empty()) + continue; + + name = sde.name(); + + switch (sde.type()) { + case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE: + case STAT_DIR_TYPE_ERROR_INDEX: + case STAT_DIR_TYPE_SCALAR_INDEX: + break; + + case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED: + if (name.find("/if") != std::string::npos) + name.erase(0, 4); + for (auto& i : m_stat_itf_indexes) { + counter_t count = {.packets = 0, .bytes = 0 }; + for (int k = 0; k < m_client.vec_len( + sde.get_stat_segment_combined_counter_data()); + k++) { + count.packets += + sde.get_stat_segment_combined_counter_data()[k][i].packets; + count.bytes += + sde.get_stat_segment_combined_counter_data()[k][i].bytes; + } + std::shared_ptr<interface> itf = interface::find(i); + if (itf) + itf->set(count, name); + } + break; + + default:; + } + } + + for (auto& i : m_stat_itf_indexes) { + std::shared_ptr<interface> itf = interface::find(i); + if (itf) + itf->publish_stats(); + } +} + +} // namespace VOM + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "mozilla") + * End: + */ |