[ONOS] Compute path with Explicit path objects

Change-Id: Ib487688e15db7056283feef7720f610b2f59ad84
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java
index 9b2941f..001f74b 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/DistributedPceStore.java
@@ -19,6 +19,7 @@
 
 import com.google.common.collect.ImmutableSet;
 
+import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
@@ -33,6 +34,7 @@
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.net.intent.constraint.BandwidthConstraint;
 import org.onosproject.net.resource.ResourceConsumer;
+import org.onosproject.pce.pceservice.ExplicitPathInfo;
 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
 import org.onosproject.pce.pceservice.constraint.CostConstraint;
 import org.onosproject.pce.pceservice.TunnelConsumerId;
@@ -69,9 +71,14 @@
     // List of Failed path info
     private DistributedSet<PcePathInfo> failedPathSet;
 
+    // Maintains tunnel name mapped to explicit path info
+    private ConsistentMap<String, List<ExplicitPathInfo>> tunnelNameExplicitPathInfoMap;
+
     private static final Serializer SERIALIZER = Serializer
             .using(new KryoNamespace.Builder().register(KryoNamespaces.API)
                     .register(PcePathInfo.class)
+                    .register(ExplicitPathInfo.class)
+                    .register(ExplicitPathInfo.Type.class)
                     .register(CostConstraint.class)
                     .register(CostConstraint.Type.class)
                     .register(BandwidthConstraint.class)
@@ -99,6 +106,16 @@
                 .build()
                 .asDistributedSet();
 
+        tunnelNameExplicitPathInfoMap = storageService.<String, List<ExplicitPathInfo>>consistentMapBuilder()
+                .withName("onos-pce-explicitpathinfo")
+                .withSerializer(Serializer.using(
+                        new KryoNamespace.Builder()
+                                .register(KryoNamespaces.API)
+                                .register(ExplicitPathInfo.class)
+                                .register(ExplicitPathInfo.Type.class)
+                                .build()))
+                .build();
+
         log.info("Started");
     }
 
@@ -181,4 +198,21 @@
         }
         return true;
     }
+
+    @Override
+    public boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo) {
+        checkNotNull(tunnelName);
+        checkNotNull(explicitPathInfo);
+        return tunnelNameExplicitPathInfoMap.put(tunnelName, explicitPathInfo) != null ? true : false;
+    }
+
+    @Override
+    public List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName) {
+        checkNotNull(tunnelName);
+        if (tunnelNameExplicitPathInfoMap.get(tunnelName) != null) {
+            return tunnelNameExplicitPathInfoMap.get(tunnelName).value();
+        }
+        return null;
+    }
+
 }
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/PcePathInfo.java b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/PcePathInfo.java
index 3b7b47e..6497e36 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/PcePathInfo.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/PcePathInfo.java
@@ -22,6 +22,7 @@
 
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.intent.Constraint;
+import org.onosproject.pce.pceservice.ExplicitPathInfo;
 import org.onosproject.pce.pceservice.LspType;
 
 /**
@@ -40,6 +41,8 @@
 
     private LspType lspType; // lsp type
 
+    private List<ExplicitPathInfo> explicitPathInfo; //Explicit path info to compute explicit path
+
     /**
      * Initialization of member variables.
      *
@@ -48,17 +51,20 @@
      * @param name tunnel name
      * @param constraints list of constraints
      * @param lspType lsp type
+     * @param explicitPathInfo explicit path info
      */
     public PcePathInfo(DeviceId src,
                     DeviceId dst,
                     String name,
                     List<Constraint> constraints,
-                    LspType lspType) {
+                    LspType lspType,
+                    List<ExplicitPathInfo> explicitPathInfo) {
        this.src = src;
        this.dst = dst;
        this.name = name;
        this.constraints = constraints;
        this.lspType = lspType;
+       this.explicitPathInfo = explicitPathInfo;
     }
 
     /**
@@ -70,6 +76,7 @@
        this.name = null;
        this.constraints = null;
        this.lspType = null;
+       this.explicitPathInfo = null;
     }
 
     /**
@@ -162,9 +169,27 @@
         this.lspType = lspType;
     }
 
+    /**
+     * Returns list of explicit path info.
+     *
+     * @return list of explicit path info
+     */
+    public List<ExplicitPathInfo> explicitPathInfo() {
+        return explicitPathInfo;
+    }
+
+    /**
+     * Sets list of explicit path info.
+     *
+     * @param explicitPathInfo list of explicit path info
+     */
+    public void explicitPathInfo(List<ExplicitPathInfo> explicitPathInfo) {
+        this.explicitPathInfo = explicitPathInfo;
+    }
+
     @Override
     public int hashCode() {
-        return Objects.hash(src, dst, name, constraints, lspType);
+        return Objects.hash(src, dst, name, constraints, lspType, explicitPathInfo);
     }
 
     @Override
@@ -178,7 +203,8 @@
                     Objects.equals(this.dst, other.dst) &&
                     Objects.equals(this.name, other.name) &&
                     Objects.equals(this.constraints, other.constraints) &&
-                    Objects.equals(this.lspType, other.lspType);
+                    Objects.equals(this.lspType, other.lspType) &&
+                    Objects.equals(this.explicitPathInfo, other.explicitPathInfo);
         }
         return false;
     }
@@ -187,11 +213,12 @@
     public String toString() {
         return MoreObjects.toStringHelper(getClass())
                 .omitNullValues()
-                .add("Source", src.toString())
-                .add("Destination", dst.toString())
-                .add("Name", name.toString())
-                .add("Constraints", constraints.toString())
-                .add("LspType", lspType.toString())
+                .add("Source", src)
+                .add("Destination", dst)
+                .add("Name", name)
+                .add("Constraints", constraints)
+                .add("explicitPathInfo", explicitPathInfo)
+                .add("LspType", lspType)
                 .toString();
     }
 }
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/api/PceStore.java b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/api/PceStore.java
index 3fdef15..0a7fa94 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/api/PceStore.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pcestore/api/PceStore.java
@@ -15,8 +15,11 @@
  */
 package org.onosproject.pce.pcestore.api;
 
+import java.util.List;
+
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.net.resource.ResourceConsumer;
+import org.onosproject.pce.pceservice.ExplicitPathInfo;
 import org.onosproject.pce.pcestore.PcePathInfo;
 
 import java.util.Map;
@@ -107,4 +110,21 @@
      * @return success or failure
      */
     boolean removeFailedPathInfo(PcePathInfo failedPathInfo);
+
+    /**
+     * Adds explicit path info to the map with corresponding tunnel name.
+     *
+     * @param tunnelName tunnel name as key
+     * @param explicitPathInfo list of explicit path objects
+     * @return whether it is added to map
+     */
+    boolean tunnelNameExplicitPathInfoMap(String tunnelName, List<ExplicitPathInfo> explicitPathInfo);
+
+    /**
+     * Gets explicit path info based on tunnel name.
+     *
+     * @param tunnelName tunnel name as key
+     * @return list of explicit path info
+     */
+    List<ExplicitPathInfo> getTunnelNameExplicitPathInfoMap(String tunnelName);
 }