blob: 4a6af722afd06d6e49fe53e5e17b42764dadabed [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
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()))) {
alessio3039bdb2018-11-29 14:12:32 +010089 log.debug("Devices without same deviceType: SRC {} and DST={}", srcDevice.type(), dstDevice.type());
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010090 return intent;
91 }
92
93 CltSignalType signalType = ((OduCltPort) srcPort).signalType();
Andrea Campanella1c24fb92018-12-20 16:43:59 +010094 if (Type.ROADM.equals(srcDevice.type()) ||
95 Type.ROADM_OTN.equals(srcDevice.type()) ||
96 Type.OLS.equals(srcDevice.type())) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +010097 intent = OpticalCircuitIntent.builder()
98 .appId(appId)
99 .key(key)
100 .src(ingress)
101 .dst(egress)
102 .signalType(signalType)
103 .bidirectional(bidirectional)
104 .build();
Andrea Campanella1c24fb92018-12-20 16:43:59 +0100105 } else if (Type.OTN.equals(srcDevice.type()) || Type.TERMINAL_DEVICE.equals(srcDevice.type())) {
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100106 intent = OpticalOduIntent.builder()
107 .appId(appId)
108 .key(key)
109 .src(ingress)
110 .dst(egress)
111 .signalType(signalType)
112 .bidirectional(bidirectional)
113 .build();
114 } else {
alessio3039bdb2018-11-29 14:12:32 +0100115 log.debug("Wrong Device Type for connect points {} and {}", ingress, egress);
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100116 }
117 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
118 OduSignalType signalType = ((OchPort) srcPort).signalType();
119 intent = OpticalConnectivityIntent.builder()
120 .appId(appId)
121 .key(key)
122 .src(ingress)
123 .dst(egress)
124 .signalType(signalType)
125 .bidirectional(bidirectional)
126 .ochSignal(signal)
127 .build();
128 } else {
alessio3039bdb2018-11-29 14:12:32 +0100129 log.debug("Unable to create optical intent between connect points {} and {}", ingress, egress);
130 }
131
132 return intent;
133 }
134
135 /**
136 * Returns a new optical intent created from the method parameters, strict suggestedPath is specified.
137 *
138 * @param ingress ingress description (device/port)
139 * @param egress egress description (device/port)
140 * @param deviceService device service
141 * @param key intent key
142 * @param appId application id
143 * @param bidirectional if this argument is true, the optical link created
144 * will be bidirectional, otherwise the link will be unidirectional.
145 * @param signal optical signal
146 * @param path suggested path for the intent
147 *
148 * @return created intent
149 */
150 public static Intent createExplicitOpticalIntent(ConnectPoint ingress, ConnectPoint
151 egress, DeviceService deviceService, Key key, ApplicationId appId, boolean
152 bidirectional, OchSignal signal, Path path) {
153
154 Intent intent = null;
155
156 if (ingress == null || egress == null) {
157 log.error("Invalid endpoint(s); could not create optical intent");
158 return intent;
159 }
160
161 DeviceService ds = opticalView(deviceService);
162
163 Port srcPort = ds.getPort(ingress.deviceId(), ingress.port());
164 Port dstPort = ds.getPort(egress.deviceId(), egress.port());
165
166 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
167 Device srcDevice = ds.getDevice(ingress.deviceId());
168 Device dstDevice = ds.getDevice(egress.deviceId());
169
170 // continue only if both OduClt port's Devices are of the same type
171 if (!(srcDevice.type().equals(dstDevice.type()))) {
172 log.debug("Devices without same deviceType: SRC={} and DST={}", srcDevice.type(), dstDevice.type());
173 return intent;
174 }
175
176 CltSignalType signalType = ((OduCltPort) srcPort).signalType();
Andrea Campanella1c24fb92018-12-20 16:43:59 +0100177 if (Type.ROADM.equals(srcDevice.type()) ||
178 Type.ROADM_OTN.equals(srcDevice.type()) ||
179 Type.OLS.equals(srcDevice.type())) {
alessio3039bdb2018-11-29 14:12:32 +0100180 intent = OpticalCircuitIntent.builder()
181 .appId(appId)
182 .key(key)
183 .src(ingress)
184 .dst(egress)
185 .signalType(signalType)
186 .bidirectional(bidirectional)
187 .build();
Andrea Campanella1c24fb92018-12-20 16:43:59 +0100188 } else if (Type.OTN.equals(srcDevice.type()) || Type.TERMINAL_DEVICE.equals(srcDevice.type())) {
alessio3039bdb2018-11-29 14:12:32 +0100189 intent = OpticalOduIntent.builder()
190 .appId(appId)
191 .key(key)
192 .src(ingress)
193 .dst(egress)
194 .signalType(signalType)
195 .bidirectional(bidirectional)
196 .build();
197 } else {
198 log.error("Wrong Device Type for connect points: " +
199 "ingress {} of type {}; egress {} of type {}",
200 ingress, srcDevice.type(), egress, dstDevice.type());
201 }
202 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
203 OduSignalType signalType = ((OchPort) srcPort).signalType();
204 intent = OpticalConnectivityIntent.builder()
205 .appId(appId)
206 .key(key)
207 .src(ingress)
208 .dst(egress)
209 .signalType(signalType)
210 .bidirectional(bidirectional)
211 .ochSignal(signal)
212 .suggestedPath(path)
213 .build();
214 } else {
215 log.error("Unable to create explicit optical intent between connect points {} and {}", ingress, egress);
Laszlo Papp5bdd0e42017-10-27 10:18:21 +0100216 }
217
218 return intent;
219 }
220}