blob: b10cb17b247d6419376747026eb3372992c35f07 [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
25// A Network represents a collection of interfaces participating as a single administrative unit.
26class Network {
27public:
Sreeram Ramachandran36ed53e2014-07-01 19:01:56 -070028 enum Type {
29 PHYSICAL,
30 VIRTUAL,
31 };
32
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070033 // You MUST ensure that no interfaces are still assigned to this network, say by calling
34 // clearInterfaces(), before deleting it. This is because interface removal may fail. If we
35 // automatically removed interfaces in the destructor, you wouldn't know if it failed.
36 virtual ~Network();
37
Sreeram Ramachandran36ed53e2014-07-01 19:01:56 -070038 virtual Type getType() const = 0;
39
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070040 bool hasInterface(const std::string& interface) const;
41
42 // These return 0 on success or negative errno on failure.
43 virtual int addInterface(const std::string& interface) WARN_UNUSED_RESULT = 0;
44 virtual int removeInterface(const std::string& interface) WARN_UNUSED_RESULT = 0;
45 int clearInterfaces() WARN_UNUSED_RESULT;
46
47protected:
Sreeram Ramachandran89dad012014-07-02 10:09:49 -070048 explicit Network(unsigned netId);
49
Sreeram Ramachandranf4f6c8d2014-06-23 09:54:06 -070050 const unsigned mNetId;
51 std::set<std::string> mInterfaces;
52};
53
54#endif // NETD_SERVER_NETWORK_H