blob: 930432df260c3c7c7d5e41b0c7c93690c5bd93f4 [file] [log] [blame]
Pier Luigi05514fd2018-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;
Pierb0328e42018-03-27 11:29:42 -070021import org.onosproject.net.HostId;
Pier Luigi05514fd2018-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;
Pierb0328e42018-03-27 11:29:42 -070035 // The sink id
36 private final HostId sinkHost;
Pier Luigi05514fd2018-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
Pierb0328e42018-03-27 11:29:42 -070045 *
46 * @deprecated in 1.12 ("Magpie") release.
Pier Luigi05514fd2018-02-28 17:24:03 +010047 */
48 public McastCacheKey(IpAddress mcastIp, ConnectPoint sink) {
49 checkNotNull(mcastIp, "mcastIp cannot be null");
50 checkNotNull(sink, "sink cannot be null");
51 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
52 this.mcastIp = mcastIp;
53 this.sink = sink;
Pierb0328e42018-03-27 11:29:42 -070054 this.sinkHost = null;
55 }
56
57 /**
58 * Constructs a key for multicast event cache.
59 *
60 * @param mcastIp multicast group IP address
61 * @param hostId id of the sink
62 */
63 public McastCacheKey(IpAddress mcastIp, HostId hostId) {
64 checkNotNull(mcastIp, "mcastIp cannot be null");
65 checkNotNull(hostId, "sink cannot be null");
66 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
67 this.mcastIp = mcastIp;
68 this.sinkHost = hostId;
69 this.sink = null;
Pier Luigi05514fd2018-02-28 17:24:03 +010070 }
71
72 /**
73 * Returns the multicast IP address of this key.
74 *
75 * @return multicast IP
76 */
77 public IpAddress mcastIp() {
78 return mcastIp;
79 }
80
81 /**
82 * Returns the sink of this key.
83 *
84 * @return connect point of the sink
Pierb0328e42018-03-27 11:29:42 -070085 *
86 * @deprecated in 1.12 ("Magpie") release.
Pier Luigi05514fd2018-02-28 17:24:03 +010087 */
88 public ConnectPoint sink() {
89 return sink;
90 }
91
Pierb0328e42018-03-27 11:29:42 -070092 /**
93 * Returns the sink of this key.
94 *
95 * @return host id of the sink
96 */
97 public HostId sinkHost() {
98 return sinkHost;
99 }
100
Pier Luigi05514fd2018-02-28 17:24:03 +0100101 @Override
102 public boolean equals(Object o) {
103 if (this == o) {
104 return true;
105 }
106 if (!(o instanceof McastCacheKey)) {
107 return false;
108 }
109 McastCacheKey that =
110 (McastCacheKey) o;
111 return (Objects.equals(this.mcastIp, that.mcastIp) &&
Pierb0328e42018-03-27 11:29:42 -0700112 Objects.equals(this.sink, that.sink) &&
113 Objects.equals(this.sinkHost, that.sinkHost));
Pier Luigi05514fd2018-02-28 17:24:03 +0100114 }
115
116 @Override
117 public int hashCode() {
118 return Objects.hash(mcastIp, sink);
119 }
120
121 @Override
122 public String toString() {
123 return toStringHelper(getClass())
124 .add("mcastIp", mcastIp)
125 .add("sink", sink)
Pierb0328e42018-03-27 11:29:42 -0700126 .add("sinkHost", sinkHost)
Pier Luigi05514fd2018-02-28 17:24:03 +0100127 .toString();
128 }
129}