blob: b18cb51d4c5b725e66db0f4a6c4a5213a1634e0d [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
Carmelo Cascone9db4d5c2019-04-16 17:36:33 -070032public final class PiMulticastGroupEntryHandle extends PiPreEntryHandle {
Carmelo Cascone58136812018-07-19 03:40:16 +020033
Carmelo Cascone4c289b72019-01-22 15:30:45 -080034 private final int groupId;
Carmelo Casconee44592f2018-09-12 02:24:47 -070035
Carmelo Cascone4c289b72019-01-22 15:30:45 -080036 private PiMulticastGroupEntryHandle(DeviceId deviceId, int groupId) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070037 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,
Carmelo Cascone4c289b72019-01-22 15:30:45 -080049 int groupId) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070050 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
Carmelo Cascone4c289b72019-01-22 15:30:45 -080067 /**
68 * Returns the multicast group ID associated with this handle.
69 *
70 * @return group ID
71 */
72 public int groupId() {
73 return groupId;
74 }
75
Carmelo Casconee44592f2018-09-12 02:24:47 -070076 @Override
Carmelo Cascone9db4d5c2019-04-16 17:36:33 -070077 public PiPreEntryType preEntryType() {
78 return PiPreEntryType.MULTICAST_GROUP;
Carmelo Cascone58136812018-07-19 03:40:16 +020079 }
80
81 @Override
82 public int hashCode() {
Carmelo Casconee44592f2018-09-12 02:24:47 -070083 return Objects.hashCode(deviceId(), groupId);
Carmelo Cascone58136812018-07-19 03:40:16 +020084 }
85
86 @Override
87 public boolean equals(Object o) {
88 if (this == o) {
89 return true;
90 }
91 if (o == null || getClass() != o.getClass()) {
92 return false;
93 }
94 PiMulticastGroupEntryHandle that = (PiMulticastGroupEntryHandle) o;
95 return Objects.equal(deviceId(), that.deviceId()) &&
Carmelo Casconee44592f2018-09-12 02:24:47 -070096 Objects.equal(groupId, that.groupId);
Carmelo Cascone58136812018-07-19 03:40:16 +020097 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(this)
102 .add("deviceId", deviceId())
Carmelo Casconee44592f2018-09-12 02:24:47 -0700103 .add("groupId", groupId)
Carmelo Cascone58136812018-07-19 03:40:16 +0200104 .toString();
105 }
106}