[ONOS-8018] only show line-side port for power config.

Change-Id: I53c796654d1a06ebc30424a2765f7e3f786015d6
diff --git a/cli/src/main/java/org/onosproject/cli/net/OpticalConnectPointCompleter.java b/cli/src/main/java/org/onosproject/cli/net/OpticalConnectPointCompleter.java
new file mode 100644
index 0000000..869d2c9
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/OpticalConnectPointCompleter.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli.net;
+
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.Device;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DeviceService;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * Optical ConnectPoint completer.
+ */
+@Service
+public class OpticalConnectPointCompleter implements Completer {
+    @Override
+    public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+        // Delegate string completer
+        StringsCompleter delegate = new StringsCompleter();
+
+        // Fetch our service and feed it's offerings to the string completer
+        DeviceService service = AbstractShellCommand.get(DeviceService.class);
+
+        // Generate the device ID/port number identifiers
+        for (Device device : service.getDevices()) {
+            SortedSet<String> strings = delegate.getStrings();
+            for (Port port : service.getPorts(device.id())) {
+                if (!port.number().isLogical() && (port.type().equals(Port.Type.OCH) ||
+                        port.type().equals(Port.Type.OMS) || port.type().equals(Port.Type.OTU))) {
+                    strings.add(device.id().toString() + "/" + port.number());
+                }
+            }
+        }
+
+        // Now let the completer do the work for figuring out what to offer.
+        return delegate.complete(session, commandLine, candidates);
+    }
+}
diff --git a/cli/src/main/java/org/onosproject/cli/net/PowerConfigCommand.java b/cli/src/main/java/org/onosproject/cli/net/PowerConfigCommand.java
index b7d5020..c85d0ea 100644
--- a/cli/src/main/java/org/onosproject/cli/net/PowerConfigCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/PowerConfigCommand.java
@@ -24,6 +24,7 @@
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Device;
+import org.onosproject.net.Direction;
 import org.onosproject.net.Port;
 import org.onosproject.net.behaviour.PowerConfig;
 import org.onosproject.net.device.DeviceService;
@@ -52,7 +53,7 @@
 
     @Argument(index = 1, name = "connection point", description = "{DeviceID}/{PortNumber}",
             required = true, multiValued = false)
-    @Completion(ConnectPointCompleter.class)
+    @Completion(OpticalConnectPointCompleter.class)
     private String connectPoint = null;
 
     @Argument(index = 2, name = "value", description = "target-output-power value. Unit: dBm",
@@ -68,18 +69,25 @@
             print("[ERROR] %s does not exist", cp);
             return;
         }
+        if (!port.type().equals(Port.Type.OCH) &&
+                !port.type().equals(Port.Type.OTU) &&
+                !port.type().equals(Port.Type.OMS)) {
+            log.warn("The power of selected port %s isn't editable.", port.number().toString());
+            print("The power of selected port %s isn't editable.", port.number().toString());
+            return;
+        }
         Device device = deviceService.getDevice(cp.deviceId());
         PowerConfig powerConfig = device.as(PowerConfig.class);
         // FIXME the parameter "component" equals NULL now, because there is one-to-one mapping between
         //  <component> and <optical-channel>.
         if (operation.equals("get")) {
-            Optional<Long> val = powerConfig.getTargetPower(cp.port(), null);
+            Optional<Long> val = powerConfig.getTargetPower(cp.port(), Direction.ALL);
             long power = val.isPresent() ? val.get() : Long.MIN_VALUE;
             print("The target-output-power value in port %s on device %s is %d.",
                     cp.port().toString(), cp.deviceId().toString(), power);
         } else if (operation.equals("edit-config")) {
             checkNotNull(value);
-            powerConfig.setTargetPower(cp.port(), null, value);
+            powerConfig.setTargetPower(cp.port(), Direction.ALL, value);
         } else {
             log.warn("Operation {} are not supported now.", operation);
         }