blob: 8deb5ba7270f5e0fcf96a4ba1a25238a9d9cfd57 [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;
28import org.onosproject.net.device.DeviceService;
29import org.onosproject.net.intent.Intent;
30import org.onosproject.net.intent.Key;
31import org.onosproject.net.intent.OpticalCircuitIntent;
32import org.onosproject.net.intent.OpticalConnectivityIntent;
33import org.onosproject.net.intent.OpticalOduIntent;
34import org.onosproject.net.optical.OchPort;
35
36import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
37
38import org.slf4j.Logger;
39import static org.slf4j.LoggerFactory.getLogger;
40
41/**
42 * Utility class for optical intents.
43 */
44public final class OpticalIntentUtility {
45
46 private static final Logger log = getLogger(OpticalIntentUtility.class);
47
48 private OpticalIntentUtility() {
49 }
50
51 /**
52 * Returns a new optical intent created from the method parameters.
53 *
54 * @param ingress ingress description (device/port)
55 * @param egress egress description (device/port)
56 * @param deviceService device service
57 * @param key intent key
58 * @param appId application id
59 * @param bidirectional if this argument is true, the optical link created
60 * will be bidirectional, otherwise the link will be unidirectional.
61 * @param signal optical signal
62 *
63 * @return created intent
64 */
65 public static Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint
66 egress, DeviceService deviceService, Key key, ApplicationId appId, boolean
67 bidirectional, OchSignal signal) {
68
69 Intent intent = null;
70
71 if (ingress == null || egress == null) {
72 log.debug("Invalid endpoint(s); could not create optical intent");
73 return intent;
74 }
75
76 DeviceService ds = opticalView(deviceService);
77
78 Port srcPort = ds.getPort(ingress.deviceId(), ingress.port());
79 Port dstPort = ds.getPort(egress.deviceId(), egress.port());
80
81 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
82 Device srcDevice = ds.getDevice(ingress.deviceId());
83 Device dstDevice = ds.getDevice(egress.deviceId());
84
85 // continue only if both OduClt port's Devices are of the same type
86 if (!(srcDevice.type().equals(dstDevice.type()))) {
87 log.debug("Devices without same deviceType: SRC=%s and DST=%s", srcDevice.type(), dstDevice.type());
88 return intent;
89 }
90
91 CltSignalType signalType = ((OduCltPort) srcPort).signalType();
92 if (Device.Type.ROADM.equals(srcDevice.type()) ||
93 Device.Type.ROADM_OTN.equals(srcDevice.type())) {
94 intent = OpticalCircuitIntent.builder()
95 .appId(appId)
96 .key(key)
97 .src(ingress)
98 .dst(egress)
99 .signalType(signalType)
100 .bidirectional(bidirectional)
101 .build();
102 } else if (Device.Type.OTN.equals(srcDevice.type())) {
103 intent = OpticalOduIntent.builder()
104 .appId(appId)
105 .key(key)
106 .src(ingress)
107 .dst(egress)
108 .signalType(signalType)
109 .bidirectional(bidirectional)
110 .build();
111 } else {
112 log.debug("Wrong Device Type for connect points %s and %s", ingress, egress);
113 }
114 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
115 OduSignalType signalType = ((OchPort) srcPort).signalType();
116 intent = OpticalConnectivityIntent.builder()
117 .appId(appId)
118 .key(key)
119 .src(ingress)
120 .dst(egress)
121 .signalType(signalType)
122 .bidirectional(bidirectional)
123 .ochSignal(signal)
124 .build();
125 } else {
126 log.debug("Unable to create optical intent between connect points %s and %s", ingress, egress);
127 }
128
129 return intent;
130 }
131}