Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
| 17 | package org.onosproject.net.optical.util; |
| 18 | |
| 19 | import org.onosproject.net.optical.OduCltPort; |
| 20 | |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.CltSignalType; |
| 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.OchSignal; |
| 26 | import org.onosproject.net.OduSignalType; |
| 27 | import org.onosproject.net.Port; |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 28 | import org.onosproject.net.Path; |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 29 | import org.onosproject.net.device.DeviceService; |
| 30 | import org.onosproject.net.intent.Intent; |
| 31 | import org.onosproject.net.intent.Key; |
| 32 | import org.onosproject.net.intent.OpticalCircuitIntent; |
| 33 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 34 | import org.onosproject.net.intent.OpticalOduIntent; |
| 35 | import org.onosproject.net.optical.OchPort; |
| 36 | |
Andrea Campanella | 1c24fb9 | 2018-12-20 16:43:59 +0100 | [diff] [blame] | 37 | import static org.onosproject.net.Device.Type; |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 38 | import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView; |
| 39 | |
| 40 | import org.slf4j.Logger; |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 41 | |
| 42 | import java.util.Optional; |
| 43 | |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 44 | import static org.slf4j.LoggerFactory.getLogger; |
| 45 | |
| 46 | /** |
| 47 | * Utility class for optical intents. |
| 48 | */ |
| 49 | public final class OpticalIntentUtility { |
| 50 | |
| 51 | private static final Logger log = getLogger(OpticalIntentUtility.class); |
| 52 | |
| 53 | private OpticalIntentUtility() { |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns a new optical intent created from the method parameters. |
| 58 | * |
| 59 | * @param ingress ingress description (device/port) |
| 60 | * @param egress egress description (device/port) |
| 61 | * @param deviceService device service |
| 62 | * @param key intent key |
| 63 | * @param appId application id |
| 64 | * @param bidirectional if this argument is true, the optical link created |
| 65 | * will be bidirectional, otherwise the link will be unidirectional. |
| 66 | * @param signal optical signal |
Andrea Campanella | e1e3e44 | 2019-10-21 13:45:32 +0200 | [diff] [blame] | 67 | * @param suggestedPath suggested path |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 68 | * |
| 69 | * @return created intent |
| 70 | */ |
| 71 | public static Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint |
| 72 | egress, DeviceService deviceService, Key key, ApplicationId appId, boolean |
Andrea Campanella | e1e3e44 | 2019-10-21 13:45:32 +0200 | [diff] [blame] | 73 | bidirectional, OchSignal signal, Path suggestedPath) { |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 74 | |
| 75 | Intent intent = null; |
| 76 | |
| 77 | if (ingress == null || egress == null) { |
| 78 | log.debug("Invalid endpoint(s); could not create optical intent"); |
| 79 | return intent; |
| 80 | } |
| 81 | |
| 82 | DeviceService ds = opticalView(deviceService); |
| 83 | |
| 84 | Port srcPort = ds.getPort(ingress.deviceId(), ingress.port()); |
| 85 | Port dstPort = ds.getPort(egress.deviceId(), egress.port()); |
| 86 | |
| 87 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
| 88 | Device srcDevice = ds.getDevice(ingress.deviceId()); |
| 89 | Device dstDevice = ds.getDevice(egress.deviceId()); |
| 90 | |
| 91 | // continue only if both OduClt port's Devices are of the same type |
| 92 | if (!(srcDevice.type().equals(dstDevice.type()))) { |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 93 | log.debug("Devices without same deviceType: SRC {} and DST={}", srcDevice.type(), dstDevice.type()); |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 94 | return intent; |
| 95 | } |
| 96 | |
| 97 | CltSignalType signalType = ((OduCltPort) srcPort).signalType(); |
Andrea Campanella | 1c24fb9 | 2018-12-20 16:43:59 +0100 | [diff] [blame] | 98 | if (Type.ROADM.equals(srcDevice.type()) || |
| 99 | Type.ROADM_OTN.equals(srcDevice.type()) || |
alessio | f672231 | 2019-02-12 16:43:36 +0100 | [diff] [blame] | 100 | Type.OLS.equals(srcDevice.type()) || |
| 101 | Type.TERMINAL_DEVICE.equals(srcDevice.type())) { |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 102 | intent = OpticalCircuitIntent.builder() |
| 103 | .appId(appId) |
| 104 | .key(key) |
| 105 | .src(ingress) |
| 106 | .dst(egress) |
| 107 | .signalType(signalType) |
| 108 | .bidirectional(bidirectional) |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 109 | .ochSignal(Optional.ofNullable(signal)) |
| 110 | .suggestedPath(Optional.ofNullable(suggestedPath)) |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 111 | .build(); |
alessio | f672231 | 2019-02-12 16:43:36 +0100 | [diff] [blame] | 112 | } else if (Type.OTN.equals(srcDevice.type())) { |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 113 | intent = OpticalOduIntent.builder() |
| 114 | .appId(appId) |
| 115 | .key(key) |
| 116 | .src(ingress) |
| 117 | .dst(egress) |
| 118 | .signalType(signalType) |
| 119 | .bidirectional(bidirectional) |
| 120 | .build(); |
| 121 | } else { |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 122 | log.debug("Wrong Device Type for connect points {} and {}", ingress, egress); |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 123 | } |
| 124 | } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) { |
| 125 | OduSignalType signalType = ((OchPort) srcPort).signalType(); |
| 126 | intent = OpticalConnectivityIntent.builder() |
| 127 | .appId(appId) |
| 128 | .key(key) |
| 129 | .src(ingress) |
| 130 | .dst(egress) |
| 131 | .signalType(signalType) |
| 132 | .bidirectional(bidirectional) |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 133 | .ochSignal(Optional.ofNullable(signal)) |
| 134 | .suggestedPath(Optional.ofNullable(suggestedPath)) |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 135 | .build(); |
| 136 | } else { |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 137 | log.debug("Unable to create optical intent between connect points {} and {}", ingress, egress); |
| 138 | } |
| 139 | |
| 140 | return intent; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Returns a new optical intent created from the method parameters, strict suggestedPath is specified. |
| 145 | * |
| 146 | * @param ingress ingress description (device/port) |
| 147 | * @param egress egress description (device/port) |
| 148 | * @param deviceService device service |
| 149 | * @param key intent key |
| 150 | * @param appId application id |
| 151 | * @param bidirectional if this argument is true, the optical link created |
| 152 | * will be bidirectional, otherwise the link will be unidirectional. |
| 153 | * @param signal optical signal |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 154 | * @param suggestedPath suggested path for the intent |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 155 | * |
| 156 | * @return created intent |
| 157 | */ |
| 158 | public static Intent createExplicitOpticalIntent(ConnectPoint ingress, ConnectPoint |
| 159 | egress, DeviceService deviceService, Key key, ApplicationId appId, boolean |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 160 | bidirectional, OchSignal signal, Path suggestedPath) { |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 161 | |
| 162 | Intent intent = null; |
| 163 | |
| 164 | if (ingress == null || egress == null) { |
| 165 | log.error("Invalid endpoint(s); could not create optical intent"); |
| 166 | return intent; |
| 167 | } |
| 168 | |
| 169 | DeviceService ds = opticalView(deviceService); |
| 170 | |
| 171 | Port srcPort = ds.getPort(ingress.deviceId(), ingress.port()); |
| 172 | Port dstPort = ds.getPort(egress.deviceId(), egress.port()); |
| 173 | |
| 174 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
| 175 | Device srcDevice = ds.getDevice(ingress.deviceId()); |
| 176 | Device dstDevice = ds.getDevice(egress.deviceId()); |
| 177 | |
| 178 | // continue only if both OduClt port's Devices are of the same type |
| 179 | if (!(srcDevice.type().equals(dstDevice.type()))) { |
| 180 | log.debug("Devices without same deviceType: SRC={} and DST={}", srcDevice.type(), dstDevice.type()); |
| 181 | return intent; |
| 182 | } |
| 183 | |
| 184 | CltSignalType signalType = ((OduCltPort) srcPort).signalType(); |
Andrea Campanella | 1c24fb9 | 2018-12-20 16:43:59 +0100 | [diff] [blame] | 185 | if (Type.ROADM.equals(srcDevice.type()) || |
| 186 | Type.ROADM_OTN.equals(srcDevice.type()) || |
alessio | f672231 | 2019-02-12 16:43:36 +0100 | [diff] [blame] | 187 | Type.OLS.equals(srcDevice.type()) || |
| 188 | Type.TERMINAL_DEVICE.equals(srcDevice.type())) { |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 189 | intent = OpticalCircuitIntent.builder() |
| 190 | .appId(appId) |
| 191 | .key(key) |
| 192 | .src(ingress) |
| 193 | .dst(egress) |
| 194 | .signalType(signalType) |
| 195 | .bidirectional(bidirectional) |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 196 | .ochSignal(Optional.ofNullable(signal)) |
| 197 | .suggestedPath(Optional.ofNullable(suggestedPath)) |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 198 | .build(); |
alessio | f672231 | 2019-02-12 16:43:36 +0100 | [diff] [blame] | 199 | } else if (Type.OTN.equals(srcDevice.type())) { |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 200 | intent = OpticalOduIntent.builder() |
| 201 | .appId(appId) |
| 202 | .key(key) |
| 203 | .src(ingress) |
| 204 | .dst(egress) |
| 205 | .signalType(signalType) |
| 206 | .bidirectional(bidirectional) |
| 207 | .build(); |
| 208 | } else { |
| 209 | log.error("Wrong Device Type for connect points: " + |
| 210 | "ingress {} of type {}; egress {} of type {}", |
| 211 | ingress, srcDevice.type(), egress, dstDevice.type()); |
| 212 | } |
| 213 | } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) { |
| 214 | OduSignalType signalType = ((OchPort) srcPort).signalType(); |
| 215 | intent = OpticalConnectivityIntent.builder() |
| 216 | .appId(appId) |
| 217 | .key(key) |
| 218 | .src(ingress) |
| 219 | .dst(egress) |
| 220 | .signalType(signalType) |
| 221 | .bidirectional(bidirectional) |
alessio | da025c4 | 2020-07-17 13:00:28 +0200 | [diff] [blame] | 222 | .ochSignal(Optional.ofNullable(signal)) |
| 223 | .suggestedPath(Optional.ofNullable(suggestedPath)) |
alessio | 3039bdb | 2018-11-29 14:12:32 +0100 | [diff] [blame] | 224 | .build(); |
| 225 | } else { |
| 226 | log.error("Unable to create explicit optical intent between connect points {} and {}", ingress, egress); |
Laszlo Papp | 5bdd0e4 | 2017-10-27 10:18:21 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | return intent; |
| 230 | } |
| 231 | } |