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 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.util.Frequency; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkArgument; |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Implementation of Lambda representing OCh (Optical Channel) Signal. |
| 28 | * |
| 29 | * <p> |
| 30 | * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)". |
| 31 | * </p> |
| 32 | */ |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 33 | public class OchSignal implements Lambda { |
| 34 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 35 | public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1); |
| 36 | public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5); |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 37 | private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM; |
| 38 | private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ; |
| 39 | |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 40 | |
| 41 | private final GridType gridType; |
| 42 | private final ChannelSpacing channelSpacing; |
| 43 | // Frequency = 193.1 THz + spacingMultiplier * channelSpacing |
| 44 | private final int spacingMultiplier; |
| 45 | // Slot width = slotGranularity * 12.5 GHz |
| 46 | private final int slotGranularity; |
| 47 | |
| 48 | /** |
| 49 | * Creates an instance with the specified arguments. |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 50 | * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)} |
| 51 | * unless you want to use the concrete type, OchSignal, directly. |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 52 | * |
| 53 | * @param gridType grid type |
| 54 | * @param channelSpacing channel spacing |
| 55 | * @param spacingMultiplier channel spacing multiplier |
| 56 | * @param slotGranularity slot width granularity |
| 57 | */ |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 58 | public OchSignal(GridType gridType, ChannelSpacing channelSpacing, |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 59 | int spacingMultiplier, int slotGranularity) { |
| 60 | this.gridType = checkNotNull(gridType); |
| 61 | this.channelSpacing = checkNotNull(channelSpacing); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 62 | // Negative values are permitted for spacingMultiplier |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 63 | this.spacingMultiplier = spacingMultiplier; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 64 | checkArgument(slotGranularity > 0, "slotGranularity must be larger than 0, received %s", slotGranularity); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 65 | this.slotGranularity = slotGranularity; |
| 66 | } |
| 67 | |
| 68 | /** |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 69 | * Create OCh signal from channel number. |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 70 | * |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 71 | * @param channel channel number |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 72 | * @param maxFrequency maximum frequency |
| 73 | * @param grid grid spacing frequency |
| 74 | */ |
Marc De Leenheer | 0b8b2ef | 2015-08-03 15:39:00 -0700 | [diff] [blame] | 75 | public OchSignal(int channel, Frequency maxFrequency, Frequency grid) { |
Marc De Leenheer | c973308 | 2015-06-04 12:22:38 -0700 | [diff] [blame] | 76 | // Calculate center frequency |
| 77 | Frequency centerFrequency = maxFrequency.subtract(grid.multiply(channel - 1)); |
| 78 | |
| 79 | this.gridType = DEFAULT_OCH_GRIDTYPE; |
| 80 | this.channelSpacing = DEFAULT_CHANNEL_SPACING; |
| 81 | this.spacingMultiplier = (int) (centerFrequency.subtract(OchSignal.CENTER_FREQUENCY).asHz() / grid.asHz()); |
| 82 | this.slotGranularity = (int) Math.round((double) grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz()); |
| 83 | } |
| 84 | |
| 85 | public OchSignal(Frequency centerFrequency, ChannelSpacing channelSpacing, int slotGranularity) { |
| 86 | this.gridType = DEFAULT_OCH_GRIDTYPE; |
| 87 | this.channelSpacing = channelSpacing; |
| 88 | this.spacingMultiplier = (int) Math.round((double) centerFrequency. |
| 89 | subtract(OchSignal.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz()); |
| 90 | this.slotGranularity = slotGranularity; |
| 91 | } |
| 92 | |
| 93 | /** |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 94 | * Returns grid type. |
| 95 | * |
| 96 | * @return grid type |
| 97 | */ |
| 98 | public GridType gridType() { |
| 99 | return gridType; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns channel spacing. |
| 104 | * |
| 105 | * @return channel spacing |
| 106 | */ |
| 107 | public ChannelSpacing channelSpacing() { |
| 108 | return channelSpacing; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns spacing multiplier. |
| 113 | * |
| 114 | * @return spacing multiplier |
| 115 | */ |
| 116 | public int spacingMultiplier() { |
| 117 | return spacingMultiplier; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Returns slow width granularity. |
| 122 | * |
| 123 | * @return slow width granularity |
| 124 | */ |
| 125 | public int slotGranularity() { |
| 126 | return slotGranularity; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Returns central frequency in MHz. |
| 131 | * |
| 132 | * @return frequency in MHz |
| 133 | */ |
| 134 | public Frequency centralFrequency() { |
| 135 | return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Returns slot width. |
| 140 | * |
| 141 | * @return slot width |
| 142 | */ |
| 143 | public Frequency slotWidth() { |
| 144 | return FLEX_GRID_SLOT.multiply(slotGranularity); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public int hashCode() { |
| 149 | return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public boolean equals(Object obj) { |
| 154 | if (this == obj) { |
| 155 | return true; |
| 156 | } |
| 157 | if (!(obj instanceof OchSignal)) { |
| 158 | return false; |
| 159 | } |
| 160 | final OchSignal other = (OchSignal) obj; |
| 161 | return Objects.equals(this.gridType, other.gridType) |
| 162 | && Objects.equals(this.channelSpacing, other.channelSpacing) |
| 163 | && Objects.equals(this.spacingMultiplier, other.spacingMultiplier) |
| 164 | && Objects.equals(this.slotGranularity, other.slotGranularity); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String toString() { |
| 169 | return MoreObjects.toStringHelper(this) |
| 170 | .add("gridType", gridType) |
| 171 | .add("channelSpacing", channelSpacing) |
| 172 | .add("spacingMultiplier", spacingMultiplier) |
| 173 | .add("slotGranularity", slotGranularity) |
| 174 | .toString(); |
| 175 | } |
| 176 | } |