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