andrea
Committed by Gerrit Code Review

[ONOS-3405] Change EthType Json encoding to Hex and extend decoding with Hex support alongside int

Change-Id: I629f52016256d6c5cc258ab9e1c5a7b916991d5b
......@@ -15,11 +15,8 @@
*/
package org.onosproject.codec.impl;
import static org.onlab.util.Tools.nullIsIllegal;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
......@@ -37,8 +34,10 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.HashMap;
import java.util.Map;
import static org.onlab.util.Tools.nullIsIllegal;
/**
* Decode portion of the criterion codec.
......@@ -106,12 +105,16 @@ public final class DecodeCriterionCodecHelper {
private class EthTypeDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
int ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt();
int ethType;
if (json.get(CriterionCodec.ETH_TYPE).isInt()) {
ethType = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE).asInt();
} else {
ethType = Integer.decode(json.get(CriterionCodec.ETH_TYPE).textValue());
}
return Criteria.matchEthType(ethType);
}
}
private class EthDstDecoder implements CriterionDecoder {
@Override
public Criterion decodeCriterion(ObjectNode json) {
......
......@@ -15,8 +15,7 @@
*/
package org.onosproject.codec.impl;
import java.util.EnumMap;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.util.HexString;
import org.onosproject.codec.CodecContext;
import org.onosproject.net.OchSignal;
......@@ -50,7 +49,7 @@ import org.onosproject.net.flow.criteria.UdpPortCriterion;
import org.onosproject.net.flow.criteria.VlanIdCriterion;
import org.onosproject.net.flow.criteria.VlanPcpCriterion;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.EnumMap;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -69,7 +68,7 @@ public final class EncodeCriterionCodecHelper {
* Initializes the formatter lookup map for the criterion subclasses.
*
* @param criterion Criterion to encode
* @param context context of the JSON encoding
* @param context context of the JSON encoding
*/
public EncodeCriterionCodecHelper(Criterion criterion, CodecContext context) {
this.criterion = criterion;
......@@ -171,7 +170,8 @@ public final class EncodeCriterionCodecHelper {
public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
final EthTypeCriterion ethTypeCriterion =
(EthTypeCriterion) criterion;
return root.put(CriterionCodec.ETH_TYPE, ethTypeCriterion.ethType().toShort());
return root.put(CriterionCodec.ETH_TYPE, "0x"
+ Integer.toHexString(ethTypeCriterion.ethType().toShort() & 0xffff));
}
}
......
......@@ -138,8 +138,8 @@ public final class CriterionJsonMatcher extends
* @return true if the JSON matches the criterion, false otherwise.
*/
private boolean matchCriterion(EthTypeCriterion criterion) {
final int ethType = criterion.ethType().toShort();
final int jsonEthType = jsonCriterion.get("ethType").intValue();
final int ethType = criterion.ethType().toShort() & 0xffff;
final int jsonEthType = Integer.decode(jsonCriterion.get("ethType").textValue()) & 0xffff;
if (ethType != jsonEthType) {
description.appendText("ethType was "
+ Integer.toString(jsonEthType));
......
......@@ -9,7 +9,7 @@
{"type":"IN_PORT", "port":23},
{"type":"IN_PHY_PORT", "port":44},
{"type":"METADATA", "metadata":123456},
{"type":"ETH_TYPE","ethType":2054},
{"type":"ETH_TYPE","ethType":"0x806"},
{"type":"ETH_SRC","mac":"00:11:22:33:44:55"},
{"type":"ETH_DST","mac":"00:11:22:33:44:55"},
{"type":"VLAN_VID","vlanId":777},
......
......@@ -35,5 +35,5 @@
],
"deferred":[]
},
"selector": {"criteria":[{"type":"ETH_TYPE","ethType":2054}]}
"selector": {"criteria":[{"type":"ETH_TYPE","ethType":"0x806"}]}
}
......
......@@ -262,7 +262,6 @@ public class OnosSwaggerMojo extends AbstractMojo {
addSummaryDescriptions(methodNode, comment);
addJsonSchemaDefinition(definitions, tag);
addJsonSchemaDefinition(definitions, tag);
processParameters(javaMethod, methodNode, method, tag);
......
......@@ -168,7 +168,7 @@
"ethType": {
"type": "integer",
"format": "int64",
"example": -30516
"example": "0x88cc"
}
}
}
......
......@@ -24,7 +24,7 @@
},
"deviceId": {
"type": "string",
"example": "of:0000000000000003"
"example": "of:0000000000000001"
},
"treatment": {
"type": "object",
......@@ -91,7 +91,7 @@
"ethType": {
"type": "integer",
"format": "int64",
"example": -30516
"example": "0x88cc"
}
}
}
......
......@@ -13,7 +13,7 @@
"criteria": [
{
"type": "ETH_TYPE",
"ethType": 2054
"ethType": "0x806"
}
]
}
......