Skeletons for Intent-runtime, Flow-manager and Match-action modules.

This task is a part of ONOS-1395.
(Sub-tasks: ONOS-1397, ONOS-1398, ONOS-1400)

Change-Id: I30064f658b6c193aee8419079dad380163364475
diff --git a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
new file mode 100644
index 0000000..5e9ed52
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
@@ -0,0 +1,112 @@
+package net.onrc.onos.api.intent;
+
+import java.util.Collection;
+import java.util.EventListener;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
+import net.onrc.onos.api.flowmanager.IFlow;
+
+/**
+ * An interface class for the Intent-Runtime Service. The role of the
+ * Intent-Runtime Service is to manage a set of IFlow objects based on the
+ * specified Intent objects.
+ * <p>
+ * It compiles accepted Intents to IFlow objects by allocating resources and
+ * calculating paths based on the constrains described in the Intents, and
+ * executes installation/uninstallation of the IFlow objects using FlowManager
+ * Service.
+ */
+public interface IIntentRuntimeService {
+    /**
+     * Adds specified intent.
+     *
+     * @param intent Intent to be added.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean addIntent(Intent intent);
+
+    /**
+     * Removes specified intent.
+     *
+     * @param id ID of the intent to be removed.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean removeIntent(String id);
+
+    /**
+     * Overwrites existing intent by new specified intent.
+     *
+     * @param id ID of the existing intent to be overwritten.
+     * @param intent The new intent to be added.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean updateIntent(String id, Intent intent);
+
+    /**
+     * Gets specific intent.
+     *
+     * @param id ID of the intent should be retrieved
+     * @return Intent if it exists, null otherwise.
+     */
+    Intent getIntent(String id);
+
+    /**
+     * Gets all intents.
+     *
+     * @return collection of intents.
+     */
+    Collection<Intent> getIntents();
+
+    /**
+     * Executes batch operation of intents.
+     *
+     * @param ops BatchOperations to be executed.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean executeBatch(BatchOperation<Intent> ops);
+
+    /**
+     * Gets IFlow objects managed by the specified intent.
+     *
+     * @param intentId ID of the target Intent.
+     * @return Collection of IFlow objects if exists, null otherwise.
+     */
+    Collection<IFlow> getFlows(String intentId);
+
+    /**
+     * Gets Intent object which manages the specified IFlow object.
+     *
+     * @param flowId ID of the target IFlow object.
+     * @return Intent which manages the specified IFlow object, null otherwise.
+     */
+    Intent getIntentByFlow(String flowId);
+
+    /**
+     * Sets a conflict detection policy.
+     *
+     * @param policy ConflictDetectionPolicy object to be set.
+     */
+    void setConflictDetectionPolicy(ConflictDetectionPolicy policy);
+
+    /**
+     * Gets the conflict detection policy.
+     *
+     * @return ConflictDetectionPolicy object being applied currently.
+     */
+    ConflictDetectionPolicy getConflictDetectionPolicy();
+
+    /**
+     * Adds event listener to this service.
+     *
+     * @param listener EventListener to be added.
+     */
+    void addEventListener(EventListener listener);
+
+    /**
+     * Removes event listener from this service.
+     *
+     * @param listener EventListener to be removed.
+     */
+    void removeEventListener(EventListener listener);
+}
diff --git a/src/main/java/net/onrc/onos/api/intent/Intent.java b/src/main/java/net/onrc/onos/api/intent/Intent.java
new file mode 100644
index 0000000..93d6459
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/Intent.java
@@ -0,0 +1,53 @@
+package net.onrc.onos.api.intent;
+
+import java.util.List;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
+import net.onrc.onos.api.flowmanager.IFlow;
+
+/**
+ * The base class for the connectivity abstraction. It allows applications to
+ * specify end hosts, apply some basic filtering to traffic, and constrain
+ * traffic.
+ * <p>
+ * This class is sub-classed to provide other intent types like shortest path
+ * connectivity and bandwidth constrained shortest path connectivity.
+ * <p>
+ * The reasoning behind "intent" is that the applications can provide some
+ * abstract representation of how traffic should flow be handled by the
+ * networking, allowing the network OS to compile, reserve and optimize the
+ * data-plane to satisfy those constraints.
+ */
+public abstract class Intent implements IBatchOperationTarget {
+    protected String id;
+
+    /**
+     * Constructor.
+     *
+     * @param id ID for this Intent object.
+     */
+    public Intent(String id) {
+        this.id = id;
+    }
+
+    /**
+     * Gets ID for this Intent object.
+     *
+     * @return ID for this Intent object.
+     */
+    @Override
+    public String getId() {
+        return id;
+    }
+
+    /**
+     * Compiles this Intent object to the list of FlowOperations.
+     * <p>
+     * All Intent object must implement this method and IntentRuntimeModule use
+     * this method to process this Intent.
+     *
+     * @return The list of FlowOperations of this Intent.
+     */
+    public abstract List<BatchOperation<IFlow>> compile();
+}
diff --git a/src/main/java/net/onrc/onos/api/intent/OpticalConnectivityIntent.java b/src/main/java/net/onrc/onos/api/intent/OpticalConnectivityIntent.java
new file mode 100644
index 0000000..89f6208
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/OpticalConnectivityIntent.java
@@ -0,0 +1,58 @@
+package net.onrc.onos.api.intent;
+
+import java.util.List;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.flowmanager.IFlow;
+import net.onrc.onos.core.util.SwitchPort;
+
+/**
+ * An optical layer Intent for a connectivity from a transponder port to another
+ * transponder port.
+ * <p>
+ * This class doesn't accepts lambda specifier. This class computes path between
+ * ports and assign lambda automatically. The lambda can be specified using
+ * OpticalPathFlow class.
+ */
+public class OpticalConnectivityIntent extends Intent {
+    protected SwitchPort srcSwitchPort;
+    protected SwitchPort dstSwitchPort;
+
+    /**
+     * Constructor.
+     *
+     * @param id ID for this new Intent object.
+     * @param srcSwitchPort The source transponder port.
+     * @param dstSwitchPort The destination transponder port.
+     */
+    public OpticalConnectivityIntent(String id,
+            SwitchPort srcSwitchPort, SwitchPort dstSwitchPort) {
+        super(id);
+        this.srcSwitchPort = srcSwitchPort;
+        this.dstSwitchPort = dstSwitchPort;
+    }
+
+    /**
+     * Gets source transponder port.
+     *
+     * @return The source transponder port.
+     */
+    public SwitchPort getSrcSwitchPort() {
+        return srcSwitchPort;
+    }
+
+    /**
+     * Gets destination transponder port.
+     *
+     * @return The source transponder port.
+     */
+    public SwitchPort getDstSwitchPort() {
+        return dstSwitchPort;
+    }
+
+    @Override
+    public List<BatchOperation<IFlow>> compile() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/api/intent/PacketConnectivityIntent.java b/src/main/java/net/onrc/onos/api/intent/PacketConnectivityIntent.java
new file mode 100644
index 0000000..99660c8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/PacketConnectivityIntent.java
@@ -0,0 +1,172 @@
+package net.onrc.onos.api.intent;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.flowmanager.IFlow;
+import net.onrc.onos.core.matchaction.match.PacketMatch;
+import net.onrc.onos.core.util.SwitchPort;
+
+/**
+ * A packet layer Intent for a connectivity from a set of ports to a set of
+ * ports.
+ * <p>
+ * TODO: Design methods to support the ReactiveForwarding and the SDN-IP. <br>
+ * NOTE: Should this class support modifier methods? Should this object a
+ * read-only object?
+ */
+public class PacketConnectivityIntent extends Intent {
+    protected Set<SwitchPort> srcSwitchPorts;
+    protected PacketMatch match;
+    protected Set<SwitchPort> dstSwitchPorts;
+    protected boolean canSetupOpticalFlow;
+    protected int idleTimeoutValue;
+    protected int hardTimeoutValue;
+
+    /**
+     * Creates a connectivity intent for the packet layer.
+     * <p>
+     * When the "canSetupOpticalFlow" option is true, this intent will compute
+     * the packet/optical converged path, decompose it to the OpticalPathFlow
+     * and the PacketPathFlow objects, and execute the operations to add them
+     * considering the dependency between the packet and optical layers.
+     *
+     * @param id ID for this new Intent object.
+     * @param srcSwitchPorts The set of source switch ports.
+     * @param match Traffic specifier for this object.
+     * @param dstSwitchPorts The set of destination switch ports.
+     * @param canSetupOpticalFlow The flag whether this intent can create
+     *        optical flows if needed.
+     */
+    public PacketConnectivityIntent(String id,
+            Collection<SwitchPort> srcSwitchPorts, PacketMatch match,
+            Collection<SwitchPort> dstSwitchPorts, boolean canSetupOpticalFlow) {
+        super(id);
+        this.srcSwitchPorts = new HashSet<SwitchPort>(srcSwitchPorts);
+        this.match = match;
+        this.dstSwitchPorts = new HashSet<SwitchPort>(dstSwitchPorts);
+        this.canSetupOpticalFlow = canSetupOpticalFlow;
+        this.idleTimeoutValue = 0;
+        this.hardTimeoutValue = 0;
+
+        // TODO: check consistency between these parameters.
+    }
+
+    /**
+     * Gets the set of source switch ports.
+     *
+     * @return the set of source switch ports.
+     */
+    public Collection<SwitchPort> getSrcSwitchPorts() {
+        return Collections.unmodifiableCollection(srcSwitchPorts);
+    }
+
+    /**
+     * Gets the traffic specifier.
+     *
+     * @return The traffic specifier.
+     */
+    public PacketMatch getMatch() {
+        return match;
+    }
+
+    /**
+     * Gets the set of destination switch ports.
+     *
+     * @return the set of destination switch ports.
+     */
+    public Collection<SwitchPort> getDstSwitchPorts() {
+        return Collections.unmodifiableCollection(dstSwitchPorts);
+    }
+
+    /**
+     * Adds the specified port to the set of source ports.
+     *
+     * @param port SwitchPort object to be added
+     */
+    public void addSrcSwitchPort(SwitchPort port) {
+        // TODO implement it.
+    }
+
+    /**
+     * Adds the specified port to the set of destination ports.
+     *
+     * @param port SwitchPort object to be added
+     */
+    public void addDstSwitchPort(SwitchPort port) {
+        // TODO implement it.
+    }
+
+    /**
+     * Removes the specified port from the set of source ports.
+     *
+     * @param port SwitchPort object to be removed
+     */
+    public void removeSrcSwitchPort(SwitchPort port) {
+        // TODO implement it.
+    }
+
+    /**
+     * Removes the specified port from the set of destination ports.
+     *
+     * @param port SwitchPort object to be removed
+     */
+    public void removeDstSwitchPort(SwitchPort port) {
+        // TODO implement it.
+    }
+
+    /**
+     * Sets idle-timeout value.
+     *
+     * @param timeout Idle-timeout value (seconds)
+     */
+    public void setIdleTimeout(int timeout) {
+        idleTimeoutValue = timeout;
+    }
+
+    /**
+     * Sets hard-timeout value.
+     *
+     * @param timeout Hard-timeout value (seconds)
+     */
+    public void setHardTimeout(int timeout) {
+        hardTimeoutValue = timeout;
+    }
+
+    /**
+     * Gets idle-timeout value.
+     *
+     * @return Idle-timeout value (seconds)
+     */
+    public int getIdleTimeout() {
+        return idleTimeoutValue;
+    }
+
+    /**
+     * Gets hard-timeout value.
+     *
+     * @return Hard-timeout value (seconds)
+     */
+    public int getHardTimeout() {
+        return hardTimeoutValue;
+    }
+
+    /**
+     * Returns whether this intent can create optical flows if needed.
+     *
+     * @return whether this intent can create optical flows.
+     */
+    public boolean canSetupOpticalFlow() {
+        return canSetupOpticalFlow;
+    }
+
+    @Override
+    public List<BatchOperation<IFlow>> compile() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}