blob: d26cfef60e8e6634725a37fc2e52a16e00f841f8 [file] [log] [blame]
Brian O'Connor5296b322014-10-23 14:59:05 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Brian O'Connor5296b322014-10-23 14:59:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Brian O'Connor5296b322014-10-23 14:59:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Brian O'Connor5296b322014-10-23 14:59:05 -070015 */
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070016package org.onosproject.net.optical.cli;
Brian O'Connor5296b322014-10-23 14:59:05 -070017
Brian O'Connor5296b322014-10-23 14:59:05 -070018import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -070020import org.apache.karaf.shell.commands.Option;
Marc De Leenheeradfeffd2017-06-22 16:05:34 -070021import org.onlab.util.Spectrum;
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070022import org.onosproject.cli.app.AllApplicationNamesCompleter;
23import org.onosproject.cli.net.ConnectPointCompleter;
24import org.onosproject.cli.net.ConnectivityIntentCommand;
Marc De Leenheeradfeffd2017-06-22 16:05:34 -070025import org.onosproject.net.ChannelSpacing;
Toru Furusawa72ee30c2016-01-08 13:29:04 -080026import org.onosproject.net.CltSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.ConnectPoint;
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +020028import org.onosproject.net.Device;
Marc De Leenheer88194c32015-05-29 22:10:59 -070029import org.onosproject.net.DeviceId;
Marc De Leenheeradfeffd2017-06-22 16:05:34 -070030import org.onosproject.net.GridType;
31import org.onosproject.net.OchSignal;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070032import org.onosproject.net.OduSignalType;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070033import org.onosproject.net.Port;
34import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.intent.Intent;
36import org.onosproject.net.intent.IntentService;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070037import org.onosproject.net.intent.OpticalCircuitIntent;
Brian O'Connorabafb502014-12-02 22:26:20 -080038import org.onosproject.net.intent.OpticalConnectivityIntent;
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +020039import org.onosproject.net.intent.OpticalOduIntent;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080040import org.onosproject.net.optical.OchPort;
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -070041import org.onosproject.net.optical.OduCltPort;
Brian O'Connor5296b322014-10-23 14:59:05 -070042
Marc De Leenheer88194c32015-05-29 22:10:59 -070043import java.util.List;
44
45import static com.google.common.base.Preconditions.checkArgument;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080046import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
Marc De Leenheer88194c32015-05-29 22:10:59 -070047
Brian O'Connor5296b322014-10-23 14:59:05 -070048/**
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070049 * Installs optical connectivity or circuit intents, depending on given port types.
Brian O'Connor5296b322014-10-23 14:59:05 -070050 */
51@Command(scope = "onos", name = "add-optical-intent",
52 description = "Installs optical connectivity intent")
53public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
54
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070055 // OSGi workaround
56 @SuppressWarnings("unused")
57 private ConnectPointCompleter cpCompleter;
58
59 // OSGi workaround
60 @SuppressWarnings("unused")
61 private AllApplicationNamesCompleter appCompleter;
62
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -080063 @Argument(index = 0, name = "ingress",
Brian O'Connor5296b322014-10-23 14:59:05 -070064 description = "Ingress Device/Port Description",
65 required = true, multiValued = false)
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -080066 String ingressString = "";
Brian O'Connor5296b322014-10-23 14:59:05 -070067
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -080068 @Argument(index = 1, name = "egress",
Brian O'Connor5296b322014-10-23 14:59:05 -070069 description = "Egress Device/Port Description",
70 required = true, multiValued = false)
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -080071 String egressString = "";
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -070072
73 @Option(name = "-b", aliases = "--bidirectional",
74 description = "If this argument is passed the optical link created will be bidirectional, " +
75 "else the link will be unidirectional.",
76 required = false, multiValued = false)
77 private boolean bidirectional = false;
78
Marc De Leenheeradfeffd2017-06-22 16:05:34 -070079 @Option(name = "-c", aliases = "--channel",
80 description = "Optical channel in GHz to use for the intent (e.g., 193.1). " +
81 "Uses 50 GHz spaced DWDM channel plan by default.",
82 required = false, multiValued = false)
83 private Double channel;
84
Brian O'Connor5296b322014-10-23 14:59:05 -070085
Marc De Leenheer88194c32015-05-29 22:10:59 -070086 private ConnectPoint createConnectPoint(String devicePortString) {
87 String[] splitted = devicePortString.split("/");
88
89 checkArgument(splitted.length == 2,
90 "Connect point must be in \"deviceUri/portNumber\" format");
91
92 DeviceId deviceId = DeviceId.deviceId(splitted[0]);
Marc De Leenheer88194c32015-05-29 22:10:59 -070093 DeviceService deviceService = get(DeviceService.class);
94
95 List<Port> ports = deviceService.getPorts(deviceId);
96
97 for (Port port : ports) {
98 if (splitted[1].equals(port.number().name())) {
99 return new ConnectPoint(deviceId, port.number());
100 }
101 }
102
103 return null;
104 }
105
Marc De Leenheeradfeffd2017-06-22 16:05:34 -0700106 private OchSignal createOchSignal(Double channel) {
107 if (channel == null) {
108 return null;
109 }
110
111 ChannelSpacing spacing = ChannelSpacing.CHL_50GHZ;
112 int multiplier = (int) (Math.round(channel - Spectrum.CENTER_FREQUENCY.asHz() / spacing.frequency().asHz()));
113 return new OchSignal(GridType.DWDM, spacing, multiplier, 4);
114 }
115
Brian O'Connor5296b322014-10-23 14:59:05 -0700116 @Override
117 protected void execute() {
118 IntentService service = get(IntentService.class);
119
Yuta HIGUCHId2f041e2017-03-10 12:45:15 -0800120 ConnectPoint ingress = createConnectPoint(ingressString);
121 ConnectPoint egress = createConnectPoint(egressString);
Brian O'Connor5296b322014-10-23 14:59:05 -0700122
Marc De Leenheer88194c32015-05-29 22:10:59 -0700123 if (ingress == null || egress == null) {
Ayaka Koshibeafb546f2015-10-23 17:13:58 -0700124 print("Invalid endpoint(s); could not create optical intent");
125 return;
Marc De Leenheer88194c32015-05-29 22:10:59 -0700126 }
Brian O'Connor5296b322014-10-23 14:59:05 -0700127
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -0800128 DeviceService deviceService = opticalView(get(DeviceService.class));
129
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700130 Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
131 Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
132
133 Intent intent;
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200134
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700135 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200136 Device srcDevice = deviceService.getDevice(ingress.deviceId());
137 Device dstDevice = deviceService.getDevice(egress.deviceId());
138
139 // continue only if both OduClt port's Devices are of the same type
140 if (!(srcDevice.type().equals(dstDevice.type()))) {
141 print("Devices without same deviceType: SRC=%s and DST=%s", srcDevice.type(), dstDevice.type());
142 return;
143 }
144
145 CltSignalType signalType = ((OduCltPort) srcPort).signalType();
Konstantinos Kanonakis5c69c752017-02-22 13:20:41 -0600146 if (Device.Type.ROADM.equals(srcDevice.type()) ||
147 Device.Type.ROADM_OTN.equals(srcDevice.type())) {
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200148 intent = OpticalCircuitIntent.builder()
149 .appId(appId())
150 .key(key())
151 .src(ingress)
152 .dst(egress)
153 .signalType(signalType)
154 .bidirectional(bidirectional)
155 .build();
156 } else if (Device.Type.OTN.equals(srcDevice.type())) {
157 intent = OpticalOduIntent.builder()
158 .appId(appId())
159 .key(key())
160 .src(ingress)
161 .dst(egress)
162 .signalType(signalType)
163 .bidirectional(bidirectional)
164 .build();
165 } else {
166 print("Wrong Device Type for connect points %s and %s", ingress, egress);
167 return;
168 }
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700169 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200170 OduSignalType signalType = ((OchPort) srcPort).signalType();
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700171 intent = OpticalConnectivityIntent.builder()
172 .appId(appId())
173 .key(key())
174 .src(ingress)
175 .dst(egress)
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200176 .signalType(signalType)
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -0700177 .bidirectional(bidirectional)
Marc De Leenheeradfeffd2017-06-22 16:05:34 -0700178 .ochSignal(createOchSignal(channel))
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700179 .build();
180 } else {
Rimon Ashkenazy27438ff2016-03-22 15:57:45 +0200181 print("Unable to create optical intent between connect points %s and %s", ingress, egress);
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700182 return;
183 }
184
Brian O'Connor5296b322014-10-23 14:59:05 -0700185 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -0800186 print("Optical intent submitted:\n%s", intent.toString());
Brian O'Connor5296b322014-10-23 14:59:05 -0700187 }
Brian O'Connor5296b322014-10-23 14:59:05 -0700188}