Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 17 | #pragma once |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 18 | |
| 19 | #include "NetdConstants.h" |
| 20 | |
| 21 | #include <set> |
| 22 | #include <string> |
| 23 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 24 | namespace android::net { |
Lorenzo Colitti | 7035f22 | 2017-02-13 18:29:00 +0900 | [diff] [blame] | 25 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 26 | // A Network represents a collection of interfaces participating as a single administrative unit. |
| 27 | class Network { |
| 28 | public: |
Sreeram Ramachandran | 36ed53e | 2014-07-01 19:01:56 -0700 | [diff] [blame] | 29 | enum Type { |
Lorenzo Colitti | 3667936 | 2015-02-25 10:26:19 +0900 | [diff] [blame] | 30 | DUMMY, |
Sreeram Ramachandran | 6a77353 | 2014-07-11 09:10:20 -0700 | [diff] [blame] | 31 | LOCAL, |
Sreeram Ramachandran | 36ed53e | 2014-07-01 19:01:56 -0700 | [diff] [blame] | 32 | PHYSICAL, |
| 33 | VIRTUAL, |
| 34 | }; |
| 35 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 36 | // You MUST ensure that no interfaces are still assigned to this network, say by calling |
| 37 | // clearInterfaces(), before deleting it. This is because interface removal may fail. If we |
| 38 | // automatically removed interfaces in the destructor, you wouldn't know if it failed. |
| 39 | virtual ~Network(); |
| 40 | |
Sreeram Ramachandran | 36ed53e | 2014-07-01 19:01:56 -0700 | [diff] [blame] | 41 | virtual Type getType() const = 0; |
Sreeram Ramachandran | e09b20a | 2014-07-05 17:15:14 -0700 | [diff] [blame] | 42 | unsigned getNetId() const; |
Sreeram Ramachandran | 36ed53e | 2014-07-01 19:01:56 -0700 | [diff] [blame] | 43 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 44 | bool hasInterface(const std::string& interface) const; |
Sreeram Ramachandran | 48e19b0 | 2014-07-22 22:23:20 -0700 | [diff] [blame] | 45 | const std::set<std::string>& getInterfaces() const; |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 46 | |
| 47 | // These return 0 on success or negative errno on failure. |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 48 | [[nodiscard]] virtual int addInterface(const std::string& interface) = 0; |
| 49 | [[nodiscard]] virtual int removeInterface(const std::string& interface) = 0; |
| 50 | [[nodiscard]] int clearInterfaces(); |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 51 | |
Erik Kline | 2d3a163 | 2016-03-15 16:33:48 +0900 | [diff] [blame] | 52 | std::string toString() const; |
| 53 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 54 | protected: |
Sreeram Ramachandran | 89dad01 | 2014-07-02 10:09:49 -0700 | [diff] [blame] | 55 | explicit Network(unsigned netId); |
| 56 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 57 | const unsigned mNetId; |
| 58 | std::set<std::string> mInterfaces; |
| 59 | }; |
| 60 | |
Bernie Innocenti | 762dcf4 | 2019-06-14 19:52:49 +0900 | [diff] [blame] | 61 | } // namespace android::net |