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