blob: 69af3ff7775fd8c3d99718002c5a301b62ea8092 [file] [log] [blame]
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -07001/*
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
17#ifndef NETD_SERVER_NETWORK_H
18#define NETD_SERVER_NETWORK_H
19
20#include "NetdConstants.h"
21
22#include <set>
23#include <string>
24
Lorenzo Colitti7035f222017-02-13 18:29:00 +090025namespace android {
26namespace net {
27
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070028// A Network represents a collection of interfaces participating as a single administrative unit.
29class Network {
30public:
Sreeram Ramachandran36ed53e2014-07-01 19:01:56 -070031 enum Type {
Lorenzo Colitti36679362015-02-25 10:26:19 +090032 DUMMY,
Sreeram Ramachandran6a773532014-07-11 09:10:20 -070033 LOCAL,
Sreeram Ramachandran36ed53e2014-07-01 19:01:56 -070034 PHYSICAL,
35 VIRTUAL,
36 };
37
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070038 // You MUST ensure that no interfaces are still assigned to this network, say by calling
39 // clearInterfaces(), before deleting it. This is because interface removal may fail. If we
40 // automatically removed interfaces in the destructor, you wouldn't know if it failed.
41 virtual ~Network();
42
Sreeram Ramachandran36ed53e2014-07-01 19:01:56 -070043 virtual Type getType() const = 0;
Sreeram Ramachandrane09b20a2014-07-05 17:15:14 -070044 unsigned getNetId() const;
Sreeram Ramachandran36ed53e2014-07-01 19:01:56 -070045
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070046 bool hasInterface(const std::string& interface) const;
Sreeram Ramachandran48e19b02014-07-22 22:23:20 -070047 const std::set<std::string>& getInterfaces() const;
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070048
49 // These return 0 on success or negative errno on failure.
50 virtual int addInterface(const std::string& interface) WARN_UNUSED_RESULT = 0;
51 virtual int removeInterface(const std::string& interface) WARN_UNUSED_RESULT = 0;
52 int clearInterfaces() WARN_UNUSED_RESULT;
53
Erik Kline2d3a1632016-03-15 16:33:48 +090054 std::string toString() const;
55
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070056protected:
Sreeram Ramachandran89dad012014-07-02 10:09:49 -070057 explicit Network(unsigned netId);
58
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070059 const unsigned mNetId;
60 std::set<std::string> mInterfaces;
61};
62
Lorenzo Colitti7035f222017-02-13 18:29:00 +090063} // namespace net
64} // namespace android
65
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070066#endif // NETD_SERVER_NETWORK_H