1 /*
2  * Copyright (c) 2022-2023 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_PHYSICAL_NETWORK_H
17 #define INCLUDE_PHYSICAL_NETWORK_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "netsys_network.h"
23 #include "network_permission.h"
24 
25 namespace OHOS {
26 namespace nmd {
27 class PhysicalNetwork : public NetsysNetwork {
28 public:
29     PhysicalNetwork(uint16_t netId, NetworkPermission permission);
30     virtual ~PhysicalNetwork() = default;
31 
32     /**
33      * Call RouteManager's AddInterfaceToDefaultNetwork
34      *
35      */
36     void AddDefault();
37 
38     /**
39      * Call RouteManager's RemoveInterfaceFromDefaultNetwork
40      *
41      */
42     void RemoveDefault();
43 
44     /**
45      * Judge network type whether or not physical
46      *
47      * @return Returns true physical
48      */
IsPhysical()49     bool IsPhysical() override
50     {
51         return true;
52     }
53 
54     /**
55      * Get Network permission
56      *
57      * @return Returns permission_
58      */
GetPermission()59     NetworkPermission GetPermission() const
60     {
61         return permission_;
62     }
63 
64 private:
GetNetworkType()65     std::string GetNetworkType() const override
66     {
67         return "PHYSICAL";
68     };
69     int32_t AddInterface(std::string &interfaceName) override;
70     int32_t RemoveInterface(std::string &interfaceName) override;
71     bool isDefault_ = false;
72     NetworkPermission permission_;
73     std::mutex physicalNetMutex_;
74 };
75 } // namespace nmd
76 } // namespace OHOS
77 #endif // INCLUDE_PHYSICAL_NETWORK_H
78