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