blob: 7d433cd7378d74709d749879d7c373c00512035d [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 }
Charles Chan8d316332018-06-19 20:31:57 -070065 if (!(obj instanceof XconnectKey)) {
66 return false;
67 }
68 final XconnectKey other = (XconnectKey) obj;
69 return Objects.equals(this.deviceId, other.deviceId) &&
70 Objects.equals(this.vlanId, other.vlanId);
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(deviceId, vlanId);
76 }
77
78 @Override
79 public String toString() {
80 return MoreObjects.toStringHelper(getClass())
81 .add("deviceId", deviceId)
82 .add("vlanId", vlanId)
83 .toString();
84 }
85}