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