blob: 0a54be7eb2e2aea69e1b3b77758a6a4733b6a296 [file] [log] [blame]
Ivan Eroshkin2947ed52019-10-30 14:23:58 +01001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 *
16 * This work was done in Nokia Bell Labs.
17 *
18 */
19
20package org.onosproject.net.optical.util;
21
22
23import org.onlab.util.Frequency;
24import org.onosproject.net.ChannelSpacing;
25import org.onosproject.net.GridType;
26import org.onosproject.net.OchSignal;
27import org.slf4j.Logger;
28
29import java.util.HashMap;
30import java.util.Map;
31
32import static org.slf4j.LoggerFactory.getLogger;
33
34
35/**
36 * Optical Channel Utility is a set of methods to convert different
37 * set of parameters to the OchSignal instance and backwards.
38 */
39public final class OpticalChannelUtility {
40
41 private static final Logger log = getLogger(OpticalChannelUtility.class);
42 private static final double SLOT_GRANULARITY_CONSTANT = 12.5;
43 private static final int NOMINAL_CENTRAL_FREQUENCY_GHZ = 193100; // According to ITU-T 694.1
44
45 private OpticalChannelUtility() {}
46
47 /**
48 * This method creates OchSignal instance based on Central Frequency and
49 * the Slot Width of the channel.
50 * @param centralFrequency - central frequency of the connection.
51 * @param slotWidth - bandwidth of the optical channel.
52 * @param gridType - type of the frequency grid.
53 * @param channelSpacing - channel spacing.
54 * @return - returns created instance of OchSignal.
55 */
56 public static final OchSignal createOchSignal(Frequency centralFrequency, Frequency slotWidth,
57 GridType gridType, ChannelSpacing channelSpacing) {
58
59 int spacingMultiplier = computeSpacingMultiplier(centralFrequency, channelSpacing);
60 int slotGranularity = computeSlotGranularity(slotWidth);
61
62 return (new OchSignal(gridType, channelSpacing, spacingMultiplier, slotGranularity));
63 }
64
65 /**
66 * This method creates OchSignal instance from frequency bounds.
67 * @param lowerBound - lower bound of the frequency.
68 * @param upperBound - upper bound of the frequency.
69 * @param gridType - type of the frequency grid.
70 * @param channelSpacing - channel spacing.
71 * @return - returns created instance of OchSignal.
72 */
73 public static final OchSignal createOchSignalFromBounds(
74 Frequency lowerBound, Frequency upperBound, GridType gridType,
75 ChannelSpacing channelSpacing) {
76
77 // Transferring everything to the frequencies
78 Frequency slotWidth = upperBound.subtract(lowerBound);
79 Frequency halfBw = slotWidth.floorDivision(2);
80 Frequency centralFrequency = lowerBound.add(halfBw);
81
82 int spacingMultiplier = computeSpacingMultiplier(centralFrequency, channelSpacing);
83 int slotGranularity = computeSlotGranularity(slotWidth);
84
85 return (new OchSignal(gridType, channelSpacing, spacingMultiplier, slotGranularity));
86 }
87
88 /**
89 * This method extracts frequency bounds from OchSignal instance.
90 * @param signal - OchSignal instance.
91 * @param channelSpacing - channel spacing.
92 * @return - HashMap with upper and lower bounds of frequency.
93 */
94 public static final Map<String, Frequency> extractOchFreqBounds(OchSignal signal, ChannelSpacing channelSpacing) {
95
96 // Initializing variables
97 int spacingMultiplier = signal.spacingMultiplier();
98 int slotGranularity = signal.slotGranularity();
99
100 // Computing central frequency
101 Frequency central = computeCentralFrequency(spacingMultiplier, channelSpacing);
102
103 // Computing HALF of slot width
104 Frequency halfSlotWidth = computeSlotWidth(slotGranularity).floorDivision(2);
105
106 // Getting frequency bounds
107 Frequency minFreq = central.subtract(halfSlotWidth);
108 Frequency maxFreq = central.add(halfSlotWidth);
109
110 Map<String, Frequency> freqs = new HashMap<String, Frequency>();
111 freqs.put("minFreq", minFreq);
112 freqs.put("maxFreq", maxFreq);
113
114 return freqs;
115 }
116
117 /**
118 * This method extracts Central Frequency and Slot Width from OchSignal instance.
119 * @param signal - OchSignal instance.
120 * @param channelSpacing - channel spacing.
121 * @return - HashMap with upper and lower bounds of frequency.
122 */
123 public static final Map<String, Frequency> extractOch(OchSignal signal, ChannelSpacing channelSpacing) {
124
125 // Initializing variables
126 int spacingMultiplier = signal.spacingMultiplier();
127 int slotGranularity = signal.slotGranularity();
128
129 // Computing central frequency
130 Frequency central = computeCentralFrequency(spacingMultiplier, channelSpacing);
131 // Computing slot width
132 Frequency sw = computeSlotWidth(slotGranularity);
133
134 Map<String, Frequency> freqs = new HashMap<String, Frequency>();
135 freqs.put("centralFrequency", central);
136 freqs.put("slotWidth", sw);
137
138 return freqs;
139 }
140
141 /**
142 * This method computes the Spacing Multiplier value
143 * from Central Frequency and Channel Spacing values.
144 * @param centralFrequency - central frequency.
145 * @param channelSpacing - channel spacing.
146 * @return - computed spacing multiplier.
147 */
148 public static final int computeSpacingMultiplier(
149 Frequency centralFrequency, ChannelSpacing channelSpacing) {
150
151 double centfreq = Double.parseDouble(String.valueOf(centralFrequency.asGHz()));
152 // Computing spacing multiplier from definition (see OchSignal class comments)
153 double spMult = (centfreq - NOMINAL_CENTRAL_FREQUENCY_GHZ) /
154 Double.parseDouble(String.valueOf(channelSpacing.frequency().asGHz()));
155
156 return ((int) (spMult));
157 }
158
159 /**
160 * This method computes Slot Granularity from Slot Width value.
161 * @param slotWidth - slot width.
162 * @return - computed slot granularity.
163 */
164 public static final int computeSlotGranularity(Frequency slotWidth) {
165
166 double slotw = Double.parseDouble(String.valueOf(slotWidth.asGHz()));
167 // Computing according to the definition
168 double slotgr = slotw / SLOT_GRANULARITY_CONSTANT;
169
170 return ((int) slotgr);
171 }
172
173 /**
174 * This method computes the Central Frequency value
175 * from Spacing Multiplier and Channel Spacing values.
176 * @param spacingMultiplier - spacing multiplier.
177 * @param channelSpacing - channel spacing.
178 * @return - central frequency as an instance of Frequency.
179 */
180 public static final Frequency computeCentralFrequency(
181 int spacingMultiplier, ChannelSpacing channelSpacing) {
182
183 // Computing central frequency
184 double centralFreq = NOMINAL_CENTRAL_FREQUENCY_GHZ + spacingMultiplier *
185 Double.parseDouble(String.valueOf(channelSpacing.frequency().asGHz()));
186
187 return Frequency.ofGHz(centralFreq);
188 }
189
190 /**
191 * This method computes Slot Width value from Slot Granularity value.
192 * @param slotGranularity - slot granularity.
193 * @return - slot width as an instance of Frequency.
194 */
195 public static final Frequency computeSlotWidth(int slotGranularity) {
196
197 // Computing slot width
198 double slotWidth = slotGranularity * SLOT_GRANULARITY_CONSTANT;
199
200 return Frequency.ofGHz(slotWidth);
201 }
202
203}