blob: f174282fb90685fbd6a77b94d3c81e82f47acb6d [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Madan Jampanic27b6b22016-02-05 11:36:31 -08003 *
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.iptopology.api;
17
18import java.util.Objects;
19
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.ElementId;
22
23import com.google.common.base.MoreObjects;
24
25/**
26 * Abstraction of a network termination point expressed as a pair of the network element identifier and device
27 * interface.
28 */
29public class TerminationPoint {
30 private final ElementId elementId;
31 private final DeviceInterface deviceInterface;
32
33 /**
34 * Constructor to initialize its parameters.
35 *
36 * @param elementId network element identifier
37 * @param deviceInterface device interface
38 */
39 public TerminationPoint(ElementId elementId, DeviceInterface deviceInterface) {
40 this.elementId = elementId;
41 this.deviceInterface = deviceInterface;
42 }
43
44 /**
45 * Returns the network element identifier.
46 *
47 * @return element identifier
48 */
49 public ElementId elementId() {
50 return elementId;
51 }
52
53 /**
54 * Returns the identifier of the infrastructure device if the termination
55 * point belongs to a network element which is indeed an ip
56 * device.
57 *
58 * @return network element identifier as a device identifier
59 * @throws java.lang.IllegalStateException if termination point is not
60 * associated with a device
61 */
62 public DeviceId deviceId() {
63 if (elementId instanceof DeviceId) {
64 return (DeviceId) elementId;
65 }
66 throw new IllegalStateException("Termination point not associated " +
67 "with an ip device");
68 }
69
70 /**
71 * Returns Device interface details.
72 *
73 * @return device interface details
74 */
75 public DeviceInterface deviceInterface() {
76 return deviceInterface;
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(elementId, deviceInterface);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89 if (obj instanceof TerminationPoint) {
90 final TerminationPoint other = (TerminationPoint) obj;
91 return Objects.equals(this.elementId, other.elementId)
92 && Objects.equals(this.deviceInterface, other.deviceInterface);
93 }
94 return false;
95 }
96
97 @Override
98 public String toString() {
99 return MoreObjects.toStringHelper(this)
100 .add("elementId", elementId)
101 .add("deviceInterface", deviceInterface)
102 .toString();
103 }
Satish Kf6d87cb2015-11-30 19:59:22 +0530104}