blob: 3adc9086c426742a12bf8820d7fa982c68b623e6 [file] [log] [blame]
Sho SHIMIZU91210a72015-04-29 12:54:28 -07001/*
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 */
16package org.onosproject.net;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.util.Frequency;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080020import org.onlab.util.Spectrum;
Sho SHIMIZU91210a72015-04-29 12:54:28 -070021
22import java.util.Objects;
23
24import static com.google.common.base.Preconditions.checkArgument;
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Implementation of Lambda representing OCh (Optical Channel) Signal.
29 *
30 * <p>
31 * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)".
32 * </p>
33 */
Sho SHIMIZU91210a72015-04-29 12:54:28 -070034public class OchSignal implements Lambda {
35
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070036 public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
Marc De Leenheerc9733082015-06-04 12:22:38 -070037 private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM;
38 private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ;
39
Sho SHIMIZU91210a72015-04-29 12:54:28 -070040
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 SHIMIZU4fea4fd2015-05-07 11:50:23 -070050 * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)}
51 * unless you want to use the concrete type, OchSignal, directly.
Sho SHIMIZU91210a72015-04-29 12:54:28 -070052 *
53 * @param gridType grid type
54 * @param channelSpacing channel spacing
55 * @param spacingMultiplier channel spacing multiplier
56 * @param slotGranularity slot width granularity
57 */
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070058 public OchSignal(GridType gridType, ChannelSpacing channelSpacing,
Sho SHIMIZU91210a72015-04-29 12:54:28 -070059 int spacingMultiplier, int slotGranularity) {
60 this.gridType = checkNotNull(gridType);
61 this.channelSpacing = checkNotNull(channelSpacing);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070062 // Negative values are permitted for spacingMultiplier
Sho SHIMIZU91210a72015-04-29 12:54:28 -070063 this.spacingMultiplier = spacingMultiplier;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070064 checkArgument(slotGranularity > 0, "slotGranularity must be larger than 0, received %s", slotGranularity);
Sho SHIMIZU91210a72015-04-29 12:54:28 -070065 this.slotGranularity = slotGranularity;
66 }
67
68 /**
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070069 * Create OCh signal from channel number.
Marc De Leenheerc9733082015-06-04 12:22:38 -070070 *
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070071 * @param channel channel number
Marc De Leenheerc9733082015-06-04 12:22:38 -070072 * @param maxFrequency maximum frequency
73 * @param grid grid spacing frequency
74 */
Marc De Leenheer0b8b2ef2015-08-03 15:39:00 -070075 public OchSignal(int channel, Frequency maxFrequency, Frequency grid) {
Marc De Leenheerc9733082015-06-04 12:22:38 -070076 // 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;
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080081 this.spacingMultiplier = (int) (centerFrequency.subtract(Spectrum.CENTER_FREQUENCY).asHz() / grid.asHz());
Marc De Leenheerc9733082015-06-04 12:22:38 -070082 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.
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -080089 subtract(Spectrum.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz());
Marc De Leenheerc9733082015-06-04 12:22:38 -070090 this.slotGranularity = slotGranularity;
91 }
92
93 /**
Sho SHIMIZU91210a72015-04-29 12:54:28 -070094 * 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() {
Marc De Leenheerb0fb41d2015-12-03 22:16:53 -0800135 return Spectrum.CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
Sho SHIMIZU91210a72015-04-29 12:54:28 -0700136 }
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}