blob: db57208141073f0df2806a2b029e1ba4cc172046 [file] [log] [blame]
JP Abgrall4a5f5ca2011-06-15 18:37:39 -07001/*
2 * Copyright (C) 2011 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#ifndef _BANDWIDTH_CONTROLLER_H
17#define _BANDWIDTH_CONTROLLER_H
18
19#include <list>
20#include <string>
21
22class BandwidthController {
23public:
24 BandwidthController();
25 int enableBandwidthControl(void);
26 int disableBandwidthControl(void);
27 int setInterfaceQuota(const char *iface, int64_t bytes);
28
29protected:
30 int runCommands(const char *commands[], int numCommands,
31 bool allowFailure = false);
32 int removeQuota(const char *iface);
33 std::list<std::string /*ifaceName*/> ifaceRules;
34
35private:
36 static const char *cleanupCommands[];
37 static const char *setupCommands[];
38 static const char *basicAccountingCommands[];
39 static const int MAX_CMD_LEN;
40 static const int MAX_IFACENAME_LEN;
41 static const int MAX_CMD_ARGS;
42 static const char IPTABLES_PATH[];
43
44 static int runIptablesCmd(const char *cmd);
45};
46
47#endif