Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
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; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 21 | import org.onosproject.net.CltSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 23 | import org.onosproject.net.Device; |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 24 | import org.onosproject.net.OchPort; |
| 25 | import org.onosproject.net.OduCltPort; |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 27 | import org.onosproject.net.OduSignalType; |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 28 | import org.onosproject.net.Port; |
| 29 | import org.onosproject.net.device.DeviceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.intent.Intent; |
| 31 | import org.onosproject.net.intent.IntentService; |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 32 | import org.onosproject.net.intent.OpticalCircuitIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 34 | import org.onosproject.net.intent.OpticalOduIntent; |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 35 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 36 | import java.util.List; |
| 37 | |
| 38 | import static com.google.common.base.Preconditions.checkArgument; |
| 39 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 40 | /** |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 41 | * Installs optical connectivity or circuit intents, depending on given port types. |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 42 | */ |
| 43 | @Command(scope = "onos", name = "add-optical-intent", |
| 44 | description = "Installs optical connectivity intent") |
| 45 | public class AddOpticalIntentCommand extends ConnectivityIntentCommand { |
| 46 | |
| 47 | @Argument(index = 0, name = "ingressDevice", |
| 48 | description = "Ingress Device/Port Description", |
| 49 | required = true, multiValued = false) |
Ayaka Koshibe | afb546f | 2015-10-23 17:13:58 -0700 | [diff] [blame] | 50 | String ingressDeviceString = ""; |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 51 | |
| 52 | @Argument(index = 1, name = "egressDevice", |
| 53 | description = "Egress Device/Port Description", |
| 54 | required = true, multiValued = false) |
Ayaka Koshibe | afb546f | 2015-10-23 17:13:58 -0700 | [diff] [blame] | 55 | String egressDeviceString = ""; |
Aaron Kruglikov | 0a4da0d | 2015-06-10 14:40:48 -0700 | [diff] [blame] | 56 | |
| 57 | @Option(name = "-b", aliases = "--bidirectional", |
| 58 | description = "If this argument is passed the optical link created will be bidirectional, " + |
| 59 | "else the link will be unidirectional.", |
| 60 | required = false, multiValued = false) |
| 61 | private boolean bidirectional = false; |
| 62 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 63 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 64 | private ConnectPoint createConnectPoint(String devicePortString) { |
| 65 | String[] splitted = devicePortString.split("/"); |
| 66 | |
| 67 | checkArgument(splitted.length == 2, |
| 68 | "Connect point must be in \"deviceUri/portNumber\" format"); |
| 69 | |
| 70 | DeviceId deviceId = DeviceId.deviceId(splitted[0]); |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 71 | DeviceService deviceService = get(DeviceService.class); |
| 72 | |
| 73 | List<Port> ports = deviceService.getPorts(deviceId); |
| 74 | |
| 75 | for (Port port : ports) { |
| 76 | if (splitted[1].equals(port.number().name())) { |
| 77 | return new ConnectPoint(deviceId, port.number()); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return null; |
| 82 | } |
| 83 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 84 | @Override |
| 85 | protected void execute() { |
| 86 | IntentService service = get(IntentService.class); |
| 87 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 88 | ConnectPoint ingress = createConnectPoint(ingressDeviceString); |
| 89 | ConnectPoint egress = createConnectPoint(egressDeviceString); |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 90 | |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 91 | if (ingress == null || egress == null) { |
Ayaka Koshibe | afb546f | 2015-10-23 17:13:58 -0700 | [diff] [blame] | 92 | print("Invalid endpoint(s); could not create optical intent"); |
| 93 | return; |
Marc De Leenheer | 88194c3 | 2015-05-29 22:10:59 -0700 | [diff] [blame] | 94 | } |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 95 | |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 96 | DeviceService deviceService = get(DeviceService.class); |
| 97 | Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port()); |
| 98 | Port dstPort = deviceService.getPort(egress.deviceId(), egress.port()); |
| 99 | |
| 100 | Intent intent; |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 101 | |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 102 | if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 103 | Device srcDevice = deviceService.getDevice(ingress.deviceId()); |
| 104 | Device dstDevice = deviceService.getDevice(egress.deviceId()); |
| 105 | |
| 106 | // continue only if both OduClt port's Devices are of the same type |
| 107 | if (!(srcDevice.type().equals(dstDevice.type()))) { |
| 108 | print("Devices without same deviceType: SRC=%s and DST=%s", srcDevice.type(), dstDevice.type()); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | CltSignalType signalType = ((OduCltPort) srcPort).signalType(); |
| 113 | if (Device.Type.ROADM.equals(srcDevice.type())) { |
| 114 | intent = OpticalCircuitIntent.builder() |
| 115 | .appId(appId()) |
| 116 | .key(key()) |
| 117 | .src(ingress) |
| 118 | .dst(egress) |
| 119 | .signalType(signalType) |
| 120 | .bidirectional(bidirectional) |
| 121 | .build(); |
| 122 | } else if (Device.Type.OTN.equals(srcDevice.type())) { |
| 123 | intent = OpticalOduIntent.builder() |
| 124 | .appId(appId()) |
| 125 | .key(key()) |
| 126 | .src(ingress) |
| 127 | .dst(egress) |
| 128 | .signalType(signalType) |
| 129 | .bidirectional(bidirectional) |
| 130 | .build(); |
| 131 | } else { |
| 132 | print("Wrong Device Type for connect points %s and %s", ingress, egress); |
| 133 | return; |
| 134 | } |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 135 | } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 136 | OduSignalType signalType = ((OchPort) srcPort).signalType(); |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 137 | intent = OpticalConnectivityIntent.builder() |
| 138 | .appId(appId()) |
| 139 | .key(key()) |
| 140 | .src(ingress) |
| 141 | .dst(egress) |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 142 | .signalType(signalType) |
Aaron Kruglikov | 0a4da0d | 2015-06-10 14:40:48 -0700 | [diff] [blame] | 143 | .bidirectional(bidirectional) |
Marc De Leenheer | 9f7d189 | 2015-05-30 13:22:24 -0700 | [diff] [blame] | 144 | .build(); |
| 145 | } else { |
Rimon Ashkenazy | 27438ff | 2016-03-22 15:57:45 +0200 | [diff] [blame] | 146 | 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] | 147 | return; |
| 148 | } |
| 149 | |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 150 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 151 | print("Optical intent submitted:\n%s", intent.toString()); |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 152 | } |
Brian O'Connor | 5296b32 | 2014-10-23 14:59:05 -0700 | [diff] [blame] | 153 | } |