blob: e629b5e223a7552543d87c524d661f3a2d949eeb [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;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkArgument;
24import 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 */
33// TODO: consider which is better, OchSignal or OpticalChannelSignal
34public class OchSignal implements Lambda {
35
36 private static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1);
37 private static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
38
39 private final GridType gridType;
40 private final ChannelSpacing channelSpacing;
41 // Frequency = 193.1 THz + spacingMultiplier * channelSpacing
42 private final int spacingMultiplier;
43 // Slot width = slotGranularity * 12.5 GHz
44 private final int slotGranularity;
45
46 /**
47 * Creates an instance with the specified arguments.
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070048 * It it recommended to use {@link Lambda#ochSignal(GridType, ChannelSpacing, int, int)}
49 * unless you want to use the concrete type, OchSignal, directly.
Sho SHIMIZU91210a72015-04-29 12:54:28 -070050 *
51 * @param gridType grid type
52 * @param channelSpacing channel spacing
53 * @param spacingMultiplier channel spacing multiplier
54 * @param slotGranularity slot width granularity
55 */
Sho SHIMIZU4fea4fd2015-05-07 11:50:23 -070056 public OchSignal(GridType gridType, ChannelSpacing channelSpacing,
Sho SHIMIZU91210a72015-04-29 12:54:28 -070057 int spacingMultiplier, int slotGranularity) {
58 this.gridType = checkNotNull(gridType);
59 this.channelSpacing = checkNotNull(channelSpacing);
60 // TODO: check the precondition for spacingMultiplier. Is negative value permitted?
61 this.spacingMultiplier = spacingMultiplier;
62
63 checkArgument(slotGranularity > 0, "slotGranularity must be more than 0, but %s", slotGranularity);
64 this.slotGranularity = slotGranularity;
65 }
66
67 /**
68 * Returns grid type.
69 *
70 * @return grid type
71 */
72 public GridType gridType() {
73 return gridType;
74 }
75
76 /**
77 * Returns channel spacing.
78 *
79 * @return channel spacing
80 */
81 public ChannelSpacing channelSpacing() {
82 return channelSpacing;
83 }
84
85 /**
86 * Returns spacing multiplier.
87 *
88 * @return spacing multiplier
89 */
90 public int spacingMultiplier() {
91 return spacingMultiplier;
92 }
93
94 /**
95 * Returns slow width granularity.
96 *
97 * @return slow width granularity
98 */
99 public int slotGranularity() {
100 return slotGranularity;
101 }
102
103 /**
104 * Returns central frequency in MHz.
105 *
106 * @return frequency in MHz
107 */
108 public Frequency centralFrequency() {
109 return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
110 }
111
112 /**
113 * Returns slot width.
114 *
115 * @return slot width
116 */
117 public Frequency slotWidth() {
118 return FLEX_GRID_SLOT.multiply(slotGranularity);
119 }
120
121 @Override
122 public int hashCode() {
123 return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity);
124 }
125
126 @Override
127 public boolean equals(Object obj) {
128 if (this == obj) {
129 return true;
130 }
131 if (!(obj instanceof OchSignal)) {
132 return false;
133 }
134 final OchSignal other = (OchSignal) obj;
135 return Objects.equals(this.gridType, other.gridType)
136 && Objects.equals(this.channelSpacing, other.channelSpacing)
137 && Objects.equals(this.spacingMultiplier, other.spacingMultiplier)
138 && Objects.equals(this.slotGranularity, other.slotGranularity);
139 }
140
141 @Override
142 public String toString() {
143 return MoreObjects.toStringHelper(this)
144 .add("gridType", gridType)
145 .add("channelSpacing", channelSpacing)
146 .add("spacingMultiplier", spacingMultiplier)
147 .add("slotGranularity", slotGranularity)
148 .toString();
149 }
150}