1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License.
5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at
6b1b8bc3fSopenharmony_ci *
7b1b8bc3fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b1b8bc3fSopenharmony_ci *
9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and
13b1b8bc3fSopenharmony_ci * limitations under the License.
14b1b8bc3fSopenharmony_ci */
15b1b8bc3fSopenharmony_ci
16b1b8bc3fSopenharmony_ci#ifndef BPF_STATS_H
17b1b8bc3fSopenharmony_ci#define BPF_STATS_H
18b1b8bc3fSopenharmony_ci
19b1b8bc3fSopenharmony_ci#include <vector>
20b1b8bc3fSopenharmony_ci#include <cstdint>
21b1b8bc3fSopenharmony_ci#include <string>
22b1b8bc3fSopenharmony_ci
23b1b8bc3fSopenharmony_ci#include "bpf_def.h"
24b1b8bc3fSopenharmony_ci#include "bpf_mapper.h"
25b1b8bc3fSopenharmony_ci#include "net_manager_constants.h"
26b1b8bc3fSopenharmony_ci#include "net_stats_info.h"
27b1b8bc3fSopenharmony_ci
28b1b8bc3fSopenharmony_cinamespace OHOS::NetManagerStandard {
29b1b8bc3fSopenharmony_cienum class StatsType {
30b1b8bc3fSopenharmony_ci    STATS_TYPE_RX_BYTES = 0,
31b1b8bc3fSopenharmony_ci    STATS_TYPE_RX_PACKETS = 1,
32b1b8bc3fSopenharmony_ci    STATS_TYPE_TX_BYTES = 2,
33b1b8bc3fSopenharmony_ci    STATS_TYPE_TX_PACKETS = 3,
34b1b8bc3fSopenharmony_ci};
35b1b8bc3fSopenharmony_ci
36b1b8bc3fSopenharmony_ciclass NetsysBpfStats {
37b1b8bc3fSopenharmony_cipublic:
38b1b8bc3fSopenharmony_ci    NetsysBpfStats() = default;
39b1b8bc3fSopenharmony_ci    ~NetsysBpfStats() = default;
40b1b8bc3fSopenharmony_ci
41b1b8bc3fSopenharmony_ci    /**
42b1b8bc3fSopenharmony_ci     * Get the Total Stats
43b1b8bc3fSopenharmony_ci     *
44b1b8bc3fSopenharmony_ci     * @param stats Output traffic data
45b1b8bc3fSopenharmony_ci     * @param type StatsType traffic data type
46b1b8bc3fSopenharmony_ci     * @return returns total stats
47b1b8bc3fSopenharmony_ci     */
48b1b8bc3fSopenharmony_ci    int32_t GetTotalStats(uint64_t &stats, StatsType type);
49b1b8bc3fSopenharmony_ci
50b1b8bc3fSopenharmony_ci    /**
51b1b8bc3fSopenharmony_ci     * Get the Uid Stats
52b1b8bc3fSopenharmony_ci     *
53b1b8bc3fSopenharmony_ci     * @param stats Output traffic data
54b1b8bc3fSopenharmony_ci     * @param type StatsType traffic data type
55b1b8bc3fSopenharmony_ci     * @param uid app uid
56b1b8bc3fSopenharmony_ci     * @return returns uid stats
57b1b8bc3fSopenharmony_ci     */
58b1b8bc3fSopenharmony_ci    int32_t GetUidStats(uint64_t &stats, StatsType type, uint32_t uid);
59b1b8bc3fSopenharmony_ci
60b1b8bc3fSopenharmony_ci    /**
61b1b8bc3fSopenharmony_ci     * Get the Iface Stats
62b1b8bc3fSopenharmony_ci     *
63b1b8bc3fSopenharmony_ci     * @param stats Output traffic data
64b1b8bc3fSopenharmony_ci     * @param type StatsType traffic data type
65b1b8bc3fSopenharmony_ci     * @param interfaceName iface name
66b1b8bc3fSopenharmony_ci     * @return returns iface stats.
67b1b8bc3fSopenharmony_ci     */
68b1b8bc3fSopenharmony_ci    int32_t GetIfaceStats(uint64_t &stats, StatsType type, const std::string &interfaceName);
69b1b8bc3fSopenharmony_ci
70b1b8bc3fSopenharmony_ci    /**
71b1b8bc3fSopenharmony_ci     * Get the sim Stats of uid
72b1b8bc3fSopenharmony_ci     *
73b1b8bc3fSopenharmony_ci     * @param stats Stats data.
74b1b8bc3fSopenharmony_ci     * @return returns 0 for success other as failed.
75b1b8bc3fSopenharmony_ci     */
76b1b8bc3fSopenharmony_ci    int32_t GetAllSimStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats);
77b1b8bc3fSopenharmony_ci
78b1b8bc3fSopenharmony_ci    /**
79b1b8bc3fSopenharmony_ci     * Get the Iface with uid Stats
80b1b8bc3fSopenharmony_ci     *
81b1b8bc3fSopenharmony_ci     * @param stats Stats data.
82b1b8bc3fSopenharmony_ci     * @return returns 0 for success other as failed.
83b1b8bc3fSopenharmony_ci     */
84b1b8bc3fSopenharmony_ci    int32_t GetAllStatsInfo(std::vector<OHOS::NetManagerStandard::NetStatsInfo> &stats);
85b1b8bc3fSopenharmony_ci
86b1b8bc3fSopenharmony_ci    /**
87b1b8bc3fSopenharmony_ci     * Delete the Iface Stats with uid
88b1b8bc3fSopenharmony_ci     *
89b1b8bc3fSopenharmony_ci     * @param uid the uid of application
90b1b8bc3fSopenharmony_ci     * @return returns 0 for success other as failed.
91b1b8bc3fSopenharmony_ci     */
92b1b8bc3fSopenharmony_ci    int32_t DeleteStatsInfo(const std::string &path, uint32_t uid);
93b1b8bc3fSopenharmony_ci
94b1b8bc3fSopenharmony_ci    int32_t GetCookieStats(uint64_t &stats, StatsType statsType, uint64_t cookie);
95b1b8bc3fSopenharmony_ci
96b1b8bc3fSopenharmony_ciprivate:
97b1b8bc3fSopenharmony_ci    static int32_t GetNumberFromStatsValue(uint64_t &stats, StatsType statsType, const stats_value &value);
98b1b8bc3fSopenharmony_ci};
99b1b8bc3fSopenharmony_ci} // namespace OHOS::NetManagerStandard
100b1b8bc3fSopenharmony_ci#endif // BPF_STATS_H
101