1 /* 2 * Copyright (c) 2021-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_NETSYS_NETWORK_H 17 #define INCLUDE_NETSYS_NETWORK_H 18 19 #include <set> 20 #include <string> 21 22 namespace OHOS { 23 namespace nmd { 24 class NetsysNetwork { 25 public: 26 NetsysNetwork() = default; 27 virtual ~NetsysNetwork() = default; 28 29 /** 30 * Get network type 31 * 32 * @return Returns network type, it could be either 33 */ 34 virtual std::string GetNetworkType() const = 0; 35 36 /** 37 * Add an interface to a network 38 * 39 * @param interafceName The name of the interface to add 40 * 41 * @return Returns 0, successfully add an interface to a network, otherwise it will fail 42 */ 43 virtual int32_t AddInterface(std::string &) = 0; 44 45 /** 46 * Remove an interface from a network 47 * 48 * @param interafceName The name of the interface 49 * 50 * @return Returns 0, successfully remove an interface from a network, otherwise it will fail 51 */ 52 virtual int32_t RemoveInterface(std::string &) = 0; 53 54 /** 55 * Clear all interfaces 56 * 57 * @return Returns 0, successfully clear all interfaces, otherwise it will fail 58 */ 59 int32_t ClearInterfaces(); 60 61 /** 62 * Clear all interfaces 63 * 64 * @param interafceName The name of the interface 65 * 66 * @return Returns true exist interface, false otherwise 67 */ 68 bool ExistInterface(std::string &interfaceName); 69 70 /** 71 * Judge network type whether or not physical 72 * 73 * @return Returns true physical, false otherwise 74 */ IsPhysical()75 virtual bool IsPhysical() 76 { 77 return false; 78 } 79 80 /** 81 * Get all interfaces 82 * 83 * @return Returns interfaces_ 84 */ GetAllInterface()85 const std::set<std::string> &GetAllInterface() const 86 { 87 return interfaces_; 88 } 89 90 /** 91 * Get netId 92 * 93 * @return Returns netId_ 94 */ GetNetId()95 uint16_t GetNetId() const 96 { 97 return netId_; 98 } 99 100 protected: 101 explicit NetsysNetwork(uint16_t netId); 102 uint16_t netId_; 103 std::set<std::string> interfaces_; 104 }; 105 } // namespace nmd 106 } // namespace OHOS 107 #endif // INCLUDE_NETSYS_NETWORK_H 108