Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 15 | */ |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 16 | package org.onosproject.net.optical.cli; |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
Aaron Kruglikov | 0a4da0d | 2015-06-10 14:40:48 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.commands.Option; |
Marc De Leenheer | adfeffd | 2017-06-22 16:05:34 -0700 | [diff] [blame] | 21 | import org.onlab.util.Spectrum; |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 22 | import org.onosproject.cli.app.AllApplicationNamesCompleter; |
| 23 | import org.onosproject.cli.net.ConnectPointCompleter; |
| 24 | import org.onosproject.cli.net.ConnectivityIntentCommand; |
Marc De Leenheer | adfeffd | 2017-06-22 16:05:34 -0700 | [diff] [blame] | 25 | import org.onosproject.net.ChannelSpacing; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 26 | import org.onosproject.net.CltSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.ConnectPoint; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 28 | import org.onosproject.net.Device; |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | adfeffd | 2017-06-22 16:05:34 -0700 | [diff] [blame] | 30 | import org.onosproject.net.GridType; |
| 31 | import org.onosproject.net.OchSignal; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 32 | import org.onosproject.net.OduSignalType; |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 33 | import org.onosproject.net.Port; |
| 34 | import org.onosproject.net.device.DeviceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.intent.Intent; |
| 36 | import org.onosproject.net.intent.IntentService; |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 37 | import org.onosproject.net.intent.OpticalCircuitIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 39 | import org.onosproject.net.intent.OpticalOduIntent; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 40 | import org.onosproject.net.optical.OchPort; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 41 | import org.onosproject.net.optical.OduCltPort; |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 42 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 43 | import java.util.List; |
| 44 | |
| 45 | import static com.google.common.base.Preconditions.checkArgument; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 46 | import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView; |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 47 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 48 | /** |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 49 | * Installs optical connectivity or circuit intents, depending on given port types. |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 50 | */ |
| 51 | @Command(scope = "onos", name = "add-optical-intent", |
| 52 | description = "Installs optical connectivity intent") |
| 53 | public class AddOpticalIntentCommand extends ConnectivityIntentCommand { |
| 54 | |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 55 | // OSGi workaround |
| 56 | @SuppressWarnings("unused") |
| 57 | private ConnectPointCompleter cpCompleter; |
| 58 | |
| 59 | // OSGi workaround |
| 60 | @SuppressWarnings("unused") |
| 61 | private AllApplicationNamesCompleter appCompleter; |
| 62 | |
Yuta HIGUCHI | d2f041e | 2017-03-10 12:45:15 -0800 | [diff] [blame] | 63 | @Argument(index = 0, name = "ingress", |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 64 | description = "Ingress Device/Port Description", |
| 65 | required = true, multiValued = false) |
Yuta HIGUCHI | d2f041e | 2017-03-10 12:45:15 -0800 | [diff] [blame] | 66 | String ingressString = ""; |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 67 | |
Yuta HIGUCHI | d2f041e | 2017-03-10 12:45:15 -0800 | [diff] [blame] | 68 | @Argument(index = 1, name = "egress", |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 69 | description = "Egress Device/Port Description", |
| 70 | required = true, multiValued = false) |
Yuta HIGUCHI | d2f041e | 2017-03-10 12:45:15 -0800 | [diff] [blame] | 71 | String egressString = ""; |
Aaron Kruglikov | 0a4da0d | 2015-06-10 14:40:48 -0700 | [diff] [blame] | 72 | |
| 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 Leenheer | adfeffd | 2017-06-22 16:05:34 -0700 | [diff] [blame] | 79 | @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'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 85 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 86 | 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 Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 93 | 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 Leenheer | adfeffd | 2017-06-22 16:05:34 -0700 | [diff] [blame] | 106 | 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'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 116 | @Override |
| 117 | protected void execute() { |
| 118 | IntentService service = get(IntentService.class); |
| 119 | |
Yuta HIGUCHI | d2f041e | 2017-03-10 12:45:15 -0800 | [diff] [blame] | 120 | ConnectPoint ingress = createConnectPoint(ingressString); |
| 121 | ConnectPoint egress = createConnectPoint(egressString); |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 122 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 123 | if (ingress == null || egress == null) { |
Ayaka Koshibe | afb546f | 2015-10-23 17:13:58 -0700 | [diff] [blame] | 124 | print("Invalid endpoint(s); could not create optical intent"); |
| 125 | return; |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 126 | } |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 127 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 128 | DeviceService deviceService = opticalView(get(DeviceService.class)); |
| 129 | |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 130 | Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port()); |
| 131 | Port dstPort = deviceService.getPort(egress.deviceId(), egress.port()); |
| 132 | |
| 133 | Intent intent; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 134 | |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 135 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 136 | 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 Kanonakis | 5c69c75 | 2017-02-22 13:20:41 -0600 | [diff] [blame] | 146 | if (Device.Type.ROADM.equals(srcDevice.type()) || |
| 147 | Device.Type.ROADM_OTN.equals(srcDevice.type())) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 148 | 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 Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 169 | } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 170 | OduSignalType signalType = ((OchPort) srcPort).signalType(); |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 171 | intent = OpticalConnectivityIntent.builder() |
| 172 | .appId(appId()) |
| 173 | .key(key()) |
| 174 | .src(ingress) |
| 175 | .dst(egress) |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 176 | .signalType(signalType) |
Aaron Kruglikov | 0a4da0d | 2015-06-10 14:40:48 -0700 | [diff] [blame] | 177 | .bidirectional(bidirectional) |
Marc De Leenheer | adfeffd | 2017-06-22 16:05:34 -0700 | [diff] [blame] | 178 | .ochSignal(createOchSignal(channel)) |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 179 | .build(); |
| 180 | } else { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 181 | print("Unable to create optical intent between connect points %s and %s", ingress, egress); |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 185 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 186 | print("Optical intent submitted:\n%s", intent.toString()); |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 187 | } |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 188 | } |