1 /* 2 * Copyright (C) 2021 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_NETWORK_CONTROLLER_H__ 17 #define INCLUDE_NETWORK_CONTROLLER_H__ 18 19 #include <map> 20 #include <vector> 21 #include <set> 22 #include "nmd_network.h" 23 24 namespace OHOS { 25 namespace nmd { 26 class NetworkController { 27 public: 28 NetworkController() = default; 29 ~NetworkController(); 30 31 int CreatePhysicalNetwork(uint16_t netId, NetworkPermission permission); 32 33 int DestroyNetwork(int netId); 34 35 int SetDefaultNetwork(int netId); 36 37 int ClearDefaultNetwork(); 38 39 int GetDefaultNetwork(); 40 41 int AddInterfaceToNetwork(int netId, std::string &interafceName); 42 43 int RemoveInterfaceFromNetwork(int netId, std::string &interafceName); 44 45 int AddRoute(int netId, std::string interfaceName, std::string destination, std::string nextHop); 46 47 int RemoveRoute(int netId, std::string interfaceName, std::string destination, std::string nextHop); 48 49 int GetFwmarkForNetwork(int netId); 50 51 int SetPermissionForNetwork(int netId, NetworkPermission permission); 52 53 std::vector<nmd::NmdNetwork *> GetNetworks(); 54 55 nmd::NmdNetwork *GetNetwork(int netId); 56 57 private: 58 int defaultNetId; 59 std::map<int, NmdNetwork *> networks; 60 std::tuple<bool, nmd::NmdNetwork *> FindNetworkById(int netId); 61 int GetNetworkForInterface(std::string &interfaceName); 62 }; 63 } // namespace nmd 64 } // namespace OHOS 65 #endif // !INCLUDE_NETWORK_CONTROLLER_H__ 66