Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.segmentrouting.mcast; |
| 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onosproject.net.ConnectPoint; |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 21 | import org.onosproject.net.HostId; |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | import static com.google.common.base.Preconditions.checkArgument; |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
| 30 | * Key of the multicast event cache. |
| 31 | */ |
| 32 | class McastCacheKey { |
| 33 | // The group ip |
| 34 | private final IpAddress mcastIp; |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 35 | // The sink id |
| 36 | private final HostId sinkHost; |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 37 | // 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 |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 45 | * |
| 46 | * @deprecated in 1.12 ("Magpie") release. |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 47 | */ |
Pier | 71c5577 | 2018-04-17 17:25:22 +0200 | [diff] [blame] | 48 | @Deprecated |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 49 | 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; |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 55 | 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 Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 71 | } |
| 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 |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 86 | * |
| 87 | * @deprecated in 1.12 ("Magpie") release. |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 88 | */ |
Pier | 71c5577 | 2018-04-17 17:25:22 +0200 | [diff] [blame] | 89 | @Deprecated |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 90 | public ConnectPoint sink() { |
| 91 | return sink; |
| 92 | } |
| 93 | |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 94 | /** |
| 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 Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 103 | @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) && |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 114 | Objects.equals(this.sink, that.sink) && |
| 115 | Objects.equals(this.sinkHost, that.sinkHost)); |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 116 | } |
| 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) |
Pier | 7b65716 | 2018-03-27 11:29:42 -0700 | [diff] [blame] | 128 | .add("sinkHost", sinkHost) |
Pier Luigi | d29ca7c | 2018-02-28 17:24:03 +0100 | [diff] [blame] | 129 | .toString(); |
| 130 | } |
| 131 | } |