blob: 8a1665da52e53a37b8f2305923d12dfa4998db9d [file] [log] [blame]
Tunahan Sezenf0843b92021-04-30 07:13:16 +00001/*
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 */
16package org.opencord.olt;
17
18import org.onosproject.net.AnnotationKeys;
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.Port;
21import org.onosproject.net.PortNumber;
22
23/**
24 * OLT device port.
25 */
26public class AccessDevicePort {
27
28 Port port;
29 Type type;
30
31 /**
32 * OLT Port Type.
33 */
34 public enum Type {
35 NNI,
36 UNI,
37 }
38
39 /**
40 * Creates an AccessDevicePort with given ONOS port object and OLT port type.
41 *
42 * @param port ONOS port
43 * @param type OLT port type
44 */
45 public AccessDevicePort(Port port, Type type) {
46 this.port = port;
47 this.type = type;
48 }
49
50 /**
51 * Get ONOS Port object.
52 *
53 * @return ONOS port
54 */
55 public Port port() {
56 return this.port;
57 }
58
59 /**
60 * Get OLT port Type.
61 *
62 * @return OLT port type
63 */
64 public Type type() {
65 return this.type;
66 }
67
68 /**
69 * Check port is enabled state on ONOS.
70 *
71 * @return is Access Device Port enabled
72 */
73 public boolean isEnabled() {
74 return this.port.isEnabled();
75 }
76
77 /**
78 * Get Device ID of OLT which the port is connected.
79 *
80 * @return OLT Device ID
81 */
82 public DeviceId deviceId() {
83 return (DeviceId) this.port.element().id();
84 }
85
86 /**
87 * Get port number.
88 *
89 * @return port number
90 */
91 public PortNumber number() {
92 return this.port.number();
93 }
94
95 /**
96 * Get port name which is combination of serial number and uni index.
97 *
98 * @return port name (ex: BBSM00010001-1)
99 */
100 public String name() {
101 return this.port.annotations().value(AnnotationKeys.PORT_NAME);
102 }
103
104 @Override
105 public String toString() {
106 return deviceId().toString() + '/' + number() + '[' + name() + ']';
107 }
108
109}