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/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceStore.java b/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceStore.java
index 31cab02..a52a843 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceStore.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/device/DeviceResourceStore.java
@@ -22,10 +22,17 @@
 import java.util.Set;
 
 public interface DeviceResourceStore {
+    /**
+     * Returns unallocated ports on the given device.
+     *
+     * @param deviceId device ID
+     * @return set of unallocated ports
+     */
     Set<Port> getFreePorts(DeviceId deviceId);
 
     /**
      * Allocates the given ports to the given intent.
+     *
      * @param ports set of ports to allocate
      * @param intentId intent ID
      * @return true if allocation was successful, false otherwise
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index 4d8077e..144f2df 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -265,7 +265,8 @@
                 if (edge.link().type() != Link.Type.OPTICAL) {
                     return -1;
                 }
-                return edge.link().annotations().value("optical.type").equals("WDM") ? +1 : -1;
+                //return edge.link().annotations().value("optical.type").equals("WDM") ? +1 : -1;
+                return 1;
             }
         };
 
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
index 8d6b5b6..ef836b5 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
@@ -37,6 +37,7 @@
 import org.onosproject.mastership.MastershipService;
 import org.onosproject.mastership.MastershipTerm;
 import org.onosproject.mastership.MastershipTermService;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.AnnotationsUtil;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultDevice;
@@ -1007,6 +1008,26 @@
                                  chassisId, annotations);
     }
 
+    private Port buildTypedPort(Device device, PortNumber number, boolean isEnabled,
+                                 PortDescription description, Annotations annotations) {
+        switch (description.type()) {
+            case OMS:
+                OmsPortDescription omsDesc = (OmsPortDescription) description;
+                return new OmsPort(device, number, isEnabled, omsDesc.minFrequency(),
+                        omsDesc.maxFrequency(), omsDesc.grid(), annotations);
+            case OCH:
+                OchPortDescription ochDesc = (OchPortDescription) description;
+                return new OchPort(device, number, isEnabled, ochDesc.signalType(),
+                        ochDesc.isTunable(), ochDesc.lambda(), annotations);
+            case ODUCLT:
+                OduCltPortDescription oduDesc = (OduCltPortDescription) description;
+                return new OduCltPort(device, number, isEnabled, oduDesc.signalType(), annotations);
+            default:
+                return new DefaultPort(device, number, isEnabled, description.type(),
+                        description.portSpeed(), annotations);
+        }
+    }
+
     /**
      * Returns a Port, merging description given from multiple Providers.
      *
@@ -1048,25 +1069,7 @@
                 }
                 annotations = merge(annotations, otherPortDesc.value().annotations());
                 PortDescription other = otherPortDesc.value();
-                switch (other.type()) {
-                    case OMS:
-                        OmsPortDescription omsPortDesc = (OmsPortDescription) otherPortDesc.value();
-                        updated = new OmsPort(device, number, isEnabled, omsPortDesc.minFrequency(),
-                                              omsPortDesc.maxFrequency(), omsPortDesc.grid(), annotations);
-                        break;
-                    case OCH:
-                        OchPortDescription ochPortDesc = (OchPortDescription) otherPortDesc.value();
-                        updated = new OchPort(device, number, isEnabled, ochPortDesc.signalType(),
-                                              ochPortDesc.isTunable(), ochPortDesc.lambda(), annotations);
-                        break;
-                    case ODUCLT:
-                        OduCltPortDescription oduCltPortDesc = (OduCltPortDescription) otherPortDesc.value();
-                        updated = new OduCltPort(device, number, isEnabled, oduCltPortDesc.signalType(), annotations);
-                        break;
-                    default:
-                        updated = new DefaultPort(
-                                device, number, isEnabled, other.type(), other.portSpeed(), annotations);
-                }
+                updated = buildTypedPort(device, number, isEnabled, other, annotations);
                 newest = otherPortDesc.timestamp();
             }
         }
@@ -1075,7 +1078,7 @@
         }
         PortDescription current = portDesc.value();
         return updated == null
-                ? new DefaultPort(device, number, isEnabled, current.type(), current.portSpeed(), annotations)
+                ? buildTypedPort(device, number, isEnabled, current, annotations)
                 : updated;
     }