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/core/matchaction/IMatchActionService.java b/src/main/java/net/onrc/onos/core/matchaction/IMatchActionService.java
new file mode 100644
index 0000000..9b829a5
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/IMatchActionService.java
@@ -0,0 +1,79 @@
+package net.onrc.onos.core.matchaction;
+
+import java.util.Collection;
+import java.util.EventListener;
+
+import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
+
+/**
+ * An interface for the match-action service.
+ */
+public interface IMatchActionService {
+    /**
+     * Adds a new match-action entry.
+     *
+     * @param matchAction MatchAction object to be added.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean addMatchAction(MatchAction matchAction);
+
+    /**
+     * Removes the existing match-action entry.
+     *
+     * @param id ID for MatchaAction object to be removed.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean removeMatchAction(String id);
+
+    /**
+     * Replaces the existing match-action entry by specified match-action entry.
+     *
+     * @param matchAction MatchAction object which overwrites existing
+     *        match-action.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean updateMatchAction(MatchAction matchAction);
+
+    /**
+     * Gets the set of match-action entries.
+     *
+     * @return The set of match-action entries.
+     */
+    Collection<MatchAction> getMatchActions();
+
+    /**
+     * Executes match-action operation plan.
+     *
+     * @param plan MatchActionPlan to be executed.
+     * @return true if succeeded, false otherwise.
+     */
+    boolean executePlan(MatchActionPlan plan);
+
+    /**
+     * 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/core/matchaction/MatchAction.java b/src/main/java/net/onrc/onos/core/matchaction/MatchAction.java
new file mode 100644
index 0000000..2f21baf
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchAction.java
@@ -0,0 +1,97 @@
+package net.onrc.onos.core.matchaction;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
+import net.onrc.onos.core.matchaction.action.IAction;
+import net.onrc.onos.core.matchaction.action.OutputAction;
+import net.onrc.onos.core.matchaction.match.IMatch;
+import net.onrc.onos.core.matchaction.match.PacketMatch;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.IPv4;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+/**
+ * A filter and actions for traffic.
+ */
+public class MatchAction implements IBatchOperationTarget {
+    protected String id;
+    protected SwitchPort port;
+    protected List<IMatch> matches;
+    protected List<IAction> actions;
+
+    /**
+     * Constructor.
+     *
+     * @param id ID for this MatchAction object.
+     * @param port Switch DPID
+     * @param matches The list of IMatch objects as match condition on the port.
+     * @param actions The list of IAction objects as actions on the switch.
+     */
+    public MatchAction(String id, SwitchPort port, List<IMatch> matches,
+            List<IAction> actions) {
+        this.id = id;
+        this.port = port;
+        this.matches = matches;
+        this.actions = actions;
+    }
+
+    /**
+     * Constructor.
+     * <p>
+     * MEMO: This is a sample constructor to create a packet layer match action.
+     *
+     * @param id ID for this MatchAction object.
+     * @param dpid Switch DPID
+     * @param srcPort Source Port
+     * @param srcMac Source Host MAC Address
+     * @param dstMac Destination Host MAC Address
+     * @param srcIp Source IP Address
+     * @param dstIp Destination IP Address
+     * @param dstPort Destination Port
+     */
+    // CHECKSTYLE:OFF suppress the warning about too many parameters
+    public MatchAction(String id, Dpid dpid, PortNumber srcPort,
+            MACAddress srcMac, MACAddress dstMac,
+            IPv4 srcIp, IPv4 dstIp, PortNumber dstPort) {
+        // CHECKSTYLE:ON
+        this(id, new SwitchPort(dpid, srcPort),
+                Arrays.asList((IMatch) new PacketMatch(srcMac, dstMac, srcIp, dstIp)),
+                Arrays.asList((IAction) new OutputAction(dstPort)));
+    }
+
+    @Override
+    public String getId() {
+        return id;
+    }
+
+    /**
+     * Gets the switch-port which is the target of this match-action.
+     *
+     * @return The target switch-port of this match-action.
+     */
+    public SwitchPort getSwitchPort() {
+        return port;
+    }
+
+    /**
+     * Gets the traffic filter of the match-action.
+     *
+     * @return The traffic filter.
+     */
+    public List<IMatch> getMatches() {
+        return matches;
+    }
+
+    /**
+     * Gets the list of actions of the match-action.
+     *
+     * @return The list of actions.
+     */
+    public List<IAction> getActions() {
+        return actions;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
new file mode 100644
index 0000000..e0957f0
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
@@ -0,0 +1,78 @@
+package net.onrc.onos.core.matchaction;
+
+import java.util.Collection;
+import java.util.EventListener;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
+
+/**
+ * Manages Match-Action entries.
+ * <p>
+ * TODO: Make all methods thread-safe
+ */
+public class MatchActionModule implements IMatchActionService {
+
+    @Override
+    public boolean addMatchAction(MatchAction matchAction) {
+        BatchOperation<MatchAction> phase = new BatchOperation<MatchAction>();
+        phase.addAddOperation(matchAction);
+        MatchActionPlan plan = new MatchActionPlan();
+        plan.addPhase(phase);
+        return executePlan(plan);
+    }
+
+    @Override
+    public boolean removeMatchAction(String id) {
+        BatchOperation<MatchAction> phase = new BatchOperation<MatchAction>();
+        phase.addRemoveOperation(id);
+        MatchActionPlan plan = new MatchActionPlan();
+        plan.addPhase(phase);
+        return executePlan(plan);
+    }
+
+    @Override
+    public boolean updateMatchAction(MatchAction matchAction) {
+        BatchOperation<MatchAction> phase = new BatchOperation<MatchAction>();
+        phase.addUpdateOperation(matchAction.getId(), matchAction);
+        MatchActionPlan plan = new MatchActionPlan();
+        plan.addPhase(phase);
+        return executePlan(plan);
+    }
+
+    @Override
+    public Collection<MatchAction> getMatchActions() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean executePlan(MatchActionPlan plan) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public void setConflictDetectionPolicy(ConflictDetectionPolicy policy) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public ConflictDetectionPolicy getConflictDetectionPolicy() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void addEventListener(EventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void removeEventListener(EventListener listener) {
+        // TODO Auto-generated method stub
+
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionPlan.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionPlan.java
new file mode 100644
index 0000000..c48dce2
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionPlan.java
@@ -0,0 +1,43 @@
+package net.onrc.onos.core.matchaction;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+
+/**
+ * A match-action plan to be executed on the match-action module.
+ * <p>
+ * The plan is a list of phases, and the phase is a batch operation of
+ * match-actions.
+ */
+public class MatchActionPlan {
+    List<BatchOperation<MatchAction>> phases;
+
+    /**
+     * Constructor.
+     */
+    public MatchActionPlan() {
+        phases = new LinkedList<BatchOperation<MatchAction>>();
+    }
+
+    /**
+     * Adds the specified phase to the plan.
+     *
+     * @param phase The batch operation of match-actions to be added to the
+     *        plan.
+     */
+    public void addPhase(BatchOperation<MatchAction> phase) {
+        phases.add(phase);
+    }
+
+    /**
+     * Gets the list of phases of the plan.
+     *
+     * @return The list of phases, batch operations of match-actions.
+     */
+    public List<BatchOperation<MatchAction>> getPhases() {
+        return Collections.unmodifiableList(phases);
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/action/IAction.java b/src/main/java/net/onrc/onos/core/matchaction/action/IAction.java
new file mode 100644
index 0000000..b381f85
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/action/IAction.java
@@ -0,0 +1,8 @@
+package net.onrc.onos.core.matchaction.action;
+
+/**
+ * An interface of action objects.
+ */
+public interface IAction {
+
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/action/ModifyLambdaAction.java b/src/main/java/net/onrc/onos/core/matchaction/action/ModifyLambdaAction.java
new file mode 100644
index 0000000..ee5cdb2
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/action/ModifyLambdaAction.java
@@ -0,0 +1,30 @@
+package net.onrc.onos.core.matchaction.action;
+
+/**
+ * An action object to modify lambda.
+ * <p>
+ * This class does not have a switch ID. The switch ID is handled by
+ * MatchAction, IFlow or Intent class.
+ */
+public class ModifyLambdaAction implements IAction {
+    protected int lambda;
+
+    /**
+     * Constructor.
+     *
+     * @param dstPort Destination port number
+     */
+    public ModifyLambdaAction(int lambda) {
+        this.lambda = lambda;
+    }
+
+    /**
+     * Gets the lambda.
+     *
+     * @return The lambda.
+     */
+    public int getLambda() {
+        return lambda;
+    }
+
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/action/OutputAction.java b/src/main/java/net/onrc/onos/core/matchaction/action/OutputAction.java
new file mode 100644
index 0000000..f570ea8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/action/OutputAction.java
@@ -0,0 +1,31 @@
+package net.onrc.onos.core.matchaction.action;
+
+import net.onrc.onos.core.util.PortNumber;
+
+/**
+ * An action object to output traffic to specified port.
+ * <p>
+ * This class does not have a switch ID. The switch ID is handled by
+ * MatchAction, IFlow or Intent class.
+ */
+public class OutputAction implements IAction {
+    protected PortNumber portNumber;
+
+    /**
+     * Constructor.
+     *
+     * @param dstPort The port number of the target output port.
+     */
+    public OutputAction(PortNumber dstPort) {
+        this.portNumber = dstPort;
+    }
+
+    /**
+     * Gets the port number of the target output port.
+     *
+     * @return The port number of the target output port.
+     */
+    public PortNumber getPortNumber() {
+        return portNumber;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/match/IMatch.java b/src/main/java/net/onrc/onos/core/matchaction/match/IMatch.java
new file mode 100644
index 0000000..904e337
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/match/IMatch.java
@@ -0,0 +1,8 @@
+package net.onrc.onos.core.matchaction.match;
+
+/**
+ * An interface for match objects.
+ */
+public interface IMatch {
+
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/match/OpticalMatch.java b/src/main/java/net/onrc/onos/core/matchaction/match/OpticalMatch.java
new file mode 100644
index 0000000..00bae0e
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/match/OpticalMatch.java
@@ -0,0 +1,39 @@
+package net.onrc.onos.core.matchaction.match;
+
+/**
+ * A match object (traffic specifier) for optical nodes, flow-paths and intents.
+ * <p>
+ * This class does not have a switch ID and a port number. They are handled by
+ * MatchAction, IFlow or Intent class.
+ */
+public class OpticalMatch implements IMatch {
+
+    // Match fields
+    protected Integer srcLambda;
+
+    /**
+     * Constructor.
+     */
+    public OpticalMatch() {
+        this(null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param srcLambda The source lambda. Null means the wild-card for the
+     *        lambda.
+     */
+    public OpticalMatch(Integer srcLambda) {
+        this.srcLambda = srcLambda;
+    }
+
+    /**
+     * Gets the source lambda.
+     *
+     * @return The source lambda, or null if it was wild-card.
+     */
+    public Integer getSrcLambda() {
+        return srcLambda;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/core/matchaction/match/PacketMatch.java b/src/main/java/net/onrc/onos/core/matchaction/match/PacketMatch.java
new file mode 100644
index 0000000..0a6caff
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/matchaction/match/PacketMatch.java
@@ -0,0 +1,78 @@
+package net.onrc.onos.core.matchaction.match;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.IPv4;
+
+/**
+ * A match object (traffic specifier) for packet nodes, flow-paths and intents.
+ * <p>
+ * This class does not have a switch ID and a port number. They are handled by
+ * MatchAction, IFlow or Intent class.
+ */
+public class PacketMatch implements IMatch {
+
+    // Match fields
+    protected MACAddress srcMacAddress;
+    protected MACAddress dstMacAddress;
+    protected IPv4 srcIpAddress;
+    protected IPv4 dstIpAddress;
+
+    /**
+     * Constructor.
+     */
+    public PacketMatch() {
+        this(null, null, null, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param srcMac Source Host MAC Address
+     * @param dstMac Destination Host MAC Address
+     * @param srcIp Source IP Address
+     * @param dstIp Destination IP Address
+     */
+    public PacketMatch(MACAddress srcMac, MACAddress dstMac,
+            IPv4 srcIp, IPv4 dstIp) {
+        this.srcMacAddress = srcMac;
+        this.dstMacAddress = dstMac;
+        this.srcIpAddress = srcIp;
+        this.dstIpAddress = dstIp;
+    }
+
+    /**
+     * Gets the source host MAC address.
+     *
+     * @return The source host MAC address.
+     */
+    public MACAddress getSrcMacAddress() {
+        return srcMacAddress;
+    }
+
+    /**
+     * Gets the destination host MAC address.
+     *
+     * @return The destination host MAC address.
+     */
+    public MACAddress getDstMacAddress() {
+        return dstMacAddress;
+    }
+
+    /**
+     * Gets the source host IP address.
+     *
+     * @return The source host IP address.
+     */
+    public IPv4 getSrcIpAddress() {
+        return srcIpAddress;
+    }
+
+    /**
+     * Gets the destination host IP address.
+     *
+     * @return The destination host IP address.
+     */
+    public IPv4 getDstIpAddress() {
+        return dstIpAddress;
+    }
+}