blob: 571e87f69079257adb8edb004f088d9a50f7506d [file] [log] [blame]
Charles Chan5adc6282018-06-19 20:56:33 -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;
17
18import org.onosproject.net.DeviceId;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Represents two devices that are paired by configuration. An EdgePair for
26 * (dev1, dev2) is the same as as EdgePair for (dev2, dev1)
27 */
28public final class EdgePair {
29 DeviceId dev1;
30 DeviceId dev2;
31
32 EdgePair(DeviceId dev1, DeviceId dev2) {
33 this.dev1 = dev1;
34 this.dev2 = dev2;
35 }
36
37 boolean includes(DeviceId dev) {
38 return dev1.equals(dev) || dev2.equals(dev);
39 }
40
41 @Override
42 public boolean equals(Object o) {
43 if (this == o) {
44 return true;
45 }
46 if (!(o instanceof EdgePair)) {
47 return false;
48 }
49 EdgePair that = (EdgePair) o;
50 return ((this.dev1.equals(that.dev1) && this.dev2.equals(that.dev2)) ||
51 (this.dev1.equals(that.dev2) && this.dev2.equals(that.dev1)));
52 }
53
54 @Override
55 public int hashCode() {
56 if (dev1.toString().compareTo(dev2.toString()) <= 0) {
57 return Objects.hash(dev1, dev2);
58 } else {
59 return Objects.hash(dev2, dev1);
60 }
61 }
62
63 @Override
64 public String toString() {
65 return toStringHelper(this)
66 .add("Dev1", dev1)
67 .add("Dev2", dev2)
68 .toString();
69 }
70}