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