blob: 1997a88c65b3d79af01e871d063f9c32c331e49e [file] [log] [blame]
Marc De Leenheerbb382352015-04-23 18:20:34 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Marc De Leenheerbb382352015-04-23 18:20:34 -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 */
16package org.onosproject.net;
17
Marc De Leenheerbb382352015-04-23 18:20:34 -070018import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070021import static com.google.common.base.Preconditions.checkNotNull;
Marc De Leenheerbb382352015-04-23 18:20:34 -070022
23/**
24 * Implementation of OCh port (Optical Channel).
25 * Also referred to as a line side port (L-port) or narrow band port.
26 * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
27 */
28public class OchPort extends DefaultPort {
29
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070030 private final OduSignalType signalType;
Marc De Leenheerbb382352015-04-23 18:20:34 -070031 private final boolean isTunable;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070032 private final OchSignal lambda;
Marc De Leenheerbb382352015-04-23 18:20:34 -070033
34 /**
35 * Creates an OCh port in the specified network element.
36 *
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070037 * @param element parent network element
38 * @param number port number
39 * @param isEnabled port enabled state
40 * @param signalType ODU signal type
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070041 * @param isTunable tunable wavelength capability
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070042 * @param lambda OCh signal
43 * @param annotations optional key/value annotations
Marc De Leenheerbb382352015-04-23 18:20:34 -070044 */
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070045 public OchPort(Element element, PortNumber number, boolean isEnabled, OduSignalType signalType,
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070046 boolean isTunable, OchSignal lambda, Annotations... annotations) {
Toru Furusawa72ee30c2016-01-08 13:29:04 -080047 super(element, number, isEnabled, Type.OCH, checkNotNull(signalType).bitRate(), annotations);
48 this.signalType = signalType;
Marc De Leenheerbb382352015-04-23 18:20:34 -070049 this.isTunable = isTunable;
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070050 this.lambda = checkNotNull(lambda);
Marc De Leenheerbb382352015-04-23 18:20:34 -070051 }
52
53 /**
54 * Returns ODU signal type.
55 *
56 * @return ODU signal type
57 */
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070058 public OduSignalType signalType() {
Marc De Leenheerbb382352015-04-23 18:20:34 -070059 return signalType;
60 }
61
62 /**
63 * Returns true if port is wavelength tunable.
64 *
65 * @return tunable wavelength capability
66 */
67 public boolean isTunable() {
68 return isTunable;
69 }
70
71 /**
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070072 * Returns OCh signal.
Marc De Leenheerbb382352015-04-23 18:20:34 -070073 *
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070074 * @return OCh signal
Marc De Leenheerbb382352015-04-23 18:20:34 -070075 */
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070076 public OchSignal lambda() {
77 return lambda;
Marc De Leenheerbb382352015-04-23 18:20:34 -070078 }
79
80 @Override
81 public int hashCode() {
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070082 return Objects.hash(number(), isEnabled(), type(), signalType, isTunable, lambda, annotations());
Marc De Leenheerbb382352015-04-23 18:20:34 -070083 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (this == obj) {
88 return true;
89 }
Satish K7cfdc632015-11-27 19:48:41 +053090
91 // Subclass is considered as a change of identity, hence equals() will return false if class type don't match
92 if (obj != null && getClass() == obj.getClass()) {
Marc De Leenheerbb382352015-04-23 18:20:34 -070093 final OchPort other = (OchPort) obj;
94 return Objects.equals(this.element().id(), other.element().id()) &&
95 Objects.equals(this.number(), other.number()) &&
96 Objects.equals(this.isEnabled(), other.isEnabled()) &&
97 Objects.equals(this.signalType, other.signalType) &&
98 Objects.equals(this.isTunable, other.isTunable) &&
Sho SHIMIZU0abceb82015-05-04 09:20:53 -070099 Objects.equals(this.lambda, other.lambda) &&
Marc De Leenheerbb382352015-04-23 18:20:34 -0700100 Objects.equals(this.annotations(), other.annotations());
101 }
102 return false;
103 }
104
105 @Override
106 public String toString() {
107 return toStringHelper(this)
108 .add("element", element().id())
109 .add("number", number())
110 .add("isEnabled", isEnabled())
111 .add("type", type())
112 .add("signalType", signalType)
113 .add("isTunable", isTunable)
Sho SHIMIZU0abceb82015-05-04 09:20:53 -0700114 .add("lambda", lambda)
Marc De Leenheerbb382352015-04-23 18:20:34 -0700115 .toString();
116 }
117}