Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.newoptical.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onlab.util.Bandwidth; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.newoptical.api.OpticalConnectivityId; |
| 23 | import org.onosproject.newoptical.api.OpticalPathService; |
| 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.PortNumber; |
| 27 | |
| 28 | @Command(scope = "onos", name = "add-optical-connectivity", |
| 29 | description = "Configure optical domain connectivity") |
| 30 | public class AddOpticalConnectivityCommand extends AbstractShellCommand { |
| 31 | |
| 32 | @Argument(index = 0, name = "ingress", description = "Ingress connect point", |
| 33 | required = true, multiValued = false) |
| 34 | String ingressStr = null; |
| 35 | |
| 36 | @Argument(index = 1, name = "egress", description = "Egress connect point", |
| 37 | required = true, multiValued = false) |
| 38 | String egressStr = null; |
| 39 | |
| 40 | @Argument(index = 2, name = "bandwidth", description = "Bandwidth", |
| 41 | required = false, multiValued = false) |
| 42 | String bandwidthStr = null; |
| 43 | |
| 44 | @Argument(index = 3, name = "latency", description = "Latency", |
| 45 | required = true, multiValued = false) |
| 46 | String latencyStr = null; |
| 47 | |
| 48 | |
| 49 | @Override |
| 50 | protected void execute() { |
| 51 | OpticalPathService opticalPathService = get(OpticalPathService.class); |
| 52 | |
| 53 | ConnectPoint ingress = readConnectPoint(ingressStr); |
| 54 | ConnectPoint egress = readConnectPoint(egressStr); |
| 55 | if (ingress == null || egress == null) { |
| 56 | print("Invalid connect points: %s, %s", ingressStr, egressStr); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | Bandwidth bandwidth = (bandwidthStr == null || bandwidthStr.isEmpty()) ? null : |
| 61 | Bandwidth.bps(Long.valueOf(bandwidthStr)); |
| 62 | |
| 63 | print("Trying to setup connectivity between %s and %s.", ingress, egress); |
| 64 | OpticalConnectivityId id = opticalPathService.setupConnectivity(ingress, egress, bandwidth, null); |
| 65 | if (id == null) { |
| 66 | print("Failed."); |
| 67 | return; |
| 68 | } |
| 69 | print("Optical path ID : %s", id.id()); |
| 70 | } |
| 71 | |
| 72 | private ConnectPoint readConnectPoint(String str) { |
| 73 | String[] strings = str.split("/"); |
| 74 | if (strings.length != 2) { |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | DeviceId devId = DeviceId.deviceId(strings[0]); |
| 79 | PortNumber port = PortNumber.portNumber(strings[1]); |
| 80 | |
| 81 | return new ConnectPoint(devId, port); |
| 82 | } |
| 83 | |
| 84 | } |