Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import com.google.common.base.Objects; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 26 | /** |
| 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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 32 | public final class PiMulticastGroupEntryHandle extends PiHandle { |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 33 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 34 | private final int groupId; |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 35 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 36 | private PiMulticastGroupEntryHandle(DeviceId deviceId, int groupId) { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 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, |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 49 | int groupId) { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 50 | return new PiMulticastGroupEntryHandle(deviceId, groupId); |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 51 | } |
| 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 Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 63 | checkNotNull(entry); |
| 64 | return new PiMulticastGroupEntryHandle(deviceId, entry.groupId()); |
| 65 | } |
| 66 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 67 | /** |
| 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 Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 76 | @Override |
| 77 | public PiEntityType entityType() { |
| 78 | return PiEntityType.PRE_MULTICAST_GROUP_ENTRY; |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int hashCode() { |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 83 | return Objects.hashCode(deviceId(), groupId); |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 84 | } |
| 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 Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 96 | Objects.equal(groupId, that.groupId); |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return MoreObjects.toStringHelper(this) |
| 102 | .add("deviceId", deviceId()) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 103 | .add("groupId", groupId) |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 104 | .toString(); |
| 105 | } |
| 106 | } |