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