blob: 9bed4fd7c6db534e0966614502499e33abf543d2 [file] [log] [blame]
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08003 *
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.onosproject.net.optical.impl;
17
18import org.onosproject.net.Annotations;
19import org.onosproject.net.OchSignal;
20import org.onosproject.net.OduSignalType;
21import org.onosproject.net.Port;
22import org.onosproject.net.optical.OchPort;
HIGUCHI Yutaf46dc4f2016-05-13 11:24:13 -070023import org.onosproject.net.utils.ForwardingPort;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080024
25import com.google.common.annotations.Beta;
26
27import static com.google.common.base.Preconditions.checkNotNull;
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070028import static org.onosproject.net.optical.device.OchPortHelper.stripHandledAnnotations;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080029
30import java.util.Objects;
31
32/**
33 * Implementation of OCh port (Optical Channel).
34 * Also referred to as a line side port (L-port) or narrow band port.
35 * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
36 */
37@Beta
38public class DefaultOchPort extends ForwardingPort implements OchPort {
39
40 // Note: try to avoid direct access to the field, use accessor.
41 // We might want to lazily parse annotation in the future
42 private final OduSignalType signalType;
43 private final boolean isTunable;
44 private final OchSignal lambda;
45
46 /**
47 * Creates an OCh port in the specified network element.
48 *
49 * @param base Port
50 * @param signalType ODU signal type
51 * @param isTunable tunable wavelength capability
52 * @param lambda OCh signal
53 */
54 public DefaultOchPort(Port base,
55 OduSignalType signalType,
56 boolean isTunable,
57 OchSignal lambda) {
58 super(base);
59 // TODO should this class be parsing annotation to instantiate signalType?
60 this.signalType = checkNotNull(signalType);
61 this.isTunable = isTunable;
62 this.lambda = checkNotNull(lambda);
63 }
64
65 @Override
66 public Type type() {
67 return Type.OCH;
68 }
69
70 @Override
71 public long portSpeed() {
72 return signalType.bitRate();
73 }
74
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080075 @Override
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070076 public Annotations unhandledAnnotations() {
77 return stripHandledAnnotations(super.annotations());
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080078 }
79
80 /**
81 * Returns ODU signal type.
82 *
83 * @return ODU signal type
84 */
85 @Override
86 public OduSignalType signalType() {
87 return signalType;
88 }
89
90 /**
91 * Returns true if port is wavelength tunable.
92 *
93 * @return tunable wavelength capability
94 */
95 @Override
96 public boolean isTunable() {
97 return isTunable;
98 }
99
100 /**
101 * Returns OCh signal.
102 *
103 * @return OCh signal
104 */
105 @Override
106 public OchSignal lambda() {
107 return lambda;
108 }
109
110 @Override
111 public int hashCode() {
112 return Objects.hash(super.hashCode(),
113 signalType(),
114 isTunable(),
115 lambda());
116 }
117
118 @Override
119 public boolean equals(Object obj) {
120 if (this == obj) {
121 return true;
122 }
123
124 if (obj != null && getClass() == obj.getClass()) {
125 final DefaultOchPort that = (DefaultOchPort) obj;
126 return super.toEqualsBuilder(that)
127 .append(this.signalType(), that.signalType())
128 .append(this.isTunable(), that.isTunable())
129 .append(this.lambda(), that.lambda())
130 .isEquals();
131 }
132 return false;
133 }
134
135 @Override
136 public String toString() {
137 return super.toStringHelper()
138 .add("signalType", signalType())
139 .add("isTunable", isTunable())
140 .add("lambda", lambda())
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -0700141 .add("annotations", unhandledAnnotations())
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800142 .toString();
143 }
144}