blob: de6e755606637c2a735b19a1be7fd8981000f725 [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
26/**
27 * Implementation of PiCounterModel for P4Runtime.
28 */
29final class P4CounterModel implements PiCounterModel {
30
31 private final PiCounterId id;
32 private final PiCounterType counterType;
33 private final Unit unit;
34 private final PiTableId table;
35 private final long size;
36
37 P4CounterModel(PiCounterId id, PiCounterType counterType,
38 Unit unit, PiTableId table, long size) {
39 this.id = id;
40 this.counterType = counterType;
41 this.unit = unit;
42 this.table = table;
43 this.size = size;
44 }
45
46 @Override
47 public PiCounterId id() {
48 return id;
49 }
50
51 @Override
52 public PiCounterType counterType() {
53 return counterType;
54 }
55
56 @Override
57 public Unit unit() {
58 return unit;
59 }
60
61 @Override
62 public PiTableId table() {
63 return table;
64 }
65
66 @Override
67 public long size() {
68 return size;
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(id, counterType, unit, table, size);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj == null || getClass() != obj.getClass()) {
82 return false;
83 }
84 final P4CounterModel other = (P4CounterModel) obj;
85 return Objects.equals(this.id, other.id)
86 && Objects.equals(this.counterType, other.counterType)
87 && Objects.equals(this.unit, other.unit)
88 && Objects.equals(this.table, other.table)
89 && Objects.equals(this.size, other.size);
90 }
91}