blob: 26f21f2e9c3c789ccc4c49c5098ec80bf7516f7d [file] [log] [blame]
Charles Chand55e84d2016-03-30 17:54:24 -07001/*
Pier3e793752018-04-19 16:47:06 +02002 * Copyright 2018-present Open Networking Foundation
Charles Chand55e84d2016-03-30 17:54:24 -07003 *
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
Pier3e793752018-04-19 16:47:06 +020017package org.onosproject.segmentrouting.mcast;
Charles Chand55e84d2016-03-30 17:54:24 -070018
19import org.onlab.packet.IpAddress;
Pier3e793752018-04-19 16:47:06 +020020import org.onosproject.net.ConnectPoint;
Charles Chand55e84d2016-03-30 17:54:24 -070021import org.onosproject.net.DeviceId;
Pier3e793752018-04-19 16:47:06 +020022
23import java.util.Objects;
24
Charles Chand55e84d2016-03-30 17:54:24 -070025import static com.google.common.base.MoreObjects.toStringHelper;
26import static com.google.common.base.Preconditions.checkArgument;
27import static com.google.common.base.Preconditions.checkNotNull;
Charles Chand55e84d2016-03-30 17:54:24 -070028
29/**
Pier3e793752018-04-19 16:47:06 +020030 * Key of multicast role store.
Charles Chand55e84d2016-03-30 17:54:24 -070031 */
Pier3e793752018-04-19 16:47:06 +020032public class McastRoleStoreKey {
33 // Identify role using group address, deviceId and source
Charles Chand55e84d2016-03-30 17:54:24 -070034 private final IpAddress mcastIp;
35 private final DeviceId deviceId;
Pier3e793752018-04-19 16:47:06 +020036 private final ConnectPoint source;
Charles Chand55e84d2016-03-30 17:54:24 -070037
38 /**
Pier3e793752018-04-19 16:47:06 +020039 * Constructs the key of multicast role store.
Charles Chand55e84d2016-03-30 17:54:24 -070040 *
41 * @param mcastIp multicast group IP address
42 * @param deviceId device ID
Pier3e793752018-04-19 16:47:06 +020043 * @param source source connect point
Charles Chand55e84d2016-03-30 17:54:24 -070044 */
Pier3e793752018-04-19 16:47:06 +020045 public McastRoleStoreKey(IpAddress mcastIp, DeviceId deviceId, ConnectPoint source) {
Charles Chand55e84d2016-03-30 17:54:24 -070046 checkNotNull(mcastIp, "mcastIp cannot be null");
47 checkNotNull(deviceId, "deviceId cannot be null");
Pier3e793752018-04-19 16:47:06 +020048 checkNotNull(source, "source cannot be null");
Charles Chand55e84d2016-03-30 17:54:24 -070049 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
50 this.mcastIp = mcastIp;
51 this.deviceId = deviceId;
Pier3e793752018-04-19 16:47:06 +020052 this.source = source;
53 }
54
55 // Constructor for serialization
56 private McastRoleStoreKey() {
57 this.mcastIp = null;
58 this.deviceId = null;
59 this.source = null;
Charles Chand55e84d2016-03-30 17:54:24 -070060 }
61
62 /**
63 * Returns the multicast IP address of this key.
64 *
65 * @return multicast IP
66 */
67 public IpAddress mcastIp() {
Charles Chan216e3c82016-04-23 14:48:16 -070068 return mcastIp;
Charles Chand55e84d2016-03-30 17:54:24 -070069 }
70
71 /**
72 * Returns the device ID of this key.
73 *
74 * @return device ID
75 */
76 public DeviceId deviceId() {
Charles Chan216e3c82016-04-23 14:48:16 -070077 return deviceId;
Charles Chand55e84d2016-03-30 17:54:24 -070078 }
79
Pier3e793752018-04-19 16:47:06 +020080 /**
81 * Returns the source connect point of this key.
82 *
83 * @return the source connect point
84 */
85 public ConnectPoint source() {
86 return source;
87 }
88
Charles Chand55e84d2016-03-30 17:54:24 -070089 @Override
90 public boolean equals(Object o) {
91 if (this == o) {
92 return true;
93 }
Pier3e793752018-04-19 16:47:06 +020094 if (!(o instanceof McastRoleStoreKey)) {
Charles Chand55e84d2016-03-30 17:54:24 -070095 return false;
96 }
Pier3e793752018-04-19 16:47:06 +020097 final McastRoleStoreKey that = (McastRoleStoreKey) o;
98
99 return Objects.equals(this.mcastIp, that.mcastIp) &&
100 Objects.equals(this.deviceId, that.deviceId) &&
101 Objects.equals(this.source, that.source);
Charles Chand55e84d2016-03-30 17:54:24 -0700102 }
103
104 @Override
105 public int hashCode() {
Pier3e793752018-04-19 16:47:06 +0200106 return Objects.hash(mcastIp, deviceId, source);
Charles Chand55e84d2016-03-30 17:54:24 -0700107 }
108
109 @Override
110 public String toString() {
111 return toStringHelper(getClass())
112 .add("mcastIp", mcastIp)
113 .add("deviceId", deviceId)
Pier3e793752018-04-19 16:47:06 +0200114 .add("source", source)
Charles Chand55e84d2016-03-30 17:54:24 -0700115 .toString();
116 }
117}