blob: b0875caa10ff01b499aa889bebc585c1172d039b [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;
21
22import java.util.Objects;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkArgument;
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Key of the multicast event cache.
30 */
31class McastCacheKey {
32 // The group ip
33 private final IpAddress mcastIp;
34 // The sink connect point
35 private final ConnectPoint sink;
36
37 /**
38 * Constructs a key for multicast event cache.
39 *
40 * @param mcastIp multicast group IP address
41 * @param sink connect point of the sink
42 */
43 public McastCacheKey(IpAddress mcastIp, ConnectPoint sink) {
44 checkNotNull(mcastIp, "mcastIp cannot be null");
45 checkNotNull(sink, "sink cannot be null");
46 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
47 this.mcastIp = mcastIp;
48 this.sink = sink;
49 }
50
51 /**
52 * Returns the multicast IP address of this key.
53 *
54 * @return multicast IP
55 */
56 public IpAddress mcastIp() {
57 return mcastIp;
58 }
59
60 /**
61 * Returns the sink of this key.
62 *
63 * @return connect point of the sink
64 */
65 public ConnectPoint sink() {
66 return sink;
67 }
68
69 @Override
70 public boolean equals(Object o) {
71 if (this == o) {
72 return true;
73 }
74 if (!(o instanceof McastCacheKey)) {
75 return false;
76 }
77 McastCacheKey that =
78 (McastCacheKey) o;
79 return (Objects.equals(this.mcastIp, that.mcastIp) &&
80 Objects.equals(this.sink, that.sink));
81 }
82
83 @Override
84 public int hashCode() {
85 return Objects.hash(mcastIp, sink);
86 }
87
88 @Override
89 public String toString() {
90 return toStringHelper(getClass())
91 .add("mcastIp", mcastIp)
92 .add("sink", sink)
93 .toString();
94 }
95}