blob: 55baec05a0e99305ad5a6a62082e3afde6728f75 [file] [log] [blame]
Naoki Shiota5a056062016-05-05 18:43:59 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Naoki Shiota5a056062016-05-05 18:43:59 -07003 *
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 */
16package org.onosproject.newoptical.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Naoki Shiota5a056062016-05-05 18:43:59 -070021import org.onlab.util.Bandwidth;
22import org.onosproject.cli.AbstractShellCommand;
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080023import org.onosproject.cli.net.ConnectPointCompleter;
Naoki Shiota5a056062016-05-05 18:43:59 -070024import org.onosproject.newoptical.api.OpticalConnectivityId;
25import org.onosproject.newoptical.api.OpticalPathService;
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080026import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
Naoki Shiota5a056062016-05-05 18:43:59 -070028import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.PortNumber;
31
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Naoki Shiota5a056062016-05-05 18:43:59 -070033@Command(scope = "onos", name = "add-optical-connectivity",
34 description = "Configure optical domain connectivity")
35public class AddOpticalConnectivityCommand extends AbstractShellCommand {
36
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080037 private final Logger log = LoggerFactory.getLogger(getClass());
38
39 // for OSGi import workaround
40 ConnectPointCompleter portCompleter;
41
Naoki Shiota5a056062016-05-05 18:43:59 -070042 @Argument(index = 0, name = "ingress", description = "Ingress connect point",
43 required = true, multiValued = false)
44 String ingressStr = null;
45
46 @Argument(index = 1, name = "egress", description = "Egress connect point",
47 required = true, multiValued = false)
48 String egressStr = null;
49
50 @Argument(index = 2, name = "bandwidth", description = "Bandwidth",
51 required = false, multiValued = false)
52 String bandwidthStr = null;
53
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080054 // not supported yet
Naoki Shiota5a056062016-05-05 18:43:59 -070055 @Argument(index = 3, name = "latency", description = "Latency",
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080056 required = false, multiValued = false)
Naoki Shiota5a056062016-05-05 18:43:59 -070057 String latencyStr = null;
58
59
60 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070061 protected void doExecute() {
Naoki Shiota5a056062016-05-05 18:43:59 -070062 OpticalPathService opticalPathService = get(OpticalPathService.class);
63
64 ConnectPoint ingress = readConnectPoint(ingressStr);
65 ConnectPoint egress = readConnectPoint(egressStr);
66 if (ingress == null || egress == null) {
67 print("Invalid connect points: %s, %s", ingressStr, egressStr);
68 return;
69 }
70
71 Bandwidth bandwidth = (bandwidthStr == null || bandwidthStr.isEmpty()) ? null :
72 Bandwidth.bps(Long.valueOf(bandwidthStr));
73
74 print("Trying to setup connectivity between %s and %s.", ingress, egress);
75 OpticalConnectivityId id = opticalPathService.setupConnectivity(ingress, egress, bandwidth, null);
76 if (id == null) {
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080077 print("Failed. See ONOS log for more details.");
78 print(" log:set TRACE org.onosproject.newoptical.OpticalPathProvisioner");
Naoki Shiota5a056062016-05-05 18:43:59 -070079 return;
80 }
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080081 // FIXME This is the last chance to know the Optical path ID.
82 // there's no other way to know existing Optical Path ID
Naoki Shiota5a056062016-05-05 18:43:59 -070083 print("Optical path ID : %s", id.id());
Yuta HIGUCHI031247c2017-03-14 20:56:04 -070084 log.info("Optical path ID {} for connectivity between {} and {}",
Yuta HIGUCHI806113f2017-03-07 22:46:20 -080085 id.id(), ingress, egress);
Naoki Shiota5a056062016-05-05 18:43:59 -070086 }
87
88 private ConnectPoint readConnectPoint(String str) {
89 String[] strings = str.split("/");
90 if (strings.length != 2) {
91 return null;
92 }
93
94 DeviceId devId = DeviceId.deviceId(strings[0]);
95 PortNumber port = PortNumber.portNumber(strings[1]);
96
97 return new ConnectPoint(devId, port);
98 }
99
100}