1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 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 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 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. 14 */ 15 16 #ifndef INCLUDE_TRAFFIC_MANAGER_H 17 #define INCLUDE_TRAFFIC_MANAGER_H 18 19 #include <ostream> 20 #include <string> 21 #include <vector> 22 23 namespace OHOS { 24 namespace nmd { 25 typedef struct TrafficStatsParcel { 26 std::string iface; 27 unsigned int ifIndex = 0; 28 long rxBytes; 29 long rxPackets; 30 long txBytes; 31 long txPackets; 32 33 friend std::ostream &operator<<(std::ostream &os, const TrafficStatsParcel &parcel) 34 { 35 os << "iface: " << parcel.iface << "ifIndex: " << parcel.ifIndex << "rxBytes: " << parcel.rxBytes 36 << "rxPackets: " << parcel.rxPackets << "txBytes: " << parcel.txBytes << "txPackets: " << parcel.txPackets; 37 return os; 38 } 39 } TrafficStatsParcel; 40 41 class TrafficManager { 42 public: 43 TrafficManager(); 44 ~TrafficManager(); 45 46 static TrafficStatsParcel GetInterfaceTraffic(const std::string &ifName); 47 static long GetAllRxTraffic(); 48 static long GetAllTxTraffic(); 49 static void TrafficManagerLog(); 50 }; 51 } // namespace nmd 52 } // namespace OHOS 53 #endif // INCLUDE_TRAFFIC_MANAGER_H 54