Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -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 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 19 | import org.onlab.util.Frequency; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 20 | import org.onlab.util.Spectrum; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 21 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 22 | import java.util.List; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 23 | import java.util.Objects; |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 24 | import java.util.Set; |
| 25 | import java.util.SortedSet; |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 26 | import java.util.stream.Collectors; |
| 27 | import java.util.stream.IntStream; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 28 | |
| 29 | import static com.google.common.base.Preconditions.checkArgument; |
| 30 | import static com.google.common.base.Preconditions.checkNotNull; |
HIGUCHI Yuta | ca8cb4e | 2015-12-11 13:57:05 -0800 | [diff] [blame] | 31 | import static org.onosproject.net.ChannelSpacing.CHL_12P5GHZ; |
| 32 | import static org.onosproject.net.ChannelSpacing.CHL_6P25GHZ; |
| 33 | import static org.onosproject.net.GridType.DWDM; |
| 34 | import static org.onosproject.net.GridType.FLEX; |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Implementation of Lambda representing OCh (Optical Channel) Signal. |
| 38 | * |
| 39 | * <p> |
| 40 | * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)". |
HIGUCHI Yuta | ca8cb4e | 2015-12-11 13:57:05 -0800 | [diff] [blame] | 41 | * ITU G.694.1 "Spectral grids for WDM applications: DWDM frequency grid". |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 42 | * </p> |
| 43 | */ |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 44 | public class OchSignal implements Lambda { |
| 45 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 46 | public static final Set<Integer> FIXED_GRID_SLOT_GRANULARITIES = ImmutableSet.of(1, 2, 4, 8); |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 47 | private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM; |
| 48 | private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ; |
| 49 | |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 50 | private final GridType gridType; |
| 51 | private final ChannelSpacing channelSpacing; |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 52 | // Nominal central frequency = 193.1 THz + spacingMultiplier * channelSpacing |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 53 | private final int spacingMultiplier; |
| 54 | // Slot width = slotGranularity * 12.5 GHz |
| 55 | private final int slotGranularity; |
| 56 | |
| 57 | /** |
| 58 | * Creates an instance with the specified arguments. |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 59 | * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)} |
| 60 | * unless you want to use the concrete type, OchSignal, directly. |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 61 | * |
| 62 | * @param gridType grid type |
| 63 | * @param channelSpacing channel spacing |
| 64 | * @param spacingMultiplier channel spacing multiplier |
| 65 | * @param slotGranularity slot width granularity |
| 66 | */ |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 67 | public OchSignal(GridType gridType, ChannelSpacing channelSpacing, |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 68 | int spacingMultiplier, int slotGranularity) { |
| 69 | this.gridType = checkNotNull(gridType); |
| 70 | this.channelSpacing = checkNotNull(channelSpacing); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 71 | // Negative values are permitted for spacingMultiplier |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 72 | this.spacingMultiplier = spacingMultiplier; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 73 | checkArgument(slotGranularity > 0, "slotGranularity must be larger than 0, received %s", slotGranularity); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 74 | this.slotGranularity = slotGranularity; |
| 75 | } |
| 76 | |
| 77 | /** |
HIGUCHI Yuta | ca8cb4e | 2015-12-11 13:57:05 -0800 | [diff] [blame] | 78 | * Creates an instance of {@link OchSignal} representing a flex grid frequency slot. |
| 79 | * @param index slot index (relative to "the center frequency" 193.1THz) |
| 80 | * @return FlexGrid {@link OchSignal} |
| 81 | */ |
| 82 | public static OchSignal newFlexGridSlot(int index) { |
| 83 | return new OchSignal(FLEX, CHL_6P25GHZ, index, 1); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Creates an instance of {@link OchSignal} representing a fixed DWDM frequency slot. |
| 88 | * @param spacing channel spacing |
| 89 | * @param index slot index (relative to "the center frequency" 193.1THz) |
| 90 | * @return DWDM {@link OchSignal} |
| 91 | */ |
| 92 | public static OchSignal newDwdmSlot(ChannelSpacing spacing, int index) { |
| 93 | return new OchSignal(DWDM, spacing, index, |
| 94 | (int) (spacing.frequency().asHz() / CHL_12P5GHZ.frequency().asHz())); |
| 95 | } |
| 96 | |
| 97 | /** |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 98 | * Create OCh signal from channel number. |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 99 | * |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 100 | * @param channel channel number |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 101 | * @param maxFrequency maximum frequency |
| 102 | * @param grid grid spacing frequency |
HIGUCHI Yuta | 603e8d9 | 2015-12-11 09:57:30 -0800 | [diff] [blame] | 103 | * |
| 104 | * @deprecated in Emu (ONOS 1.4). |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 105 | */ |
HIGUCHI Yuta | 603e8d9 | 2015-12-11 09:57:30 -0800 | [diff] [blame] | 106 | @Deprecated |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 107 | public OchSignal(int channel, Frequency maxFrequency, Frequency grid) { |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 108 | // Calculate center frequency |
| 109 | Frequency centerFrequency = maxFrequency.subtract(grid.multiply(channel - 1)); |
| 110 | |
| 111 | this.gridType = DEFAULT_OCH_GRIDTYPE; |
| 112 | this.channelSpacing = DEFAULT_CHANNEL_SPACING; |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 113 | this.spacingMultiplier = (int) (centerFrequency.subtract(Spectrum.CENTER_FREQUENCY).asHz() / grid.asHz()); |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 114 | this.slotGranularity = (int) Math.round((double) grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz()); |
| 115 | } |
| 116 | |
HIGUCHI Yuta | 603e8d9 | 2015-12-11 09:57:30 -0800 | [diff] [blame] | 117 | @Deprecated |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 118 | public OchSignal(Frequency centerFrequency, ChannelSpacing channelSpacing, int slotGranularity) { |
| 119 | this.gridType = DEFAULT_OCH_GRIDTYPE; |
| 120 | this.channelSpacing = channelSpacing; |
| 121 | this.spacingMultiplier = (int) Math.round((double) centerFrequency. |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 122 | subtract(Spectrum.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz()); |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 123 | this.slotGranularity = slotGranularity; |
| 124 | } |
| 125 | |
| 126 | /** |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 127 | * Returns grid type. |
| 128 | * |
| 129 | * @return grid type |
| 130 | */ |
| 131 | public GridType gridType() { |
| 132 | return gridType; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns channel spacing. |
| 137 | * |
| 138 | * @return channel spacing |
| 139 | */ |
| 140 | public ChannelSpacing channelSpacing() { |
| 141 | return channelSpacing; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Returns spacing multiplier. |
| 146 | * |
| 147 | * @return spacing multiplier |
| 148 | */ |
| 149 | public int spacingMultiplier() { |
| 150 | return spacingMultiplier; |
| 151 | } |
| 152 | |
| 153 | /** |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 154 | * Returns slot width granularity. |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 155 | * |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 156 | * @return slot width granularity |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 157 | */ |
| 158 | public int slotGranularity() { |
| 159 | return slotGranularity; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Returns central frequency in MHz. |
| 164 | * |
| 165 | * @return frequency in MHz |
| 166 | */ |
| 167 | public Frequency centralFrequency() { |
Marc De Leenheer | b0fb41d | 2015-12-03 22:16:53 -0800 | [diff] [blame] | 168 | return Spectrum.CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Returns slot width. |
| 173 | * |
| 174 | * @return slot width |
| 175 | */ |
| 176 | public Frequency slotWidth() { |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 177 | return ChannelSpacing.CHL_12P5GHZ.frequency().multiply(slotGranularity); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Convert fixed grid OCh signal to sorted set of flex grid slots with 6.25 GHz spacing and 12.5 GHz slot width. |
| 182 | * |
| 183 | * @param ochSignal fixed grid lambda |
| 184 | * @return sorted set of flex grid OCh lambdas |
| 185 | */ |
| 186 | public static SortedSet<OchSignal> toFlexGrid(OchSignal ochSignal) { |
| 187 | checkArgument(ochSignal.gridType() != GridType.FLEX); |
| 188 | checkArgument(ochSignal.channelSpacing() != ChannelSpacing.CHL_6P25GHZ); |
| 189 | checkArgument(FIXED_GRID_SLOT_GRANULARITIES.contains(ochSignal.slotGranularity())); |
| 190 | |
| 191 | int startMultiplier = (int) (1 - ochSignal.slotGranularity() + |
| 192 | ochSignal.spacingMultiplier() * ochSignal.channelSpacing().frequency().asHz() / |
| 193 | ChannelSpacing.CHL_6P25GHZ.frequency().asHz()); |
| 194 | |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 195 | return IntStream.range(0, ochSignal.slotGranularity()) |
| 196 | .mapToObj(i -> new OchSignal(GridType.FLEX, ChannelSpacing.CHL_6P25GHZ, startMultiplier + 2 * i, 1)) |
HIGUCHI Yuta | ca8cb4e | 2015-12-11 13:57:05 -0800 | [diff] [blame] | 197 | .collect(Collectors.toCollection(DefaultOchSignalComparator::newOchSignalTreeSet)); |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Convert list of lambdas with flex grid 6.25 GHz spacing and 12.5 GHz width into fixed grid OCh signal. |
| 202 | * |
| 203 | * @param lambdas list of flex grid lambdas in sorted order |
| 204 | * @param spacing desired fixed grid spacing |
| 205 | * @return fixed grid lambda |
| 206 | */ |
| 207 | public static OchSignal toFixedGrid(List<OchSignal> lambdas, ChannelSpacing spacing) { |
| 208 | // Number of slots of 12.5 GHz that fit into requested spacing |
| 209 | int ratio = (int) (spacing.frequency().asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz()); |
| 210 | checkArgument(lambdas.size() == ratio); |
| 211 | lambdas.forEach(x -> checkArgument(x.gridType() == GridType.FLEX)); |
| 212 | lambdas.forEach(x -> checkArgument(x.channelSpacing() == ChannelSpacing.CHL_6P25GHZ)); |
| 213 | lambdas.forEach(x -> checkArgument(x.slotGranularity() == 1)); |
| 214 | // Consecutive lambdas (multiplier increments by 2 because spacing is 6.25 GHz but slot width is 12.5 GHz) |
| 215 | IntStream.range(1, lambdas.size()) |
| 216 | .forEach(i -> checkArgument( |
| 217 | lambdas.get(i).spacingMultiplier() == lambdas.get(i - 1).spacingMultiplier() + 2)); |
| 218 | // Is center frequency compatible with requested spacing |
| 219 | Frequency center = lambdas.get(ratio / 2).centralFrequency().subtract(ChannelSpacing.CHL_6P25GHZ.frequency()); |
| 220 | checkArgument(Spectrum.CENTER_FREQUENCY.subtract(center).asHz() % spacing.frequency().asHz() == 0); |
| 221 | |
| 222 | // Multiplier sits in middle of given lambdas, then convert from 6.25 to requested spacing |
HIGUCHI Yuta | ca8cb4e | 2015-12-11 13:57:05 -0800 | [diff] [blame] | 223 | int spacingMultiplier = lambdas.stream() |
| 224 | .mapToInt(OchSignal::spacingMultiplier) |
| 225 | .sum() / lambdas.size() |
| 226 | / (int) (spacing.frequency().asHz() / CHL_6P25GHZ.frequency().asHz()); |
Marc De Leenheer | 2c30530 | 2015-12-07 21:37:44 -0800 | [diff] [blame] | 227 | |
| 228 | return new OchSignal(GridType.DWDM, spacing, spacingMultiplier, lambdas.size()); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public int hashCode() { |
| 233 | return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity); |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public boolean equals(Object obj) { |
| 238 | if (this == obj) { |
| 239 | return true; |
| 240 | } |
| 241 | if (!(obj instanceof OchSignal)) { |
| 242 | return false; |
| 243 | } |
| 244 | final OchSignal other = (OchSignal) obj; |
| 245 | return Objects.equals(this.gridType, other.gridType) |
| 246 | && Objects.equals(this.channelSpacing, other.channelSpacing) |
| 247 | && Objects.equals(this.spacingMultiplier, other.spacingMultiplier) |
| 248 | && Objects.equals(this.slotGranularity, other.slotGranularity); |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public String toString() { |
Naoki Shiota | 0b5ccd2 | 2015-12-11 15:47:01 -0800 | [diff] [blame] | 253 | return String.format("%s{%+d×%.2fGHz ± %.2fGHz}", |
| 254 | this.getClass().getSimpleName(), |
| 255 | spacingMultiplier, |
| 256 | (double) slotGranularity * channelSpacing.frequency().asHz() |
| 257 | / Frequency.ofGHz(1).asHz(), |
| 258 | (double) slotGranularity * ChannelSpacing.CHL_12P5GHZ.frequency().asHz() |
| 259 | / Frequency.ofGHz(1).asHz() / 2.0); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 260 | } |
| 261 | } |