/* * Copyright (c) 2021 Huawei Device Co., Ltd. * 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. */ #ifndef NETWORK_PLUGIN_H #define NETWORK_PLUGIN_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "logging.h" #include "network_plugin_config.pb.h" #include "network_plugin_result.pb.h" struct NetDetails { uint64_t tx; uint64_t rx; std::string type; }; struct NetworkCell { int32_t pid; uint64_t tx; uint64_t rx; struct timespec ts; std::vector details; }; enum NetworkNum { IFACE_INDEX = 2, UID_INDEX = 4, RX_INDEX = 6, TX_INDEX = 8, DEC_BASE = 10, }; class NetworkPlugin { public: NetworkPlugin(); ~NetworkPlugin() {}; int Start(const uint8_t* configData, uint32_t configSize); int Report(uint8_t* configData, uint32_t configSize); int Stop(); protected: std::string GetRateNodePath(); int32_t GetUid(int32_t pid); bool ReadTxRxBytes(int32_t pid, NetworkCell &cell); void AddNetDetails(NetworkCell& cell, NetDetails& data); // for UT void setPathForTest(std::string path) { fileForTest_ = path; } std::string getPathForTest() { return fileForTest_; } private: NetworkConfig protoConfig_; std::unique_ptr buffer_; std::unique_ptr fp_; std::unordered_map pidUid_; std::string fileForTest_; }; #endif