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 @@
*/
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.FlowRule;
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 @@ public final class FlowRuleCodec extends JsonCodec<FlowRule> {
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 @@ public final class FlowRuleCodec extends JsonCodec<FlowRule> {
+ " 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);
......
......@@ -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.L2ModificationInstruction;
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 @@ public class FlowRuleCodecTest {
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"));
}
......
......@@ -3,6 +3,7 @@
"isPermanent":"false",
"timeout":1,
"deviceId":"of:0000000000000001",
"tableId": 1,
"selector":
{"criteria":
[
......
......@@ -3,6 +3,7 @@
"isPermanent":"false",
"timeout":1,
"deviceId":"of:0000000000000001",
"tableId": 1,
"treatment":
{
"instructions":
......
......@@ -3,6 +3,7 @@
"isPermanent":"false",
"timeout":1,
"deviceId":"of:0000000000000001",
"tableId": 1,
"selector":
{"criteria":
[
......
{
"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
}
]
}
}
......