blob: c06fa528f1c92a37ba0bd551262b4b378e7b70c3 [file] [log] [blame]
Carmelo Cascone4c289b72019-01-22 15:30:45 -08001/*
2 * Copyright 2019-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.net.pi.runtime;
18
19import com.google.common.base.MoreObjects;
20import com.google.common.base.Objects;
21import org.onosproject.net.DeviceId;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Global identifier of a PI counter cell instantiated on a device, uniquely
27 * defined by a device ID and cell ID.
28 */
29public final class PiCounterCellHandle extends PiHandle {
30
31 private final PiCounterCellId cellId;
32
33 private PiCounterCellHandle(DeviceId deviceId, PiCounterCellId cellId) {
34 super(deviceId);
35 this.cellId = checkNotNull(cellId);
36 }
37
38 /**
39 * Creates a new handle for the given device ID and counter cell ID.
40 *
41 * @param deviceId device ID
42 * @param cellId counter cell ID
43 * @return new counter cell handle
44 */
45 public static PiCounterCellHandle of(DeviceId deviceId, PiCounterCellId cellId) {
46 return new PiCounterCellHandle(deviceId, cellId);
47 }
48
49 /**
50 * Creates a new handle for the given device ID and counter cell.
51 *
52 * @param deviceId device ID
53 * @param cell counter cell
54 * @return new counter cell handle
55 */
56 public static PiCounterCellHandle of(DeviceId deviceId, PiCounterCell cell) {
57 return new PiCounterCellHandle(deviceId, cell.cellId());
58 }
59
60 /**
61 * Returns the counter cell ID associated with this handle.
62 *
63 * @return counter cell ID
64 */
65 public PiCounterCellId cellId() {
66 return cellId;
67 }
68
69 @Override
70 public PiEntityType entityType() {
71 return PiEntityType.COUNTER_CELL;
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hashCode(deviceId(), cellId);
77 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj == null || getClass() != obj.getClass()) {
85 return false;
86 }
87 final PiCounterCellHandle other = (PiCounterCellHandle) obj;
88 return Objects.equal(this.deviceId(), other.deviceId())
89 && Objects.equal(this.cellId, other.cellId);
90 }
91
92 @Override
93 public String toString() {
94 return MoreObjects.toStringHelper(this)
95 .add("deviceId", deviceId())
96 .add("cellId", cellId)
97 .toString();
98 }
99}