blob: 77bd39e991202557cfe045476f7be52262f42f26 [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
Joey Armstrong7f6d6d22023-01-09 17:09:50 -05002 * Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07003 *
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 Silva29fb20e2022-05-26 09:59:54 -030016package org.opencord.olt;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070017
Gustavo Silva29fb20e2022-05-26 09:59:54 -030018import org.onosproject.net.AnnotationKeys;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070019import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.Port;
21
22import java.util.Objects;
23
24/**
25 * OLT device port.
26 */
27public 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 Silva29fb20e2022-05-26 09:59:54 -030039 this.name = getPortName(port);
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070040 }
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 Silva29fb20e2022-05-26 09:59:54 -030093
94 private String getPortName(Port port) {
95 String name = port.annotations().value(AnnotationKeys.PORT_NAME);
96 return name == null ? "" : name;
97 }
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070098}