blob: 7956f57f9a0e89aa65d480804de41c2616bd2c11 [file] [log] [blame]
Laszlo Papp5bdd0e42017-10-27 10:18:21 +01001/*
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
17package org.onosproject.net.optical.util;
18
19import org.onosproject.net.optical.OduCltPort;
20
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.CltSignalType;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.Device;
25import org.onosproject.net.OchSignal;
26import org.onosproject.net.OduSignalType;
27import org.onosproject.net.Port;
alessio3039bdb2018-11-29 14:12:32 +010028import org.onosproject.net.Path;
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010029import org.onosproject.net.device.DeviceService;
30import org.onosproject.net.intent.Intent;
31import org.onosproject.net.intent.Key;
32import org.onosproject.net.intent.OpticalCircuitIntent;
33import org.onosproject.net.intent.OpticalConnectivityIntent;
34import org.onosproject.net.intent.OpticalOduIntent;
35import org.onosproject.net.optical.OchPort;
36
Andrea Campanella1c24fb92018-12-20 16:43:59 +010037import static org.onosproject.net.Device.Type;
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010038import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
39
40import org.slf4j.Logger;
alessioda025c42020-07-17 13:00:28 +020041
42import java.util.Optional;
43
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010044import static org.slf4j.LoggerFactory.getLogger;
45
46/**
47 * Utility class for optical intents.
48 */
49public 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 Campanellae1e3e442019-10-21 13:45:32 +020067 * @param suggestedPath suggested path
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010068 *
69 * @return created intent
70 */
71 public static Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint
72 egress, DeviceService deviceService, Key key, ApplicationId appId, boolean
Andrea Campanellae1e3e442019-10-21 13:45:32 +020073 bidirectional, OchSignal signal, Path suggestedPath) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010074
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()))) {
alessio3039bdb2018-11-29 14:12:32 +010093 log.debug("Devices without same deviceType: SRC {} and DST={}", srcDevice.type(), dstDevice.type());
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010094 return intent;
95 }
96
97 CltSignalType signalType = ((OduCltPort) srcPort).signalType();
Andrea Campanella1c24fb92018-12-20 16:43:59 +010098 if (Type.ROADM.equals(srcDevice.type()) ||
99 Type.ROADM_OTN.equals(srcDevice.type()) ||
alessiof6722312019-02-12 16:43:36 +0100100 Type.OLS.equals(srcDevice.type()) ||
101 Type.TERMINAL_DEVICE.equals(srcDevice.type())) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100102 intent = OpticalCircuitIntent.builder()
103 .appId(appId)
104 .key(key)
105 .src(ingress)
106 .dst(egress)
107 .signalType(signalType)
108 .bidirectional(bidirectional)
alessioda025c42020-07-17 13:00:28 +0200109 .ochSignal(Optional.ofNullable(signal))
110 .suggestedPath(Optional.ofNullable(suggestedPath))
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100111 .build();
alessiof6722312019-02-12 16:43:36 +0100112 } else if (Type.OTN.equals(srcDevice.type())) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100113 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 {
alessio3039bdb2018-11-29 14:12:32 +0100122 log.debug("Wrong Device Type for connect points {} and {}", ingress, egress);
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100123 }
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)
alessioda025c42020-07-17 13:00:28 +0200133 .ochSignal(Optional.ofNullable(signal))
134 .suggestedPath(Optional.ofNullable(suggestedPath))
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100135 .build();
136 } else {
alessio3039bdb2018-11-29 14:12:32 +0100137 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
alessioda025c42020-07-17 13:00:28 +0200154 * @param suggestedPath suggested path for the intent
alessio3039bdb2018-11-29 14:12:32 +0100155 *
156 * @return created intent
157 */
158 public static Intent createExplicitOpticalIntent(ConnectPoint ingress, ConnectPoint
159 egress, DeviceService deviceService, Key key, ApplicationId appId, boolean
alessioda025c42020-07-17 13:00:28 +0200160 bidirectional, OchSignal signal, Path suggestedPath) {
alessio3039bdb2018-11-29 14:12:32 +0100161
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 Campanella1c24fb92018-12-20 16:43:59 +0100185 if (Type.ROADM.equals(srcDevice.type()) ||
186 Type.ROADM_OTN.equals(srcDevice.type()) ||
alessiof6722312019-02-12 16:43:36 +0100187 Type.OLS.equals(srcDevice.type()) ||
188 Type.TERMINAL_DEVICE.equals(srcDevice.type())) {
alessio3039bdb2018-11-29 14:12:32 +0100189 intent = OpticalCircuitIntent.builder()
190 .appId(appId)
191 .key(key)
192 .src(ingress)
193 .dst(egress)
194 .signalType(signalType)
195 .bidirectional(bidirectional)
alessioda025c42020-07-17 13:00:28 +0200196 .ochSignal(Optional.ofNullable(signal))
197 .suggestedPath(Optional.ofNullable(suggestedPath))
alessio3039bdb2018-11-29 14:12:32 +0100198 .build();
alessiof6722312019-02-12 16:43:36 +0100199 } else if (Type.OTN.equals(srcDevice.type())) {
alessio3039bdb2018-11-29 14:12:32 +0100200 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)
alessioda025c42020-07-17 13:00:28 +0200222 .ochSignal(Optional.ofNullable(signal))
223 .suggestedPath(Optional.ofNullable(suggestedPath))
alessio3039bdb2018-11-29 14:12:32 +0100224 .build();
225 } else {
226 log.error("Unable to create explicit optical intent between connect points {} and {}", ingress, egress);
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100227 }
228
229 return intent;
230 }
231}