Add a new method sendMsg(OFMessage msg, TableType type) in OpenFlowSwitch interface to support multiple-table aware FlowRuleService.
  Other changes are caused due to the new method.
Add type() in FlowRule interface to determine the table in which the flow rule need to be set.

Change-Id: I6518a01f4a5fba23f09f70b619f3844b5e33ce8f
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
index c83c156..e555794 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
@@ -40,6 +40,8 @@
     private final boolean permanent;
     private final GroupId groupId;
 
+    private final Type type;
+
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
             TrafficTreatment treatment, int priority, long flowId,
@@ -55,12 +57,42 @@
         this.appId = (short) (flowId >>> 48);
         this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
         this.id = FlowId.valueOf(flowId);
+        this.type = Type.DEFAULT;
     }
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
                            TrafficTreatment treatment, int priority, ApplicationId appId,
                            int timeout, boolean permanent) {
-        this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0), timeout, permanent);
+        this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0),
+                timeout, permanent);
+    }
+
+    public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
+                           TrafficTreatment treatment, int priority, ApplicationId appId,
+                           int timeout, boolean permanent, Type type) {
+
+        if (priority < FlowRule.MIN_PRIORITY) {
+            throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY);
+        }
+
+        this.deviceId = deviceId;
+        this.priority = priority;
+        this.selector = selector;
+        this.treatment = treatment;
+        this.appId = appId.id();
+        this.groupId = new DefaultGroupId(0);
+        this.timeout = timeout;
+        this.permanent = permanent;
+        this.created = System.currentTimeMillis();
+        this.type = type;
+
+        /*
+         * id consists of the following.
+         * | appId (16 bits) | groupId (16 bits) | flowId (32 bits) |
+         */
+        this.id = FlowId.valueOf((((long) this.appId) << 48) | (((long) this.groupId.id()) << 32)
+                | (this.hash() & 0xffffffffL));
+
     }
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
@@ -80,6 +112,7 @@
         this.timeout = timeout;
         this.permanent = permanent;
         this.created = System.currentTimeMillis();
+        this.type = Type.DEFAULT;
 
         /*
          * id consists of the following.
@@ -100,10 +133,10 @@
         this.timeout = rule.timeout();
         this.permanent = rule.isPermanent();
         this.created = System.currentTimeMillis();
+        this.type = rule.type();
 
     }
 
-
     @Override
     public FlowId id() {
         return id;
@@ -198,4 +231,9 @@
         return permanent;
     }
 
+    @Override
+    public Type type() {
+        return type;
+    }
+
 }
diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java b/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java
index 0a13d40..b03f620 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/FlowRule.java
@@ -27,6 +27,22 @@
     static final int MAX_TIMEOUT = 60;
     static final int MIN_PRIORITY = 0;
 
+    /**
+     * The FlowRule type is used to determine in which table the flow rule
+     * needs to be put for multi-table support switch.
+     * For single table switch, Default is used.
+     */
+    public static enum Type {
+        /* Default type - used in flow rule for single table switch */
+        DEFAULT,
+        /* Used in flow entry for IP table */
+        IP,
+        /* Used in flow entry for MPLS table */
+        MPLS,
+        /* Used in flow entry for ACL table */
+        ACL
+    }
+
     //TODO: build cookie value
     /**
      * Returns the ID of this flow.
@@ -93,4 +109,11 @@
      */
     boolean isPermanent();
 
+    /**
+     * Returns the flow rule type.
+     *
+     * @return flow rule type
+     */
+    Type type();
+
 }