blob: efbc12d0329ee44d782ccfbfcfd481b48eb73733 [file] [log] [blame]
Diego Garciaaab99472019-01-10 13:53:31 +01001/*
2 * Copyright 2018-present Open Networking Foundation
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 *
16 * This work was partially supported by EC H2020 project METRO-HAUL (761727).
17 */
18package org.onosproject.drivers.odtn.tapi;
19
Andrea Campanellab9e491b2019-02-18 17:45:01 +010020import com.fasterxml.jackson.databind.JsonNode;
Diego Garciaaab99472019-01-10 13:53:31 +010021import org.onosproject.net.ChannelSpacing;
Andrea Campanellab9e491b2019-02-18 17:45:01 +010022import org.onosproject.net.GridType;
23import org.onosproject.net.OchSignal;
24import org.slf4j.Logger;
25
26import java.util.Iterator;
27import java.util.LinkedHashSet;
28import java.util.Set;
29import java.util.stream.IntStream;
30
31import static org.slf4j.LoggerFactory.getLogger;
Diego Garciaaab99472019-01-10 13:53:31 +010032
33/**
34 * Tapi 2.1 OLS device related helpers.
35 */
36public final class TapiDeviceHelper {
37
Andrea Campanellab9e491b2019-02-18 17:45:01 +010038 private static final Logger log = getLogger(TapiDeviceHelper.class);
39
Diego Garciaaab99472019-01-10 13:53:31 +010040 public static final String SERVICE_INTERFACE_POINT = "service-interface-point";
Andrea Campanella3d2ba462019-08-22 16:29:21 +020041 public static final String TAPI_COMMON = "tapi-common";
Andrea Campanellab9e491b2019-02-18 17:45:01 +010042 public static final String CONTEXT = "tapi-common:context";
Diego Garciaaab99472019-01-10 13:53:31 +010043 public static final String UUID = "uuid";
44 public static final String MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC =
Andrea Campanellab9e491b2019-02-18 17:45:01 +010045 "tapi-photonic-media:media-channel-service-interface-point-spec";
Diego Garciaaab99472019-01-10 13:53:31 +010046 public static final String MC_POOL = "mc-pool";
47 public static final String LAYER_PROTOCOL_NAME = "layer-protocol-name";
48 public static final String PHOTONIC_MEDIA = "PHOTONIC_MEDIA";
49 public static final String SUPPORTED_LAYER_PROTOCOL_QUALIFIER = "supported-layer-protocol-qualifier";
50 public static final String PHOTONIC_LAYER_QUALIFIER_NMC = "PHOTONIC_LAYER_QUALIFIER_NMC";
51 public static final String FREQUENCY_CONSTRAINT = "frequency-constraint";
52 public static final String GRID_TYPE = "grid-type";
53 public static final String ADJUSTMENT_GRANULARITY = "adjustment-granularity";
54 public static final String UPPER_FREQUENCY = "upper-frequency";
55 public static final String LOWER_FREQUENCY = "lower-frequency";
Diego Garciaaab99472019-01-10 13:53:31 +010056 public static final long BASE_FREQUENCY = 193100000; //Working in Mhz
Andrea Campanella2bdf2042019-01-28 13:47:11 +010057 public static final String TAPI_CONNECTIVITY_CONNECTIVITY_SERVICE = "tapi-connectivity:connectivity-service";
58 public static final String END_POINT = "end-point";
59 public static final String SERVICE_LAYER = "service-layer";
60 public static final String SERVICE_TYPE = "service-type";
61 public static final String POINT_TO_POINT_CONNECTIVITY = "POINT_TO_POINT_CONNECTIVITY";
62 public static final String LOCAL_ID = "local-id";
63 public static final String LAYER_PROTOCOL_QUALIFIER = "layer-protocol-qualifier";
64 public static final String TAPI_PHOTONIC_MEDIA_PHOTONIC_LAYER_QUALIFIER_NMC =
65 "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC";
66 public static final String SERVICE_INTERFACE_POINT_UUID = "service-interface-point-uuid";
Andrea Campanellab9e491b2019-02-18 17:45:01 +010067 public static final String AVAILABLE_SPECTRUM = "available-spectrum";
68 protected static final String SUPPORTABLE_SPECTRUM = "supportable-spectrum";
Diego Garciaaab99472019-01-10 13:53:31 +010069
70 private TapiDeviceHelper(){}
71
72 /**
73 * Returns the slot granularity corresponding to a channelSpacing.
74 *
75 * @param chSpacing OchSingal channel spacing {@link ChannelSpacing}
76 * @return OchSignal slot width granularity
77 */
78 public static int getSlotGranularity(ChannelSpacing chSpacing) {
79 if (chSpacing.equals(ChannelSpacing.CHL_100GHZ)) {
80 return 8;
81 } else if (chSpacing.equals(ChannelSpacing.CHL_50GHZ)) {
82 return 4;
83 } else if (chSpacing.equals(ChannelSpacing.CHL_25GHZ)) {
84 return 2;
85 } else if (chSpacing.equals(ChannelSpacing.CHL_12P5GHZ)) {
86 return 1;
87 } else {
88 return 0;
89 }
90 }
91
92 /**
93 * Returns the ChannelSpacing corresponding to an adjustmentGranularity.
94 *
95 * @param adjustmentGranularity {@link String}
96 * @return OchSingnal ChannelSpacing {@link ChannelSpacing}
97 */
98 public static ChannelSpacing getChannelSpacing(String adjustmentGranularity) {
99 switch (adjustmentGranularity) {
100 case "G_100GHZ ":
101 return ChannelSpacing.CHL_100GHZ;
102 case "G_50GHZ":
103 return ChannelSpacing.CHL_50GHZ;
104 case "G_25GHZ":
105 return ChannelSpacing.CHL_25GHZ;
106 case "G_12_5GHZ ":
107 return ChannelSpacing.CHL_12P5GHZ;
108 case "G_6_25GHZ ":
109 return ChannelSpacing.CHL_6P25GHZ;
110 default:
111 return ChannelSpacing.CHL_0GHZ;
112 }
113 }
114
115 /**
116 * To Mbps conversion from Hz.
117 *
118 * @param speed the speed in Hz
119 * @return the speed in Mbps
120 */
121 public static long toMbpsFromHz(long speed) {
122 return speed / 1000000;
123 }
Andrea Campanellab9e491b2019-02-18 17:45:01 +0100124
125 /**
126 * If SIP info match our criteria, SIP component shall includes mc-pool information which must be obtained in order
127 * to complete the OchSignal info. with the TAPI SIP information included in spectrum-supported, spectrum-available
128 * and spectrum-occupied tapi objects.
129 *
130 * @param mcPool the MC_POOL json node
131 * @return the set of OCH signals given the port's information
132 **/
133 protected static Set<OchSignal> getOchSignal(JsonNode mcPool) {
134
135 Set<OchSignal> lambdas = new LinkedHashSet<>();
136 long availableUpperFrec = 0;
137 long availableLowerFrec = 0;
138 String availableAdjustmentGranularity = "";
139 String availableGridType = "";
140 JsonNode availableSpectrum = mcPool.get(AVAILABLE_SPECTRUM);
141
142 if (availableSpectrum == null) {
143 availableSpectrum = mcPool.get(SUPPORTABLE_SPECTRUM);
144 }
145
146 Iterator<JsonNode> iterAvailable = availableSpectrum.iterator();
147 while (iterAvailable.hasNext()) {
148 JsonNode availableSpec = iterAvailable.next();
149 availableUpperFrec = availableSpec.get(UPPER_FREQUENCY).asLong();
150 availableLowerFrec = availableSpec.get(LOWER_FREQUENCY).asLong();
151 log.info("availableUpperFrec {}, availableLowerFrec {}", availableUpperFrec,
152 availableLowerFrec);
153 availableAdjustmentGranularity = availableSpec.get(FREQUENCY_CONSTRAINT)
154 .get(ADJUSTMENT_GRANULARITY).textValue();
155 availableGridType = availableSpec.get(FREQUENCY_CONSTRAINT).get(GRID_TYPE).textValue();
156
157 int slotGranularity;
158 ChannelSpacing chSpacing = getChannelSpacing(availableAdjustmentGranularity);
159 double spacingFrequency = chSpacing.frequency().asGHz();
160 int lambdaCount = (int) ((availableUpperFrec - availableLowerFrec) / spacingFrequency);
161 GridType gridType = GridType.valueOf(availableGridType);
162 if (gridType == GridType.DWDM) {
163 slotGranularity = getSlotGranularity(chSpacing);
164 int finalSlotGranularity = slotGranularity;
165 IntStream.range(0, lambdaCount).forEach(x -> lambdas.add(new OchSignal(GridType.DWDM, chSpacing,
166 x - (lambdaCount / 2), finalSlotGranularity)));
167 } else if (gridType == GridType.CWDM) {
168 log.warn("GridType CWDM. Not implemented");
169 } else if (gridType == GridType.FLEX) {
170 log.warn("GridType FLEX. Not implemented");
171 } else {
172 log.warn("Unknown GridType");
173 }
174 }
175 return lambdas;
176 }
Diego Garciaaab99472019-01-10 13:53:31 +0100177}