blob: b53644df0a54f1271e76d37efee3baba2fcda31e [file] [log] [blame]
Andrea Campanella3a361452019-08-02 10:17:53 +02001/*
2 * Copyright 2019-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
17
18package org.onosproject.net.optical.cli;
19
20import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
22import org.apache.karaf.shell.api.action.Completion;
23import org.apache.karaf.shell.api.action.lifecycle.Service;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.cli.net.OpticalConnectPointCompleter;
26import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.Device;
28import org.onosproject.net.behaviour.LambdaQuery;
29import org.onosproject.net.device.DeviceService;
30
31/**
32 * Lists all the available wavelengths (lambdas) for a given port.
33 */
34@Service
35@Command(scope = "onos", name = "available-wavelength",
36 description = "Lists all the available wavelengths for a given port")
37public class PortAvailableWaveLengthCommand extends AbstractShellCommand {
38
39 private static final String FMT =
40 "signal=%s, central-frequency=%f";
41
42 @Argument(index = 0, name = "connectPoint",
43 description = "Device/Port Description",
44 required = true, multiValued = false)
45 @Completion(OpticalConnectPointCompleter.class)
46 String connectPointString = "";
47
48
49 @Override
50 protected void doExecute() throws Exception {
51 DeviceService deviceService = get(DeviceService.class);
52 ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString);
53
54 Device d = deviceService.getDevice(cp.deviceId());
55 if (d.is(LambdaQuery.class)) {
56 LambdaQuery lambdaQuery = d.as(LambdaQuery.class);
57 lambdaQuery.queryLambdas(cp.port()).forEach(lambda -> {
58 print(FMT, lambda.toString(), lambda.centralFrequency().asGHz());
59 });
60
61 } else {
62 print("Device is not capable of querying lambdas");
63 }
64
65 }
66}