Fix optical port types in device store (ONOS-2046).
Fix CLI add-optical-intent cmd for TL1-based devices (ONOS-2045).

Change-Id: I4ba79476104d9906707cc7cc683fedd4ce4343bb
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
index 97341d7..c76bc3d 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
@@ -20,6 +20,7 @@
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.OchPort;
 import org.onosproject.net.OduCltPort;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.OduSignalType;
 import org.onosproject.net.Port;
 import org.onosproject.net.device.DeviceService;
@@ -28,6 +29,10 @@
 import org.onosproject.net.intent.OpticalCircuitIntent;
 import org.onosproject.net.intent.OpticalConnectivityIntent;
 
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * Installs optical connectivity or circuit intents, depending on given port types.
  */
@@ -45,13 +50,37 @@
               required = true, multiValued = false)
     String egressDeviceString = null;
 
+    private ConnectPoint createConnectPoint(String devicePortString) {
+        String[] splitted = devicePortString.split("/");
+
+        checkArgument(splitted.length == 2,
+                "Connect point must be in \"deviceUri/portNumber\" format");
+
+        DeviceId deviceId = DeviceId.deviceId(splitted[0]);
+
+        DeviceService deviceService = get(DeviceService.class);
+
+        List<Port> ports = deviceService.getPorts(deviceId);
+
+        for (Port port : ports) {
+            if (splitted[1].equals(port.number().name())) {
+                return new ConnectPoint(deviceId, port.number());
+            }
+        }
+
+        return null;
+    }
+
     @Override
     protected void execute() {
         IntentService service = get(IntentService.class);
 
-        ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
+        ConnectPoint ingress = createConnectPoint(ingressDeviceString);
+        ConnectPoint egress = createConnectPoint(egressDeviceString);
 
-        ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
+        if (ingress == null || egress == null) {
+            print("Could not create optical intent");
+        }
 
         DeviceService deviceService = get(DeviceService.class);
         Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());