blob: c434fdb3c8bd3e814be60ec5d7d7b8a354ed8298 [file] [log] [blame]
Andrea Campanellae1e3e442019-10-21 13:45:32 +02001/*
2 * Copyright 2018-present Open Networking Foundation
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
17package org.onosproject.odtn.cli.impl;
18
19import com.google.common.annotations.Beta;
20import org.apache.commons.lang3.tuple.Pair;
21import org.apache.karaf.shell.api.action.Argument;
22import org.apache.karaf.shell.api.action.Command;
23import org.apache.karaf.shell.api.action.Completion;
24import org.apache.karaf.shell.api.action.Option;
25import org.apache.karaf.shell.api.action.lifecycle.Service;
26import org.onosproject.cli.AbstractShellCommand;
27import org.onosproject.cli.net.ConnectPointCompleter;
28import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.intent.IntentId;
30import org.onosproject.odtn.GnpyService;
31import org.slf4j.Logger;
32
33import static com.google.common.base.Preconditions.checkArgument;
34import static org.slf4j.LoggerFactory.getLogger;
35
36@Beta
37@Service
38@Command(scope = "onos", name = "odtn-gnpy-connection-command",
39 description = "show tapi context command")
40public class GnpyConnectionRequestCommand extends AbstractShellCommand {
41
42 private static final Logger log = getLogger(GnpyConnectionRequestCommand.class);
43
44 @Argument(index = 0, name = "ingress",
45 description = "Ingress Device/Port Description",
46 required = true, multiValued = false)
47 @Completion(ConnectPointCompleter.class)
48 String ingressString = "";
49
50 @Argument(index = 1, name = "egress",
51 description = "Egress Device/Port Description",
52 required = true, multiValued = false)
53 @Completion(ConnectPointCompleter.class)
54 String egressString = "";
55
56 @Option(name = "-b", aliases = "--bidirectional",
57 description = "If this argument is passed the optical link created will be bidirectional, " +
58 "else the link will be unidirectional.",
59 required = false, multiValued = false)
60 private boolean bidirectional = false;
61
62 @Override
63 protected void doExecute() {
64 GnpyService service = get(GnpyService.class);
65
66 if (!service.isConnected()) {
67 print("gNPY is not connected, please issue `odtn-connect-gnpy-command` first");
68 return;
69 }
70
71 ConnectPoint ingress = createConnectPoint(ingressString);
72 ConnectPoint egress = createConnectPoint(egressString);
73
74 Pair<IntentId, Double> intentIdAndOsnr =
75 service.obtainConnectivity(ingress, egress, bidirectional);
76
77 if (intentIdAndOsnr != null) {
78 print("Optical Connectivity from %s to %s submitted through GNPy. \n", ingress, egress);
79 print("Expected GSNR %.2f dB", intentIdAndOsnr.getRight().doubleValue());
80 print("Intent: %s", intentIdAndOsnr.getLeft());
81 } else {
82 print("Error in submitting Optical Connectivity submitted through GNPy, please see logs");
83 }
84 }
85
86 private ConnectPoint createConnectPoint(String devicePortString) {
87 String[] splitted = devicePortString.split("/");
88
89 checkArgument(splitted.length == 2,
90 "Connect point must be in \"deviceUri/portNumber\" format");
91
92 return ConnectPoint.deviceConnectPoint(devicePortString);
93 }
94
95}