blob: 6cd668c4666394285bcca7f1bb04c87f2c385617 [file] [log] [blame]
Sudeep Desaic3f655b2020-02-05 17:55:50 +05301/*
2 * Copyright 2020-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 * This work was partially supported by EC H2020 project METRO-HAUL (761727).
17 */
18package org.onosproject.cli.net;
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.net.ConnectPoint;
26import org.onosproject.net.Device;
27import org.onosproject.net.Port;
28import org.onosproject.net.behaviour.BitErrorRateState;
29import org.onosproject.net.device.DeviceService;
30import org.slf4j.Logger;
31
32import java.util.Optional;
33
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Get the bit-error-rate for specific optical-channel.
38 * This is a command for BitErrorRate.
39 */
40@Service
41@Command(scope = "onos", name = "bit-error-rate",
42 description = "Get ber for specific optical-channel")
43public class BitErrorCommand extends AbstractShellCommand {
44
45 private static final Logger log = getLogger(BitErrorCommand.class);
46
47 @Argument(index = 0, name = "connection point", description = "{DeviceID}/{PortNumber}",
48 required = true, multiValued = false)
49 @Completion(OpticalConnectPointCompleter.class)
50 private String connectPoint = null;
51
52 @Override
53 protected void doExecute() throws Exception {
54 DeviceService deviceService = get(DeviceService.class);
55 ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPoint);
56 Port port = deviceService.getPort(cp);
57 if (port == null) {
58 print("[ERROR] %s does not exist", cp);
59 return;
60 }
61
62 Device device = deviceService.getDevice(cp.deviceId());
63 BitErrorRateState bitErrorRateState = device.as(BitErrorRateState.class);
64 Optional<Double> preFecBerVal = bitErrorRateState.getPreFecBer(cp.deviceId(), cp.port());
65 if (preFecBerVal.isPresent()) {
66 double preFecBer = preFecBerVal.orElse(Double.MIN_VALUE);
67 print("The pre-fec-ber value in port %s on device %s is %f.",
68 cp.port().toString(), cp.deviceId().toString(), preFecBer);
69 }
70 Optional<Double> postFecBerVal = bitErrorRateState.getPostFecBer(cp.deviceId(), cp.port());
71 if (postFecBerVal.isPresent()) {
72 double postFecBer = postFecBerVal.orElse(Double.MIN_VALUE);
73 print("The post-fec-ber value in port %s on device %s is %f.",
74 cp.port().toString(), cp.deviceId().toString(), postFecBer);
75 }
76 }
77}