• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 package com.android.networkstack.tethering;
18 
19 import com.android.net.module.util.Struct;
20 import com.android.net.module.util.Struct.Field;
21 import com.android.net.module.util.Struct.Type;
22 
23 /** The value of BpfMap which is used for tethering per-interface limit. */
24 public class TetherLimitValue extends Struct {
25     // Use the signed long variable to store the int64 limit on limit BPF map.
26     // S64 is enough for each interface limit even at 5Gbps for ~468 years.
27     // 2^63 / (5 * 1000 * 1000 * 1000) * 8 / 86400 / 365 = 468.
28     // Note that QUOTA_UNLIMITED (-1) indicates there is no limit.
29     @Field(order = 0, type = Type.S64)
30     public final long limit;
31 
TetherLimitValue(final long limit)32     public TetherLimitValue(final long limit) {
33         this.limit = limit;
34     }
35 
36     // TODO: remove equals, hashCode and toString once aosp/1536721 is merged.
37     @Override
equals(Object obj)38     public boolean equals(Object obj) {
39         if (this == obj) return true;
40 
41         if (!(obj instanceof TetherLimitValue)) return false;
42 
43         final TetherLimitValue that = (TetherLimitValue) obj;
44 
45         return limit == that.limit;
46     }
47 
48     @Override
hashCode()49     public int hashCode() {
50         return Long.hashCode(limit);
51     }
52 
53     @Override
toString()54     public String toString() {
55         return String.format("limit: %d", limit);
56     }
57 }
58