blob: aa327971515fb0da5276cf6b027c606c4143d73c [file] [log] [blame]
Charles Chanc91c8782016-03-30 17:54:24 -07001/*
Piere99511d2018-04-19 16:47:06 +02002 * Copyright 2018-present Open Networking Foundation
Charles Chanc91c8782016-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
Piere99511d2018-04-19 16:47:06 +020017package org.onosproject.segmentrouting.mcast;
Charles Chanc91c8782016-03-30 17:54:24 -070018
19import org.onlab.packet.IpAddress;
Piere99511d2018-04-19 16:47:06 +020020import org.onlab.packet.VlanId;
Charles Chanc91c8782016-03-30 17:54:24 -070021import org.onosproject.net.DeviceId;
22import static com.google.common.base.MoreObjects.toStringHelper;
23import static com.google.common.base.Preconditions.checkArgument;
24import static com.google.common.base.Preconditions.checkNotNull;
25import java.util.Objects;
26
27/**
28 * Key of multicast next objective store.
29 */
Charles Chan72779502016-04-23 17:36:10 -070030public class McastStoreKey {
Piere99511d2018-04-19 16:47:06 +020031 // Identify a flow using group address, deviceId, and assigned vlan
Charles Chanc91c8782016-03-30 17:54:24 -070032 private final IpAddress mcastIp;
33 private final DeviceId deviceId;
Piere99511d2018-04-19 16:47:06 +020034 private final VlanId vlanId;
Charles Chanc91c8782016-03-30 17:54:24 -070035
36 /**
37 * Constructs the key of multicast next objective store.
38 *
39 * @param mcastIp multicast group IP address
40 * @param deviceId device ID
Piere99511d2018-04-19 16:47:06 +020041 *
42 * @deprecated in 1.12 ("Magpie") release.
Charles Chanc91c8782016-03-30 17:54:24 -070043 */
Piere99511d2018-04-19 16:47:06 +020044 @Deprecated
Charles Chan72779502016-04-23 17:36:10 -070045 public McastStoreKey(IpAddress mcastIp, DeviceId deviceId) {
Charles Chanc91c8782016-03-30 17:54:24 -070046 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;
Piere99511d2018-04-19 16:47:06 +020051 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 Chanc91c8782016-03-30 17:54:24 -070077 }
78
79 /**
80 * Returns the multicast IP address of this key.
81 *
82 * @return multicast IP
83 */
84 public IpAddress mcastIp() {
Charles Chana4ee4f92016-04-23 14:48:16 -070085 return mcastIp;
Charles Chanc91c8782016-03-30 17:54:24 -070086 }
87
88 /**
89 * Returns the device ID of this key.
90 *
91 * @return device ID
92 */
93 public DeviceId deviceId() {
Charles Chana4ee4f92016-04-23 14:48:16 -070094 return deviceId;
Charles Chanc91c8782016-03-30 17:54:24 -070095 }
96
Piere99511d2018-04-19 16:47:06 +020097 /**
98 * Returns the vlan ID of this key.
99 *
100 * @return vlan ID
101 */
102 public VlanId vlanId() {
103 return vlanId;
104 }
105
Charles Chanc91c8782016-03-30 17:54:24 -0700106 @Override
107 public boolean equals(Object o) {
108 if (this == o) {
109 return true;
110 }
Charles Chan72779502016-04-23 17:36:10 -0700111 if (!(o instanceof McastStoreKey)) {
Charles Chanc91c8782016-03-30 17:54:24 -0700112 return false;
113 }
Charles Chan72779502016-04-23 17:36:10 -0700114 McastStoreKey that =
115 (McastStoreKey) o;
Charles Chanc91c8782016-03-30 17:54:24 -0700116 return (Objects.equals(this.mcastIp, that.mcastIp) &&
Piere99511d2018-04-19 16:47:06 +0200117 Objects.equals(this.deviceId, that.deviceId) &&
118 Objects.equals(this.vlanId, that.vlanId));
Charles Chanc91c8782016-03-30 17:54:24 -0700119 }
120
121 @Override
122 public int hashCode() {
Piere99511d2018-04-19 16:47:06 +0200123 return Objects.hash(mcastIp, deviceId, vlanId);
Charles Chanc91c8782016-03-30 17:54:24 -0700124 }
125
126 @Override
127 public String toString() {
128 return toStringHelper(getClass())
129 .add("mcastIp", mcastIp)
130 .add("deviceId", deviceId)
Piere99511d2018-04-19 16:47:06 +0200131 .add("vlanId", vlanId)
Charles Chanc91c8782016-03-30 17:54:24 -0700132 .toString();
133 }
134}