blob: e77552178c49538ca422dca318210eae21be5f62 [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 Leenheerc9733082015-06-04 12:22:38 -070020import org.onosproject.net.resource.link.LambdaResourceAllocation;
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 CENTER_FREQUENCY = Frequency.ofTHz(193.1);
37 public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
Marc De Leenheerc9733082015-06-04 12:22:38 -070038 private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM;
39 private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ;
40
Sho SHIMIZU91210a72015-04-29 12:54:28 -070041
42 private final GridType gridType;
43 private final ChannelSpacing channelSpacing;
44 // Frequency = 193.1 THz + spacingMultiplier * channelSpacing
45 private final int spacingMultiplier;
46 // Slot width = slotGranularity * 12.5 GHz
47 private final int slotGranularity;
48
49 /**
50 * Creates an instance with the specified arguments.
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070051 * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)}
52 * unless you want to use the concrete type, OchSignal, directly.
Sho SHIMIZU91210a72015-04-29 12:54:28 -070053 *
54 * @param gridType grid type
55 * @param channelSpacing channel spacing
56 * @param spacingMultiplier channel spacing multiplier
57 * @param slotGranularity slot width granularity
58 */
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070059 public OchSignal(GridType gridType, ChannelSpacing channelSpacing,
Sho SHIMIZU91210a72015-04-29 12:54:28 -070060 int spacingMultiplier, int slotGranularity) {
61 this.gridType = checkNotNull(gridType);
62 this.channelSpacing = checkNotNull(channelSpacing);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070063 // Negative values are permitted for spacingMultiplier
Sho SHIMIZU91210a72015-04-29 12:54:28 -070064 this.spacingMultiplier = spacingMultiplier;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070065 checkArgument(slotGranularity > 0, "slotGranularity must be larger than 0, received %s", slotGranularity);
Sho SHIMIZU91210a72015-04-29 12:54:28 -070066 this.slotGranularity = slotGranularity;
67 }
68
69 /**
Marc De Leenheerc9733082015-06-04 12:22:38 -070070 * Create OCh signal from lambda resource allocation.
71 *
72 * @param alloc lambda resource allocation
73 * @param maxFrequency maximum frequency
74 * @param grid grid spacing frequency
75 */
76 public OchSignal(LambdaResourceAllocation alloc, Frequency maxFrequency, Frequency grid) {
77 int channel = alloc.lambda().toInt();
78
79 // Calculate center frequency
80 Frequency centerFrequency = maxFrequency.subtract(grid.multiply(channel - 1));
81
82 this.gridType = DEFAULT_OCH_GRIDTYPE;
83 this.channelSpacing = DEFAULT_CHANNEL_SPACING;
84 this.spacingMultiplier = (int) (centerFrequency.subtract(OchSignal.CENTER_FREQUENCY).asHz() / grid.asHz());
85 this.slotGranularity = (int) Math.round((double) grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz());
86 }
87
88 public OchSignal(Frequency centerFrequency, ChannelSpacing channelSpacing, int slotGranularity) {
89 this.gridType = DEFAULT_OCH_GRIDTYPE;
90 this.channelSpacing = channelSpacing;
91 this.spacingMultiplier = (int) Math.round((double) centerFrequency.
92 subtract(OchSignal.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz());
93 this.slotGranularity = slotGranularity;
94 }
95
96 /**
Sho SHIMIZU91210a72015-04-29 12:54:28 -070097 * Returns grid type.
98 *
99 * @return grid type
100 */
101 public GridType gridType() {
102 return gridType;
103 }
104
105 /**
106 * Returns channel spacing.
107 *
108 * @return channel spacing
109 */
110 public ChannelSpacing channelSpacing() {
111 return channelSpacing;
112 }
113
114 /**
115 * Returns spacing multiplier.
116 *
117 * @return spacing multiplier
118 */
119 public int spacingMultiplier() {
120 return spacingMultiplier;
121 }
122
123 /**
124 * Returns slow width granularity.
125 *
126 * @return slow width granularity
127 */
128 public int slotGranularity() {
129 return slotGranularity;
130 }
131
132 /**
133 * Returns central frequency in MHz.
134 *
135 * @return frequency in MHz
136 */
137 public Frequency centralFrequency() {
138 return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
139 }
140
141 /**
142 * Returns slot width.
143 *
144 * @return slot width
145 */
146 public Frequency slotWidth() {
147 return FLEX_GRID_SLOT.multiply(slotGranularity);
148 }
149
150 @Override
151 public int hashCode() {
152 return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity);
153 }
154
155 @Override
156 public boolean equals(Object obj) {
157 if (this == obj) {
158 return true;
159 }
160 if (!(obj instanceof OchSignal)) {
161 return false;
162 }
163 final OchSignal other = (OchSignal) obj;
164 return Objects.equals(this.gridType, other.gridType)
165 && Objects.equals(this.channelSpacing, other.channelSpacing)
166 && Objects.equals(this.spacingMultiplier, other.spacingMultiplier)
167 && Objects.equals(this.slotGranularity, other.slotGranularity);
168 }
169
170 @Override
171 public String toString() {
172 return MoreObjects.toStringHelper(this)
173 .add("gridType", gridType)
174 .add("channelSpacing", channelSpacing)
175 .add("spacingMultiplier", spacingMultiplier)
176 .add("slotGranularity", slotGranularity)
177 .toString();
178 }
179}