blob: 137a259710366322f5b46b81029397ec4ce6563d [file] [log] [blame]
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +00001/*
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.opencord.igmpproxy;
18
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.Ip4Address;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.PortNumber;
23
24import java.util.Objects;
25
26/**
27 * Identification of group member.
28 */
29public final class GroupMemberId {
30 private Ip4Address groupIp;
31 private DeviceId deviceId;
32 private PortNumber portNum;
33
34 /**
35 * Constructor for serializer.
36 */
37 private GroupMemberId() {
38 this.groupIp = null;
39 this.deviceId = null;
40 this.portNum = null;
41 }
42
43 private GroupMemberId(Ip4Address groupIp, DeviceId deviceId, PortNumber portNum) {
44 this.groupIp = groupIp;
45 this.deviceId = deviceId;
46 this.portNum = portNum;
47 }
48
49 /**
50 * Creates new group member identification.
51 *
52 * @param groupIp group ip of member
53 * @param deviceId device id
54 * @param portNum port number of connect point
55 * @return new identification of group-member
56 */
57 public static GroupMemberId of(Ip4Address groupIp, DeviceId deviceId, PortNumber portNum) {
58 return new GroupMemberId(groupIp, deviceId, portNum);
59 }
60
61 @Override
62 public String toString() {
63 return MoreObjects.toStringHelper(this)
64 .add("groupIp", groupIp)
65 .add("deviceId", deviceId)
66 .add("portNumber", portNum).toString();
67 }
68
69 /**
70 * Get group ip of group.
71 *
72 * @return group ip
73 */
74 public Ip4Address getGroupIp() {
75 return groupIp;
76 }
77
78 /**
79 * Get device id of connect point.
80 *
81 * @return device id
82 */
83 public DeviceId getDeviceId() {
84 return deviceId;
85 }
86
87 /**
88 * Get port number of connect point.
89 *
90 * @return port number
91 */
92 public PortNumber getPortNum() {
93 return portNum;
94 }
95
96 @Override
97 public boolean equals(Object o) {
98 if (this == o) {
99 return true;
100 }
101 if (o == null || getClass() != o.getClass()) {
102 return false;
103 }
104 GroupMemberId that = (GroupMemberId) o;
105 return Objects.equals(groupIp, that.groupIp) &&
106 Objects.equals(deviceId, that.deviceId) &&
107 Objects.equals(portNum, that.portNum);
108 }
109
110 @Override
111 public int hashCode() {
112 return Objects.hash(groupIp, deviceId, portNum);
113 }
114}
115