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