blob: 01f33ff05ded27b0641e1d455d86004f5d685425 [file] [log] [blame]
Carmelo Cascone87892e22017-11-13 16:01:29 -08001/*
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
17package org.onosproject.p4runtime.model;
18
19import org.onosproject.net.pi.model.PiCounterId;
20import org.onosproject.net.pi.model.PiCounterModel;
21import org.onosproject.net.pi.model.PiCounterType;
22import org.onosproject.net.pi.model.PiTableId;
23
24import java.util.Objects;
25
pierventre4d2a5422021-01-10 17:29:03 -080026import static com.google.common.base.MoreObjects.toStringHelper;
27
Carmelo Cascone87892e22017-11-13 16:01:29 -080028/**
29 * Implementation of PiCounterModel for P4Runtime.
30 */
31final 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 }
pierventre4d2a5422021-01-10 17:29:03 -080093
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 Cascone87892e22017-11-13 16:01:29 -0800104}