Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 org.onosproject.p4runtime.model; |
| 18 | |
| 19 | import org.onosproject.net.pi.model.PiCounterId; |
| 20 | import org.onosproject.net.pi.model.PiCounterModel; |
| 21 | import org.onosproject.net.pi.model.PiCounterType; |
| 22 | import org.onosproject.net.pi.model.PiTableId; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
pierventre | 4d2a542 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Implementation of PiCounterModel for P4Runtime. |
| 30 | */ |
| 31 | final class P4CounterModel implements PiCounterModel { |
| 32 | |
| 33 | private final PiCounterId id; |
| 34 | private final PiCounterType counterType; |
| 35 | private final Unit unit; |
| 36 | private final PiTableId table; |
| 37 | private final long size; |
| 38 | |
| 39 | P4CounterModel(PiCounterId id, PiCounterType counterType, |
| 40 | Unit unit, PiTableId table, long size) { |
| 41 | this.id = id; |
| 42 | this.counterType = counterType; |
| 43 | this.unit = unit; |
| 44 | this.table = table; |
| 45 | this.size = size; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public PiCounterId id() { |
| 50 | return id; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public PiCounterType counterType() { |
| 55 | return counterType; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Unit unit() { |
| 60 | return unit; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public PiTableId table() { |
| 65 | return table; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public long size() { |
| 70 | return size; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int hashCode() { |
| 75 | return Objects.hash(id, counterType, unit, table, size); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object obj) { |
| 80 | if (this == obj) { |
| 81 | return true; |
| 82 | } |
| 83 | if (obj == null || getClass() != obj.getClass()) { |
| 84 | return false; |
| 85 | } |
| 86 | final P4CounterModel other = (P4CounterModel) obj; |
| 87 | return Objects.equals(this.id, other.id) |
| 88 | && Objects.equals(this.counterType, other.counterType) |
| 89 | && Objects.equals(this.unit, other.unit) |
| 90 | && Objects.equals(this.table, other.table) |
| 91 | && Objects.equals(this.size, other.size); |
| 92 | } |
pierventre | 4d2a542 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 93 | |
| 94 | @Override |
| 95 | public String toString() { |
| 96 | return toStringHelper(this) |
| 97 | .add("id", id) |
| 98 | .add("counterType", counterType) |
| 99 | .add("unit", unit) |
| 100 | .add("table", table) |
| 101 | .add("size", size) |
| 102 | .toString(); |
| 103 | } |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 104 | } |