Support to specify table id when insert Flow Rule through REST API

Change-Id: I5ac45403a3f8b454ddfd873556e398b45f82842e
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java
index 6c02841..b764489 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/FlowRuleCodec.java
@@ -15,6 +15,8 @@
  */
 package org.onosproject.codec.impl;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.onosproject.codec.CodecContext;
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.core.CoreService;
@@ -24,8 +26,6 @@
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
 import static org.onlab.util.Tools.nullIsIllegal;
 
 /**
@@ -36,6 +36,7 @@
     private static final String PRIORITY = "priority";
     private static final String TIMEOUT = "timeout";
     private static final String IS_PERMANENT = "isPermanent";
+    private static final String TABLE_ID = "tableId";
     private static final String DEVICE_ID = "deviceId";
     private static final String TREATMENT = "treatment";
     private static final String SELECTOR = "selector";
@@ -71,6 +72,11 @@
                             + " if the flow is temporary").asInt());
         }
 
+        JsonNode tableIdJson = json.get(TABLE_ID);
+        if (tableIdJson != null) {
+            resultBuilder.forTable(tableIdJson.asInt());
+        }
+
         DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID),
                 DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
         resultBuilder.forDevice(deviceId);
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java
index 2a5ba24..ae1abf1 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java
@@ -15,20 +15,8 @@
  */
 package org.onosproject.codec.impl;
 
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onosproject.net.NetTestTools.APP_ID;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.EthType;
@@ -83,8 +71,19 @@
 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
 import org.onosproject.net.flow.instructions.L4ModificationInstruction;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onosproject.net.NetTestTools.APP_ID;
 
 /**
  * Flow rule codec unit tests.
@@ -139,6 +138,7 @@
         assertThat(rule.isPermanent(), is(false));
         assertThat(rule.timeout(), is(1));
         assertThat(rule.priority(), is(1));
+        assertThat(rule.tableId(), is(1));
         assertThat(rule.deviceId().toString(), is("of:0000000000000001"));
     }
 
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/criteria-flow.json b/core/common/src/test/resources/org/onosproject/codec/impl/criteria-flow.json
index 82c0f59..0e8cfbc 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/criteria-flow.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/criteria-flow.json
@@ -3,6 +3,7 @@
   "isPermanent":"false",
   "timeout":1,
   "deviceId":"of:0000000000000001",
+  "tableId": 1,
   "selector":
       {"criteria":
           [
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/instructions-flow.json b/core/common/src/test/resources/org/onosproject/codec/impl/instructions-flow.json
index fb3c03b..14ef6f3 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/instructions-flow.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/instructions-flow.json
@@ -3,6 +3,7 @@
   "isPermanent":"false",
   "timeout":1,
   "deviceId":"of:0000000000000001",
+  "tableId": 1,
   "treatment":
   {
       "instructions":
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/sigid-flow.json b/core/common/src/test/resources/org/onosproject/codec/impl/sigid-flow.json
index 49d6b1c..f818814 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/sigid-flow.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/sigid-flow.json
@@ -3,6 +3,7 @@
   "isPermanent":"false",
   "timeout":1,
   "deviceId":"of:0000000000000001",
+  "tableId": 1,
   "selector":
   {"criteria":
   [
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/simple-flow.json b/core/common/src/test/resources/org/onosproject/codec/impl/simple-flow.json
index dc241f5..1575dbc 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/simple-flow.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/simple-flow.json
@@ -1,12 +1,24 @@
 {
-   "priority":1,
-   "isPermanent":"false",
-   "timeout":1,
-   "deviceId":"of:0000000000000001",
-   "treatment":
-      {"instructions":
-         [{"type":"OUTPUT","port":-3}],"deferred":[]},
-   "selector":
-      {"criteria":
-         [{"type":"ETH_TYPE","ethType":2054}]}
+  "priority": 1,
+  "isPermanent": "false",
+  "timeout": 1,
+  "deviceId": "of:0000000000000001",
+  "tableId": 1,
+  "treatment": {
+    "instructions": [
+      {
+        "type": "OUTPUT",
+        "port": -3
+      }
+    ],
+    "deferred": []
+  },
+  "selector": {
+    "criteria": [
+      {
+        "type": "ETH_TYPE",
+        "ethType": 2054
+      }
+    ]
+  }
 }