Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 517afab | 2023-01-09 14:22:22 -0500 | [diff] [blame] | 2 | * Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 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 | package org.opencord.igmpproxy.statemachine; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.packet.Ip4Address; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Identification of state machine. |
| 26 | */ |
| 27 | public final class StateMachineId { |
| 28 | private DeviceId deviceId; |
| 29 | private Ip4Address groupIp; |
| 30 | |
| 31 | /** |
| 32 | * Constructor for serializer. |
| 33 | */ |
| 34 | private StateMachineId() { |
| 35 | this.deviceId = null; |
| 36 | this.groupIp = null; |
| 37 | } |
| 38 | |
| 39 | private StateMachineId(DeviceId deviceId, Ip4Address groupIp) { |
| 40 | this.deviceId = deviceId; |
| 41 | this.groupIp = groupIp; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates new state-machine identification using device-id and group-ip. |
| 46 | * |
| 47 | * @param deviceId device id of state-machie |
| 48 | * @param groupIp group ip of state-machine |
| 49 | * @return created identification |
| 50 | */ |
| 51 | public static StateMachineId of(DeviceId deviceId, Ip4Address groupIp) { |
| 52 | return new StateMachineId(deviceId, groupIp); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns device id of identification. |
| 57 | * |
| 58 | * @return device id |
| 59 | */ |
| 60 | public DeviceId getDeviceId() { |
| 61 | return deviceId; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns group ip of identification. |
| 66 | * |
| 67 | * @return group ip |
| 68 | */ |
| 69 | public Ip4Address getGroupIp() { |
| 70 | return groupIp; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public String toString() { |
| 75 | return MoreObjects.toStringHelper(this) |
| 76 | .add("deviceId", deviceId) |
| 77 | .add("groupIp", groupIp) |
| 78 | .toString(); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public boolean equals(Object o) { |
| 83 | if (this == o) { |
| 84 | return true; |
| 85 | } |
| 86 | if (o == null || getClass() != o.getClass()) { |
| 87 | return false; |
| 88 | } |
| 89 | StateMachineId that = (StateMachineId) o; |
| 90 | return Objects.equals(deviceId, that.deviceId) && |
| 91 | Objects.equals(groupIp, that.groupIp); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public int hashCode() { |
| 96 | return Objects.hash(deviceId, groupIp); |
| 97 | } |
| 98 | } |