blob: 65a3f28c79fe221b48180a3244254c03ada55b33 [file] [log] [blame]
Carmelo Cascone58136812018-07-19 03:40:16 +02001/*
2 * Copyright 2018-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
Carmelo Cascone58136812018-07-19 03:40:16 +020026/**
27 * Global identifier of a PI multicast group entry applied to the packet
28 * replication engine of a device, uniquely defined by a device ID, and group
29 * ID.
30 */
31@Beta
32public final class PiMulticastGroupEntryHandle extends PiHandle<PiMulticastGroupEntry> {
33
Carmelo Casconee44592f2018-09-12 02:24:47 -070034 private final long groupId;
35
36 private PiMulticastGroupEntryHandle(DeviceId deviceId, long groupId) {
37 super(deviceId);
38 this.groupId = groupId;
39 }
40
41 /**
42 * Creates a new handle for the given device ID and PI multicast group ID.
43 *
44 * @param deviceId device ID
45 * @param groupId multicast group ID
46 * @return PI multicast group entry handle
47 */
48 public static PiMulticastGroupEntryHandle of(DeviceId deviceId,
49 long groupId) {
50 return new PiMulticastGroupEntryHandle(deviceId, groupId);
Carmelo Cascone58136812018-07-19 03:40:16 +020051 }
52
53 /**
54 * Creates a new handle for the given device ID and PI multicast group
55 * entry.
56 *
57 * @param deviceId device ID
58 * @param entry PI multicast group entry
59 * @return PI multicast group entry handle
60 */
61 public static PiMulticastGroupEntryHandle of(DeviceId deviceId,
62 PiMulticastGroupEntry entry) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070063 checkNotNull(entry);
64 return new PiMulticastGroupEntryHandle(deviceId, entry.groupId());
65 }
66
67 @Override
68 public PiEntityType entityType() {
69 return PiEntityType.PRE_MULTICAST_GROUP_ENTRY;
Carmelo Cascone58136812018-07-19 03:40:16 +020070 }
71
72 @Override
73 public int hashCode() {
Carmelo Casconee44592f2018-09-12 02:24:47 -070074 return Objects.hashCode(deviceId(), groupId);
Carmelo Cascone58136812018-07-19 03:40:16 +020075 }
76
77 @Override
78 public boolean equals(Object o) {
79 if (this == o) {
80 return true;
81 }
82 if (o == null || getClass() != o.getClass()) {
83 return false;
84 }
85 PiMulticastGroupEntryHandle that = (PiMulticastGroupEntryHandle) o;
86 return Objects.equal(deviceId(), that.deviceId()) &&
Carmelo Casconee44592f2018-09-12 02:24:47 -070087 Objects.equal(groupId, that.groupId);
Carmelo Cascone58136812018-07-19 03:40:16 +020088 }
89
90 @Override
91 public String toString() {
92 return MoreObjects.toStringHelper(this)
93 .add("deviceId", deviceId())
Carmelo Casconee44592f2018-09-12 02:24:47 -070094 .add("groupId", groupId)
Carmelo Cascone58136812018-07-19 03:40:16 +020095 .toString();
96 }
97}