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