Jian Li
Committed by Gerrit Code Review

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

Change-Id: I5ac45403a3f8b454ddfd873556e398b45f82842e
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.codec.impl; 16 package org.onosproject.codec.impl;
17 17
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
18 import org.onosproject.codec.CodecContext; 20 import org.onosproject.codec.CodecContext;
19 import org.onosproject.codec.JsonCodec; 21 import org.onosproject.codec.JsonCodec;
20 import org.onosproject.core.CoreService; 22 import org.onosproject.core.CoreService;
...@@ -24,8 +26,6 @@ import org.onosproject.net.flow.FlowRule; ...@@ -24,8 +26,6 @@ import org.onosproject.net.flow.FlowRule;
24 import org.onosproject.net.flow.TrafficSelector; 26 import org.onosproject.net.flow.TrafficSelector;
25 import org.onosproject.net.flow.TrafficTreatment; 27 import org.onosproject.net.flow.TrafficTreatment;
26 28
27 -import com.fasterxml.jackson.databind.node.ObjectNode;
28 -
29 import static org.onlab.util.Tools.nullIsIllegal; 29 import static org.onlab.util.Tools.nullIsIllegal;
30 30
31 /** 31 /**
...@@ -36,6 +36,7 @@ public final class FlowRuleCodec extends JsonCodec<FlowRule> { ...@@ -36,6 +36,7 @@ public final class FlowRuleCodec extends JsonCodec<FlowRule> {
36 private static final String PRIORITY = "priority"; 36 private static final String PRIORITY = "priority";
37 private static final String TIMEOUT = "timeout"; 37 private static final String TIMEOUT = "timeout";
38 private static final String IS_PERMANENT = "isPermanent"; 38 private static final String IS_PERMANENT = "isPermanent";
39 + private static final String TABLE_ID = "tableId";
39 private static final String DEVICE_ID = "deviceId"; 40 private static final String DEVICE_ID = "deviceId";
40 private static final String TREATMENT = "treatment"; 41 private static final String TREATMENT = "treatment";
41 private static final String SELECTOR = "selector"; 42 private static final String SELECTOR = "selector";
...@@ -71,6 +72,11 @@ public final class FlowRuleCodec extends JsonCodec<FlowRule> { ...@@ -71,6 +72,11 @@ public final class FlowRuleCodec extends JsonCodec<FlowRule> {
71 + " if the flow is temporary").asInt()); 72 + " if the flow is temporary").asInt());
72 } 73 }
73 74
75 + JsonNode tableIdJson = json.get(TABLE_ID);
76 + if (tableIdJson != null) {
77 + resultBuilder.forTable(tableIdJson.asInt());
78 + }
79 +
74 DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), 80 DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID),
75 DEVICE_ID + MISSING_MEMBER_MESSAGE).asText()); 81 DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
76 resultBuilder.forDevice(deviceId); 82 resultBuilder.forDevice(deviceId);
......
...@@ -15,20 +15,8 @@ ...@@ -15,20 +15,8 @@
15 */ 15 */
16 package org.onosproject.codec.impl; 16 package org.onosproject.codec.impl;
17 17
18 -import static org.easymock.EasyMock.createMock; 18 +import com.fasterxml.jackson.databind.JsonNode;
19 -import static org.easymock.EasyMock.expect; 19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 -import static org.easymock.EasyMock.replay;
21 -import static org.hamcrest.MatcherAssert.assertThat;
22 -import static org.hamcrest.Matchers.instanceOf;
23 -import static org.hamcrest.Matchers.is;
24 -import static org.hamcrest.Matchers.notNullValue;
25 -import static org.onosproject.net.NetTestTools.APP_ID;
26 -
27 -import java.io.IOException;
28 -import java.io.InputStream;
29 -import java.util.SortedMap;
30 -import java.util.TreeMap;
31 -
32 import org.junit.Before; 20 import org.junit.Before;
33 import org.junit.Test; 21 import org.junit.Test;
34 import org.onlab.packet.EthType; 22 import org.onlab.packet.EthType;
...@@ -83,8 +71,19 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction; ...@@ -83,8 +71,19 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction;
83 import org.onosproject.net.flow.instructions.L3ModificationInstruction; 71 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
84 import org.onosproject.net.flow.instructions.L4ModificationInstruction; 72 import org.onosproject.net.flow.instructions.L4ModificationInstruction;
85 73
86 -import com.fasterxml.jackson.databind.JsonNode; 74 +import java.io.IOException;
87 -import com.fasterxml.jackson.databind.node.ObjectNode; 75 +import java.io.InputStream;
76 +import java.util.SortedMap;
77 +import java.util.TreeMap;
78 +
79 +import static org.easymock.EasyMock.createMock;
80 +import static org.easymock.EasyMock.expect;
81 +import static org.easymock.EasyMock.replay;
82 +import static org.hamcrest.MatcherAssert.assertThat;
83 +import static org.hamcrest.Matchers.instanceOf;
84 +import static org.hamcrest.Matchers.is;
85 +import static org.hamcrest.Matchers.notNullValue;
86 +import static org.onosproject.net.NetTestTools.APP_ID;
88 87
89 /** 88 /**
90 * Flow rule codec unit tests. 89 * Flow rule codec unit tests.
...@@ -139,6 +138,7 @@ public class FlowRuleCodecTest { ...@@ -139,6 +138,7 @@ public class FlowRuleCodecTest {
139 assertThat(rule.isPermanent(), is(false)); 138 assertThat(rule.isPermanent(), is(false));
140 assertThat(rule.timeout(), is(1)); 139 assertThat(rule.timeout(), is(1));
141 assertThat(rule.priority(), is(1)); 140 assertThat(rule.priority(), is(1));
141 + assertThat(rule.tableId(), is(1));
142 assertThat(rule.deviceId().toString(), is("of:0000000000000001")); 142 assertThat(rule.deviceId().toString(), is("of:0000000000000001"));
143 } 143 }
144 144
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
3 "isPermanent":"false", 3 "isPermanent":"false",
4 "timeout":1, 4 "timeout":1,
5 "deviceId":"of:0000000000000001", 5 "deviceId":"of:0000000000000001",
6 + "tableId": 1,
6 "selector": 7 "selector":
7 {"criteria": 8 {"criteria":
8 [ 9 [
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
3 "isPermanent":"false", 3 "isPermanent":"false",
4 "timeout":1, 4 "timeout":1,
5 "deviceId":"of:0000000000000001", 5 "deviceId":"of:0000000000000001",
6 + "tableId": 1,
6 "treatment": 7 "treatment":
7 { 8 {
8 "instructions": 9 "instructions":
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
3 "isPermanent":"false", 3 "isPermanent":"false",
4 "timeout":1, 4 "timeout":1,
5 "deviceId":"of:0000000000000001", 5 "deviceId":"of:0000000000000001",
6 + "tableId": 1,
6 "selector": 7 "selector":
7 {"criteria": 8 {"criteria":
8 [ 9 [
......
1 { 1 {
2 - "priority":1, 2 + "priority": 1,
3 - "isPermanent":"false", 3 + "isPermanent": "false",
4 - "timeout":1, 4 + "timeout": 1,
5 - "deviceId":"of:0000000000000001", 5 + "deviceId": "of:0000000000000001",
6 - "treatment": 6 + "tableId": 1,
7 - {"instructions": 7 + "treatment": {
8 - [{"type":"OUTPUT","port":-3}],"deferred":[]}, 8 + "instructions": [
9 - "selector": 9 + {
10 - {"criteria": 10 + "type": "OUTPUT",
11 - [{"type":"ETH_TYPE","ethType":2054}]} 11 + "port": -3
12 + }
13 + ],
14 + "deferred": []
15 + },
16 + "selector": {
17 + "criteria": [
18 + {
19 + "type": "ETH_TYPE",
20 + "ethType": 2054
21 + }
22 + ]
23 + }
12 } 24 }
......