blob: 55d2131d33dba492c8ceb3984cd3cfacb847e81f [file] [log] [blame]
Pier Luigid29ca7c2018-02-28 17:24:03 +01001/*
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.segmentrouting.mcast;
18
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.ConnectPoint;
Pier7b657162018-03-27 11:29:42 -070021import org.onosproject.net.HostId;
Pier Luigid29ca7c2018-02-28 17:24:03 +010022
23import java.util.Objects;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26import static com.google.common.base.Preconditions.checkArgument;
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * Key of the multicast event cache.
31 */
32class McastCacheKey {
33 // The group ip
34 private final IpAddress mcastIp;
Pier7b657162018-03-27 11:29:42 -070035 // The sink id
36 private final HostId sinkHost;
Pier Luigid29ca7c2018-02-28 17:24:03 +010037 // The sink connect point
38 private final ConnectPoint sink;
39
40 /**
41 * Constructs a key for multicast event cache.
42 *
43 * @param mcastIp multicast group IP address
44 * @param sink connect point of the sink
Pier7b657162018-03-27 11:29:42 -070045 *
46 * @deprecated in 1.12 ("Magpie") release.
Pier Luigid29ca7c2018-02-28 17:24:03 +010047 */
Pier71c55772018-04-17 17:25:22 +020048 @Deprecated
Pier Luigid29ca7c2018-02-28 17:24:03 +010049 public McastCacheKey(IpAddress mcastIp, ConnectPoint sink) {
50 checkNotNull(mcastIp, "mcastIp cannot be null");
51 checkNotNull(sink, "sink cannot be null");
52 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
53 this.mcastIp = mcastIp;
54 this.sink = sink;
Pier7b657162018-03-27 11:29:42 -070055 this.sinkHost = null;
56 }
57
58 /**
59 * Constructs a key for multicast event cache.
60 *
61 * @param mcastIp multicast group IP address
62 * @param hostId id of the sink
63 */
64 public McastCacheKey(IpAddress mcastIp, HostId hostId) {
65 checkNotNull(mcastIp, "mcastIp cannot be null");
66 checkNotNull(hostId, "sink cannot be null");
67 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
68 this.mcastIp = mcastIp;
69 this.sinkHost = hostId;
70 this.sink = null;
Pier Luigid29ca7c2018-02-28 17:24:03 +010071 }
72
73 /**
74 * Returns the multicast IP address of this key.
75 *
76 * @return multicast IP
77 */
78 public IpAddress mcastIp() {
79 return mcastIp;
80 }
81
82 /**
83 * Returns the sink of this key.
84 *
85 * @return connect point of the sink
Pier7b657162018-03-27 11:29:42 -070086 *
87 * @deprecated in 1.12 ("Magpie") release.
Pier Luigid29ca7c2018-02-28 17:24:03 +010088 */
Pier71c55772018-04-17 17:25:22 +020089 @Deprecated
Pier Luigid29ca7c2018-02-28 17:24:03 +010090 public ConnectPoint sink() {
91 return sink;
92 }
93
Pier7b657162018-03-27 11:29:42 -070094 /**
95 * Returns the sink of this key.
96 *
97 * @return host id of the sink
98 */
99 public HostId sinkHost() {
100 return sinkHost;
101 }
102
Pier Luigid29ca7c2018-02-28 17:24:03 +0100103 @Override
104 public boolean equals(Object o) {
105 if (this == o) {
106 return true;
107 }
108 if (!(o instanceof McastCacheKey)) {
109 return false;
110 }
111 McastCacheKey that =
112 (McastCacheKey) o;
113 return (Objects.equals(this.mcastIp, that.mcastIp) &&
Pier7b657162018-03-27 11:29:42 -0700114 Objects.equals(this.sink, that.sink) &&
115 Objects.equals(this.sinkHost, that.sinkHost));
Pier Luigid29ca7c2018-02-28 17:24:03 +0100116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hash(mcastIp, sink);
121 }
122
123 @Override
124 public String toString() {
125 return toStringHelper(getClass())
126 .add("mcastIp", mcastIp)
127 .add("sink", sink)
Pier7b657162018-03-27 11:29:42 -0700128 .add("sinkHost", sinkHost)
Pier Luigid29ca7c2018-02-28 17:24:03 +0100129 .toString();
130 }
131}