blob: 1f2d4462b27d25fd3191fe98edf1099e6c7b6f8c [file] [log] [blame]
Charles Chan8d316332018-06-19 20:31:57 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.segmentrouting.xconnect.api;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.VlanId;
20import org.onosproject.net.DeviceId;
21
22import java.util.Objects;
23
24/**
25 * Xconnect key.
26 */
27public class XconnectKey {
28 private DeviceId deviceId;
29 private VlanId vlanId;
30
31 /**
32 * Constructs new XconnectKey with given device ID and VLAN ID.
33 *
34 * @param deviceId device ID
35 * @param vlanId vlan ID
36 */
37 public XconnectKey(DeviceId deviceId, VlanId vlanId) {
38 this.deviceId = deviceId;
39 this.vlanId = vlanId;
40 }
41
42 /**
43 * Gets device ID.
44 *
45 * @return device ID of the Xconnect key
46 */
47 public DeviceId deviceId() {
48 return deviceId;
49 }
50
51 /**
52 * Gets VLAN ID.
53 *
54 * @return VLAN ID of the Xconnect key
55 */
56 public VlanId vlanId() {
57 return vlanId;
58 }
59
60 @Override
61 public boolean equals(final Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (!super.equals(obj)) {
66 return false;
67 }
68 if (!(obj instanceof XconnectKey)) {
69 return false;
70 }
71 final XconnectKey other = (XconnectKey) obj;
72 return Objects.equals(this.deviceId, other.deviceId) &&
73 Objects.equals(this.vlanId, other.vlanId);
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(deviceId, vlanId);
79 }
80
81 @Override
82 public String toString() {
83 return MoreObjects.toStringHelper(getClass())
84 .add("deviceId", deviceId)
85 .add("vlanId", vlanId)
86 .toString();
87 }
88}