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); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 37 | |
| 38 | private final GridType gridType; |
| 39 | private final ChannelSpacing channelSpacing; |
| 40 | // Frequency = 193.1 THz + spacingMultiplier * channelSpacing |
| 41 | private final int spacingMultiplier; |
| 42 | // Slot width = slotGranularity * 12.5 GHz |
| 43 | private final int slotGranularity; |
| 44 | |
| 45 | /** |
| 46 | * Creates an instance with the specified arguments. |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 47 | * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)} |
| 48 | * unless you want to use the concrete type, OchSignal, directly. |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 49 | * |
| 50 | * @param gridType grid type |
| 51 | * @param channelSpacing channel spacing |
| 52 | * @param spacingMultiplier channel spacing multiplier |
| 53 | * @param slotGranularity slot width granularity |
| 54 | */ |
Sho SHIMIZU | 4fea4fd | 2015-05-07 11:50:23 -0700 | [diff] [blame] | 55 | public OchSignal(GridType gridType, ChannelSpacing channelSpacing, |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 56 | int spacingMultiplier, int slotGranularity) { |
| 57 | this.gridType = checkNotNull(gridType); |
| 58 | this.channelSpacing = checkNotNull(channelSpacing); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 59 | // Negative values are permitted for spacingMultiplier |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 60 | this.spacingMultiplier = spacingMultiplier; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 61 | checkArgument(slotGranularity > 0, "slotGranularity must be larger than 0, received %s", slotGranularity); |
Sho SHIMIZU | 91210a7 | 2015-04-29 12:54:28 -0700 | [diff] [blame] | 62 | this.slotGranularity = slotGranularity; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns grid type. |
| 67 | * |
| 68 | * @return grid type |
| 69 | */ |
| 70 | public GridType gridType() { |
| 71 | return gridType; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns channel spacing. |
| 76 | * |
| 77 | * @return channel spacing |
| 78 | */ |
| 79 | public ChannelSpacing channelSpacing() { |
| 80 | return channelSpacing; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns spacing multiplier. |
| 85 | * |
| 86 | * @return spacing multiplier |
| 87 | */ |
| 88 | public int spacingMultiplier() { |
| 89 | return spacingMultiplier; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns slow width granularity. |
| 94 | * |
| 95 | * @return slow width granularity |
| 96 | */ |
| 97 | public int slotGranularity() { |
| 98 | return slotGranularity; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns central frequency in MHz. |
| 103 | * |
| 104 | * @return frequency in MHz |
| 105 | */ |
| 106 | public Frequency centralFrequency() { |
| 107 | return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Returns slot width. |
| 112 | * |
| 113 | * @return slot width |
| 114 | */ |
| 115 | public Frequency slotWidth() { |
| 116 | return FLEX_GRID_SLOT.multiply(slotGranularity); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public int hashCode() { |
| 121 | return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public boolean equals(Object obj) { |
| 126 | if (this == obj) { |
| 127 | return true; |
| 128 | } |
| 129 | if (!(obj instanceof OchSignal)) { |
| 130 | return false; |
| 131 | } |
| 132 | final OchSignal other = (OchSignal) obj; |
| 133 | return Objects.equals(this.gridType, other.gridType) |
| 134 | && Objects.equals(this.channelSpacing, other.channelSpacing) |
| 135 | && Objects.equals(this.spacingMultiplier, other.spacingMultiplier) |
| 136 | && Objects.equals(this.slotGranularity, other.slotGranularity); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public String toString() { |
| 141 | return MoreObjects.toStringHelper(this) |
| 142 | .add("gridType", gridType) |
| 143 | .add("channelSpacing", channelSpacing) |
| 144 | .add("spacingMultiplier", spacingMultiplier) |
| 145 | .add("slotGranularity", slotGranularity) |
| 146 | .toString(); |
| 147 | } |
| 148 | } |