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