Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [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; |
| 17 | |
| 18 | import org.onlab.util.Frequency; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Implementation of OCh port (Optical Channel). |
| 26 | * Also referred to as a line side port (L-port) or narrow band port. |
| 27 | * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)" |
| 28 | */ |
| 29 | public class OchPort extends DefaultPort { |
| 30 | |
| 31 | public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1); |
| 32 | public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5); |
| 33 | |
| 34 | public enum SignalType { |
| 35 | ODU0, |
| 36 | ODU1, |
| 37 | ODU2, |
| 38 | ODU2e, |
| 39 | ODU3, |
| 40 | ODU4 |
| 41 | } |
| 42 | |
| 43 | public enum GridType { |
| 44 | RES, // ?? |
| 45 | DWDM, // Dense Wavelength Division Multiplexing |
| 46 | CWDM, // Coarse WDM |
| 47 | FLEX // Flex Grid |
| 48 | } |
| 49 | |
| 50 | public enum ChannelSpacing { |
| 51 | CHL_100GHZ(100), // 100 GHz |
| 52 | CHL_50GHZ(50), // 50 GHz |
| 53 | CHL_25GHZ(25), // 25 GHz |
| 54 | CHL_12P5GHZ(12.5), // 12.5 GHz |
| 55 | CHL_6P25GHZ(6.5); // 6.25 GHz |
| 56 | |
| 57 | private final Frequency frequency; |
| 58 | |
| 59 | ChannelSpacing(double value) { |
| 60 | this.frequency = Frequency.ofGHz(value); |
| 61 | } |
| 62 | |
| 63 | public Frequency frequency() { |
| 64 | return frequency; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private final SignalType signalType; |
| 69 | private final boolean isTunable; |
| 70 | private final GridType gridType; |
| 71 | private final ChannelSpacing channelSpacing; |
| 72 | // Frequency = 193.1 THz + spacingMultiplier * channelSpacing |
| 73 | private final int spacingMultiplier; |
| 74 | // Slot width = slotGranularity * 12.5 GHz |
| 75 | private final int slotGranularity; |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | * Creates an OCh port in the specified network element. |
| 80 | * |
| 81 | * @param element parent network element |
| 82 | * @param number port number |
| 83 | * @param isEnabled port enabled state |
| 84 | * @param signalType ODU signal type |
| 85 | * @param isTunable maximum frequency in MHz |
| 86 | * @param gridType grid type |
| 87 | * @param channelSpacing channel spacing |
| 88 | * @param spacingMultiplier channel spacing multiplier |
| 89 | * @param slotGranularity slot width granularity |
| 90 | * @param annotations optional key/value annotations |
| 91 | */ |
| 92 | public OchPort(Element element, PortNumber number, boolean isEnabled, SignalType signalType, |
| 93 | boolean isTunable, GridType gridType, ChannelSpacing channelSpacing, |
| 94 | int spacingMultiplier, int slotGranularity, Annotations... annotations) { |
| 95 | super(element, number, isEnabled, Type.OCH, 0, annotations); |
| 96 | this.signalType = signalType; |
| 97 | this.isTunable = isTunable; |
| 98 | this.gridType = gridType; |
| 99 | this.channelSpacing = channelSpacing; |
| 100 | this.spacingMultiplier = spacingMultiplier; |
| 101 | this.slotGranularity = slotGranularity; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns ODU signal type. |
| 106 | * |
| 107 | * @return ODU signal type |
| 108 | */ |
| 109 | public SignalType signalType() { |
| 110 | return signalType; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns true if port is wavelength tunable. |
| 115 | * |
| 116 | * @return tunable wavelength capability |
| 117 | */ |
| 118 | public boolean isTunable() { |
| 119 | return isTunable; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns grid type. |
| 124 | * |
| 125 | * @return grid type |
| 126 | */ |
| 127 | public GridType gridType() { |
| 128 | return gridType; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns channel spacing. |
| 133 | * |
| 134 | * @return channel spacing |
| 135 | */ |
| 136 | public ChannelSpacing channelSpacing() { |
| 137 | return channelSpacing; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Returns spacing multiplier. |
| 142 | * |
| 143 | * @return spacing multiplier |
| 144 | */ |
| 145 | public int spacingMultiplier() { |
| 146 | return spacingMultiplier; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns slow width granularity. |
| 151 | * |
| 152 | * @return slow width granularity |
| 153 | */ |
| 154 | public int slotGranularity() { |
| 155 | return slotGranularity; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns central frequency in MHz. |
| 160 | * |
| 161 | * @return frequency in MHz |
| 162 | */ |
| 163 | public Frequency centralFrequency() { |
| 164 | return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns slot width. |
| 169 | * |
| 170 | * @return slot width |
| 171 | */ |
| 172 | public Frequency slotWidth() { |
| 173 | return FLEX_GRID_SLOT.multiply(slotGranularity); |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public int hashCode() { |
| 178 | return Objects.hash(number(), isEnabled(), type(), signalType, isTunable, |
| 179 | gridType, channelSpacing, spacingMultiplier, slotGranularity, annotations()); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public boolean equals(Object obj) { |
| 184 | if (this == obj) { |
| 185 | return true; |
| 186 | } |
| 187 | if (obj instanceof OchPort) { |
| 188 | final OchPort other = (OchPort) obj; |
| 189 | return Objects.equals(this.element().id(), other.element().id()) && |
| 190 | Objects.equals(this.number(), other.number()) && |
| 191 | Objects.equals(this.isEnabled(), other.isEnabled()) && |
| 192 | Objects.equals(this.signalType, other.signalType) && |
| 193 | Objects.equals(this.isTunable, other.isTunable) && |
| 194 | Objects.equals(this.gridType, other.gridType) && |
| 195 | Objects.equals(this.channelSpacing, other.channelSpacing) && |
| 196 | Objects.equals(this.spacingMultiplier, other.spacingMultiplier) && |
| 197 | Objects.equals(this.slotGranularity, other.slotGranularity) && |
| 198 | Objects.equals(this.annotations(), other.annotations()); |
| 199 | } |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public String toString() { |
| 205 | return toStringHelper(this) |
| 206 | .add("element", element().id()) |
| 207 | .add("number", number()) |
| 208 | .add("isEnabled", isEnabled()) |
| 209 | .add("type", type()) |
| 210 | .add("signalType", signalType) |
| 211 | .add("isTunable", isTunable) |
| 212 | .add("gridType", gridType) |
| 213 | .add("channelSpacing", channelSpacing) |
| 214 | .add("spacingMultiplier", spacingMultiplier) |
| 215 | .add("slotGranularity", slotGranularity) |
| 216 | .toString(); |
| 217 | } |
| 218 | } |