Frequency computation
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / fixedflex / GridUtils.java
1 /*
2  * Copyright © 2020 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.common.fixedflex;
10
11 import java.math.BigDecimal;
12 import java.util.Arrays;
13 import java.util.HashMap;
14 import java.util.Map;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyGHz;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMaps;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
20 import org.opendaylight.yangtools.yang.common.Uint16;
21
22 /**
23  * Util class for grid.
24  *
25  */
26 public final class GridUtils {
27
28     private GridUtils() {
29     }
30
31     public static Map<AvailFreqMapsKey, AvailFreqMaps> initFreqMaps4FixedGrid2Available() {
32         byte[] byteArray = new byte[GridConstant.NB_OCTECTS];
33         Arrays.fill(byteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
34         Map<AvailFreqMapsKey, AvailFreqMaps> waveMap = new HashMap<>();
35         AvailFreqMaps availFreqMaps = new AvailFreqMapsBuilder().setMapName(GridConstant.C_BAND)
36                 .setFreqMapGranularity(new FrequencyGHz(BigDecimal.valueOf(GridConstant.GRANULARITY)))
37                 .setStartEdgeFreq(new FrequencyTHz(BigDecimal.valueOf(GridConstant.START_EDGE_FREQUENCY)))
38                 .setEffectiveBits(Uint16.valueOf(GridConstant.EFFECTIVE_BITS))
39                 .setFreqMap(byteArray)
40                 .build();
41         waveMap.put(availFreqMaps.key(), availFreqMaps);
42         return waveMap;
43     }
44
45     /**
46      * Compute the wavelength index from Spectrum assignment stop index.
47      * Only for fix grid and device 1.2.1.
48      * @param stopIndex int
49      * @return the wavelength number.
50      */
51     public static long getWaveLengthIndexFromSpectrumAssigment(int stopIndex) {
52         return (stopIndex + 1) / GridConstant.NB_SLOTS_100G;
53     }
54
55     /**
56      * Compute the frequency in TGz for the given index.
57      * @param index int
58      * @return the frequency in THz for the provided index.
59      */
60     public static BigDecimal getFrequencyFromIndex(int index) {
61         int nvalue = index - 284;
62         return BigDecimal.valueOf(GridConstant.CENTRAL_FREQUENCY + (nvalue * GridConstant.GRANULARITY / 1000));
63     }
64
65 }