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.onlab.packet.VlanId; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | import static com.google.common.base.Preconditions.checkArgument; |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | /** |
| 28 | * Key of multicast next objective store. |
| 29 | */ |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 30 | public class McastStoreKey { |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 31 | // Identify a flow using group address, deviceId, and assigned vlan |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 32 | private final IpAddress mcastIp; |
| 33 | private final DeviceId deviceId; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 34 | private final VlanId vlanId; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Constructs the key of multicast next objective store. |
| 38 | * |
| 39 | * @param mcastIp multicast group IP address |
| 40 | * @param deviceId device ID |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 41 | * |
| 42 | * @deprecated in 1.12 ("Magpie") release. |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 43 | */ |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 44 | @Deprecated |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 45 | public McastStoreKey(IpAddress mcastIp, DeviceId deviceId) { |
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"); |
| 48 | checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address"); |
| 49 | this.mcastIp = mcastIp; |
| 50 | this.deviceId = deviceId; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 51 | this.vlanId = null; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Constructs the key of multicast next objective store. |
| 56 | * |
| 57 | * @param mcastIp multicast group IP address |
| 58 | * @param deviceId device ID |
| 59 | * @param vlanId vlan id |
| 60 | */ |
| 61 | public McastStoreKey(IpAddress mcastIp, DeviceId deviceId, VlanId vlanId) { |
| 62 | checkNotNull(mcastIp, "mcastIp cannot be null"); |
| 63 | checkNotNull(deviceId, "deviceId cannot be null"); |
| 64 | checkNotNull(vlanId, "vlan id cannot be null"); |
| 65 | checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address"); |
| 66 | this.mcastIp = mcastIp; |
| 67 | this.deviceId = deviceId; |
| 68 | // FIXME probably we should avoid not valid values |
| 69 | this.vlanId = vlanId; |
| 70 | } |
| 71 | |
| 72 | // Constructor for serialization |
| 73 | private McastStoreKey() { |
| 74 | this.mcastIp = null; |
| 75 | this.deviceId = null; |
| 76 | this.vlanId = null; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the multicast IP address of this key. |
| 81 | * |
| 82 | * @return multicast IP |
| 83 | */ |
| 84 | public IpAddress mcastIp() { |
Charles Chan | a4ee4f9 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 85 | return mcastIp; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns the device ID of this key. |
| 90 | * |
| 91 | * @return device ID |
| 92 | */ |
| 93 | public DeviceId deviceId() { |
Charles Chan | a4ee4f9 | 2016-04-23 14:48:16 -0700 | [diff] [blame] | 94 | return deviceId; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 97 | /** |
| 98 | * Returns the vlan ID of this key. |
| 99 | * |
| 100 | * @return vlan ID |
| 101 | */ |
| 102 | public VlanId vlanId() { |
| 103 | return vlanId; |
| 104 | } |
| 105 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 106 | @Override |
| 107 | public boolean equals(Object o) { |
| 108 | if (this == o) { |
| 109 | return true; |
| 110 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 111 | if (!(o instanceof McastStoreKey)) { |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 112 | return false; |
| 113 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 114 | McastStoreKey that = |
| 115 | (McastStoreKey) o; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 116 | return (Objects.equals(this.mcastIp, that.mcastIp) && |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 117 | Objects.equals(this.deviceId, that.deviceId) && |
| 118 | Objects.equals(this.vlanId, that.vlanId)); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public int hashCode() { |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 123 | return Objects.hash(mcastIp, deviceId, vlanId); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public String toString() { |
| 128 | return toStringHelper(getClass()) |
| 129 | .add("mcastIp", mcastIp) |
| 130 | .add("deviceId", deviceId) |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 131 | .add("vlanId", vlanId) |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 132 | .toString(); |
| 133 | } |
| 134 | } |