blob: 3579054229a89ed9492e35321557365b4ff8ee0c [file] [log] [blame]
Carmelo Cascone326ad2d2017-11-28 18:09:13 -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.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;
Carmelo Casconee44592f2018-09-12 02:24:47 -070023import org.onosproject.net.pi.model.PiActionProfileId;
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080024
25/**
Carmelo Casconecb4327a2018-09-11 15:17:23 -070026 * Global identifier of a PI action profile group applied to a device, uniquely
27 * defined by a device ID, action profile ID and group ID.
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080028 */
29@Beta
Carmelo Cascone4c289b72019-01-22 15:30:45 -080030public final class PiActionProfileGroupHandle extends PiHandle {
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080031
Carmelo Casconee44592f2018-09-12 02:24:47 -070032 private final PiActionProfileId actionProfileId;
Carmelo Casconecb4327a2018-09-11 15:17:23 -070033 private final PiActionProfileGroupId groupId;
Carmelo Casconee44592f2018-09-12 02:24:47 -070034
Carmelo Casconecb4327a2018-09-11 15:17:23 -070035 private PiActionProfileGroupHandle(DeviceId deviceId, PiActionProfileGroup group) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070036 super(deviceId);
Carmelo Cascone99c59db2019-01-17 15:39:35 -080037 actionProfileId = group.actionProfile();
Carmelo Casconee44592f2018-09-12 02:24:47 -070038 groupId = group.id();
Carmelo Casconee75b7942017-11-21 17:14:49 -080039 }
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080040
Carmelo Casconee75b7942017-11-21 17:14:49 -080041 /**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080042 * Creates a new handle for the given device ID and PI action profile
43 * group.
Carmelo Casconee75b7942017-11-21 17:14:49 -080044 *
45 * @param deviceId device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080046 * @param group PI action profile group
Carmelo Casconecb4327a2018-09-11 15:17:23 -070047 * @return PI action profile group handle
Carmelo Casconee75b7942017-11-21 17:14:49 -080048 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -070049 public static PiActionProfileGroupHandle of(DeviceId deviceId,
50 PiActionProfileGroup group) {
51 return new PiActionProfileGroupHandle(deviceId, group);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080052 }
53
Carmelo Cascone4c289b72019-01-22 15:30:45 -080054 /**
55 * Returns the action profile ID of this handle.
56 *
57 * @return action profile ID
58 */
59 public PiActionProfileId actionProfile() {
60 return actionProfileId;
61 }
62
63 /**
64 * Returns the group ID of this handle.
65 *
66 * @return group ID
67 */
68 public PiActionProfileGroupId groupId() {
69 return groupId;
70 }
71
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080072 @Override
Carmelo Casconee44592f2018-09-12 02:24:47 -070073 public PiEntityType entityType() {
Carmelo Casconecb4327a2018-09-11 15:17:23 -070074 return PiEntityType.ACTION_PROFILE_GROUP;
Carmelo Casconee44592f2018-09-12 02:24:47 -070075 }
76
77 @Override
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080078 public int hashCode() {
79 return Objects.hashCode(deviceId(),
Carmelo Casconee44592f2018-09-12 02:24:47 -070080 actionProfileId,
81 groupId);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080082 }
83
84 @Override
85 public boolean equals(Object o) {
86 if (this == o) {
87 return true;
88 }
89 if (o == null || getClass() != o.getClass()) {
90 return false;
91 }
Carmelo Casconecb4327a2018-09-11 15:17:23 -070092 PiActionProfileGroupHandle that = (PiActionProfileGroupHandle) o;
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080093 return Objects.equal(deviceId(), that.deviceId()) &&
Carmelo Casconee44592f2018-09-12 02:24:47 -070094 Objects.equal(actionProfileId,
95 that.actionProfileId) &&
96 Objects.equal(groupId, that.groupId);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080097 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(this)
102 .add("deviceId", deviceId())
Carmelo Cascone99c59db2019-01-17 15:39:35 -0800103 .add("actionProfile", actionProfileId)
Carmelo Casconee44592f2018-09-12 02:24:47 -0700104 .add("groupId", groupId)
Carmelo Cascone326ad2d2017-11-28 18:09:13 -0800105 .toString();
106 }
107}