blob: 53c6cec28ab9238405c912d581b255b4ed1cfabf [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;
41import static org.slf4j.LoggerFactory.getLogger;
42
43/**
44 * Utility class for optical intents.
45 */
46public 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 Campanellae1e3e442019-10-21 13:45:32 +020064 * @param suggestedPath suggested path
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010065 *
66 * @return created intent
67 */
68 public static Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint
69 egress, DeviceService deviceService, Key key, ApplicationId appId, boolean
Andrea Campanellae1e3e442019-10-21 13:45:32 +020070 bidirectional, OchSignal signal, Path suggestedPath) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010071
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()))) {
alessio3039bdb2018-11-29 14:12:32 +010090 log.debug("Devices without same deviceType: SRC {} and DST={}", srcDevice.type(), dstDevice.type());
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010091 return intent;
92 }
93
94 CltSignalType signalType = ((OduCltPort) srcPort).signalType();
Andrea Campanella1c24fb92018-12-20 16:43:59 +010095 if (Type.ROADM.equals(srcDevice.type()) ||
96 Type.ROADM_OTN.equals(srcDevice.type()) ||
alessiof6722312019-02-12 16:43:36 +010097 Type.OLS.equals(srcDevice.type()) ||
98 Type.TERMINAL_DEVICE.equals(srcDevice.type())) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010099 intent = OpticalCircuitIntent.builder()
100 .appId(appId)
101 .key(key)
102 .src(ingress)
103 .dst(egress)
104 .signalType(signalType)
105 .bidirectional(bidirectional)
106 .build();
alessiof6722312019-02-12 16:43:36 +0100107 } else if (Type.OTN.equals(srcDevice.type())) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100108 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 {
alessio3039bdb2018-11-29 14:12:32 +0100117 log.debug("Wrong Device Type for connect points {} and {}", ingress, egress);
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100118 }
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 Campanellae1e3e442019-10-21 13:45:32 +0200129 .suggestedPath(suggestedPath)
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100130 .build();
131 } else {
alessio3039bdb2018-11-29 14:12:32 +0100132 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 Campanella1c24fb92018-12-20 16:43:59 +0100180 if (Type.ROADM.equals(srcDevice.type()) ||
181 Type.ROADM_OTN.equals(srcDevice.type()) ||
alessiof6722312019-02-12 16:43:36 +0100182 Type.OLS.equals(srcDevice.type()) ||
183 Type.TERMINAL_DEVICE.equals(srcDevice.type())) {
alessio3039bdb2018-11-29 14:12:32 +0100184 intent = OpticalCircuitIntent.builder()
185 .appId(appId)
186 .key(key)
187 .src(ingress)
188 .dst(egress)
189 .signalType(signalType)
190 .bidirectional(bidirectional)
191 .build();
alessiof6722312019-02-12 16:43:36 +0100192 } else if (Type.OTN.equals(srcDevice.type())) {
alessio3039bdb2018-11-29 14:12:32 +0100193 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 Papp5bdd0e42017-10-27 10:18:21 +0100220 }
221
222 return intent;
223 }
224}