Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | c53a0d2 | 2018-10-09 15:06:38 -0700 | [diff] [blame^] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 22 | import org.onlab.util.Bandwidth; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 24 | import org.onosproject.cli.net.ConnectPointCompleter; |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 25 | import org.onosproject.newoptical.api.OpticalConnectivityId; |
| 26 | import org.onosproject.newoptical.api.OpticalPathService; |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
| 30 | import org.onosproject.net.DeviceId; |
| 31 | import org.onosproject.net.PortNumber; |
| 32 | |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 33 | @Service |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 34 | @Command(scope = "onos", name = "add-optical-connectivity", |
| 35 | description = "Configure optical domain connectivity") |
| 36 | public class AddOpticalConnectivityCommand extends AbstractShellCommand { |
| 37 | |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 38 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 39 | |
| 40 | // for OSGi import workaround |
| 41 | ConnectPointCompleter portCompleter; |
| 42 | |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 43 | @Argument(index = 0, name = "ingress", description = "Ingress connect point", |
| 44 | required = true, multiValued = false) |
Ray Milkey | c53a0d2 | 2018-10-09 15:06:38 -0700 | [diff] [blame^] | 45 | @Completion(ConnectPointCompleter.class) |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 46 | String ingressStr = null; |
| 47 | |
| 48 | @Argument(index = 1, name = "egress", description = "Egress connect point", |
| 49 | required = true, multiValued = false) |
Ray Milkey | c53a0d2 | 2018-10-09 15:06:38 -0700 | [diff] [blame^] | 50 | @Completion(ConnectPointCompleter.class) |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 51 | String egressStr = null; |
| 52 | |
| 53 | @Argument(index = 2, name = "bandwidth", description = "Bandwidth", |
| 54 | required = false, multiValued = false) |
| 55 | String bandwidthStr = null; |
| 56 | |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 57 | // not supported yet |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 58 | @Argument(index = 3, name = "latency", description = "Latency", |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 59 | required = false, multiValued = false) |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 60 | String latencyStr = null; |
| 61 | |
| 62 | |
| 63 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 64 | protected void doExecute() { |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 65 | OpticalPathService opticalPathService = get(OpticalPathService.class); |
| 66 | |
| 67 | ConnectPoint ingress = readConnectPoint(ingressStr); |
| 68 | ConnectPoint egress = readConnectPoint(egressStr); |
| 69 | if (ingress == null || egress == null) { |
| 70 | print("Invalid connect points: %s, %s", ingressStr, egressStr); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | Bandwidth bandwidth = (bandwidthStr == null || bandwidthStr.isEmpty()) ? null : |
| 75 | Bandwidth.bps(Long.valueOf(bandwidthStr)); |
| 76 | |
| 77 | print("Trying to setup connectivity between %s and %s.", ingress, egress); |
| 78 | OpticalConnectivityId id = opticalPathService.setupConnectivity(ingress, egress, bandwidth, null); |
| 79 | if (id == null) { |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 80 | print("Failed. See ONOS log for more details."); |
| 81 | print(" log:set TRACE org.onosproject.newoptical.OpticalPathProvisioner"); |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 82 | return; |
| 83 | } |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 84 | // FIXME This is the last chance to know the Optical path ID. |
| 85 | // there's no other way to know existing Optical Path ID |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 86 | print("Optical path ID : %s", id.id()); |
Yuta HIGUCHI | 031247c | 2017-03-14 20:56:04 -0700 | [diff] [blame] | 87 | log.info("Optical path ID {} for connectivity between {} and {}", |
Yuta HIGUCHI | 806113f | 2017-03-07 22:46:20 -0800 | [diff] [blame] | 88 | id.id(), ingress, egress); |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | private ConnectPoint readConnectPoint(String str) { |
| 92 | String[] strings = str.split("/"); |
| 93 | if (strings.length != 2) { |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | DeviceId devId = DeviceId.deviceId(strings[0]); |
| 98 | PortNumber port = PortNumber.portNumber(strings[1]); |
| 99 | |
| 100 | return new ConnectPoint(devId, port); |
| 101 | } |
| 102 | |
| 103 | } |