blob: 3df2ff84448f0bf0f83f5bda434a86182b2553dc [file] [log] [blame]
Naoki Shiota5a056062016-05-05 18:43:59 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.util.Bandwidth;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.newoptical.api.OpticalConnectivityId;
23import org.onosproject.newoptical.api.OpticalPathService;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.PortNumber;
27
28@Command(scope = "onos", name = "add-optical-connectivity",
29 description = "Configure optical domain connectivity")
30public 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}