blob: 382f60be0a538991a7b37acc6e859587f0292b25 [file] [log] [blame]
Frank Wangd7e3b4b2017-09-24 13:37:54 +09001/*
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.net.pi.runtime;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22import org.onosproject.net.DeviceId;
23
Carmelo Casconee44592f2018-09-12 02:24:47 -070024import static com.google.common.base.Preconditions.checkNotNull;
25
Frank Wangd7e3b4b2017-09-24 13:37:54 +090026/**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080027 * Global identifier of a PI meter cell instantiated on a device, uniquely
28 * defined by a device ID and meter cell ID.
Frank Wangd7e3b4b2017-09-24 13:37:54 +090029 */
30@Beta
Carmelo Cascone4c289b72019-01-22 15:30:45 -080031public final class PiMeterCellHandle extends PiHandle {
Frank Wangd7e3b4b2017-09-24 13:37:54 +090032
Carmelo Casconee44592f2018-09-12 02:24:47 -070033 private final PiMeterCellId cellId;
34
Carmelo Cascone4c289b72019-01-22 15:30:45 -080035 private PiMeterCellHandle(DeviceId deviceId, PiMeterCellId meterCellId) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070036 super(deviceId);
37 this.cellId = meterCellId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090038 }
39
40 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -070041 * Creates a new handle for the given device ID and PI meter cell ID.
Frank Wangd7e3b4b2017-09-24 13:37:54 +090042 *
Carmelo Casconee44592f2018-09-12 02:24:47 -070043 * @param deviceId device ID
44 * @param meterCellId meter cell ID
45 * @return PI meter handle
46 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -080047 public static PiMeterCellHandle of(DeviceId deviceId,
48 PiMeterCellId meterCellId) {
49 return new PiMeterCellHandle(deviceId, meterCellId);
Carmelo Casconee44592f2018-09-12 02:24:47 -070050 }
51
52 /**
53 * Creates a new handle for the given device ID and PI meter cell
54 * configuration.
55 *
56 * @param deviceId device ID
Frank Wangd7e3b4b2017-09-24 13:37:54 +090057 * @param meterCellConfig meter config
58 * @return PI meter handle
59 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -080060 public static PiMeterCellHandle of(DeviceId deviceId,
61 PiMeterCellConfig meterCellConfig) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070062 checkNotNull(meterCellConfig);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080063 return new PiMeterCellHandle(deviceId, meterCellConfig.cellId());
64 }
65
66 /**
67 * Returns the cell ID associated with this handle.
68 *
69 * @return cell ID
70 */
71 public PiMeterCellId cellId() {
72 return cellId;
Carmelo Casconee44592f2018-09-12 02:24:47 -070073 }
74
75 @Override
76 public PiEntityType entityType() {
77 return PiEntityType.METER_CELL_CONFIG;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090078 }
79
80 @Override
81 public int hashCode() {
Carmelo Casconee44592f2018-09-12 02:24:47 -070082 return Objects.hashCode(deviceId(), cellId);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090083 }
84
85 @Override
86 public boolean equals(Object o) {
87 if (this == o) {
88 return true;
89 }
90 if (o == null || getClass() != o.getClass()) {
91 return false;
92 }
Carmelo Cascone4c289b72019-01-22 15:30:45 -080093 PiMeterCellHandle that = (PiMeterCellHandle) o;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090094 return Objects.equal(deviceId(), that.deviceId()) &&
Carmelo Casconee44592f2018-09-12 02:24:47 -070095 Objects.equal(cellId, that.cellId);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090096 }
97
98 @Override
99 public String toString() {
100 return MoreObjects.toStringHelper(this)
101 .add("deviceId", deviceId())
Carmelo Casconee44592f2018-09-12 02:24:47 -0700102 .add("meterCellId", cellId)
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900103 .toString();
104 }
Carmelo Casconee44592f2018-09-12 02:24:47 -0700105}