Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.iptopology.api; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.ElementId; |
| 22 | |
| 23 | import 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 | */ |
| 29 | public 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 K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 104 | } |