[ODTN] fix to enable use of suggested path while requiring an intent between OCUCLT ports
- patch 2,3,4,5: checkstyle
- patch 6: andrea's comment

Change-Id: Ia144be2186ca241f4aebe562e0018580b42c987c
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
index 4f8fcbe..7686e7a 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
@@ -30,6 +30,7 @@
 import org.onosproject.net.OduSignalType;
 import org.onosproject.net.OduSignalUtils;
 import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.TributarySlot;
 import org.onosproject.net.behaviour.TributarySlotQuery;
 import org.onosproject.net.device.DeviceService;
@@ -240,7 +241,18 @@
             required = resources;
         } else {
             // Find OCh ports with available resources
-            Pair<OchPort, OchPort> ochPorts = findPorts(intent.getSrc(), intent.getDst(), intent.getSignalType());
+            Pair<OchPort, OchPort> ochPorts = null;
+
+            if (intent.suggestedPath().isPresent()) {
+                PortNumber srcPortNumber = intent.suggestedPath().get().src().port();
+                PortNumber dstPortNumber = intent.suggestedPath().get().dst().port();
+
+                ochPorts = Pair.of(
+                        (OchPort) deviceService.getPort(intent.getSrc().deviceId(), srcPortNumber),
+                        (OchPort) deviceService.getPort(intent.getDst().deviceId(), dstPortNumber));
+            } else {
+                ochPorts = findPorts(intent.getSrc(), intent.getDst(), intent.getSignalType());
+            }
 
             if (ochPorts == null) {
                 throw new OpticalIntentCompilationException("Unable to find suitable OCH ports for intent " + intent);
diff --git a/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java b/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
index cff8d93..1570a2e 100644
--- a/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
+++ b/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
@@ -32,6 +32,7 @@
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.OchSignal;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.flow.criteria.Criterion;
 import org.onosproject.net.flow.criteria.OchSignalCriterion;
@@ -74,7 +75,7 @@
 
 
 /**
- * Query, submit and withdraw optical network intents.
+ * Query, submit and withdraw optical intents.
  */
 @Path("intents")
 public class OpticalIntentsWebResource extends AbstractWebResource {
@@ -317,10 +318,9 @@
                     listLinks.add(link);
                 }
 
-                if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) ||
-                        (!listLinks.get(0).src().port().equals(ingress.port())) ||
-                        (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) ||
-                        (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
+                if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId()))
+                        || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId()))
+                ) {
                     throw new IllegalArgumentException(
                             "Suggested path not compatible with ingress or egress connect points");
                 }
@@ -332,6 +332,12 @@
 
                 suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
 
+                if (!deviceService.getPort(suggestedPath.src()).type().equals(Port.Type.OCH)
+                || !deviceService.getPort(suggestedPath.dst()).type().equals(Port.Type.OCH)) {
+                    throw new IllegalArgumentException(
+                            "End-points of suggested path must be ports of type OCH");
+                }
+
                 log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
             }
         }