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