ONOS-4416 Remove OduCltPort out of core.

Change-Id: I04324a72e48af84afdbfa32b84c8e57f39411000
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java b/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java
index 14f6aeb..51000a9 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.device.impl;
 
 import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
+import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
 import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
 import static org.slf4j.LoggerFactory.getLogger;
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -25,7 +26,6 @@
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.OtuPort;
-import org.onosproject.net.OduCltPort;
 import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.SparseAnnotations;
@@ -36,6 +36,7 @@
 import org.onosproject.net.device.OtuPortDescription;
 import org.onosproject.net.device.PortDescription;
 import org.onosproject.net.optical.OchPort;
+import org.onosproject.net.optical.OduCltPort;
 import org.onosproject.net.optical.OmsPort;
 import org.onosproject.net.optical.OpticalDevice;
 import org.slf4j.Logger;
@@ -121,8 +122,12 @@
                 }
                 return descr;
             case ODUCLT:
-                OduCltPortDescription odu = (OduCltPortDescription) descr;
-                return new OduCltPortDescription(port, odu.isEnabled(), odu.signalType(), sa);
+                if (descr instanceof OduCltPortDescription) {
+                    // TODO This block can go away once deprecation is complete.
+                    OduCltPortDescription odu = (OduCltPortDescription) descr;
+                    return oduCltPortDescription(port, odu.isEnabled(), odu.signalType(), sa);
+                }
+                return descr;
             case PACKET:
             case FIBER:
             case COPPER:
@@ -223,8 +228,19 @@
                 return new DefaultPortDescription(ptn, isup, port.type(), port.portSpeed(), an);
 
             case ODUCLT:
-                OduCltPort odu = (OduCltPort) port;
-                return new OduCltPortDescription(ptn, isup, odu.signalType(), an);
+                if (port instanceof org.onosproject.net.OduCltPort) {
+                    // remove if-block once deprecation is complete
+                    org.onosproject.net.OduCltPort odu = (org.onosproject.net.OduCltPort) port;
+                    return oduCltPortDescription(ptn, isup, odu.signalType(), an);
+                }
+                if (port.element().is(OpticalDevice.class)) {
+                    OpticalDevice optDevice = port.element().as(OpticalDevice.class);
+                    if (optDevice.portIs(port, OduCltPort.class)) {
+                        OduCltPort odu = (OduCltPort) port;
+                        return oduCltPortDescription(ptn, isup, odu.signalType(), an);
+                    }
+                }
+                return new DefaultPortDescription(ptn, isup, port.type(), port.portSpeed(), an);
             case OTU:
                 OtuPort otu = (OtuPort) port;
                 return new OtuPortDescription(ptn, isup, otu.signalType(), an);
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
index bf8152e..baa5260 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
@@ -32,7 +32,6 @@
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.CltSignalType;
 import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.OduCltPort;
 import org.onosproject.net.OduSignalId;
 import org.onosproject.net.OduSignalType;
 import org.onosproject.net.OduSignalUtils;
@@ -60,6 +59,7 @@
 import org.onosproject.net.intent.OpticalConnectivityIntent;
 import org.onosproject.net.intent.impl.IntentCompilationException;
 import org.onosproject.net.optical.OchPort;
+import org.onosproject.net.optical.OduCltPort;
 import org.onosproject.net.intent.IntentSetMultimap;
 import org.onosproject.net.resource.ResourceAllocation;
 import org.onosproject.net.resource.Resource;
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompiler.java
index 918438c..18a8f17 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompiler.java
@@ -27,7 +27,6 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
 import org.onosproject.net.LinkKey;
-import org.onosproject.net.OduCltPort;
 import org.onosproject.net.OduSignalId;
 import org.onosproject.net.OduSignalType;
 import org.onosproject.net.OduSignalUtils;
@@ -50,6 +49,7 @@
 import org.onosproject.net.intent.IntentExtensionService;
 import org.onosproject.net.intent.OpticalOduIntent;
 import org.onosproject.net.intent.impl.IntentCompilationException;
+import org.onosproject.net.optical.OduCltPort;
 import org.onosproject.net.resource.Resource;
 import org.onosproject.net.resource.ResourceService;
 import org.onosproject.net.resource.ResourceAllocation;
@@ -77,6 +77,7 @@
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.onosproject.net.LinkKey.linkKey;
+import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
 
 /**
  * An intent compiler for {@link org.onosproject.net.intent.OpticalOduIntent}.
@@ -105,6 +106,7 @@
 
     @Activate
     public void activate() {
+        deviceService = opticalView(deviceService);
         appId = coreService.registerApplication("org.onosproject.net.intent");
         intentManager.registerCompiler(OpticalOduIntent.class, this);
     }
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
index 9d72cd0..1a7f778 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
@@ -35,7 +35,6 @@
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.OchSignal;
-import org.onosproject.net.OduCltPort;
 import org.onosproject.net.OduSignalId;
 import org.onosproject.net.OduSignalType;
 import org.onosproject.net.OduSignalUtils;
@@ -58,7 +57,9 @@
 import org.onosproject.net.intent.MockIdGenerator;
 import org.onosproject.net.intent.OpticalCircuitIntent;
 import org.onosproject.net.optical.OchPort;
+import org.onosproject.net.optical.OduCltPort;
 import org.onosproject.net.optical.impl.DefaultOchPort;
+import org.onosproject.net.optical.impl.DefaultOduCltPort;
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.net.intent.IntentSetMultimap;
 import org.onosproject.net.behaviour.TributarySlotQuery;
@@ -124,9 +125,11 @@
 
     // OduClt ports with signalType=1GBE
     private static final OduCltPort D1P1 =
-            new OduCltPort(device1, PortNumber.portNumber(1), true, CltSignalType.CLT_1GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1),
+                                  CltSignalType.CLT_1GBE);
     private static final OduCltPort D2P1 =
-            new OduCltPort(device2, PortNumber.portNumber(1), true, CltSignalType.CLT_1GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations1),
+                                  CltSignalType.CLT_1GBE);
 
     // Och ports with signalType=ODU2
     private static final OchPort D1P2 =
@@ -140,9 +143,11 @@
 
     // OduClt ports with signalType=10GBE
     private static final OduCltPort D1P3 =
-            new OduCltPort(device1, PortNumber.portNumber(3), true, CltSignalType.CLT_10GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1),
+                                  CltSignalType.CLT_10GBE);
     private static final OduCltPort D2P3 =
-            new OduCltPort(device2, PortNumber.portNumber(3), true, CltSignalType.CLT_10GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device2, PortNumber.portNumber(3), true, annotations1),
+                                  CltSignalType.CLT_10GBE);
 
 
     private OpticalCircuitIntent intent;
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompilerTest.java
index 62182eb..5f45ae4 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/OpticalOduIntentCompilerTest.java
@@ -23,6 +23,7 @@
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.core.IdGenerator;
+import org.onosproject.net.AbstractProjectableModel;
 import org.onosproject.net.Annotations;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.CltSignalType;
@@ -30,10 +31,10 @@
 import org.onosproject.net.DefaultDevice;
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DefaultPath;
+import org.onosproject.net.DefaultPort;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
-import org.onosproject.net.OduCltPort;
 import org.onosproject.net.OduSignalId;
 import org.onosproject.net.OduSignalType;
 import org.onosproject.net.OduSignalUtils;
@@ -56,11 +57,15 @@
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.MockIdGenerator;
 import org.onosproject.net.intent.OpticalOduIntent;
+import org.onosproject.net.optical.OduCltPort;
+import org.onosproject.net.optical.impl.DefaultOduCltPort;
 import org.onosproject.net.provider.ProviderId;
 import org.onosproject.net.topology.LinkWeight;
 import org.onosproject.net.topology.Topology;
 import org.onosproject.net.topology.TopologyServiceAdapter;
 import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.driver.DriverServiceAdapter;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Sets;
@@ -116,9 +121,11 @@
 
     // OduClt ports with signalType=1GBE
     private static final OduCltPort D1P1 =
-            new OduCltPort(device1, PortNumber.portNumber(1), true, CltSignalType.CLT_1GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(1), true, annotations1),
+                                  CltSignalType.CLT_1GBE);
     private static final OduCltPort D3P2 =
-            new OduCltPort(device3, PortNumber.portNumber(2), true, CltSignalType.CLT_1GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device3, PortNumber.portNumber(2), true, annotations1),
+                                  CltSignalType.CLT_1GBE);
 
     // Otu ports with signalType=ODU2
     private static final OtuPort D1P2 =
@@ -132,9 +139,11 @@
 
     // OduClt ports with signalType=10GBE
     private static final OduCltPort D1P3 =
-            new OduCltPort(device1, PortNumber.portNumber(3), true, CltSignalType.CLT_10GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device1, PortNumber.portNumber(3), true, annotations1),
+                                  CltSignalType.CLT_10GBE);
     private static final OduCltPort D3P3 =
-            new OduCltPort(device3, PortNumber.portNumber(3), true, CltSignalType.CLT_10GBE, annotations1);
+            new DefaultOduCltPort(new DefaultPort(device3, PortNumber.portNumber(3), true, annotations1),
+                                  CltSignalType.CLT_10GBE);
 
     // OduCltPort ConnectPoints
     private final ConnectPoint d1p1 = new ConnectPoint(device1.id(), D1P1.number());
@@ -204,11 +213,11 @@
             if (deviceId.equals(deviceId(DEV1))) {
                 switch (portNumber.toString()) {
                     case "1":
-                        return (Port) D1P1;
+                        return D1P1;
                     case "2":
-                        return (Port) D1P2;
+                        return D1P2;
                     case "3":
-                        return (Port) D1P3;
+                        return D1P3;
                     default:
                         return null;
                 }
@@ -216,9 +225,9 @@
             if (deviceId.equals(deviceId(DEV2))) {
                 switch (portNumber.toString()) {
                     case "1":
-                        return (Port) D2P1;
+                        return D2P1;
                     case "2":
-                        return (Port) D2P2;
+                        return D2P2;
                     default:
                         return null;
                 }
@@ -226,11 +235,11 @@
             if (deviceId.equals(deviceId(DEV3))) {
                 switch (portNumber.toString()) {
                     case "1":
-                        return (Port) D3P1;
+                        return D3P1;
                     case "2":
-                        return (Port) D3P2;
+                        return D3P2;
                     case "3":
-                        return (Port) D3P3;
+                        return D3P3;
                     default:
                         return null;
                 }
@@ -239,8 +248,15 @@
         }
     }
 
+    private static class MockDriverService extends DriverServiceAdapter
+            implements DriverService {
+        // TODO override to return appropriate driver,
+        // with DefaultOpticalDevice support, etc.
+    }
+
     @Before
     public void setUp() {
+        AbstractProjectableModel.setDriverService(null, new MockDriverService());
         sut =  new OpticalOduIntentCompiler();
         coreService = createMock(CoreService.class);
         expect(coreService.registerApplication("org.onosproject.net.intent"))