HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 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; |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 28 | import static org.onosproject.net.optical.device.OchPortHelper.stripHandledAnnotations; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 29 | |
| 30 | import 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 |
| 38 | public 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 Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 75 | @Override |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 76 | public Annotations unhandledAnnotations() { |
| 77 | return stripHandledAnnotations(super.annotations()); |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 78 | } |
| 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 HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 141 | .add("annotations", unhandledAnnotations()) |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 142 | .toString(); |
| 143 | } |
| 144 | } |