Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2021-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 | */ |
| 16 | package org.opencord.olt.impl; |
| 17 | |
| 18 | import org.onosproject.net.ConnectPoint; |
| 19 | import org.onosproject.net.Port; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | /** |
| 24 | * OLT device port. |
| 25 | */ |
| 26 | public class AccessDevicePort { |
| 27 | |
| 28 | private ConnectPoint cp; |
| 29 | private String name; |
| 30 | |
| 31 | /** |
| 32 | * Creates an AccessDevicePort with given ONOS port. |
| 33 | * |
| 34 | * @param port ONOS port |
| 35 | */ |
| 36 | public AccessDevicePort(Port port) { |
| 37 | this.cp = ConnectPoint.deviceConnectPoint(port.element().id() + "/" + port.number().toLong()); |
| 38 | this.name = OltUtils.getPortName(port); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Creates an AccessDevicePort with given ONOS connectPoint and name. |
| 43 | * |
| 44 | * @param cp ONOS connect point |
| 45 | * @param name OLT port name |
| 46 | */ |
| 47 | public AccessDevicePort(ConnectPoint cp, String name) { |
| 48 | this.cp = cp; |
| 49 | this.name = name; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get ONOS ConnectPoint object. |
| 54 | * |
| 55 | * @return ONOS connect point |
| 56 | */ |
| 57 | public ConnectPoint connectPoint() { |
| 58 | return this.cp; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get OLT port name which is combination of serial number and uni index. |
| 63 | * |
| 64 | * @return OLT port name (ex: BBSM00010001-1) |
| 65 | */ |
| 66 | public String name() { |
| 67 | return this.name; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public String toString() { |
| 72 | return cp.toString() + '[' + name + ']'; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean equals(Object o) { |
| 77 | if (this == o) { |
| 78 | return true; |
| 79 | } |
| 80 | if (o == null || getClass() != o.getClass()) { |
| 81 | return false; |
| 82 | } |
| 83 | AccessDevicePort that = (AccessDevicePort) o; |
| 84 | return Objects.equals(cp, that.cp) && |
| 85 | Objects.equals(name, that.name); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public int hashCode() { |
| 90 | return Objects.hash(cp, name); |
| 91 | } |
| 92 | } |