blob: 6891b7783681d90b20ab0eea81fcd8b1a6e7fdf4 [file] [log] [blame]
Charles Chand55e84d2016-03-30 17:54:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chand55e84d2016-03-30 17:54:24 -07003 *
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
Charles Chand2990362016-04-18 13:44:03 -070017package org.onosproject.segmentrouting.storekey;
Charles Chand55e84d2016-03-30 17:54:24 -070018
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.DeviceId;
21import static com.google.common.base.MoreObjects.toStringHelper;
22import static com.google.common.base.Preconditions.checkArgument;
23import static com.google.common.base.Preconditions.checkNotNull;
24import java.util.Objects;
25
26/**
27 * Key of multicast next objective store.
28 */
Charles Chan2199c302016-04-23 17:36:10 -070029public class McastStoreKey {
Charles Chand55e84d2016-03-30 17:54:24 -070030 private final IpAddress mcastIp;
31 private final DeviceId deviceId;
32
33 /**
34 * Constructs the key of multicast next objective store.
35 *
36 * @param mcastIp multicast group IP address
37 * @param deviceId device ID
38 */
Charles Chan2199c302016-04-23 17:36:10 -070039 public McastStoreKey(IpAddress mcastIp, DeviceId deviceId) {
Charles Chand55e84d2016-03-30 17:54:24 -070040 checkNotNull(mcastIp, "mcastIp cannot be null");
41 checkNotNull(deviceId, "deviceId cannot be null");
42 checkArgument(mcastIp.isMulticast(), "mcastIp must be a multicast address");
43 this.mcastIp = mcastIp;
44 this.deviceId = deviceId;
45 }
46
47 /**
48 * Returns the multicast IP address of this key.
49 *
50 * @return multicast IP
51 */
52 public IpAddress mcastIp() {
Charles Chan216e3c82016-04-23 14:48:16 -070053 return mcastIp;
Charles Chand55e84d2016-03-30 17:54:24 -070054 }
55
56 /**
57 * Returns the device ID of this key.
58 *
59 * @return device ID
60 */
61 public DeviceId deviceId() {
Charles Chan216e3c82016-04-23 14:48:16 -070062 return deviceId;
Charles Chand55e84d2016-03-30 17:54:24 -070063 }
64
65 @Override
66 public boolean equals(Object o) {
67 if (this == o) {
68 return true;
69 }
Charles Chan2199c302016-04-23 17:36:10 -070070 if (!(o instanceof McastStoreKey)) {
Charles Chand55e84d2016-03-30 17:54:24 -070071 return false;
72 }
Charles Chan2199c302016-04-23 17:36:10 -070073 McastStoreKey that =
74 (McastStoreKey) o;
Charles Chand55e84d2016-03-30 17:54:24 -070075 return (Objects.equals(this.mcastIp, that.mcastIp) &&
76 Objects.equals(this.deviceId, that.deviceId));
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(mcastIp, deviceId);
82 }
83
84 @Override
85 public String toString() {
86 return toStringHelper(getClass())
87 .add("mcastIp", mcastIp)
88 .add("deviceId", deviceId)
89 .toString();
90 }
91}