blob: 6969714f5e27989a35bbaf0d2cec8a8d22fe1461 [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/**
26 * Global identifier of a PI action group applied to a device, uniquely defined
27 * by a device ID, action profile ID and group ID.
28 */
29@Beta
30public final class PiActionGroupHandle extends PiHandle<PiActionGroup> {
31
Carmelo Casconee44592f2018-09-12 02:24:47 -070032 private final PiActionProfileId actionProfileId;
33 private final PiActionGroupId groupId;
34
Carmelo Casconee75b7942017-11-21 17:14:49 -080035 private PiActionGroupHandle(DeviceId deviceId, PiActionGroup group) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070036 super(deviceId);
37 actionProfileId = group.actionProfileId();
38 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 /**
42 * Creates a new handle for the given device ID and PI action group.
43 *
44 * @param deviceId device ID
45 * @param group PI action group
46 * @return PI action group handle
47 */
48 public static PiActionGroupHandle of(DeviceId deviceId,
49 PiActionGroup group) {
50 return new PiActionGroupHandle(deviceId, group);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080051 }
52
53 @Override
Carmelo Casconee44592f2018-09-12 02:24:47 -070054 public PiEntityType entityType() {
55 return PiEntityType.GROUP;
56 }
57
58 @Override
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080059 public int hashCode() {
60 return Objects.hashCode(deviceId(),
Carmelo Casconee44592f2018-09-12 02:24:47 -070061 actionProfileId,
62 groupId);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080063 }
64
65 @Override
66 public boolean equals(Object o) {
67 if (this == o) {
68 return true;
69 }
70 if (o == null || getClass() != o.getClass()) {
71 return false;
72 }
73 PiActionGroupHandle that = (PiActionGroupHandle) o;
74 return Objects.equal(deviceId(), that.deviceId()) &&
Carmelo Casconee44592f2018-09-12 02:24:47 -070075 Objects.equal(actionProfileId,
76 that.actionProfileId) &&
77 Objects.equal(groupId, that.groupId);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080078 }
79
80 @Override
81 public String toString() {
82 return MoreObjects.toStringHelper(this)
83 .add("deviceId", deviceId())
Carmelo Casconee44592f2018-09-12 02:24:47 -070084 .add("actionProfileId", actionProfileId)
85 .add("groupId", groupId)
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080086 .toString();
87 }
88}