ONOS-3503 Remove OchPort out of core.

- Implementation of a Behavior OpticalDevice has the knowledge of
  translating annotations into optical specific port.
- OpticalDeviceServiceView checks if the Device is a OpticalDevice
  and translate all the Ports to optical specific port before returning.

- This commit contains feedbacks, issues, and fixes by Michele Santuari.

- Note: 3 more Port types to go (OduClt, Oms, Otu)

Change-Id: I4cbda8bc1922fbdd4dac8de8d02294bad74b8058
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 3d3bca4..001c273 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddOpticalIntentCommand.java
@@ -21,7 +21,6 @@
 import org.onosproject.net.CltSignalType;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Device;
-import org.onosproject.net.OchPort;
 import org.onosproject.net.OduCltPort;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.OduSignalType;
@@ -32,10 +31,12 @@
 import org.onosproject.net.intent.OpticalCircuitIntent;
 import org.onosproject.net.intent.OpticalConnectivityIntent;
 import org.onosproject.net.intent.OpticalOduIntent;
+import org.onosproject.net.optical.OchPort;
 
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView;
 
 /**
  * Installs optical connectivity or circuit intents, depending on given port types.
@@ -93,7 +94,8 @@
             return;
         }
 
-        DeviceService deviceService = get(DeviceService.class);
+        DeviceService deviceService = opticalView(get(DeviceService.class));
+
         Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
         Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
 
@@ -142,6 +144,19 @@
                     .signalType(signalType)
                     .bidirectional(bidirectional)
                     .build();
+        } else if (srcPort instanceof org.onosproject.net.OchPort &&
+                   dstPort instanceof org.onosproject.net.OchPort) {
+            print("WARN: encountered old OchPort model");
+            // old OchPort model can be removed when ready
+            OduSignalType signalType = ((org.onosproject.net.OchPort) srcPort).signalType();
+            intent = OpticalConnectivityIntent.builder()
+                    .appId(appId())
+                    .key(key())
+                    .src(ingress)
+                    .dst(egress)
+                    .signalType(signalType)
+                    .bidirectional(bidirectional)
+                    .build();
         } else {
             print("Unable to create optical intent between connect points %s and %s", ingress, egress);
             return;