Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1 | /* |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 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 | |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 17 | package org.onosproject.segmentrouting.mcast; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 18 | |
| 19 | import org.onlab.packet.IpAddress; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 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; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 30 | * Key of multicast role store. |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 31 | */ |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 32 | public class McastRoleStoreKey { |
| 33 | // Identify role using group address, deviceId and source |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 34 | private final IpAddress mcastIp; |
| 35 | private final DeviceId deviceId; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 36 | private final ConnectPoint source; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 39 | * Constructs the key of multicast role store. |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 40 | * |
| 41 | * @param mcastIp multicast group IP address |
| 42 | * @param deviceId device ID |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 43 | * @param source source connect point |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 44 | */ |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 45 | public McastRoleStoreKey(IpAddress mcastIp, DeviceId deviceId, ConnectPoint source) { |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 46 | checkNotNull(mcastIp, "mcastIp cannot be null"); |
| 47 | checkNotNull(deviceId, "deviceId cannot be null"); |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 48 | checkNotNull(source, "source cannot be null"); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 49 | checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address"); |
| 50 | this.mcastIp = mcastIp; |
| 51 | this.deviceId = deviceId; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 52 | this.source = source; |
| 53 | } |
| 54 | |
| 55 | // Constructor for serialization |
| 56 | private McastRoleStoreKey() { |
| 57 | this.mcastIp = null; |
| 58 | this.deviceId = null; |
| 59 | this.source = null; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the multicast IP address of this key. |
| 64 | * |
| 65 | * @return multicast IP |
| 66 | */ |
| 67 | public IpAddress mcastIp() { |
Charles Chan | a4ee4f9 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 68 | return mcastIp; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the device ID of this key. |
| 73 | * |
| 74 | * @return device ID |
| 75 | */ |
| 76 | public DeviceId deviceId() { |
Charles Chan | a4ee4f9 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 77 | return deviceId; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 80 | /** |
| 81 | * Returns the source connect point of this key. |
| 82 | * |
| 83 | * @return the source connect point |
| 84 | */ |
| 85 | public ConnectPoint source() { |
| 86 | return source; |
| 87 | } |
| 88 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 89 | @Override |
| 90 | public boolean equals(Object o) { |
| 91 | if (this == o) { |
| 92 | return true; |
| 93 | } |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 94 | if (!(o instanceof McastRoleStoreKey)) { |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 95 | return false; |
| 96 | } |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 97 | final McastRoleStoreKey that = (McastRoleStoreKey) o; |
| 98 | |
| 99 | return Objects.equals(this.mcastIp, that.mcastIp) && |
| 100 | Objects.equals(this.deviceId, that.deviceId) && |
| 101 | Objects.equals(this.source, that.source); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public int hashCode() { |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 106 | return Objects.hash(mcastIp, deviceId, source); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public String toString() { |
| 111 | return toStringHelper(getClass()) |
| 112 | .add("mcastIp", mcastIp) |
| 113 | .add("deviceId", deviceId) |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 114 | .add("source", source) |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 115 | .toString(); |
| 116 | } |
| 117 | } |