blob: 526db725c4e8042cbfc9139d9bbe316d87b37c28 [file] [log] [blame]
Charles Chanc91c8782016-03-30 17:54:24 -07001/*
2 * Copyright 2015-present Open Networking Laboratory
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
17package org.onosproject.segmentrouting.grouphandler;
18
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 */
29public class McastNextObjectiveStoreKey {
30 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 */
39 public McastNextObjectiveStoreKey(IpAddress mcastIp, DeviceId deviceId) {
40 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() {
53 return this.mcastIp;
54 }
55
56 /**
57 * Returns the device ID of this key.
58 *
59 * @return device ID
60 */
61 public DeviceId deviceId() {
62 return this.deviceId;
63 }
64
65 @Override
66 public boolean equals(Object o) {
67 if (this == o) {
68 return true;
69 }
70 if (!(o instanceof McastNextObjectiveStoreKey)) {
71 return false;
72 }
73 McastNextObjectiveStoreKey that =
74 (McastNextObjectiveStoreKey) o;
75 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}