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