blob: a11c8ec49fd6fc2e2b2a9d3d3922fe9872256791 [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.PiMeterId;
20import org.onosproject.net.pi.model.PiMeterModel;
21import org.onosproject.net.pi.model.PiMeterType;
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 PiMeterModel for P4Runtime.
30 */
31final class P4MeterModel implements PiMeterModel {
32
33 private final PiMeterId id;
34 private final PiMeterType meterType;
35 private final Unit unit;
36 private final PiTableId table;
37 private final long size;
38
39 P4MeterModel(PiMeterId id, PiMeterType meterType, Unit unit, PiTableId table, long size) {
40 this.id = id;
41 this.meterType = meterType;
42 this.unit = unit;
43 this.table = table;
44 this.size = size;
45 }
46
47 @Override
48 public PiMeterId id() {
49 return id;
50 }
51
52 @Override
53 public PiMeterType meterType() {
54 return meterType;
55 }
56
57 @Override
58 public Unit unit() {
59 return unit;
60 }
61
62 @Override
63 public PiTableId table() {
64 return table;
65 }
66
67 @Override
68 public long size() {
69 return size;
70 }
71
72 @Override
73 public int hashCode() {
74 return Objects.hash(id, meterType, unit, table, size);
75 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj) {
80 return true;
81 }
82 if (obj == null || getClass() != obj.getClass()) {
83 return false;
84 }
85 final P4MeterModel other = (P4MeterModel) obj;
86 return Objects.equals(this.id, other.id)
87 && Objects.equals(this.meterType, other.meterType)
88 && Objects.equals(this.unit, other.unit)
89 && Objects.equals(this.table, other.table)
90 && Objects.equals(this.size, other.size);
91 }
pierventre4d2a5422021-01-10 17:29:03 -080092
93 @Override
94 public String toString() {
95 return toStringHelper(this)
96 .add("id", id)
97 .add("meterType", meterType)
98 .add("unit", unit)
99 .add("table", table)
100 .add("size", size)
101 .toString();
102 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800103}